Chromium Code Reviews| 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_process.h" | 5 #include "content/child/child_process.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | |
| 10 #include "base/command_line.h" | |
| 9 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/statistics_recorder.h" | 13 #include "base/metrics/statistics_recorder.h" |
| 12 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 13 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 17 #include "base/threading/thread_local.h" | 19 #include "base/threading/thread_local.h" |
| 18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 19 #include "content/child/child_thread_impl.h" | 21 #include "content/child/child_thread_impl.h" |
| 22 #include "content/public/common/content_switches.h" | |
| 20 | 23 |
| 21 #if defined(OS_ANDROID) | 24 #if defined(OS_ANDROID) |
| 22 #include "base/debug/debugger.h" | 25 #include "base/debug/debugger.h" |
| 23 #endif | 26 #endif |
| 24 | 27 |
| 25 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 28 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 26 #include <signal.h> | 29 #include <signal.h> |
| 27 static void SigUSR1Handler(int signal) { } | 30 static void SigUSR1Handler(int signal) { } |
| 28 #endif | 31 #endif |
| 29 | 32 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 60 | 63 |
| 61 ChildProcess::~ChildProcess() { | 64 ChildProcess::~ChildProcess() { |
| 62 DCHECK(g_lazy_tls.Pointer()->Get() == this); | 65 DCHECK(g_lazy_tls.Pointer()->Get() == this); |
| 63 | 66 |
| 64 // Signal this event before destroying the child process. That way all | 67 // Signal this event before destroying the child process. That way all |
| 65 // background threads can cleanup. | 68 // background threads can cleanup. |
| 66 // For example, in the renderer the RenderThread instances will be able to | 69 // For example, in the renderer the RenderThread instances will be able to |
| 67 // notice shutdown before the render process begins waiting for them to exit. | 70 // notice shutdown before the render process begins waiting for them to exit. |
| 68 shutdown_event_.Signal(); | 71 shutdown_event_.Signal(); |
| 69 | 72 |
| 70 // Kill the main thread object before nulling child_process, since | |
| 71 // destruction code might depend on it. | |
| 72 if (main_thread_) { // null in unittests. | 73 if (main_thread_) { // null in unittests. |
| 73 main_thread_->Shutdown(); | 74 if (main_thread_->IsRenderThread()) { |
|
jochen (gone - plz use gerrit)
2017/01/11 12:26:25
why not do this work in RenderThreadImpl::Shutdown
Torne
2017/01/11 12:50:58
If there's a good way to do that it seems like a g
haraken
2017/01/11 12:52:25
Because we need to call main_thread_.release(). It
jochen (gone - plz use gerrit)
2017/01/11 12:52:59
Shutdown() could return an enum indicating what to
| |
| 74 main_thread_.reset(); | 75 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 76 switches::kSingleProcess)) { | |
| 77 // In a multi-process mode, we immediately exit the renderer. | |
| 78 // Historically we had a graceful shutdown sequence here but it was | |
| 79 // 1) a waste of performance and 2) a source of lots of complicated | |
| 80 // crashes caused by shutdown ordering. Immediate exit eliminates | |
| 81 // those problems. | |
| 82 _exit(0); | |
| 83 } else { | |
| 84 // In a single-process mode, we cannot call _exit(0) here because | |
| 85 // it will exit the process before the browser side is ready to exit. | |
| 86 // On the other hand, we cannot call main_thread_.reset() because | |
| 87 // it is unsafe to destruct main_thread_ without shutting down the | |
| 88 // main_thread_ (we no longer have the shutdown sequence). Hence we | |
| 89 // leak main_thread_. | |
| 90 // | |
| 91 // Then we need to disable at-exit callbacks because some of the | |
| 92 // at-exit callbacks are expected to run after main_thread_ has been | |
| 93 // destructed. | |
| 94 base::AtExitManager::DisableAllAtExitManagers(); | |
|
jochen (gone - plz use gerrit)
2017/01/11 12:26:25
won't that disable at exit managers for stuff that
Torne
2017/01/11 12:50:58
Yes. The assumption is that as the only shipping c
haraken
2017/01/11 12:52:25
You're right. Ideally we should stop calling at-ex
| |
| 95 main_thread_.release(); | |
| 96 } | |
| 97 } else { | |
| 98 main_thread_->Shutdown(); | |
| 99 main_thread_.reset(); | |
| 100 } | |
| 75 } | 101 } |
| 76 | 102 |
| 77 g_lazy_tls.Pointer()->Set(NULL); | 103 g_lazy_tls.Pointer()->Set(NULL); |
| 78 io_thread_.Stop(); | 104 io_thread_.Stop(); |
| 79 } | 105 } |
| 80 | 106 |
| 81 ChildThreadImpl* ChildProcess::main_thread() { | 107 ChildThreadImpl* ChildProcess::main_thread() { |
| 82 return main_thread_.get(); | 108 return main_thread_.get(); |
| 83 } | 109 } |
| 84 | 110 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 memset(&sa, 0, sizeof(sa)); | 178 memset(&sa, 0, sizeof(sa)); |
| 153 sa.sa_handler = SigUSR1Handler; | 179 sa.sa_handler = SigUSR1Handler; |
| 154 sigaction(SIGUSR1, &sa, NULL); | 180 sigaction(SIGUSR1, &sa, NULL); |
| 155 | 181 |
| 156 pause(); | 182 pause(); |
| 157 #endif // defined(OS_ANDROID) | 183 #endif // defined(OS_ANDROID) |
| 158 #endif // defined(OS_POSIX) | 184 #endif // defined(OS_POSIX) |
| 159 } | 185 } |
| 160 | 186 |
| 161 } // namespace content | 187 } // namespace content |
| OLD | NEW |