| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_message_filter.h" | 5 #include "content/browser/browser_message_filter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/process.h" | 10 #include "base/process.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "content/browser/user_metrics.h" | 12 #include "content/public/browser/user_metrics.h" |
| 13 #include "content/public/common/result_codes.h" | 13 #include "content/public/common/result_codes.h" |
| 14 #include "ipc/ipc_sync_message.h" | 14 #include "ipc/ipc_sync_message.h" |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 using content::UserMetricsAction; |
| 17 | 18 |
| 18 BrowserMessageFilter::BrowserMessageFilter() | 19 BrowserMessageFilter::BrowserMessageFilter() |
| 19 : channel_(NULL), peer_handle_(base::kNullProcessHandle) { | 20 : channel_(NULL), peer_handle_(base::kNullProcessHandle) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 BrowserMessageFilter::~BrowserMessageFilter() { | 23 BrowserMessageFilter::~BrowserMessageFilter() { |
| 23 base::CloseProcessHandle(peer_handle_); | 24 base::CloseProcessHandle(peer_handle_); |
| 24 } | 25 } |
| 25 | 26 |
| 26 void BrowserMessageFilter::OnFilterAdded(IPC::Channel* channel) { | 27 void BrowserMessageFilter::OnFilterAdded(IPC::Channel* channel) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 base::Bind(&BrowserMessageFilter::DispatchMessage, this, message))); | 83 base::Bind(&BrowserMessageFilter::DispatchMessage, this, message))); |
| 83 return true; | 84 return true; |
| 84 } | 85 } |
| 85 | 86 |
| 86 bool BrowserMessageFilter::DispatchMessage(const IPC::Message& message) { | 87 bool BrowserMessageFilter::DispatchMessage(const IPC::Message& message) { |
| 87 bool message_was_ok = true; | 88 bool message_was_ok = true; |
| 88 bool rv = OnMessageReceived(message, &message_was_ok); | 89 bool rv = OnMessageReceived(message, &message_was_ok); |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) || rv) << | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) || rv) << |
| 90 "Must handle messages that were dispatched to another thread!"; | 91 "Must handle messages that were dispatched to another thread!"; |
| 91 if (!message_was_ok) { | 92 if (!message_was_ok) { |
| 92 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_BMF")); | 93 content::RecordAction(UserMetricsAction("BadMessageTerminate_BMF")); |
| 93 BadMessageReceived(); | 94 BadMessageReceived(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 return rv; | 97 return rv; |
| 97 } | 98 } |
| 98 | 99 |
| 99 void BrowserMessageFilter::BadMessageReceived() { | 100 void BrowserMessageFilter::BadMessageReceived() { |
| 100 base::KillProcess(peer_handle(), content::RESULT_CODE_KILLED_BAD_MESSAGE, | 101 base::KillProcess(peer_handle(), content::RESULT_CODE_KILLED_BAD_MESSAGE, |
| 101 false); | 102 false); |
| 102 } | 103 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 "messages in the renderer or else deadlocks can occur if the page " | 119 "messages in the renderer or else deadlocks can occur if the page " |
| 119 "has windowed plugins! (message type " << message.type() << ")"; | 120 "has windowed plugins! (message type " << message.type() << ")"; |
| 120 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); | 121 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message); |
| 121 reply->set_reply_error(); | 122 reply->set_reply_error(); |
| 122 sender->Send(reply); | 123 sender->Send(reply); |
| 123 return false; | 124 return false; |
| 124 } | 125 } |
| 125 #endif | 126 #endif |
| 126 return true; | 127 return true; |
| 127 } | 128 } |
| OLD | NEW |