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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/debug/leak_annotations.h" | 6 #include "base/debug/leak_annotations.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "base/timer/hi_res_timer_manager.h" | 10 #include "base/timer/hi_res_timer_manager.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "content/child/child_process.h" | 12 #include "content/child/child_process.h" |
13 #include "content/common/sandbox_linux/sandbox_linux.h" | 13 #include "content/common/sandbox_linux/sandbox_linux.h" |
14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
15 #include "content/public/common/main_function_params.h" | 15 #include "content/public/common/main_function_params.h" |
16 #include "content/public/common/mojo_channel_switches.h" | |
16 #include "content/public/common/sandbox_init.h" | 17 #include "content/public/common/sandbox_init.h" |
17 #include "content/utility/utility_thread_impl.h" | 18 #include "content/utility/utility_thread_impl.h" |
18 | 19 |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
21 #include "sandbox/win/src/sandbox.h" | 22 #include "sandbox/win/src/sandbox.h" |
22 #endif | 23 #endif |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 // Mainline routine for running as the utility process. | 27 // Mainline routine for running as the utility process. |
27 int UtilityMain(const MainFunctionParams& parameters) { | 28 int UtilityMain(const MainFunctionParams& parameters) { |
28 // The main message loop of the utility process. | 29 // The main message loop of the utility process. |
29 base::MessageLoop main_message_loop; | 30 base::MessageLoop main_message_loop; |
30 base::PlatformThread::SetName("CrUtilityMain"); | 31 base::PlatformThread::SetName("CrUtilityMain"); |
31 | 32 |
32 #if defined(OS_LINUX) | 33 #if defined(OS_LINUX) |
33 // Initializes the sandbox before any threads are created. | 34 // Initializes the sandbox before any threads are created. |
34 // TODO(jorgelo): move this after GTK initialization when we enable a strict | 35 // TODO(jorgelo): move this after GTK initialization when we enable a strict |
35 // Seccomp-BPF policy. | 36 // Seccomp-BPF policy. |
36 if (parameters.zygote_child) | 37 if (parameters.zygote_child) |
37 LinuxSandbox::InitializeSandbox(); | 38 LinuxSandbox::InitializeSandbox(); |
38 #endif | 39 #endif |
39 | 40 |
40 ChildProcess utility_process; | 41 ChildProcess utility_process; |
41 utility_process.set_main_thread(new UtilityThreadImpl()); | 42 utility_process.set_main_thread(new UtilityThreadImpl()); |
42 | 43 |
43 base::HighResolutionTimerManager hi_res_timer_manager; | 44 // TODO(leonhsl): Both utility process and service utility process would come |
45 // here, but the later is launched without connection to service manager. | |
46 // However, service manager connection is necessary for instantiation of the | |
47 // process-wide base::PowerMonitor, which is further necessary to | |
48 // base::HighResolutionTimerManager. So in case of service utility process, we | |
49 // disable base::HighResolutionTimerManager for now, until we resolved | |
50 // http://crbug.com/646833. | |
51 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
52 switches::kServiceRequestChannelToken)) | |
Vitaly Buka (NO REVIEWS)
2017/01/18 19:07:50
Please add {}
Vitaly Buka (NO REVIEWS)
2017/01/19 04:25:35
Probably you can just base::HighResolutionTimerMan
leonhsl(Using Gerrit)
2017/01/19 07:06:44
I suppose the comment above means that we can just
| |
53 base::HighResolutionTimerManager hi_res_timer_manager; | |
44 | 54 |
45 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
46 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); | 56 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); |
47 if (!no_sandbox) { | 57 if (!no_sandbox) { |
48 sandbox::TargetServices* target_services = | 58 sandbox::TargetServices* target_services = |
49 parameters.sandbox_info->target_services; | 59 parameters.sandbox_info->target_services; |
50 if (!target_services) | 60 if (!target_services) |
51 return false; | 61 return false; |
52 char buffer; | 62 char buffer; |
53 // Ensure RtlGenRandom is warm before the token is lowered; otherwise, | 63 // Ensure RtlGenRandom is warm before the token is lowered; otherwise, |
54 // base::RandBytes() will CHECK fail when v8 is initialized. | 64 // base::RandBytes() will CHECK fail when v8 is initialized. |
55 base::RandBytes(&buffer, sizeof(buffer)); | 65 base::RandBytes(&buffer, sizeof(buffer)); |
56 target_services->LowerToken(); | 66 target_services->LowerToken(); |
57 } | 67 } |
58 #endif | 68 #endif |
59 | 69 |
60 base::RunLoop().Run(); | 70 base::RunLoop().Run(); |
61 | 71 |
62 #if defined(LEAK_SANITIZER) | 72 #if defined(LEAK_SANITIZER) |
63 // Invoke LeakSanitizer before shutting down the utility thread, to avoid | 73 // Invoke LeakSanitizer before shutting down the utility thread, to avoid |
64 // reporting shutdown-only leaks. | 74 // reporting shutdown-only leaks. |
65 __lsan_do_leak_check(); | 75 __lsan_do_leak_check(); |
66 #endif | 76 #endif |
67 | 77 |
68 return 0; | 78 return 0; |
69 } | 79 } |
70 | 80 |
71 } // namespace content | 81 } // namespace content |
OLD | NEW |