OLD | NEW |
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_impl.h" | 5 #include "content/child/child_thread_impl.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 void ChildThreadImpl::SingleProcessChannelDelegateDeleter::operator()( | 239 void ChildThreadImpl::SingleProcessChannelDelegateDeleter::operator()( |
240 SingleProcessChannelDelegate* delegate) const { | 240 SingleProcessChannelDelegate* delegate) const { |
241 delegate->DeleteSoon(); | 241 delegate->DeleteSoon(); |
242 } | 242 } |
243 | 243 |
244 ChildThreadImpl::Options::Options() | 244 ChildThreadImpl::Options::Options() |
245 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 245 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
246 switches::kProcessChannelID)), | 246 switches::kProcessChannelID)), |
247 use_mojo_channel(false), | 247 use_mojo_channel(false), |
248 in_browser_process(false) { | 248 in_browser_process(false), |
| 249 task_runner(base::MessageLoopProxy::current()) { |
249 } | 250 } |
250 | 251 |
251 ChildThreadImpl::Options::~Options() { | 252 ChildThreadImpl::Options::~Options() { |
252 } | 253 } |
253 | 254 |
254 ChildThreadImpl::Options::Builder::Builder() { | 255 ChildThreadImpl::Options::Builder::Builder() { |
255 } | 256 } |
256 | 257 |
257 ChildThreadImpl::Options::Builder& | 258 ChildThreadImpl::Options::Builder& |
258 ChildThreadImpl::Options::Builder::InBrowserProcess(bool in_browser_process) { | 259 ChildThreadImpl::Options::Builder::InBrowserProcess(bool in_browser_process) { |
(...skipping 14 matching lines...) Expand all Loading... |
273 return *this; | 274 return *this; |
274 } | 275 } |
275 | 276 |
276 ChildThreadImpl::Options::Builder& | 277 ChildThreadImpl::Options::Builder& |
277 ChildThreadImpl::Options::Builder::AddStartupFilter( | 278 ChildThreadImpl::Options::Builder::AddStartupFilter( |
278 IPC::MessageFilter* filter) { | 279 IPC::MessageFilter* filter) { |
279 options_.startup_filters.push_back(filter); | 280 options_.startup_filters.push_back(filter); |
280 return *this; | 281 return *this; |
281 } | 282 } |
282 | 283 |
| 284 ChildThreadImpl::Options::Builder& |
| 285 ChildThreadImpl::Options::Builder::WithTaskRunner( |
| 286 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 287 options_.task_runner = task_runner; |
| 288 return *this; |
| 289 } |
| 290 |
283 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { | 291 ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() { |
284 return options_; | 292 return options_; |
285 } | 293 } |
286 | 294 |
287 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( | 295 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter( |
288 IPC::Sender* sender) | 296 IPC::Sender* sender) |
289 : sender_(sender) {} | 297 : sender_(sender) {} |
290 | 298 |
291 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { | 299 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) { |
292 return sender_->Send(msg); | 300 return sender_->Send(msg); |
293 } | 301 } |
294 | 302 |
295 ChildThreadImpl::ChildThreadImpl() | 303 ChildThreadImpl::ChildThreadImpl() |
296 : router_(this), | 304 : router_(this), |
| 305 task_runner_(base::MessageLoopProxy::current()), |
297 in_browser_process_(false), | 306 in_browser_process_(false), |
298 channel_connected_factory_(this) { | 307 channel_connected_factory_(this) { |
299 Init(Options::Builder().Build()); | 308 Init(Options::Builder().Build()); |
300 } | 309 } |
301 | 310 |
302 ChildThreadImpl::ChildThreadImpl(const Options& options) | 311 ChildThreadImpl::ChildThreadImpl(const Options& options) |
303 : router_(this), | 312 : router_(this), |
| 313 task_runner_(options.task_runner), |
304 in_browser_process_(options.in_browser_process), | 314 in_browser_process_(options.in_browser_process), |
305 channel_connected_factory_(this) { | 315 channel_connected_factory_(this) { |
306 Init(options); | 316 Init(options); |
307 } | 317 } |
308 | 318 |
309 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 319 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
310 bool create_pipe_now = true; | 320 bool create_pipe_now = true; |
311 if (use_mojo_channel) { | 321 if (use_mojo_channel) { |
312 VLOG(1) << "Mojo is enabled on child"; | 322 VLOG(1) << "Mojo is enabled on child"; |
313 scoped_refptr<base::TaskRunner> io_task_runner = | 323 scoped_refptr<base::TaskRunner> io_task_runner = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 IPC::Logging::GetInstance()->SetIPCSender(this); | 361 IPC::Logging::GetInstance()->SetIPCSender(this); |
352 #endif | 362 #endif |
353 | 363 |
354 mojo_application_.reset(new MojoApplication); | 364 mojo_application_.reset(new MojoApplication); |
355 | 365 |
356 sync_message_filter_ = | 366 sync_message_filter_ = |
357 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 367 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
358 thread_safe_sender_ = new ThreadSafeSender( | 368 thread_safe_sender_ = new ThreadSafeSender( |
359 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); | 369 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); |
360 | 370 |
361 resource_dispatcher_.reset(new ResourceDispatcher( | 371 resource_dispatcher_.reset(new ResourceDispatcher(this, GetTaskRunner())); |
362 this, message_loop()->task_runner())); | |
363 websocket_dispatcher_.reset(new WebSocketDispatcher); | 372 websocket_dispatcher_.reset(new WebSocketDispatcher); |
364 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 373 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
365 | 374 |
366 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 375 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
367 resource_message_filter_ = | 376 resource_message_filter_ = |
368 new ChildResourceMessageFilter(resource_dispatcher()); | 377 new ChildResourceMessageFilter(resource_dispatcher()); |
369 | 378 |
370 service_worker_message_filter_ = | 379 service_worker_message_filter_ = |
371 new ServiceWorkerMessageFilter(thread_safe_sender_.get()); | 380 new ServiceWorkerMessageFilter(thread_safe_sender_.get()); |
372 | 381 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 bool ChildThreadImpl::Send(IPC::Message* msg) { | 526 bool ChildThreadImpl::Send(IPC::Message* msg) { |
518 DCHECK(base::MessageLoop::current() == message_loop()); | 527 DCHECK(base::MessageLoop::current() == message_loop()); |
519 if (!channel_) { | 528 if (!channel_) { |
520 delete msg; | 529 delete msg; |
521 return false; | 530 return false; |
522 } | 531 } |
523 | 532 |
524 return channel_->Send(msg); | 533 return channel_->Send(msg); |
525 } | 534 } |
526 | 535 |
| 536 scoped_refptr<base::SingleThreadTaskRunner> ChildThreadImpl::GetTaskRunner() { |
| 537 return task_runner_; |
| 538 } |
| 539 |
527 #if defined(OS_WIN) | 540 #if defined(OS_WIN) |
528 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { | 541 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
529 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); | 542 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
530 } | 543 } |
531 | 544 |
532 void ChildThreadImpl::ReleaseCachedFonts() { | 545 void ChildThreadImpl::ReleaseCachedFonts() { |
533 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); | 546 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
534 } | 547 } |
535 #endif | 548 #endif |
536 | 549 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 // doesn't cause such issues. TODO(gab): Remove this once the experiment is | 748 // doesn't cause such issues. TODO(gab): Remove this once the experiment is |
736 // over (http://crbug.com/458594). | 749 // over (http://crbug.com/458594). |
737 base::FieldTrial* trial = | 750 base::FieldTrial* trial = |
738 base::FieldTrialList::Find("BackgroundRendererProcesses"); | 751 base::FieldTrialList::Find("BackgroundRendererProcesses"); |
739 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") | 752 if (trial && trial->group_name() == "AllowBackgroundModeFromRenderer") |
740 base::Process::Current().SetProcessBackgrounded(background); | 753 base::Process::Current().SetProcessBackgrounded(background); |
741 #endif // OS_WIN | 754 #endif // OS_WIN |
742 } | 755 } |
743 | 756 |
744 } // namespace content | 757 } // namespace content |
OLD | NEW |