| 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/common/child_process.h" | 5 #include "content/common/child_process.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 7 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 8 #include <signal.h> // For SigUSR1Handler below. | 8 #include <signal.h> // For SigUSR1Handler below. |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/metrics/statistics_recorder.h" | 12 #include "base/metrics/statistics_recorder.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "content/common/child_thread.h" | 17 #include "content/common/child_thread.h" |
| 18 | 18 |
| 19 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
| 20 #include "base/debug/debugger.h" | 20 #include "base/debug/debugger.h" |
| 21 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 22 #include <sys/resource.h> |
| 21 #endif | 23 #endif |
| 22 | 24 |
| 23 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 25 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 24 static void SigUSR1Handler(int signal) { } | 26 static void SigUSR1Handler(int signal) { } |
| 25 #endif | 27 #endif |
| 26 | 28 |
| 27 namespace content { | 29 namespace content { |
| 28 | 30 |
| 29 ChildProcess* ChildProcess::child_process_; | 31 ChildProcess* ChildProcess::child_process_; |
| 30 | 32 |
| 33 #if defined(OS_ANDROID) |
| 34 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 35 namespace { |
| 36 void SetHighThreadPriority() { |
| 37 int nice_value = -6; // High priority. |
| 38 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); |
| 39 } |
| 40 } |
| 41 #endif |
| 42 |
| 31 ChildProcess::ChildProcess() | 43 ChildProcess::ChildProcess() |
| 32 : ref_count_(0), | 44 : ref_count_(0), |
| 33 shutdown_event_(true, false), | 45 shutdown_event_(true, false), |
| 34 io_thread_("Chrome_ChildIOThread") { | 46 io_thread_("Chrome_ChildIOThread") { |
| 35 DCHECK(!child_process_); | 47 DCHECK(!child_process_); |
| 36 child_process_ = this; | 48 child_process_ = this; |
| 37 | 49 |
| 38 base::StatisticsRecorder::Initialize(); | 50 base::StatisticsRecorder::Initialize(); |
| 39 | 51 |
| 40 // We can't recover from failing to start the IO thread. | 52 // We can't recover from failing to start the IO thread. |
| 41 CHECK(io_thread_.StartWithOptions( | 53 CHECK(io_thread_.StartWithOptions( |
| 42 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 54 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 55 |
| 56 #if defined(OS_ANDROID) |
| 57 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 58 io_thread_.message_loop()->PostTask(FROM_HERE, |
| 59 base::Bind(&SetHighThreadPriority)); |
| 60 #endif |
| 43 } | 61 } |
| 44 | 62 |
| 45 ChildProcess::~ChildProcess() { | 63 ChildProcess::~ChildProcess() { |
| 46 DCHECK(child_process_ == this); | 64 DCHECK(child_process_ == this); |
| 47 | 65 |
| 48 // Signal this event before destroying the child process. That way all | 66 // Signal this event before destroying the child process. That way all |
| 49 // background threads can cleanup. | 67 // background threads can cleanup. |
| 50 // For example, in the renderer the RenderThread instances will be able to | 68 // For example, in the renderer the RenderThread instances will be able to |
| 51 // notice shutdown before the render process begins waiting for them to exit. | 69 // notice shutdown before the render process begins waiting for them to exit. |
| 52 shutdown_event_.Signal(); | 70 shutdown_event_.Signal(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 memset(&sa, 0, sizeof(sa)); | 139 memset(&sa, 0, sizeof(sa)); |
| 122 sa.sa_handler = SigUSR1Handler; | 140 sa.sa_handler = SigUSR1Handler; |
| 123 sigaction(SIGUSR1, &sa, NULL); | 141 sigaction(SIGUSR1, &sa, NULL); |
| 124 | 142 |
| 125 pause(); | 143 pause(); |
| 126 #endif // defined(OS_ANDROID) | 144 #endif // defined(OS_ANDROID) |
| 127 #endif // defined(OS_POSIX) | 145 #endif // defined(OS_POSIX) |
| 128 } | 146 } |
| 129 | 147 |
| 130 } // namespace content | 148 } // namespace content |
| OLD | NEW |