Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: content/public/browser/browser_message_filter.cc

Issue 292443004: Remove IPC_BEGIN_MESSAGE_MAP_EX macro since r270839 made all bad IPCs kill their child processes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/public/browser/browser_message_filter.h" 5 #include "content/public/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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/process/kill.h" 11 #include "base/process/kill.h"
12 #include "base/process/process_handle.h" 12 #include "base/process/process_handle.h"
13 #include "base/task_runner.h" 13 #include "base/task_runner.h"
14 #include "content/browser/browser_child_process_host_impl.h"
14 #include "content/public/browser/user_metrics.h" 15 #include "content/public/browser/user_metrics.h"
15 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
16 #include "content/public/common/result_codes.h" 17 #include "content/public/common/result_codes.h"
17 #include "ipc/ipc_sync_message.h" 18 #include "ipc/ipc_sync_message.h"
18 #include "ipc/message_filter.h" 19 #include "ipc/message_filter.h"
19 20
20 using content::BrowserMessageFilter; 21 using content::BrowserMessageFilter;
21 22
22 namespace content { 23 namespace content {
23 24
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 virtual bool GetSupportedMessageClasses( 81 virtual bool GetSupportedMessageClasses(
81 std::vector<uint32>* supported_message_classes) const OVERRIDE { 82 std::vector<uint32>* supported_message_classes) const OVERRIDE {
82 supported_message_classes->assign( 83 supported_message_classes->assign(
83 filter_->message_classes_to_filter().begin(), 84 filter_->message_classes_to_filter().begin(),
84 filter_->message_classes_to_filter().end()); 85 filter_->message_classes_to_filter().end());
85 return true; 86 return true;
86 } 87 }
87 88
88 // Dispatches a message to the derived class. 89 // Dispatches a message to the derived class.
89 bool DispatchMessage(const IPC::Message& message) { 90 bool DispatchMessage(const IPC::Message& message) {
90 bool message_was_ok = true; 91 bool rv = filter_->OnMessageReceived(message);
91 bool rv = filter_->OnMessageReceived(message, &message_was_ok);
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) || rv) << 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) || rv) <<
93 "Must handle messages that were dispatched to another thread!"; 93 "Must handle messages that were dispatched to another thread!";
94 if (!message_was_ok) {
95 content::RecordAction(
96 base::UserMetricsAction("BadMessageTerminate_BMF"));
97 filter_->BadMessageReceived();
98 }
99
100 return rv; 94 return rv;
101 } 95 }
102 96
103 scoped_refptr<BrowserMessageFilter> filter_; 97 scoped_refptr<BrowserMessageFilter> filter_;
104 98
105 DISALLOW_COPY_AND_ASSIGN(Internal); 99 DISALLOW_COPY_AND_ASSIGN(Internal);
106 }; 100 };
107 101
108 BrowserMessageFilter::BrowserMessageFilter(uint32 message_class_to_filter) 102 BrowserMessageFilter::BrowserMessageFilter(uint32 message_class_to_filter)
109 : internal_(NULL), 103 : internal_(NULL),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 reply->set_reply_error(); 193 reply->set_reply_error();
200 sender->Send(reply); 194 sender->Send(reply);
201 return false; 195 return false;
202 } 196 }
203 #endif 197 #endif
204 return true; 198 return true;
205 } 199 }
206 200
207 void BrowserMessageFilter::BadMessageReceived() { 201 void BrowserMessageFilter::BadMessageReceived() {
208 CommandLine* command_line = CommandLine::ForCurrentProcess(); 202 CommandLine* command_line = CommandLine::ForCurrentProcess();
203 if (command_line->HasSwitch(switches::kDisableKillAfterBadIPC))
204 return;
209 205
210 if (!command_line->HasSwitch(switches::kDisableKillAfterBadIPC)) { 206 BrowserChildProcessHostImpl::HistogramBadMessageTerminated(
211 base::KillProcess(PeerHandle(), content::RESULT_CODE_KILLED_BAD_MESSAGE, 207 PROCESS_TYPE_RENDERER);
212 false); 208 base::KillProcess(PeerHandle(), content::RESULT_CODE_KILLED_BAD_MESSAGE,
213 } 209 false);
214 } 210 }
215 211
216 BrowserMessageFilter::~BrowserMessageFilter() { 212 BrowserMessageFilter::~BrowserMessageFilter() {
217 #if defined(OS_WIN) 213 #if defined(OS_WIN)
218 if (peer_handle_ != base::kNullProcessHandle) 214 if (peer_handle_ != base::kNullProcessHandle)
219 base::CloseProcessHandle(peer_handle_); 215 base::CloseProcessHandle(peer_handle_);
220 #endif 216 #endif
221 } 217 }
222 218
223 IPC::MessageFilter* BrowserMessageFilter::GetFilter() { 219 IPC::MessageFilter* BrowserMessageFilter::GetFilter() {
224 // We create this on demand so that if a filter is used in a unit test but 220 // We create this on demand so that if a filter is used in a unit test but
225 // never attached to a channel, we don't leak Internal and this; 221 // never attached to a channel, we don't leak Internal and this;
226 DCHECK(!internal_) << "Should only be called once."; 222 DCHECK(!internal_) << "Should only be called once.";
227 internal_ = new Internal(this); 223 internal_ = new Internal(this);
228 return internal_; 224 return internal_;
229 } 225 }
230 226
231 } // namespace content 227 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/browser_message_filter.h ('k') | content/public/test/mock_render_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698