| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 using tracked_objects::ThreadData; | 87 using tracked_objects::ThreadData; |
| 88 | 88 |
| 89 namespace content { | 89 namespace content { |
| 90 namespace { | 90 namespace { |
| 91 | 91 |
| 92 // How long to wait for a connection to the browser process before giving up. | 92 // How long to wait for a connection to the browser process before giving up. |
| 93 const int kConnectionTimeoutS = 15; | 93 const int kConnectionTimeoutS = 15; |
| 94 | 94 |
| 95 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl>>::DestructorAtExit | 95 base::LazyInstance<base::ThreadLocalPointer<ChildThreadImpl>>::DestructorAtExit |
| 96 g_lazy_tls = LAZY_INSTANCE_INITIALIZER; | 96 g_lazy_child_tls = LAZY_INSTANCE_INITIALIZER; |
| 97 | 97 |
| 98 // This isn't needed on Windows because there the sandbox's job object | 98 // This isn't needed on Windows because there the sandbox's job object |
| 99 // terminates child processes automatically. For unsandboxed processes (i.e. | 99 // terminates child processes automatically. For unsandboxed processes (i.e. |
| 100 // plugins), PluginThread has EnsureTerminateMessageFilter. | 100 // plugins), PluginThread has EnsureTerminateMessageFilter. |
| 101 #if defined(OS_POSIX) | 101 #if defined(OS_POSIX) |
| 102 | 102 |
| 103 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ | 103 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 104 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ | 104 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 105 defined(UNDEFINED_SANITIZER) | 105 defined(UNDEFINED_SANITIZER) |
| 106 // A thread delegate that waits for |duration| and then exits the process with | 106 // A thread delegate that waits for |duration| and then exits the process with |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 413 } |
| 414 | 414 |
| 415 DCHECK(handle.is_valid()); | 415 DCHECK(handle.is_valid()); |
| 416 channel_->Init( | 416 channel_->Init( |
| 417 IPC::ChannelMojo::CreateClientFactory( | 417 IPC::ChannelMojo::CreateClientFactory( |
| 418 std::move(handle), ChildProcess::current()->io_task_runner()), | 418 std::move(handle), ChildProcess::current()->io_task_runner()), |
| 419 true /* create_pipe_now */); | 419 true /* create_pipe_now */); |
| 420 } | 420 } |
| 421 | 421 |
| 422 void ChildThreadImpl::Init(const Options& options) { | 422 void ChildThreadImpl::Init(const Options& options) { |
| 423 g_lazy_tls.Pointer()->Set(this); | 423 g_lazy_child_tls.Pointer()->Set(this); |
| 424 on_channel_error_called_ = false; | 424 on_channel_error_called_ = false; |
| 425 message_loop_ = base::MessageLoop::current(); | 425 message_loop_ = base::MessageLoop::current(); |
| 426 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) | 426 #if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED) |
| 427 // We must make sure to instantiate the IPC Logger *before* we create the | 427 // We must make sure to instantiate the IPC Logger *before* we create the |
| 428 // channel, otherwise we can get a callback on the IO thread which creates | 428 // channel, otherwise we can get a callback on the IO thread which creates |
| 429 // the logger, and the logger does not like being created on the IO thread. | 429 // the logger, and the logger does not like being created on the IO thread. |
| 430 IPC::Logging::GetInstance(); | 430 IPC::Logging::GetInstance(); |
| 431 #endif | 431 #endif |
| 432 | 432 |
| 433 channel_ = | 433 channel_ = |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 591 |
| 592 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 592 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
| 593 // reset it as it's not guaranteed to outlive this object. | 593 // reset it as it's not guaranteed to outlive this object. |
| 594 // NOTE: this also has the side-effect of not closing the main IPC channel to | 594 // NOTE: this also has the side-effect of not closing the main IPC channel to |
| 595 // the browser process. This is needed because this is the signal that the | 595 // the browser process. This is needed because this is the signal that the |
| 596 // browser uses to know that this process has died, so we need it to be alive | 596 // browser uses to know that this process has died, so we need it to be alive |
| 597 // until this process is shut down, and the OS closes the handle | 597 // until this process is shut down, and the OS closes the handle |
| 598 // automatically. We used to watch the object handle on Windows to do this, | 598 // automatically. We used to watch the object handle on Windows to do this, |
| 599 // but it wasn't possible to do so on POSIX. | 599 // but it wasn't possible to do so on POSIX. |
| 600 channel_->ClearIPCTaskRunner(); | 600 channel_->ClearIPCTaskRunner(); |
| 601 g_lazy_tls.Pointer()->Set(NULL); | 601 g_lazy_child_tls.Pointer()->Set(NULL); |
| 602 } | 602 } |
| 603 | 603 |
| 604 void ChildThreadImpl::Shutdown() { | 604 void ChildThreadImpl::Shutdown() { |
| 605 // Delete objects that hold references to blink so derived classes can | 605 // Delete objects that hold references to blink so derived classes can |
| 606 // safely shutdown blink in their Shutdown implementation. | 606 // safely shutdown blink in their Shutdown implementation. |
| 607 file_system_dispatcher_.reset(); | 607 file_system_dispatcher_.reset(); |
| 608 quota_dispatcher_.reset(); | 608 quota_dispatcher_.reset(); |
| 609 WebFileSystemImpl::DeleteThreadSpecificInstance(); | 609 WebFileSystemImpl::DeleteThreadSpecificInstance(); |
| 610 } | 610 } |
| 611 | 611 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 806 |
| 807 Send( | 807 Send( |
| 808 new ChildProcessHostMsg_ChildProfilerData(sequence_number, process_data)); | 808 new ChildProcessHostMsg_ChildProfilerData(sequence_number, process_data)); |
| 809 } | 809 } |
| 810 | 810 |
| 811 void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase) { | 811 void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase) { |
| 812 ThreadData::OnProfilingPhaseCompleted(profiling_phase); | 812 ThreadData::OnProfilingPhaseCompleted(profiling_phase); |
| 813 } | 813 } |
| 814 | 814 |
| 815 ChildThreadImpl* ChildThreadImpl::current() { | 815 ChildThreadImpl* ChildThreadImpl::current() { |
| 816 return g_lazy_tls.Pointer()->Get(); | 816 return g_lazy_child_tls.Pointer()->Get(); |
| 817 } | 817 } |
| 818 | 818 |
| 819 #if defined(OS_ANDROID) | 819 #if defined(OS_ANDROID) |
| 820 // The method must NOT be called on the child thread itself. | 820 // The method must NOT be called on the child thread itself. |
| 821 // It may block the child thread if so. | 821 // It may block the child thread if so. |
| 822 void ChildThreadImpl::ShutdownThread() { | 822 void ChildThreadImpl::ShutdownThread() { |
| 823 DCHECK(!ChildThreadImpl::current()) << | 823 DCHECK(!ChildThreadImpl::current()) << |
| 824 "this method should NOT be called from child thread itself"; | 824 "this method should NOT be called from child thread itself"; |
| 825 g_quit_closure.Get().PostQuitFromNonMainThread(); | 825 g_quit_closure.Get().PostQuitFromNonMainThread(); |
| 826 } | 826 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 Listener* route = router_.GetRoute(routing_id); | 859 Listener* route = router_.GetRoute(routing_id); |
| 860 if (route) | 860 if (route) |
| 861 route->OnAssociatedInterfaceRequest(name, request.PassHandle()); | 861 route->OnAssociatedInterfaceRequest(name, request.PassHandle()); |
| 862 } | 862 } |
| 863 | 863 |
| 864 bool ChildThreadImpl::IsInBrowserProcess() const { | 864 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 865 return static_cast<bool>(browser_process_io_runner_); | 865 return static_cast<bool>(browser_process_io_runner_); |
| 866 } | 866 } |
| 867 | 867 |
| 868 } // namespace content | 868 } // namespace content |
| OLD | NEW |