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

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

Issue 165333004: Revert "Allow MessageFilters to restrict listening to specific message classes" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
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"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return true; 69 return true;
70 } 70 }
71 71
72 BrowserThread::PostTask( 72 BrowserThread::PostTask(
73 thread, FROM_HERE, 73 thread, FROM_HERE,
74 base::Bind( 74 base::Bind(
75 base::IgnoreResult(&Internal::DispatchMessage), this, message)); 75 base::IgnoreResult(&Internal::DispatchMessage), this, message));
76 return true; 76 return true;
77 } 77 }
78 78
79 virtual bool GetSupportedMessageClasses(
80 std::vector<uint32>* supported_message_classes) const OVERRIDE {
81 supported_message_classes->assign(
82 filter_->message_classes_to_filter().begin(),
83 filter_->message_classes_to_filter().end());
84 return true;
85 }
86
87 // Dispatches a message to the derived class. 79 // Dispatches a message to the derived class.
88 bool DispatchMessage(const IPC::Message& message) { 80 bool DispatchMessage(const IPC::Message& message) {
89 bool message_was_ok = true; 81 bool message_was_ok = true;
90 bool rv = filter_->OnMessageReceived(message, &message_was_ok); 82 bool rv = filter_->OnMessageReceived(message, &message_was_ok);
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) || rv) << 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO) || rv) <<
92 "Must handle messages that were dispatched to another thread!"; 84 "Must handle messages that were dispatched to another thread!";
93 if (!message_was_ok) { 85 if (!message_was_ok) {
94 content::RecordAction( 86 content::RecordAction(
95 base::UserMetricsAction("BadMessageTerminate_BMF")); 87 base::UserMetricsAction("BadMessageTerminate_BMF"));
96 filter_->BadMessageReceived(); 88 filter_->BadMessageReceived();
97 } 89 }
98 90
99 return rv; 91 return rv;
100 } 92 }
101 93
102 scoped_refptr<BrowserMessageFilter> filter_; 94 scoped_refptr<BrowserMessageFilter> filter_;
103 95
104 DISALLOW_COPY_AND_ASSIGN(Internal); 96 DISALLOW_COPY_AND_ASSIGN(Internal);
105 }; 97 };
106 98
107 BrowserMessageFilter::BrowserMessageFilter(uint32 message_class_to_filter) 99 BrowserMessageFilter::BrowserMessageFilter()
108 : internal_(NULL), 100 : internal_(NULL), channel_(NULL),
109 channel_(NULL),
110 #if defined(OS_WIN) 101 #if defined(OS_WIN)
111 peer_handle_(base::kNullProcessHandle), 102 peer_handle_(base::kNullProcessHandle),
112 #endif 103 #endif
113 peer_pid_(base::kNullProcessId), 104 peer_pid_(base::kNullProcessId) {
114 message_classes_to_filter_(1, message_class_to_filter) {}
115
116 BrowserMessageFilter::BrowserMessageFilter(
117 const uint32* message_classes_to_filter,
118 size_t num_message_classes_to_filter)
119 : internal_(NULL),
120 channel_(NULL),
121 #if defined(OS_WIN)
122 peer_handle_(base::kNullProcessHandle),
123 #endif
124 peer_pid_(base::kNullProcessId),
125 message_classes_to_filter_(
126 message_classes_to_filter,
127 message_classes_to_filter + num_message_classes_to_filter) {
128 DCHECK(num_message_classes_to_filter);
129 } 105 }
130 106
131 base::ProcessHandle BrowserMessageFilter::PeerHandle() { 107 base::ProcessHandle BrowserMessageFilter::PeerHandle() {
132 #if defined(OS_WIN) 108 #if defined(OS_WIN)
133 base::AutoLock lock(peer_handle_lock_); 109 base::AutoLock lock(peer_handle_lock_);
134 if (peer_handle_ == base::kNullProcessHandle) 110 if (peer_handle_ == base::kNullProcessHandle)
135 base::OpenPrivilegedProcessHandle(peer_pid_, &peer_handle_); 111 base::OpenPrivilegedProcessHandle(peer_pid_, &peer_handle_);
136 112
137 return peer_handle_; 113 return peer_handle_;
138 #else 114 #else
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 197
222 IPC::ChannelProxy::MessageFilter* BrowserMessageFilter::GetFilter() { 198 IPC::ChannelProxy::MessageFilter* BrowserMessageFilter::GetFilter() {
223 // We create this on demand so that if a filter is used in a unit test but 199 // We create this on demand so that if a filter is used in a unit test but
224 // never attached to a channel, we don't leak Internal and this; 200 // never attached to a channel, we don't leak Internal and this;
225 DCHECK(!internal_) << "Should only be called once."; 201 DCHECK(!internal_) << "Should only be called once.";
226 internal_ = new Internal(this); 202 internal_ = new Internal(this);
227 return internal_; 203 return internal_;
228 } 204 }
229 205
230 } // namespace content 206 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/browser_message_filter.h ('k') | content/shell/browser/shell_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698