| 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.h" | 5 #include "content/child/child_thread.h" |
| 6 | 6 |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // A non joinable thread has been created. The thread will either terminate | 104 // A non joinable thread has been created. The thread will either terminate |
| 105 // the process or will be terminated by the process. Therefore, keep the | 105 // the process or will be terminated by the process. Therefore, keep the |
| 106 // delegate object alive for the lifetime of the process. | 106 // delegate object alive for the lifetime of the process. |
| 107 WaitAndExitDelegate* leaking_delegate = delegate.release(); | 107 WaitAndExitDelegate* leaking_delegate = delegate.release(); |
| 108 ANNOTATE_LEAKING_OBJECT_PTR(leaking_delegate); | 108 ANNOTATE_LEAKING_OBJECT_PTR(leaking_delegate); |
| 109 ignore_result(leaking_delegate); | 109 ignore_result(leaking_delegate); |
| 110 return true; | 110 return true; |
| 111 } | 111 } |
| 112 #endif | 112 #endif |
| 113 | 113 |
| 114 class SuicideOnChannelErrorFilter : public IPC::MessageFilter { | 114 class SuicideOnSenderErrorFilter : public IPC::MessageFilter { |
| 115 public: | 115 public: |
| 116 // IPC::MessageFilter | 116 // IPC::MessageFilter |
| 117 virtual void OnChannelError() OVERRIDE { | 117 virtual void OnSenderError() OVERRIDE { |
| 118 // For renderer/worker processes: | 118 // For renderer/worker processes: |
| 119 // On POSIX, at least, one can install an unload handler which loops | 119 // On POSIX, at least, one can install an unload handler which loops |
| 120 // forever and leave behind a renderer process which eats 100% CPU forever. | 120 // forever and leave behind a renderer process which eats 100% CPU forever. |
| 121 // | 121 // |
| 122 // This is because the terminate signals (ViewMsg_ShouldClose and the error | 122 // This is because the terminate signals (ViewMsg_ShouldClose and the error |
| 123 // from the IPC channel) are routed to the main message loop but never | 123 // from the IPC sender) are routed to the main message loop but never |
| 124 // processed (because that message loop is stuck in V8). | 124 // processed (because that message loop is stuck in V8). |
| 125 // | 125 // |
| 126 // One could make the browser SIGKILL the renderers, but that leaves open a | 126 // One could make the browser SIGKILL the renderers, but that leaves open a |
| 127 // large window where a browser failure (or a user, manually terminating | 127 // large window where a browser failure (or a user, manually terminating |
| 128 // the browser because "it's stuck") will leave behind a process eating all | 128 // the browser because "it's stuck") will leave behind a process eating all |
| 129 // the CPU. | 129 // the CPU. |
| 130 // | 130 // |
| 131 // So, we install a filter on the channel so that we can process this event | 131 // So, we install a filter on the sender so that we can process this event |
| 132 // here and kill the process. | 132 // here and kill the process. |
| 133 // TODO(earthdok): Re-enable on CrOS http://crbug.com/360622 | 133 // TODO(earthdok): Re-enable on CrOS http://crbug.com/360622 |
| 134 #if (defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ | 134 #if (defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 135 defined(THREAD_SANITIZER)) && !defined(OS_CHROMEOS) | 135 defined(THREAD_SANITIZER)) && !defined(OS_CHROMEOS) |
| 136 // Some sanitizer tools rely on exit handlers (e.g. to run leak detection, | 136 // Some sanitizer tools rely on exit handlers (e.g. to run leak detection, |
| 137 // or dump code coverage data to disk). Instead of exiting the process | 137 // or dump code coverage data to disk). Instead of exiting the process |
| 138 // immediately, we give it 60 seconds to run exit handlers. | 138 // immediately, we give it 60 seconds to run exit handlers. |
| 139 CHECK(CreateWaitAndExitThread(base::TimeDelta::FromSeconds(60))); | 139 CHECK(CreateWaitAndExitThread(base::TimeDelta::FromSeconds(60))); |
| 140 #if defined(LEAK_SANITIZER) | 140 #if defined(LEAK_SANITIZER) |
| 141 // Invoke LeakSanitizer early to avoid detecting shutdown-only leaks. If | 141 // Invoke LeakSanitizer early to avoid detecting shutdown-only leaks. If |
| 142 // leaks are found, the process will exit here. | 142 // leaks are found, the process will exit here. |
| 143 __lsan_do_leak_check(); | 143 __lsan_do_leak_check(); |
| 144 #endif | 144 #endif |
| 145 #else | 145 #else |
| 146 _exit(0); | 146 _exit(0); |
| 147 #endif | 147 #endif |
| 148 } | 148 } |
| 149 | 149 |
| 150 protected: | 150 protected: |
| 151 virtual ~SuicideOnChannelErrorFilter() {} | 151 virtual ~SuicideOnSenderErrorFilter() {} |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 #endif // OS(POSIX) | 154 #endif // OS(POSIX) |
| 155 | 155 |
| 156 #if defined(OS_ANDROID) | 156 #if defined(OS_ANDROID) |
| 157 ChildThread* g_child_thread = NULL; | 157 ChildThread* g_child_thread = NULL; |
| 158 | 158 |
| 159 // A lock protects g_child_thread. | 159 // A lock protects g_child_thread. |
| 160 base::LazyInstance<base::Lock> g_lazy_child_thread_lock = | 160 base::LazyInstance<base::Lock> g_lazy_child_thread_lock = |
| 161 LAZY_INSTANCE_INITIALIZER; | 161 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 channel_->AddFilter(power_monitor_source->GetMessageFilter()); | 279 channel_->AddFilter(power_monitor_source->GetMessageFilter()); |
| 280 | 280 |
| 281 power_monitor_.reset(new base::PowerMonitor( | 281 power_monitor_.reset(new base::PowerMonitor( |
| 282 power_monitor_source.PassAs<base::PowerMonitorSource>())); | 282 power_monitor_source.PassAs<base::PowerMonitorSource>())); |
| 283 } | 283 } |
| 284 | 284 |
| 285 #if defined(OS_POSIX) | 285 #if defined(OS_POSIX) |
| 286 // Check that --process-type is specified so we don't do this in unit tests | 286 // Check that --process-type is specified so we don't do this in unit tests |
| 287 // and single-process mode. | 287 // and single-process mode. |
| 288 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) | 288 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) |
| 289 channel_->AddFilter(new SuicideOnChannelErrorFilter()); | 289 channel_->AddFilter(new SuicideOnSenderErrorFilter()); |
| 290 #endif | 290 #endif |
| 291 | 291 |
| 292 base::MessageLoop::current()->PostDelayedTask( | 292 base::MessageLoop::current()->PostDelayedTask( |
| 293 FROM_HERE, | 293 FROM_HERE, |
| 294 base::Bind(&ChildThread::EnsureConnected, | 294 base::Bind(&ChildThread::EnsureConnected, |
| 295 channel_connected_factory_.GetWeakPtr()), | 295 channel_connected_factory_.GetWeakPtr()), |
| 296 base::TimeDelta::FromSeconds(kConnectionTimeoutS)); | 296 base::TimeDelta::FromSeconds(kConnectionTimeoutS)); |
| 297 | 297 |
| 298 #if defined(OS_ANDROID) | 298 #if defined(OS_ANDROID) |
| 299 { | 299 { |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 561 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
| 562 | 562 |
| 563 #ifdef OS_WIN | 563 #ifdef OS_WIN |
| 564 // Windows Vista+ has a fancy process backgrounding mode that can only be set | 564 // Windows Vista+ has a fancy process backgrounding mode that can only be set |
| 565 // from within the process. | 565 // from within the process. |
| 566 base::Process::Current().SetProcessBackgrounded(background); | 566 base::Process::Current().SetProcessBackgrounded(background); |
| 567 #endif // OS_WIN | 567 #endif // OS_WIN |
| 568 } | 568 } |
| 569 | 569 |
| 570 } // namespace content | 570 } // namespace content |
| OLD | NEW |