1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/bad_message.h"
6 
7 #include "base/logging.h"
8 #include "base/metrics/histogram_functions.h"
9 #include "content/public/browser/browser_message_filter.h"
10 #include "content/public/browser/render_process_host.h"
11 
12 namespace bad_message {
13 
14 namespace {
15 
LogBadMessage(BadMessageReason reason)16 void LogBadMessage(BadMessageReason reason) {
17   LOG(ERROR) << "Terminating renderer for bad IPC message, reason " << reason;
18   base::UmaHistogramSparse("Stability.BadMessageTerminated.Chrome", reason);
19 }
20 
21 }  // namespace
22 
ReceivedBadMessage(content::RenderProcessHost * host,BadMessageReason reason)23 void ReceivedBadMessage(content::RenderProcessHost* host,
24                         BadMessageReason reason) {
25   LogBadMessage(reason);
26   host->ShutdownForBadMessage(
27       content::RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP);
28 }
29 
ReceivedBadMessage(content::BrowserMessageFilter * filter,BadMessageReason reason)30 void ReceivedBadMessage(content::BrowserMessageFilter* filter,
31                         BadMessageReason reason) {
32   LogBadMessage(reason);
33   filter->ShutdownForBadMessage();
34 }
35 
36 }  // namespace bad_message
37