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

Side by Side Diff: content/child/child_thread.cc

Issue 203073005: (NOT READY FOR REVIEW) Introduce MessagePortBypassFilter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « content/child/child_thread.h ('k') | content/child/webmessageportchannel_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/child/child_thread.h" 5 #include "content/child/child_thread.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/allocator/allocator_extension.h" 11 #include "base/allocator/allocator_extension.h"
12 #include "base/base_switches.h" 12 #include "base/base_switches.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/debug/leak_annotations.h" 15 #include "base/debug/leak_annotations.h"
16 #include "base/id_map.h"
16 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
19 #include "base/process/kill.h" 20 #include "base/process/kill.h"
20 #include "base/process/process_handle.h" 21 #include "base/process/process_handle.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/synchronization/condition_variable.h" 23 #include "base/synchronization/condition_variable.h"
23 #include "base/synchronization/lock.h" 24 #include "base/synchronization/lock.h"
24 #include "base/threading/thread_local.h" 25 #include "base/threading/thread_local.h"
25 #include "base/tracked_objects.h" 26 #include "base/tracked_objects.h"
26 #include "components/tracing/child_trace_message_filter.h" 27 #include "components/tracing/child_trace_message_filter.h"
27 #include "content/child/child_histogram_message_filter.h" 28 #include "content/child/child_histogram_message_filter.h"
28 #include "content/child/child_process.h" 29 #include "content/child/child_process.h"
29 #include "content/child/child_resource_message_filter.h" 30 #include "content/child/child_resource_message_filter.h"
30 #include "content/child/child_shared_bitmap_manager.h" 31 #include "content/child/child_shared_bitmap_manager.h"
31 #include "content/child/fileapi/file_system_dispatcher.h" 32 #include "content/child/fileapi/file_system_dispatcher.h"
32 #include "content/child/power_monitor_broadcast_source.h" 33 #include "content/child/power_monitor_broadcast_source.h"
33 #include "content/child/quota_dispatcher.h" 34 #include "content/child/quota_dispatcher.h"
34 #include "content/child/quota_message_filter.h" 35 #include "content/child/quota_message_filter.h"
35 #include "content/child/resource_dispatcher.h" 36 #include "content/child/resource_dispatcher.h"
36 #include "content/child/service_worker/service_worker_dispatcher.h" 37 #include "content/child/service_worker/service_worker_dispatcher.h"
37 #include "content/child/service_worker/service_worker_message_filter.h" 38 #include "content/child/service_worker/service_worker_message_filter.h"
38 #include "content/child/socket_stream_dispatcher.h" 39 #include "content/child/socket_stream_dispatcher.h"
39 #include "content/child/thread_safe_sender.h" 40 #include "content/child/thread_safe_sender.h"
40 #include "content/child/websocket_dispatcher.h" 41 #include "content/child/websocket_dispatcher.h"
41 #include "content/common/child_process_messages.h" 42 #include "content/common/child_process_messages.h"
43 #include "content/common/message_port_messages.h"
42 #include "content/public/common/content_switches.h" 44 #include "content/public/common/content_switches.h"
43 #include "ipc/ipc_logging.h" 45 #include "ipc/ipc_logging.h"
44 #include "ipc/ipc_switches.h" 46 #include "ipc/ipc_switches.h"
45 #include "ipc/ipc_sync_channel.h" 47 #include "ipc/ipc_sync_channel.h"
46 #include "ipc/ipc_sync_message_filter.h" 48 #include "ipc/ipc_sync_message_filter.h"
47 49
48 #if defined(OS_WIN) 50 #if defined(OS_WIN)
49 #include "content/common/handle_enumerator_win.h" 51 #include "content/common/handle_enumerator_win.h"
50 #endif 52 #endif
51 53
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 g_lazy_child_thread_cv = LAZY_INSTANCE_INITIALIZER; 188 g_lazy_child_thread_cv = LAZY_INSTANCE_INITIALIZER;
187 189
188 void QuitMainThreadMessageLoop() { 190 void QuitMainThreadMessageLoop() {
189 base::MessageLoop::current()->Quit(); 191 base::MessageLoop::current()->Quit();
190 } 192 }
191 193
192 #endif 194 #endif
193 195
194 } // namespace 196 } // namespace
195 197
198 MessagePortBypassFilter::MessagePortBypassFilter(
199 base::SingleThreadTaskRunner* ipc_task_runner)
200 : ipc_task_runner_(ipc_task_runner),
201 child_thread_loop_(base::MessageLoopProxy::current()) {}
202
203 MessagePortBypassFilter::~MessagePortBypassFilter() {}
204
205 bool MessagePortBypassFilter::OnMessageReceived(const IPC::Message& message) {
206 DCHECK(ipc_task_runner_->BelongsToCurrentThread());
207 IPC::Listener* listener = routes_.Lookup(message.routing_id());
208 if (!listener)
209 return false;
210 if (message.type() != MessagePortMsg_Message::ID)
211 return false;
212 return listener->OnMessageReceived(message);
213 }
214
215 bool MessagePortBypassFilter::GetSupportedMessageClasses(
216 std::vector<uint32>* supported_message_classes) const {
217 supported_message_classes->push_back(MessagePortMsgStart);
218 return true;
219 }
220
221 void MessagePortBypassFilter::AddRoute(int32 routing_id,
222 IPC::Listener* listener) {
223 DCHECK(child_thread_loop_->BelongsToCurrentThread());
224 ipc_task_runner_->PostTask(
225 FROM_HERE,
226 base::Bind(
227 &MessagePortBypassFilter::AddRouteOnIO, this, routing_id, listener));
228 }
229
230 void MessagePortBypassFilter::AddRouteOnIO(int32 routing_id,
231 IPC::Listener* listener) {
232 DCHECK(ipc_task_runner_->BelongsToCurrentThread());
233 routes_.AddWithID(listener, routing_id);
234 }
235
236 void MessagePortBypassFilter::RemoveRoute(int32 routing_id,
237 const base::Closure& callback) {
238 DCHECK(child_thread_loop_->BelongsToCurrentThread());
239 ipc_task_runner_->PostTask(
240 FROM_HERE,
241 base::Bind(&MessagePortBypassFilter::RemoveRouteOnIO,
242 this,
243 routing_id,
244 callback));
245 }
246
247 void MessagePortBypassFilter::RemoveRouteOnIO(int32 routing_id,
248 const base::Closure& callback) {
249 DCHECK(ipc_task_runner_->BelongsToCurrentThread());
250 routes_.Remove(routing_id);
251 child_thread_loop_->PostTask(FROM_HERE, callback);
252 }
253
196 ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter( 254 ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter(
197 IPC::Sender* sender) 255 IPC::Sender* sender)
198 : sender_(sender) {} 256 : sender_(sender) {}
199 257
200 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) { 258 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) {
201 return sender_->Send(msg); 259 return sender_->Send(msg);
202 } 260 }
203 261
204 ChildThread::ChildThread() 262 ChildThread::ChildThread()
205 : router_(this), 263 : router_(this),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 314
257 service_worker_message_filter_ = 315 service_worker_message_filter_ =
258 new ServiceWorkerMessageFilter(thread_safe_sender_.get()); 316 new ServiceWorkerMessageFilter(thread_safe_sender_.get());
259 service_worker_dispatcher_.reset( 317 service_worker_dispatcher_.reset(
260 new ServiceWorkerDispatcher(thread_safe_sender_.get())); 318 new ServiceWorkerDispatcher(thread_safe_sender_.get()));
261 319
262 quota_message_filter_ = 320 quota_message_filter_ =
263 new QuotaMessageFilter(thread_safe_sender_.get()); 321 new QuotaMessageFilter(thread_safe_sender_.get());
264 quota_dispatcher_.reset(new QuotaDispatcher(thread_safe_sender_.get(), 322 quota_dispatcher_.reset(new QuotaDispatcher(thread_safe_sender_.get(),
265 quota_message_filter_.get())); 323 quota_message_filter_.get()));
324 message_port_bypass_filter_ = new MessagePortBypassFilter(
325 ChildProcess::current()->io_message_loop_proxy());
266 326
267 channel_->AddFilter(histogram_message_filter_.get()); 327 channel_->AddFilter(histogram_message_filter_.get());
268 channel_->AddFilter(sync_message_filter_.get()); 328 channel_->AddFilter(sync_message_filter_.get());
269 channel_->AddFilter(new tracing::ChildTraceMessageFilter( 329 channel_->AddFilter(new tracing::ChildTraceMessageFilter(
270 ChildProcess::current()->io_message_loop_proxy())); 330 ChildProcess::current()->io_message_loop_proxy()));
271 channel_->AddFilter(resource_message_filter_.get()); 331 channel_->AddFilter(resource_message_filter_.get());
272 channel_->AddFilter(quota_message_filter_->GetFilter()); 332 channel_->AddFilter(quota_message_filter_->GetFilter());
273 channel_->AddFilter(service_worker_message_filter_->GetFilter()); 333 channel_->AddFilter(service_worker_message_filter_->GetFilter());
334 channel_->AddFilter(message_port_bypass_filter_.get());
274 335
275 // In single process mode we may already have a power monitor 336 // In single process mode we may already have a power monitor
276 if (!base::PowerMonitor::Get()) { 337 if (!base::PowerMonitor::Get()) {
277 scoped_ptr<PowerMonitorBroadcastSource> power_monitor_source( 338 scoped_ptr<PowerMonitorBroadcastSource> power_monitor_source(
278 new PowerMonitorBroadcastSource()); 339 new PowerMonitorBroadcastSource());
279 channel_->AddFilter(power_monitor_source->GetMessageFilter()); 340 channel_->AddFilter(power_monitor_source->GetMessageFilter());
280 341
281 power_monitor_.reset(new base::PowerMonitor( 342 power_monitor_.reset(new base::PowerMonitor(
282 power_monitor_source.PassAs<base::PowerMonitorSource>())); 343 power_monitor_source.PassAs<base::PowerMonitorSource>()));
283 } 344 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 // inflight that would addref it. 600 // inflight that would addref it.
540 Send(new ChildProcessHostMsg_ShutdownRequest); 601 Send(new ChildProcessHostMsg_ShutdownRequest);
541 } 602 }
542 603
543 void ChildThread::EnsureConnected() { 604 void ChildThread::EnsureConnected() {
544 VLOG(0) << "ChildThread::EnsureConnected()"; 605 VLOG(0) << "ChildThread::EnsureConnected()";
545 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); 606 base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
546 } 607 }
547 608
548 } // namespace content 609 } // namespace content
OLDNEW
« no previous file with comments | « content/child/child_thread.h ('k') | content/child/webmessageportchannel_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698