| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "content/child/push_messaging/push_dispatcher.h" | 48 #include "content/child/push_messaging/push_dispatcher.h" |
| 49 #include "content/child/quota_dispatcher.h" | 49 #include "content/child/quota_dispatcher.h" |
| 50 #include "content/child/quota_message_filter.h" | 50 #include "content/child/quota_message_filter.h" |
| 51 #include "content/child/resource_dispatcher.h" | 51 #include "content/child/resource_dispatcher.h" |
| 52 #include "content/child/service_worker/service_worker_message_filter.h" | 52 #include "content/child/service_worker/service_worker_message_filter.h" |
| 53 #include "content/child/thread_safe_sender.h" | 53 #include "content/child/thread_safe_sender.h" |
| 54 #include "content/child/websocket_dispatcher.h" | 54 #include "content/child/websocket_dispatcher.h" |
| 55 #include "content/common/child_process_messages.h" | 55 #include "content/common/child_process_messages.h" |
| 56 #include "content/common/in_process_child_thread_params.h" | 56 #include "content/common/in_process_child_thread_params.h" |
| 57 #include "content/public/common/content_switches.h" | 57 #include "content/public/common/content_switches.h" |
| 58 #include "ipc/attachment_broker.h" |
| 58 #include "ipc/ipc_logging.h" | 59 #include "ipc/ipc_logging.h" |
| 59 #include "ipc/ipc_switches.h" | 60 #include "ipc/ipc_switches.h" |
| 60 #include "ipc/ipc_sync_channel.h" | 61 #include "ipc/ipc_sync_channel.h" |
| 61 #include "ipc/ipc_sync_message_filter.h" | 62 #include "ipc/ipc_sync_message_filter.h" |
| 62 #include "ipc/mojo/ipc_channel_mojo.h" | 63 #include "ipc/mojo/ipc_channel_mojo.h" |
| 63 | 64 |
| 64 #if defined(OS_ANDROID) | 65 #if defined(OS_ANDROID) |
| 65 #include "base/thread_task_runner_handle.h" | 66 #include "base/thread_task_runner_handle.h" |
| 66 #endif | 67 #endif |
| 67 | 68 |
| 68 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 69 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
| 69 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 70 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
| 70 #endif | 71 #endif |
| 71 | 72 |
| 72 #if defined(OS_MACOSX) | 73 #if defined(OS_MACOSX) |
| 73 #include "content/child/child_io_surface_manager_mac.h" | 74 #include "content/child/child_io_surface_manager_mac.h" |
| 74 #endif | 75 #endif |
| 75 | 76 |
| 77 #if defined(OS_WIN) |
| 78 #include "ipc/attachment_broker_win.h" |
| 79 #endif |
| 80 |
| 76 using tracked_objects::ThreadData; | 81 using tracked_objects::ThreadData; |
| 77 | 82 |
| 78 namespace content { | 83 namespace content { |
| 79 namespace { | 84 namespace { |
| 80 | 85 |
| 81 // How long to wait for a connection to the browser process before giving up. | 86 // How long to wait for a connection to the browser process before giving up. |
| 82 const int kConnectionTimeoutS = 15; | 87 const int kConnectionTimeoutS = 15; |
| 83 | 88 |
| 84 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl> > g_lazy_tls = | 89 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl> > g_lazy_tls = |
| 85 LAZY_INSTANCE_INITIALIZER; | 90 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return browser_process_io_runner_; | 305 return browser_process_io_runner_; |
| 301 return ChildProcess::current()->io_task_runner(); | 306 return ChildProcess::current()->io_task_runner(); |
| 302 } | 307 } |
| 303 | 308 |
| 304 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { | 309 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) { |
| 305 bool create_pipe_now = true; | 310 bool create_pipe_now = true; |
| 306 if (use_mojo_channel) { | 311 if (use_mojo_channel) { |
| 307 VLOG(1) << "Mojo is enabled on child"; | 312 VLOG(1) << "Mojo is enabled on child"; |
| 308 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); | 313 scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner(); |
| 309 DCHECK(io_task_runner); | 314 DCHECK(io_task_runner); |
| 310 channel_->Init(IPC::ChannelMojo::CreateClientFactory( | 315 channel_->Init( |
| 311 nullptr, io_task_runner, channel_name_), | 316 IPC::ChannelMojo::CreateClientFactory( |
| 312 create_pipe_now); | 317 nullptr, io_task_runner, channel_name_, attachment_broker_.get()), |
| 318 create_pipe_now); |
| 313 return; | 319 return; |
| 314 } | 320 } |
| 315 | 321 |
| 316 VLOG(1) << "Mojo is disabled on child"; | 322 VLOG(1) << "Mojo is disabled on child"; |
| 317 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 323 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now, |
| 324 attachment_broker_.get()); |
| 318 } | 325 } |
| 319 | 326 |
| 320 void ChildThreadImpl::Init(const Options& options) { | 327 void ChildThreadImpl::Init(const Options& options) { |
| 321 channel_name_ = options.channel_name; | 328 channel_name_ = options.channel_name; |
| 322 | 329 |
| 323 g_lazy_tls.Pointer()->Set(this); | 330 g_lazy_tls.Pointer()->Set(this); |
| 324 on_channel_error_called_ = false; | 331 on_channel_error_called_ = false; |
| 325 message_loop_ = base::MessageLoop::current(); | 332 message_loop_ = base::MessageLoop::current(); |
| 326 #ifdef IPC_MESSAGE_LOG_ENABLED | 333 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 327 // We must make sure to instantiate the IPC Logger *before* we create the | 334 // We must make sure to instantiate the IPC Logger *before* we create the |
| 328 // channel, otherwise we can get a callback on the IO thread which creates | 335 // channel, otherwise we can get a callback on the IO thread which creates |
| 329 // the logger, and the logger does not like being created on the IO thread. | 336 // the logger, and the logger does not like being created on the IO thread. |
| 330 IPC::Logging::GetInstance(); | 337 IPC::Logging::GetInstance(); |
| 331 #endif | 338 #endif |
| 332 channel_ = | 339 channel_ = |
| 333 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), | 340 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
| 334 ChildProcess::current()->GetShutDownEvent()); | 341 ChildProcess::current()->GetShutDownEvent()); |
| 335 #ifdef IPC_MESSAGE_LOG_ENABLED | 342 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 336 if (!IsInBrowserProcess()) | 343 if (!IsInBrowserProcess()) |
| 337 IPC::Logging::GetInstance()->SetIPCSender(this); | 344 IPC::Logging::GetInstance()->SetIPCSender(this); |
| 338 #endif | 345 #endif |
| 339 | 346 |
| 347 #if defined(OS_WIN) |
| 348 attachment_broker_.reset(new IPC::AttachmentBrokerWin()); |
| 349 #endif |
| 350 |
| 340 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); | 351 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); |
| 341 | 352 |
| 342 sync_message_filter_ = | 353 sync_message_filter_ = |
| 343 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 354 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
| 344 thread_safe_sender_ = new ThreadSafeSender( | 355 thread_safe_sender_ = new ThreadSafeSender( |
| 345 message_loop_->task_runner(), sync_message_filter_.get()); | 356 message_loop_->task_runner(), sync_message_filter_.get()); |
| 346 | 357 |
| 347 resource_dispatcher_.reset(new ResourceDispatcher( | 358 resource_dispatcher_.reset(new ResourceDispatcher( |
| 348 this, message_loop()->task_runner())); | 359 this, message_loop()->task_runner())); |
| 349 websocket_dispatcher_.reset(new WebSocketDispatcher); | 360 websocket_dispatcher_.reset(new WebSocketDispatcher); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 #if defined(OS_WIN) | 514 #if defined(OS_WIN) |
| 504 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { | 515 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
| 505 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); | 516 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); |
| 506 } | 517 } |
| 507 | 518 |
| 508 void ChildThreadImpl::ReleaseCachedFonts() { | 519 void ChildThreadImpl::ReleaseCachedFonts() { |
| 509 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); | 520 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); |
| 510 } | 521 } |
| 511 #endif | 522 #endif |
| 512 | 523 |
| 524 IPC::AttachmentBroker* ChildThreadImpl::GetAttachmentBroker() { |
| 525 return attachment_broker_.get(); |
| 526 } |
| 527 |
| 513 MessageRouter* ChildThreadImpl::GetRouter() { | 528 MessageRouter* ChildThreadImpl::GetRouter() { |
| 514 DCHECK(base::MessageLoop::current() == message_loop()); | 529 DCHECK(base::MessageLoop::current() == message_loop()); |
| 515 return &router_; | 530 return &router_; |
| 516 } | 531 } |
| 517 | 532 |
| 518 scoped_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 533 scoped_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
| 519 size_t buf_size) { | 534 size_t buf_size) { |
| 520 DCHECK(base::MessageLoop::current() == message_loop()); | 535 DCHECK(base::MessageLoop::current() == message_loop()); |
| 521 return AllocateSharedMemory(buf_size, this); | 536 return AllocateSharedMemory(buf_size, this); |
| 522 } | 537 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 | 704 |
| 690 void ChildThreadImpl::OnProcessBackgrounded(bool background) { | 705 void ChildThreadImpl::OnProcessBackgrounded(bool background) { |
| 691 // Set timer slack to maximum on main thread when in background. | 706 // Set timer slack to maximum on main thread when in background. |
| 692 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; | 707 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
| 693 if (background) | 708 if (background) |
| 694 timer_slack = base::TIMER_SLACK_MAXIMUM; | 709 timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 695 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 710 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
| 696 } | 711 } |
| 697 | 712 |
| 698 } // namespace content | 713 } // namespace content |
| OLD | NEW |