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
3 // found in the LICENSE file.
5 #include "content/child/child_thread_impl.h"
11 #include "base/allocator/allocator_extension.h"
12 #include "base/base_switches.h"
13 #include "base/basictypes.h"
14 #include "base/command_line.h"
15 #include "base/debug/leak_annotations.h"
16 #include "base/debug/profiler.h"
17 #include "base/lazy_instance.h"
18 #include "base/location.h"
19 #include "base/logging.h"
20 #include "base/message_loop/timer_slack.h"
21 #include "base/metrics/field_trial.h"
22 #include "base/process/process.h"
23 #include "base/process/process_handle.h"
24 #include "base/single_thread_task_runner.h"
25 #include "base/strings/string_number_conversions.h"
26 #include "base/strings/string_util.h"
27 #include "base/synchronization/condition_variable.h"
28 #include "base/synchronization/lock.h"
29 #include "base/thread_task_runner_handle.h"
30 #include "base/threading/thread_local.h"
31 #include "base/trace_event/memory_dump_manager.h"
32 #include "base/tracked_objects.h"
33 #include "components/tracing/child_trace_message_filter.h"
34 #include "content/child/bluetooth/bluetooth_message_filter.h"
35 #include "content/child/child_discardable_shared_memory_manager.h"
36 #include "content/child/child_gpu_memory_buffer_manager.h"
37 #include "content/child/child_histogram_message_filter.h"
38 #include "content/child/child_process.h"
39 #include "content/child/child_resource_message_filter.h"
40 #include "content/child/child_shared_bitmap_manager.h"
41 #include "content/child/fileapi/file_system_dispatcher.h"
42 #include "content/child/fileapi/webfilesystem_impl.h"
43 #include "content/child/geofencing/geofencing_message_filter.h"
44 #include "content/child/mojo/mojo_application.h"
45 #include "content/child/navigator_connect/navigator_connect_dispatcher.h"
46 #include "content/child/notifications/notification_dispatcher.h"
47 #include "content/child/power_monitor_broadcast_source.h"
48 #include "content/child/push_messaging/push_dispatcher.h"
49 #include "content/child/quota_dispatcher.h"
50 #include "content/child/quota_message_filter.h"
51 #include "content/child/resource_dispatcher.h"
52 #include "content/child/service_worker/service_worker_message_filter.h"
53 #include "content/child/thread_safe_sender.h"
54 #include "content/child/websocket_dispatcher.h"
55 #include "content/common/child_process_messages.h"
56 #include "content/common/in_process_child_thread_params.h"
57 #include "content/public/common/content_switches.h"
58 #include "ipc/ipc_logging.h"
59 #include "ipc/ipc_switches.h"
60 #include "ipc/ipc_sync_channel.h"
61 #include "ipc/ipc_sync_message_filter.h"
62 #include "ipc/mojo/ipc_channel_mojo.h"
64 #if defined(OS_ANDROID)
65 #include "base/thread_task_runner_handle.h"
68 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED)
69 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
72 #if defined(OS_MACOSX)
73 #include "content/child/child_io_surface_manager_mac.h"
76 using tracked_objects::ThreadData
;
81 // How long to wait for a connection to the browser process before giving up.
82 const int kConnectionTimeoutS
= 15;
84 base::LazyInstance
<base::ThreadLocalPointer
<ChildThreadImpl
> > g_lazy_tls
=
85 LAZY_INSTANCE_INITIALIZER
;
87 // This isn't needed on Windows because there the sandbox's job object
88 // terminates child processes automatically. For unsandboxed processes (i.e.
89 // plugins), PluginThread has EnsureTerminateMessageFilter.
92 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
93 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
94 defined(UNDEFINED_SANITIZER)
95 // A thread delegate that waits for |duration| and then exits the process with
97 class WaitAndExitDelegate
: public base::PlatformThread::Delegate
{
99 explicit WaitAndExitDelegate(base::TimeDelta duration
)
100 : duration_(duration
) {}
102 void ThreadMain() override
{
103 base::PlatformThread::Sleep(duration_
);
108 const base::TimeDelta duration_
;
109 DISALLOW_COPY_AND_ASSIGN(WaitAndExitDelegate
);
112 bool CreateWaitAndExitThread(base::TimeDelta duration
) {
113 scoped_ptr
<WaitAndExitDelegate
> delegate(new WaitAndExitDelegate(duration
));
115 const bool thread_created
=
116 base::PlatformThread::CreateNonJoinable(0, delegate
.get());
120 // A non joinable thread has been created. The thread will either terminate
121 // the process or will be terminated by the process. Therefore, keep the
122 // delegate object alive for the lifetime of the process.
123 WaitAndExitDelegate
* leaking_delegate
= delegate
.release();
124 ANNOTATE_LEAKING_OBJECT_PTR(leaking_delegate
);
125 ignore_result(leaking_delegate
);
130 class SuicideOnChannelErrorFilter
: public IPC::MessageFilter
{
132 // IPC::MessageFilter
133 void OnChannelError() override
{
134 // For renderer/worker processes:
135 // On POSIX, at least, one can install an unload handler which loops
136 // forever and leave behind a renderer process which eats 100% CPU forever.
138 // This is because the terminate signals (ViewMsg_ShouldClose and the error
139 // from the IPC sender) are routed to the main message loop but never
140 // processed (because that message loop is stuck in V8).
142 // One could make the browser SIGKILL the renderers, but that leaves open a
143 // large window where a browser failure (or a user, manually terminating
144 // the browser because "it's stuck") will leave behind a process eating all
147 // So, we install a filter on the sender so that we can process this event
148 // here and kill the process.
149 base::debug::StopProfiling();
150 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
151 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
152 defined(UNDEFINED_SANITIZER)
153 // Some sanitizer tools rely on exit handlers (e.g. to run leak detection,
154 // or dump code coverage data to disk). Instead of exiting the process
155 // immediately, we give it 60 seconds to run exit handlers.
156 CHECK(CreateWaitAndExitThread(base::TimeDelta::FromSeconds(60)));
157 #if defined(LEAK_SANITIZER)
158 // Invoke LeakSanitizer early to avoid detecting shutdown-only leaks. If
159 // leaks are found, the process will exit here.
160 __lsan_do_leak_check();
168 ~SuicideOnChannelErrorFilter() override
{}
173 #if defined(OS_ANDROID)
174 // A class that allows for triggering a clean shutdown from another
175 // thread through draining the main thread's msg loop.
181 void BindToMainThread();
182 void PostQuitFromNonMainThread();
185 static void PostClosure(
186 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
187 base::Closure closure
);
190 base::ConditionVariable cond_var_
;
191 base::Closure closure_
;
194 QuitClosure::QuitClosure() : cond_var_(&lock_
) {
197 QuitClosure::~QuitClosure() {
200 void QuitClosure::PostClosure(
201 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
202 base::Closure closure
) {
203 task_runner
->PostTask(FROM_HERE
, closure
);
206 void QuitClosure::BindToMainThread() {
207 base::AutoLock
lock(lock_
);
208 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner(
209 base::ThreadTaskRunnerHandle::Get());
210 base::Closure quit_closure
=
211 base::MessageLoop::current()->QuitWhenIdleClosure();
212 closure_
= base::Bind(&QuitClosure::PostClosure
, task_runner
, quit_closure
);
216 void QuitClosure::PostQuitFromNonMainThread() {
217 base::AutoLock
lock(lock_
);
218 while (closure_
.is_null())
224 base::LazyInstance
<QuitClosure
> g_quit_closure
= LAZY_INSTANCE_INITIALIZER
;
229 ChildThread
* ChildThread::Get() {
230 return ChildThreadImpl::current();
233 ChildThreadImpl::Options::Options()
234 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
235 switches::kProcessChannelID
)),
236 use_mojo_channel(false) {
239 ChildThreadImpl::Options::~Options() {
242 ChildThreadImpl::Options::Builder::Builder() {
245 ChildThreadImpl::Options::Builder
&
246 ChildThreadImpl::Options::Builder::InBrowserProcess(
247 const InProcessChildThreadParams
& params
) {
248 options_
.browser_process_io_runner
= params
.io_runner();
249 options_
.channel_name
= params
.channel_name();
253 ChildThreadImpl::Options::Builder
&
254 ChildThreadImpl::Options::Builder::UseMojoChannel(bool use_mojo_channel
) {
255 options_
.use_mojo_channel
= use_mojo_channel
;
259 ChildThreadImpl::Options::Builder
&
260 ChildThreadImpl::Options::Builder::WithChannelName(
261 const std::string
& channel_name
) {
262 options_
.channel_name
= channel_name
;
266 ChildThreadImpl::Options::Builder
&
267 ChildThreadImpl::Options::Builder::AddStartupFilter(
268 IPC::MessageFilter
* filter
) {
269 options_
.startup_filters
.push_back(filter
);
273 ChildThreadImpl::Options
ChildThreadImpl::Options::Builder::Build() {
277 ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter(
281 bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message
* msg
) {
282 return sender_
->Send(msg
);
285 ChildThreadImpl::ChildThreadImpl()
287 channel_connected_factory_(this) {
288 Init(Options::Builder().Build());
291 ChildThreadImpl::ChildThreadImpl(const Options
& options
)
293 browser_process_io_runner_(options
.browser_process_io_runner
),
294 channel_connected_factory_(this) {
298 scoped_refptr
<base::SequencedTaskRunner
> ChildThreadImpl::GetIOTaskRunner() {
299 if (IsInBrowserProcess())
300 return browser_process_io_runner_
;
301 return ChildProcess::current()->io_task_runner();
304 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel
) {
305 bool create_pipe_now
= true;
306 if (use_mojo_channel
) {
307 VLOG(1) << "Mojo is enabled on child";
308 scoped_refptr
<base::SequencedTaskRunner
> io_task_runner
= GetIOTaskRunner();
309 DCHECK(io_task_runner
);
310 channel_
->Init(IPC::ChannelMojo::CreateClientFactory(
311 nullptr, io_task_runner
, channel_name_
),
316 VLOG(1) << "Mojo is disabled on child";
317 channel_
->Init(channel_name_
, IPC::Channel::MODE_CLIENT
, create_pipe_now
);
320 void ChildThreadImpl::Init(const Options
& options
) {
321 channel_name_
= options
.channel_name
;
323 g_lazy_tls
.Pointer()->Set(this);
324 on_channel_error_called_
= false;
325 message_loop_
= base::MessageLoop::current();
326 #ifdef IPC_MESSAGE_LOG_ENABLED
327 // 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
329 // the logger, and the logger does not like being created on the IO thread.
330 IPC::Logging::GetInstance();
333 IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(),
334 ChildProcess::current()->GetShutDownEvent());
335 #ifdef IPC_MESSAGE_LOG_ENABLED
336 if (!IsInBrowserProcess())
337 IPC::Logging::GetInstance()->SetIPCSender(this);
340 mojo_application_
.reset(new MojoApplication(GetIOTaskRunner()));
342 sync_message_filter_
=
343 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent());
344 thread_safe_sender_
= new ThreadSafeSender(
345 message_loop_
->task_runner(), sync_message_filter_
.get());
347 resource_dispatcher_
.reset(new ResourceDispatcher(
348 this, message_loop()->task_runner()));
349 websocket_dispatcher_
.reset(new WebSocketDispatcher
);
350 file_system_dispatcher_
.reset(new FileSystemDispatcher());
352 histogram_message_filter_
= new ChildHistogramMessageFilter();
353 resource_message_filter_
=
354 new ChildResourceMessageFilter(resource_dispatcher());
356 service_worker_message_filter_
=
357 new ServiceWorkerMessageFilter(thread_safe_sender_
.get());
359 quota_message_filter_
=
360 new QuotaMessageFilter(thread_safe_sender_
.get());
361 quota_dispatcher_
.reset(new QuotaDispatcher(thread_safe_sender_
.get(),
362 quota_message_filter_
.get()));
363 geofencing_message_filter_
=
364 new GeofencingMessageFilter(thread_safe_sender_
.get());
365 bluetooth_message_filter_
=
366 new BluetoothMessageFilter(thread_safe_sender_
.get());
367 notification_dispatcher_
=
368 new NotificationDispatcher(thread_safe_sender_
.get());
369 push_dispatcher_
= new PushDispatcher(thread_safe_sender_
.get());
370 navigator_connect_dispatcher_
=
371 new NavigatorConnectDispatcher(thread_safe_sender_
.get());
373 channel_
->AddFilter(histogram_message_filter_
.get());
374 channel_
->AddFilter(sync_message_filter_
.get());
375 channel_
->AddFilter(resource_message_filter_
.get());
376 channel_
->AddFilter(quota_message_filter_
->GetFilter());
377 channel_
->AddFilter(notification_dispatcher_
->GetFilter());
378 channel_
->AddFilter(push_dispatcher_
->GetFilter());
379 channel_
->AddFilter(service_worker_message_filter_
->GetFilter());
380 channel_
->AddFilter(geofencing_message_filter_
->GetFilter());
381 channel_
->AddFilter(bluetooth_message_filter_
->GetFilter());
382 channel_
->AddFilter(navigator_connect_dispatcher_
->GetFilter());
384 if (!IsInBrowserProcess()) {
385 // In single process mode, browser-side tracing will cover the whole
386 // process including renderers.
387 channel_
->AddFilter(new tracing::ChildTraceMessageFilter(
388 ChildProcess::current()->io_task_runner()));
391 // In single process mode we may already have a power monitor
392 if (!base::PowerMonitor::Get()) {
393 scoped_ptr
<PowerMonitorBroadcastSource
> power_monitor_source(
394 new PowerMonitorBroadcastSource());
395 channel_
->AddFilter(power_monitor_source
->GetMessageFilter());
397 power_monitor_
.reset(new base::PowerMonitor(
398 power_monitor_source
.Pass()));
401 #if defined(OS_POSIX)
402 // Check that --process-type is specified so we don't do this in unit tests
403 // and single-process mode.
404 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType
))
405 channel_
->AddFilter(new SuicideOnChannelErrorFilter());
408 // Add filters passed here via options.
409 for (auto startup_filter
: options
.startup_filters
) {
410 channel_
->AddFilter(startup_filter
);
413 ConnectChannel(options
.use_mojo_channel
);
415 int connection_timeout
= kConnectionTimeoutS
;
416 std::string connection_override
=
417 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
418 switches::kIPCConnectionTimeout
);
419 if (!connection_override
.empty()) {
421 if (base::StringToInt(connection_override
, &temp
))
422 connection_timeout
= temp
;
425 message_loop_
->task_runner()->PostDelayedTask(
426 FROM_HERE
, base::Bind(&ChildThreadImpl::EnsureConnected
,
427 channel_connected_factory_
.GetWeakPtr()),
428 base::TimeDelta::FromSeconds(connection_timeout
));
430 #if defined(OS_ANDROID)
431 g_quit_closure
.Get().BindToMainThread();
434 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED)
435 trace_memory_controller_
.reset(new base::trace_event::TraceMemoryController(
436 message_loop_
->task_runner(), ::HeapProfilerWithPseudoStackStart
,
437 ::HeapProfilerStop
, ::GetHeapProfile
));
440 base::trace_event::MemoryDumpManager::GetInstance()->Initialize();
442 shared_bitmap_manager_
.reset(
443 new ChildSharedBitmapManager(thread_safe_sender()));
445 gpu_memory_buffer_manager_
.reset(
446 new ChildGpuMemoryBufferManager(thread_safe_sender()));
448 discardable_shared_memory_manager_
.reset(
449 new ChildDiscardableSharedMemoryManager(thread_safe_sender()));
452 ChildThreadImpl::~ChildThreadImpl() {
453 // ChildDiscardableSharedMemoryManager has to be destroyed while
454 // |thread_safe_sender_| is still valid.
455 discardable_shared_memory_manager_
.reset();
457 #ifdef IPC_MESSAGE_LOG_ENABLED
458 IPC::Logging::GetInstance()->SetIPCSender(NULL
);
461 channel_
->RemoveFilter(histogram_message_filter_
.get());
462 channel_
->RemoveFilter(sync_message_filter_
.get());
464 // The ChannelProxy object caches a pointer to the IPC thread, so need to
465 // reset it as it's not guaranteed to outlive this object.
466 // NOTE: this also has the side-effect of not closing the main IPC channel to
467 // the browser process. This is needed because this is the signal that the
468 // browser uses to know that this process has died, so we need it to be alive
469 // until this process is shut down, and the OS closes the handle
470 // automatically. We used to watch the object handle on Windows to do this,
471 // but it wasn't possible to do so on POSIX.
472 channel_
->ClearIPCTaskRunner();
473 g_lazy_tls
.Pointer()->Set(NULL
);
476 void ChildThreadImpl::Shutdown() {
477 // Delete objects that hold references to blink so derived classes can
478 // safely shutdown blink in their Shutdown implementation.
479 file_system_dispatcher_
.reset();
480 quota_dispatcher_
.reset();
481 WebFileSystemImpl::DeleteThreadSpecificInstance();
484 void ChildThreadImpl::OnChannelConnected(int32 peer_pid
) {
485 channel_connected_factory_
.InvalidateWeakPtrs();
488 void ChildThreadImpl::OnChannelError() {
489 set_on_channel_error_called(true);
490 base::MessageLoop::current()->Quit();
493 bool ChildThreadImpl::Send(IPC::Message
* msg
) {
494 DCHECK(base::MessageLoop::current() == message_loop());
500 return channel_
->Send(msg
);
504 void ChildThreadImpl::PreCacheFont(const LOGFONT
& log_font
) {
505 Send(new ChildProcessHostMsg_PreCacheFont(log_font
));
508 void ChildThreadImpl::ReleaseCachedFonts() {
509 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
513 MessageRouter
* ChildThreadImpl::GetRouter() {
514 DCHECK(base::MessageLoop::current() == message_loop());
518 scoped_ptr
<base::SharedMemory
> ChildThreadImpl::AllocateSharedMemory(
520 DCHECK(base::MessageLoop::current() == message_loop());
521 return AllocateSharedMemory(buf_size
, this);
525 scoped_ptr
<base::SharedMemory
> ChildThreadImpl::AllocateSharedMemory(
527 IPC::Sender
* sender
) {
528 scoped_ptr
<base::SharedMemory
> shared_buf
;
530 shared_buf
.reset(new base::SharedMemory
);
531 if (!shared_buf
->CreateAnonymous(buf_size
)) {
536 // On POSIX, we need to ask the browser to create the shared memory for us,
537 // since this is blocked by the sandbox.
538 base::SharedMemoryHandle shared_mem_handle
;
539 if (sender
->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory(
540 buf_size
, &shared_mem_handle
))) {
541 if (base::SharedMemory::IsHandleValid(shared_mem_handle
)) {
542 shared_buf
.reset(new base::SharedMemory(shared_mem_handle
, false));
544 NOTREACHED() << "Browser failed to allocate shared memory";
548 NOTREACHED() << "Browser allocation request message failed";
555 bool ChildThreadImpl::OnMessageReceived(const IPC::Message
& msg
) {
556 if (mojo_application_
->OnMessageReceived(msg
))
559 // Resource responses are sent to the resource dispatcher.
560 if (resource_dispatcher_
->OnMessageReceived(msg
))
562 if (websocket_dispatcher_
->OnMessageReceived(msg
))
564 if (file_system_dispatcher_
->OnMessageReceived(msg
))
568 IPC_BEGIN_MESSAGE_MAP(ChildThreadImpl
, msg
)
569 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown
, OnShutdown
)
570 #if defined(IPC_MESSAGE_LOG_ENABLED)
571 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled
,
572 OnSetIPCLoggingEnabled
)
574 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus
,
576 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData
,
577 OnGetChildProfilerData
)
578 IPC_MESSAGE_HANDLER(ChildProcessMsg_ProfilingPhaseCompleted
,
579 OnProfilingPhaseCompleted
)
580 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProcessBackgrounded
,
581 OnProcessBackgrounded
)
582 #if defined(USE_TCMALLOC)
583 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetTcmallocStats
, OnGetTcmallocStats
)
585 #if defined(OS_MACOSX)
586 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIOSurfaceManagerToken
,
587 OnSetIOSurfaceManagerToken
)
589 IPC_MESSAGE_UNHANDLED(handled
= false)
590 IPC_END_MESSAGE_MAP()
595 if (msg
.routing_id() == MSG_ROUTING_CONTROL
)
596 return OnControlMessageReceived(msg
);
598 return router_
.OnMessageReceived(msg
);
601 bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message
& msg
) {
605 void ChildThreadImpl::OnShutdown() {
606 base::MessageLoop::current()->Quit();
609 #if defined(IPC_MESSAGE_LOG_ENABLED)
610 void ChildThreadImpl::OnSetIPCLoggingEnabled(bool enable
) {
612 IPC::Logging::GetInstance()->Enable();
614 IPC::Logging::GetInstance()->Disable();
616 #endif // IPC_MESSAGE_LOG_ENABLED
618 void ChildThreadImpl::OnSetProfilerStatus(ThreadData::Status status
) {
619 ThreadData::InitializeAndSetTrackingStatus(status
);
622 void ChildThreadImpl::OnGetChildProfilerData(int sequence_number
,
623 int current_profiling_phase
) {
624 tracked_objects::ProcessDataSnapshot process_data
;
625 ThreadData::Snapshot(current_profiling_phase
, &process_data
);
628 new ChildProcessHostMsg_ChildProfilerData(sequence_number
, process_data
));
631 void ChildThreadImpl::OnProfilingPhaseCompleted(int profiling_phase
) {
632 ThreadData::OnProfilingPhaseCompleted(profiling_phase
);
635 #if defined(USE_TCMALLOC)
636 void ChildThreadImpl::OnGetTcmallocStats() {
638 char buffer
[1024 * 32];
639 base::allocator::GetStats(buffer
, sizeof(buffer
));
640 result
.append(buffer
);
641 Send(new ChildProcessHostMsg_TcmallocStats(result
));
645 #if defined(OS_MACOSX)
646 void ChildThreadImpl::OnSetIOSurfaceManagerToken(
647 const IOSurfaceManagerToken
& token
) {
648 ChildIOSurfaceManager::GetInstance()->set_token(token
);
652 ChildThreadImpl
* ChildThreadImpl::current() {
653 return g_lazy_tls
.Pointer()->Get();
656 #if defined(OS_ANDROID)
657 // The method must NOT be called on the child thread itself.
658 // It may block the child thread if so.
659 void ChildThreadImpl::ShutdownThread() {
660 DCHECK(!ChildThreadImpl::current()) <<
661 "this method should NOT be called from child thread itself";
662 g_quit_closure
.Get().PostQuitFromNonMainThread();
666 void ChildThreadImpl::OnProcessFinalRelease() {
667 if (on_channel_error_called_
) {
668 base::MessageLoop::current()->Quit();
672 // The child process shutdown sequence is a request response based mechanism,
673 // where we send out an initial feeler request to the child process host
674 // instance in the browser to verify if it's ok to shutdown the child process.
675 // The browser then sends back a response if it's ok to shutdown. This avoids
676 // race conditions if the process refcount is 0 but there's an IPC message
677 // inflight that would addref it.
678 Send(new ChildProcessHostMsg_ShutdownRequest
);
681 void ChildThreadImpl::EnsureConnected() {
682 VLOG(0) << "ChildThreadImpl::EnsureConnected()";
683 base::Process::Current().Terminate(0, false);
686 bool ChildThreadImpl::IsInBrowserProcess() const {
687 return browser_process_io_runner_
;
690 void ChildThreadImpl::OnProcessBackgrounded(bool background
) {
691 // Set timer slack to maximum on main thread when in background.
692 base::TimerSlack timer_slack
= base::TIMER_SLACK_NONE
;
694 timer_slack
= base::TIMER_SLACK_MAXIMUM
;
695 base::MessageLoop::current()->SetTimerSlack(timer_slack
);
698 } // namespace content