OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/base_switches.h" | 5 #include "base/base_switches.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/power_monitor/power_monitor.h" | |
9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
10 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
11 #include "base/timer/hi_res_timer_manager.h" | 10 #include "base/timer/hi_res_timer_manager.h" |
12 #include "content/child/child_process.h" | 11 #include "content/child/child_process.h" |
13 #include "content/common/sandbox_linux.h" | 12 #include "content/common/sandbox_linux.h" |
14 #include "content/public/common/main_function_params.h" | 13 #include "content/public/common/main_function_params.h" |
15 #include "content/public/common/sandbox_init.h" | 14 #include "content/public/common/sandbox_init.h" |
16 #include "content/worker/worker_thread.h" | 15 #include "content/worker/worker_thread.h" |
17 | 16 |
18 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
19 #include "sandbox/win/src/sandbox.h" | 18 #include "sandbox/win/src/sandbox.h" |
20 #endif | 19 #endif |
21 | 20 |
22 #if defined(OS_MACOSX) | 21 #if defined(OS_MACOSX) |
23 #include "content/common/sandbox_mac.h" | 22 #include "content/common/sandbox_mac.h" |
24 #endif | 23 #endif |
25 | 24 |
26 namespace content { | 25 namespace content { |
27 | 26 |
28 // Mainline routine for running as the worker process. | 27 // Mainline routine for running as the worker process. |
29 int WorkerMain(const MainFunctionParams& parameters) { | 28 int WorkerMain(const MainFunctionParams& parameters) { |
30 // The main message loop of the worker process. | 29 // The main message loop of the worker process. |
31 base::MessageLoop main_message_loop; | 30 base::MessageLoop main_message_loop; |
32 base::PlatformThread::SetName("CrWorkerMain"); | 31 base::PlatformThread::SetName("CrWorkerMain"); |
33 | 32 |
34 base::PowerMonitor power_monitor; | |
35 base::HighResolutionTimerManager hi_res_timer_manager; | |
36 | |
37 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
38 sandbox::TargetServices* target_services = | 34 sandbox::TargetServices* target_services = |
39 parameters.sandbox_info->target_services; | 35 parameters.sandbox_info->target_services; |
40 if (!target_services) | 36 if (!target_services) |
41 return false; | 37 return false; |
42 | 38 |
43 // Cause advapi32 to load before the sandbox is turned on. | 39 // Cause advapi32 to load before the sandbox is turned on. |
44 unsigned int dummy_rand; | 40 unsigned int dummy_rand; |
45 rand_s(&dummy_rand); | 41 rand_s(&dummy_rand); |
46 // Warm up language subsystems before the sandbox is turned on. | 42 // Warm up language subsystems before the sandbox is turned on. |
47 ::GetUserDefaultLangID(); | 43 ::GetUserDefaultLangID(); |
48 ::GetUserDefaultLCID(); | 44 ::GetUserDefaultLCID(); |
49 | 45 |
50 target_services->LowerToken(); | 46 target_services->LowerToken(); |
51 #elif defined(OS_MACOSX) | 47 #elif defined(OS_MACOSX) |
52 // Sandbox should already be activated at this point. | 48 // Sandbox should already be activated at this point. |
53 CHECK(Sandbox::SandboxIsCurrentlyActive()); | 49 CHECK(Sandbox::SandboxIsCurrentlyActive()); |
54 #elif defined(OS_LINUX) | 50 #elif defined(OS_LINUX) |
55 // On Linux, the sandbox must be initialized early, before any thread is | 51 // On Linux, the sandbox must be initialized early, before any thread is |
56 // created. | 52 // created. |
57 LinuxSandbox::InitializeSandbox(); | 53 LinuxSandbox::InitializeSandbox(); |
58 #endif | 54 #endif |
59 | 55 |
60 ChildProcess worker_process; | 56 ChildProcess worker_process; |
61 worker_process.set_main_thread(new WorkerThread()); | 57 worker_process.set_main_thread(new WorkerThread()); |
62 | 58 |
| 59 base::HighResolutionTimerManager hi_res_timer_manager; |
| 60 |
63 const CommandLine& parsed_command_line = parameters.command_line; | 61 const CommandLine& parsed_command_line = parameters.command_line; |
64 if (parsed_command_line.HasSwitch(switches::kWaitForDebugger)) { | 62 if (parsed_command_line.HasSwitch(switches::kWaitForDebugger)) { |
65 ChildProcess::WaitForDebugger("Worker"); | 63 ChildProcess::WaitForDebugger("Worker"); |
66 } | 64 } |
67 | 65 |
68 // Load the accelerator table from the browser executable and tell the | 66 // Load the accelerator table from the browser executable and tell the |
69 // message loop to use it when translating messages. | 67 // message loop to use it when translating messages. |
70 base::MessageLoop::current()->Run(); | 68 base::MessageLoop::current()->Run(); |
71 | 69 |
72 return 0; | 70 return 0; |
73 } | 71 } |
74 | 72 |
75 } // namespace content | 73 } // namespace content |
OLD | NEW |