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
3 // found in the LICENSE file.
5 #include "base/base_switches.h"
6 #include "base/command_line.h"
7 #include "base/hi_res_timer_manager.h"
8 #include "base/message_loop.h"
9 #include "base/power_monitor/power_monitor.h"
10 #include "base/strings/string_util.h"
11 #include "base/threading/platform_thread.h"
12 #include "content/child/child_process.h"
13 #include "content/common/sandbox_linux.h"
14 #include "content/public/common/main_function_params.h"
15 #include "content/public/common/sandbox_init.h"
16 #include "content/worker/worker_thread.h"
19 #include "sandbox/win/src/sandbox.h"
22 #if defined(OS_MACOSX)
23 #include "content/common/sandbox_mac.h"
28 // Mainline routine for running as the worker process.
29 int WorkerMain(const MainFunctionParams
& parameters
) {
30 // The main message loop of the worker process.
31 base::MessageLoop main_message_loop
;
32 base::PlatformThread::SetName("CrWorkerMain");
34 base::PowerMonitor power_monitor
;
35 HighResolutionTimerManager hi_res_timer_manager
;
38 sandbox::TargetServices
* target_services
=
39 parameters
.sandbox_info
->target_services
;
43 // Cause advapi32 to load before the sandbox is turned on.
44 unsigned int dummy_rand
;
46 // Warm up language subsystems before the sandbox is turned on.
47 ::GetUserDefaultLangID();
48 ::GetUserDefaultLCID();
50 target_services
->LowerToken();
51 #elif defined(OS_MACOSX)
52 // Sandbox should already be activated at this point.
53 CHECK(Sandbox::SandboxIsCurrentlyActive());
54 #elif defined(OS_LINUX)
55 // On Linux, the sandbox must be initialized early, before any thread is
57 LinuxSandbox::InitializeSandbox();
60 ChildProcess worker_process
;
61 worker_process
.set_main_thread(new WorkerThread());
63 const CommandLine
& parsed_command_line
= parameters
.command_line
;
64 if (parsed_command_line
.HasSwitch(switches::kWaitForDebugger
)) {
65 ChildProcess::WaitForDebugger("Worker");
68 // Load the accelerator table from the browser executable and tell the
69 // message loop to use it when translating messages.
70 base::MessageLoop::current()->Run();
75 } // namespace content