[content shell] hook up testRunner.dumpEditingCallbacks
[chromium-blink-merge.git] / content / worker / worker_main.cc
blobf6b2b2020b683760c6a29750611a56e8f3d7f809
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/string_util.h"
10 #include "base/system_monitor/system_monitor.h"
11 #include "base/threading/platform_thread.h"
12 #include "content/common/child_process.h"
13 #include "content/public/common/main_function_params.h"
14 #include "content/public/common/sandbox_init.h"
15 #include "content/worker/worker_thread.h"
17 #if defined(OS_WIN)
18 #include "sandbox/win/src/sandbox.h"
19 #endif
21 namespace content {
23 // Mainline routine for running as the worker process.
24 int WorkerMain(const MainFunctionParams& parameters) {
25 // The main message loop of the worker process.
26 MessageLoop main_message_loop;
27 base::PlatformThread::SetName("CrWorkerMain");
29 base::SystemMonitor system_monitor;
30 HighResolutionTimerManager hi_res_timer_manager;
32 #if defined(OS_WIN)
33 sandbox::TargetServices* target_services =
34 parameters.sandbox_info->target_services;
35 if (!target_services)
36 return false;
38 // Cause advapi32 to load before the sandbox is turned on.
39 unsigned int dummy_rand;
40 rand_s(&dummy_rand);
41 // Warm up language subsystems before the sandbox is turned on.
42 ::GetUserDefaultLangID();
43 ::GetUserDefaultLCID();
45 target_services->LowerToken();
46 #elif defined(OS_MAC)
47 // On OS X, if the sandbox fails to initialize, something has gone terribly
48 // wrong and we should die.
49 CHECK(InitializeSandbox());
50 #elif defined(OS_LINUX)
51 // On Linux, the sandbox must be initialized early, before any thread is
52 // created.
53 InitializeSandbox();
54 #endif
56 ChildProcess worker_process;
57 worker_process.set_main_thread(new WorkerThread());
59 const CommandLine& parsed_command_line = parameters.command_line;
60 if (parsed_command_line.HasSwitch(switches::kWaitForDebugger)) {
61 ChildProcess::WaitForDebugger("Worker");
64 // Load the accelerator table from the browser executable and tell the
65 // message loop to use it when translating messages.
66 MessageLoop::current()->Run();
68 return 0;
71 } // namespace content