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/optional.h" |
| 9 #include "base/power_monitor/power_monitor.h" |
8 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
9 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
10 #include "base/timer/hi_res_timer_manager.h" | 12 #include "base/timer/hi_res_timer_manager.h" |
11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
12 #include "content/child/child_process.h" | 14 #include "content/child/child_process.h" |
13 #include "content/common/sandbox_linux/sandbox_linux.h" | 15 #include "content/common/sandbox_linux/sandbox_linux.h" |
14 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
15 #include "content/public/common/main_function_params.h" | 17 #include "content/public/common/main_function_params.h" |
16 #include "content/public/common/sandbox_init.h" | 18 #include "content/public/common/sandbox_init.h" |
17 #include "content/utility/utility_thread_impl.h" | 19 #include "content/utility/utility_thread_impl.h" |
(...skipping 15 matching lines...) Expand all Loading... |
33 // Initializes the sandbox before any threads are created. | 35 // Initializes the sandbox before any threads are created. |
34 // TODO(jorgelo): move this after GTK initialization when we enable a strict | 36 // TODO(jorgelo): move this after GTK initialization when we enable a strict |
35 // Seccomp-BPF policy. | 37 // Seccomp-BPF policy. |
36 if (parameters.zygote_child) | 38 if (parameters.zygote_child) |
37 LinuxSandbox::InitializeSandbox(); | 39 LinuxSandbox::InitializeSandbox(); |
38 #endif | 40 #endif |
39 | 41 |
40 ChildProcess utility_process; | 42 ChildProcess utility_process; |
41 utility_process.set_main_thread(new UtilityThreadImpl()); | 43 utility_process.set_main_thread(new UtilityThreadImpl()); |
42 | 44 |
43 base::HighResolutionTimerManager hi_res_timer_manager; | 45 // Both utility process and service utility process would come |
| 46 // here, but the later is launched without connection to service manager, so |
| 47 // there has no base::PowerMonitor be created(See ChildThreadImpl::Init()). |
| 48 // As base::PowerMonitor is necessary to base::HighResolutionTimerManager, for |
| 49 // such case we just disable base::HighResolutionTimerManager for now. |
| 50 // Note that disabling base::HighResolutionTimerManager means high resolution |
| 51 // timer is always disabled no matter on battery or not, but it should have |
| 52 // no any bad influence because currently service utility process is not using |
| 53 // any high resolution timer. |
| 54 // TODO(leonhsl): Once http://crbug.com/646833 got resolved, re-enable |
| 55 // base::HighResolutionTimerManager here for future possible usage of high |
| 56 // resolution timer in service utility process. |
| 57 base::Optional<base::HighResolutionTimerManager> hi_res_timer_manager; |
| 58 if (base::PowerMonitor::Get()) { |
| 59 hi_res_timer_manager.emplace(); |
| 60 } |
44 | 61 |
45 #if defined(OS_WIN) | 62 #if defined(OS_WIN) |
46 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); | 63 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); |
47 if (!no_sandbox) { | 64 if (!no_sandbox) { |
48 sandbox::TargetServices* target_services = | 65 sandbox::TargetServices* target_services = |
49 parameters.sandbox_info->target_services; | 66 parameters.sandbox_info->target_services; |
50 if (!target_services) | 67 if (!target_services) |
51 return false; | 68 return false; |
52 char buffer; | 69 char buffer; |
53 // Ensure RtlGenRandom is warm before the token is lowered; otherwise, | 70 // Ensure RtlGenRandom is warm before the token is lowered; otherwise, |
54 // base::RandBytes() will CHECK fail when v8 is initialized. | 71 // base::RandBytes() will CHECK fail when v8 is initialized. |
55 base::RandBytes(&buffer, sizeof(buffer)); | 72 base::RandBytes(&buffer, sizeof(buffer)); |
56 target_services->LowerToken(); | 73 target_services->LowerToken(); |
57 } | 74 } |
58 #endif | 75 #endif |
59 | 76 |
60 base::RunLoop().Run(); | 77 base::RunLoop().Run(); |
61 | 78 |
62 #if defined(LEAK_SANITIZER) | 79 #if defined(LEAK_SANITIZER) |
63 // Invoke LeakSanitizer before shutting down the utility thread, to avoid | 80 // Invoke LeakSanitizer before shutting down the utility thread, to avoid |
64 // reporting shutdown-only leaks. | 81 // reporting shutdown-only leaks. |
65 __lsan_do_leak_check(); | 82 __lsan_do_leak_check(); |
66 #endif | 83 #endif |
67 | 84 |
68 return 0; | 85 return 0; |
69 } | 86 } |
70 | 87 |
71 } // namespace content | 88 } // namespace content |
OLD | NEW |