| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 using tracked_objects::ThreadData; | 94 using tracked_objects::ThreadData; |
| 95 | 95 |
| 96 namespace content { | 96 namespace content { |
| 97 namespace { | 97 namespace { |
| 98 | 98 |
| 99 // How long to wait for a connection to the browser process before giving up. | 99 // How long to wait for a connection to the browser process before giving up. |
| 100 const int kConnectionTimeoutS = 15; | 100 const int kConnectionTimeoutS = 15; |
| 101 | 101 |
| 102 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl>>::DestructorAtExit | 102 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl>>::DestructorAtExit |
| 103 g_lazy_tls = LAZY_INSTANCE_INITIALIZER; | 103 g_lazy_child_tls = LAZY_INSTANCE_INITIALIZER; |
| 104 | 104 |
| 105 // This isn't needed on Windows because there the sandbox's job object | 105 // This isn't needed on Windows because there the sandbox's job object |
| 106 // terminates child processes automatically. For unsandboxed processes (i.e. | 106 // terminates child processes automatically. For unsandboxed processes (i.e. |
| 107 // plugins), PluginThread has EnsureTerminateMessageFilter. | 107 // plugins), PluginThread has EnsureTerminateMessageFilter. |
| 108 #if defined(OS_POSIX) | 108 #if defined(OS_POSIX) |
| 109 | 109 |
| 110 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ | 110 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 111 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ | 111 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 112 defined(UNDEFINED_SANITIZER) | 112 defined(UNDEFINED_SANITIZER) |
| 113 // A thread delegate that waits for |duration| and then exits the process with | 113 // A thread delegate that waits for |duration| and then exits the process with |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 service_manager_connection_->AddConnectionFilter( | 425 service_manager_connection_->AddConnectionFilter( |
| 426 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface())); | 426 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface())); |
| 427 | 427 |
| 428 channel_->Init( | 428 channel_->Init( |
| 429 IPC::ChannelMojo::CreateClientFactory( | 429 IPC::ChannelMojo::CreateClientFactory( |
| 430 std::move(handle), ChildProcess::current()->io_task_runner()), | 430 std::move(handle), ChildProcess::current()->io_task_runner()), |
| 431 true /* create_pipe_now */); | 431 true /* create_pipe_now */); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void ChildThreadImpl::Init(const Options& options) { | 434 void ChildThreadImpl::Init(const Options& options) { |
| 435 g_lazy_tls.Pointer()->Set(this); | 435 g_lazy_child_tls.Pointer()->Set(this); |
| 436 on_channel_error_called_ = false; | 436 on_channel_error_called_ = false; |
| 437 message_loop_ = base::MessageLoop::current(); | 437 message_loop_ = base::MessageLoop::current(); |
| 438 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 438 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) |
| 439 // We must make sure to instantiate the IPC Logger *before* we create the | 439 // We must make sure to instantiate the IPC Logger *before* we create the |
| 440 // channel, otherwise we can get a callback on the IO thread which creates | 440 // channel, otherwise we can get a callback on the IO thread which creates |
| 441 // the logger, and the logger does not like being created on the IO thread. | 441 // the logger, and the logger does not like being created on the IO thread. |
| 442 IPC::Logging::GetInstance(); | 442 IPC::Logging::GetInstance(); |
| 443 #endif | 443 #endif |
| 444 | 444 |
| 445 channel_ = | 445 channel_ = |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 618 |
| 619 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 619 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
| 620 // reset it as it's not guaranteed to outlive this object. | 620 // reset it as it's not guaranteed to outlive this object. |
| 621 // NOTE: this also has the side-effect of not closing the main IPC channel to | 621 // NOTE: this also has the side-effect of not closing the main IPC channel to |
| 622 // the browser process. This is needed because this is the signal that the | 622 // the browser process. This is needed because this is the signal that the |
| 623 // browser uses to know that this process has died, so we need it to be alive | 623 // browser uses to know that this process has died, so we need it to be alive |
| 624 // until this process is shut down, and the OS closes the handle | 624 // until this process is shut down, and the OS closes the handle |
| 625 // automatically. We used to watch the object handle on Windows to do this, | 625 // automatically. We used to watch the object handle on Windows to do this, |
| 626 // but it wasn't possible to do so on POSIX. | 626 // but it wasn't possible to do so on POSIX. |
| 627 channel_->ClearIPCTaskRunner(); | 627 channel_->ClearIPCTaskRunner(); |
| 628 g_lazy_tls.Pointer()->Set(NULL); | 628 g_lazy_child_tls.Pointer()->Set(NULL); |
| 629 } | 629 } |
| 630 | 630 |
| 631 void ChildThreadImpl::Shutdown() { | 631 void ChildThreadImpl::Shutdown() { |
| 632 // Delete objects that hold references to blink so derived classes can | 632 // Delete objects that hold references to blink so derived classes can |
| 633 // safely shutdown blink in their Shutdown implementation. | 633 // safely shutdown blink in their Shutdown implementation. |
| 634 file_system_dispatcher_.reset(); | 634 file_system_dispatcher_.reset(); |
| 635 quota_dispatcher_.reset(); | 635 quota_dispatcher_.reset(); |
| 636 WebFileSystemImpl::DeleteThreadSpecificInstance(); | 636 WebFileSystemImpl::DeleteThreadSpecificInstance(); |
| 637 } | 637 } |
| 638 | 638 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 812 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) |
| 813 void ChildThreadImpl::OnSetIPCLoggingEnabled(bool enable) { | 813 void ChildThreadImpl::OnSetIPCLoggingEnabled(bool enable) { |
| 814 if (enable) | 814 if (enable) |
| 815 IPC::Logging::GetInstance()->Enable(); | 815 IPC::Logging::GetInstance()->Enable(); |
| 816 else | 816 else |
| 817 IPC::Logging::GetInstance()->Disable(); | 817 IPC::Logging::GetInstance()->Disable(); |
| 818 } | 818 } |
| 819 #endif // IPC_MESSAGE_LOG_ENABLED | 819 #endif // IPC_MESSAGE_LOG_ENABLED |
| 820 | 820 |
| 821 ChildThreadImpl* ChildThreadImpl::current() { | 821 ChildThreadImpl* ChildThreadImpl::current() { |
| 822 return g_lazy_tls.Pointer()->Get(); | 822 return g_lazy_child_tls.Pointer()->Get(); |
| 823 } | 823 } |
| 824 | 824 |
| 825 #if defined(OS_ANDROID) | 825 #if defined(OS_ANDROID) |
| 826 // The method must NOT be called on the child thread itself. | 826 // The method must NOT be called on the child thread itself. |
| 827 // It may block the child thread if so. | 827 // It may block the child thread if so. |
| 828 void ChildThreadImpl::ShutdownThread() { | 828 void ChildThreadImpl::ShutdownThread() { |
| 829 DCHECK(!ChildThreadImpl::current()) << | 829 DCHECK(!ChildThreadImpl::current()) << |
| 830 "this method should NOT be called from child thread itself"; | 830 "this method should NOT be called from child thread itself"; |
| 831 g_quit_closure.Get().PostQuitFromNonMainThread(); | 831 g_quit_closure.Get().PostQuitFromNonMainThread(); |
| 832 } | 832 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 Listener* route = router_.GetRoute(routing_id); | 865 Listener* route = router_.GetRoute(routing_id); |
| 866 if (route) | 866 if (route) |
| 867 route->OnAssociatedInterfaceRequest(name, request.PassHandle()); | 867 route->OnAssociatedInterfaceRequest(name, request.PassHandle()); |
| 868 } | 868 } |
| 869 | 869 |
| 870 bool ChildThreadImpl::IsInBrowserProcess() const { | 870 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 871 return static_cast<bool>(browser_process_io_runner_); | 871 return static_cast<bool>(browser_process_io_runner_); |
| 872 } | 872 } |
| 873 | 873 |
| 874 } // namespace content | 874 } // namespace content |
| OLD | NEW |