OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/bad_message.h" | 5 #include "content/browser/bad_message.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/crash_logging.h" | 8 #include "base/debug/crash_logging.h" |
9 #include "base/debug/dump_without_crashing.h" | |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "content/public/browser/browser_message_filter.h" | 13 #include "content/public/browser/browser_message_filter.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 namespace bad_message { | 18 namespace bad_message { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 void LogBadMessage(BadMessageReason reason) { | 22 void LogBadMessage(BadMessageReason reason) { |
22 LOG(ERROR) << "Terminating renderer for bad IPC message, reason " << reason; | 23 LOG(ERROR) << "Terminating renderer for bad IPC message, reason " << reason; |
23 UMA_HISTOGRAM_SPARSE_SLOWLY("Stability.BadMessageTerminated.Content", reason); | 24 UMA_HISTOGRAM_SPARSE_SLOWLY("Stability.BadMessageTerminated.Content", reason); |
24 base::debug::SetCrashKeyValue("bad_message_reason", | 25 base::debug::SetCrashKeyValue("bad_message_reason", |
25 base::IntToString(reason)); | 26 base::IntToString(reason)); |
26 } | 27 } |
27 | 28 |
28 void ReceivedBadMessageOnUIThread(int render_process_id, | 29 void ReceivedBadMessageOnUIThread(int render_process_id, |
29 BadMessageReason reason) { | 30 BadMessageReason reason) { |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
31 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 32 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
32 if (host) | 33 if (!host) |
33 ReceivedBadMessage(host, reason); | 34 return; |
35 | |
36 LogBadMessage(reason); | |
37 | |
38 // A dump has already been generated by the caller. Don't generate another. | |
39 host->ShutdownForBadMessage( | |
40 RenderProcessHost::CrashReportMode::NO_CRASH_DUMP); | |
34 } | 41 } |
35 | 42 |
36 } // namespace | 43 } // namespace |
37 | 44 |
38 void ReceivedBadMessage(RenderProcessHost* host, BadMessageReason reason) { | 45 void ReceivedBadMessage(RenderProcessHost* host, BadMessageReason reason) { |
39 LogBadMessage(reason); | 46 LogBadMessage(reason); |
40 host->ShutdownForBadMessage(); | 47 host->ShutdownForBadMessage( |
48 RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP); | |
41 } | 49 } |
42 | 50 |
43 void ReceivedBadMessage(int render_process_id, BadMessageReason reason) { | 51 void ReceivedBadMessage(int render_process_id, BadMessageReason reason) { |
52 // We generate a crash dump here since generating one after posting the UI | |
53 // thread is mostly useless. | |
54 base::debug::DumpWithoutCrashing(); | |
Charlie Reis
2017/01/12 00:39:30
I just looked at a crash report that hit this (9fa
| |
55 | |
44 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 56 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
45 BrowserThread::PostTask( | 57 BrowserThread::PostTask( |
46 BrowserThread::UI, | 58 BrowserThread::UI, |
47 FROM_HERE, | 59 FROM_HERE, |
48 base::Bind(&ReceivedBadMessageOnUIThread, render_process_id, reason)); | 60 base::Bind(&ReceivedBadMessageOnUIThread, render_process_id, reason)); |
49 return; | 61 return; |
50 } | 62 } |
51 ReceivedBadMessageOnUIThread(render_process_id, reason); | 63 ReceivedBadMessageOnUIThread(render_process_id, reason); |
52 } | 64 } |
53 | 65 |
54 void ReceivedBadMessage(BrowserMessageFilter* filter, BadMessageReason reason) { | 66 void ReceivedBadMessage(BrowserMessageFilter* filter, BadMessageReason reason) { |
55 LogBadMessage(reason); | 67 LogBadMessage(reason); |
56 filter->ShutdownForBadMessage(); | 68 filter->ShutdownForBadMessage(); |
57 } | 69 } |
58 | 70 |
59 } // namespace bad_message | 71 } // namespace bad_message |
60 } // namespace content | 72 } // namespace content |
OLD | NEW |