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