| 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/debug/crash_logging.h" | 8 #include "base/debug/crash_logging.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "content/public/browser/browser_message_filter.h" | 12 #include "content/public/browser/browser_message_filter.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 13 | 15 |
| 14 namespace content { | 16 namespace content { |
| 15 namespace bad_message { | 17 namespace bad_message { |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 void LogBadMessage(BadMessageReason reason) { | 21 void LogBadMessage(BadMessageReason reason) { |
| 20 LOG(ERROR) << "Terminating renderer for bad IPC message, reason " << reason; | 22 LOG(ERROR) << "Terminating renderer for bad IPC message, reason " << reason; |
| 21 UMA_HISTOGRAM_SPARSE_SLOWLY("Stability.BadMessageTerminated.Content", reason); | 23 UMA_HISTOGRAM_SPARSE_SLOWLY("Stability.BadMessageTerminated.Content", reason); |
| 22 base::debug::SetCrashKeyValue("bad_message_reason", | 24 base::debug::SetCrashKeyValue("bad_message_reason", |
| 23 base::IntToString(reason)); | 25 base::IntToString(reason)); |
| 24 } | 26 } |
| 25 | 27 |
| 28 void ReceivedBadMessageOnUIThread(int render_process_id, |
| 29 BadMessageReason reason) { |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 31 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
| 32 if (host) |
| 33 ReceivedBadMessage(host, reason); |
| 34 } |
| 35 |
| 26 } // namespace | 36 } // namespace |
| 27 | 37 |
| 28 void ReceivedBadMessage(RenderProcessHost* host, BadMessageReason reason) { | 38 void ReceivedBadMessage(RenderProcessHost* host, BadMessageReason reason) { |
| 29 LogBadMessage(reason); | 39 LogBadMessage(reason); |
| 30 host->ShutdownForBadMessage(); | 40 host->ShutdownForBadMessage(); |
| 31 } | 41 } |
| 32 | 42 |
| 43 void ReceivedBadMessage(int render_process_id, BadMessageReason reason) { |
| 44 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 45 BrowserThread::PostTask( |
| 46 BrowserThread::UI, |
| 47 FROM_HERE, |
| 48 base::Bind(&ReceivedBadMessageOnUIThread, render_process_id, reason)); |
| 49 return; |
| 50 } |
| 51 ReceivedBadMessageOnUIThread(render_process_id, reason); |
| 52 } |
| 53 |
| 33 void ReceivedBadMessage(BrowserMessageFilter* filter, BadMessageReason reason) { | 54 void ReceivedBadMessage(BrowserMessageFilter* filter, BadMessageReason reason) { |
| 34 LogBadMessage(reason); | 55 LogBadMessage(reason); |
| 35 filter->ShutdownForBadMessage(); | 56 filter->ShutdownForBadMessage(); |
| 36 } | 57 } |
| 37 | 58 |
| 38 } // namespace bad_message | 59 } // namespace bad_message |
| 39 } // namespace content | 60 } // namespace content |
| OLD | NEW |