| 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 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 channel_->Init( | 407 channel_->Init( |
| 408 IPC::ChannelMojo::CreateClientFactory( | 408 IPC::ChannelMojo::CreateClientFactory( |
| 409 std::move(handle), ChildProcess::current()->io_task_runner()), | 409 std::move(handle), ChildProcess::current()->io_task_runner()), |
| 410 true /* create_pipe_now */); | 410 true /* create_pipe_now */); |
| 411 } | 411 } |
| 412 | 412 |
| 413 void ChildThreadImpl::Init(const Options& options) { | 413 void ChildThreadImpl::Init(const Options& options) { |
| 414 g_lazy_tls.Pointer()->Set(this); | 414 g_lazy_tls.Pointer()->Set(this); |
| 415 on_channel_error_called_ = false; | 415 on_channel_error_called_ = false; |
| 416 message_loop_ = base::MessageLoop::current(); | 416 message_loop_ = base::MessageLoop::current(); |
| 417 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 417 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 418 // We must make sure to instantiate the IPC Logger *before* we create the | 418 // We must make sure to instantiate the IPC Logger *before* we create the |
| 419 // channel, otherwise we can get a callback on the IO thread which creates | 419 // channel, otherwise we can get a callback on the IO thread which creates |
| 420 // the logger, and the logger does not like being created on the IO thread. | 420 // the logger, and the logger does not like being created on the IO thread. |
| 421 IPC::Logging::GetInstance(); | 421 IPC::Logging::GetInstance(); |
| 422 #endif | 422 #endif |
| 423 | 423 |
| 424 channel_ = | 424 channel_ = |
| 425 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), | 425 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(), |
| 426 ChildProcess::current()->GetShutDownEvent()); | 426 ChildProcess::current()->GetShutDownEvent()); |
| 427 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 427 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 428 if (!IsInBrowserProcess()) | 428 if (!IsInBrowserProcess()) |
| 429 IPC::Logging::GetInstance()->SetIPCSender(this); | 429 IPC::Logging::GetInstance()->SetIPCSender(this); |
| 430 #endif | 430 #endif |
| 431 | 431 |
| 432 if (!IsInBrowserProcess()) { | 432 if (!IsInBrowserProcess()) { |
| 433 // Don't double-initialize IPC support in single-process mode. | 433 // Don't double-initialize IPC support in single-process mode. |
| 434 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( | 434 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( |
| 435 GetIOTaskRunner(), mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST)); | 435 GetIOTaskRunner(), mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST)); |
| 436 InitializeMojoIPCChannel(); | 436 InitializeMojoIPCChannel(); |
| 437 } | 437 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, | 565 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, |
| 566 channel_connected_factory_->GetWeakPtr()), | 566 channel_connected_factory_->GetWeakPtr()), |
| 567 base::TimeDelta::FromSeconds(connection_timeout)); | 567 base::TimeDelta::FromSeconds(connection_timeout)); |
| 568 | 568 |
| 569 #if defined(OS_ANDROID) | 569 #if defined(OS_ANDROID) |
| 570 g_quit_closure.Get().BindToMainThread(); | 570 g_quit_closure.Get().BindToMainThread(); |
| 571 #endif | 571 #endif |
| 572 } | 572 } |
| 573 | 573 |
| 574 ChildThreadImpl::~ChildThreadImpl() { | 574 ChildThreadImpl::~ChildThreadImpl() { |
| 575 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 575 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 576 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 576 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
| 577 #endif | 577 #endif |
| 578 | 578 |
| 579 channel_->RemoveFilter(histogram_message_filter_.get()); | 579 channel_->RemoveFilter(histogram_message_filter_.get()); |
| 580 channel_->RemoveFilter(sync_message_filter_.get()); | 580 channel_->RemoveFilter(sync_message_filter_.get()); |
| 581 | 581 |
| 582 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 582 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
| 583 // reset it as it's not guaranteed to outlive this object. | 583 // reset it as it's not guaranteed to outlive this object. |
| 584 // NOTE: this also has the side-effect of not closing the main IPC channel to | 584 // NOTE: this also has the side-effect of not closing the main IPC channel to |
| 585 // the browser process. This is needed because this is the signal that the | 585 // the browser process. This is needed because this is the signal that the |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { | 720 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { |
| 721 // Resource responses are sent to the resource dispatcher. | 721 // Resource responses are sent to the resource dispatcher. |
| 722 if (resource_dispatcher_->OnMessageReceived(msg)) | 722 if (resource_dispatcher_->OnMessageReceived(msg)) |
| 723 return true; | 723 return true; |
| 724 if (file_system_dispatcher_->OnMessageReceived(msg)) | 724 if (file_system_dispatcher_->OnMessageReceived(msg)) |
| 725 return true; | 725 return true; |
| 726 | 726 |
| 727 bool handled = true; | 727 bool handled = true; |
| 728 IPC_BEGIN_MESSAGE_MAP(ChildThreadImpl, msg) | 728 IPC_BEGIN_MESSAGE_MAP(ChildThreadImpl, msg) |
| 729 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) | 729 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) |
| 730 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 730 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 731 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, | 731 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, |
| 732 OnSetIPCLoggingEnabled) | 732 OnSetIPCLoggingEnabled) |
| 733 #endif | 733 #endif |
| 734 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, | 734 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, |
| 735 OnSetProfilerStatus) | 735 OnSetProfilerStatus) |
| 736 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, | 736 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, |
| 737 OnGetChildProfilerData) | 737 OnGetChildProfilerData) |
| 738 IPC_MESSAGE_HANDLER(ChildProcessMsg_ProfilingPhaseCompleted, | 738 IPC_MESSAGE_HANDLER(ChildProcessMsg_ProfilingPhaseCompleted, |
| 739 OnProfilingPhaseCompleted) | 739 OnProfilingPhaseCompleted) |
| 740 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded, | 740 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 791 |
| 792 void ChildThreadImpl::OnProcessPurgeAndSuspend() { | 792 void ChildThreadImpl::OnProcessPurgeAndSuspend() { |
| 793 } | 793 } |
| 794 | 794 |
| 795 void ChildThreadImpl::OnProcessResume() {} | 795 void ChildThreadImpl::OnProcessResume() {} |
| 796 | 796 |
| 797 void ChildThreadImpl::OnShutdown() { | 797 void ChildThreadImpl::OnShutdown() { |
| 798 base::MessageLoop::current()->QuitWhenIdle(); | 798 base::MessageLoop::current()->QuitWhenIdle(); |
| 799 } | 799 } |
| 800 | 800 |
| 801 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 801 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 802 void ChildThreadImpl::OnSetIPCLoggingEnabled(bool enable) { | 802 void ChildThreadImpl::OnSetIPCLoggingEnabled(bool enable) { |
| 803 if (enable) | 803 if (enable) |
| 804 IPC::Logging::GetInstance()->Enable(); | 804 IPC::Logging::GetInstance()->Enable(); |
| 805 else | 805 else |
| 806 IPC::Logging::GetInstance()->Disable(); | 806 IPC::Logging::GetInstance()->Disable(); |
| 807 } | 807 } |
| 808 #endif // IPC_MESSAGE_LOG_ENABLED | 808 #endif // IPC_MESSAGE_LOG_ENABLED |
| 809 | 809 |
| 810 void ChildThreadImpl::OnSetProfilerStatus(ThreadData::Status status) { | 810 void ChildThreadImpl::OnSetProfilerStatus(ThreadData::Status status) { |
| 811 ThreadData::InitializeAndSetTrackingStatus(status); | 811 ThreadData::InitializeAndSetTrackingStatus(status); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 connected_to_browser_ = true; | 882 connected_to_browser_ = true; |
| 883 child_info_ = local_info; | 883 child_info_ = local_info; |
| 884 browser_info_ = remote_info; | 884 browser_info_ = remote_info; |
| 885 } | 885 } |
| 886 | 886 |
| 887 bool ChildThreadImpl::IsInBrowserProcess() const { | 887 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 888 return static_cast<bool>(browser_process_io_runner_); | 888 return static_cast<bool>(browser_process_io_runner_); |
| 889 } | 889 } |
| 890 | 890 |
| 891 } // namespace content | 891 } // namespace content |
| OLD | NEW |