Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: content/utility/utility_main.cc

Issue 2629873002: Do not create base::HighResolutionTimerManager in service utility process (Closed)
Patch Set: Fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 std::unique_ptr<base::HighResolutionTimerManager> hi_res_timer_manager;
danakj 2017/01/20 16:37:33 you could use Optional if u dont want to add mallo
leonhsl(Using Gerrit) 2017/01/22 06:05:07 Done and thanks!
52 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
danakj 2017/01/20 16:37:33 It makes sense that if (!base::PowerMonitor::Get()
leonhsl(Using Gerrit) 2017/01/22 06:05:07 Done.
53 switches::kServiceRequestChannelToken)) {
54 hi_res_timer_manager.reset(new base::HighResolutionTimerManager());
55 }
44 56
45 #if defined(OS_WIN) 57 #if defined(OS_WIN)
46 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); 58 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox);
47 if (!no_sandbox) { 59 if (!no_sandbox) {
48 sandbox::TargetServices* target_services = 60 sandbox::TargetServices* target_services =
49 parameters.sandbox_info->target_services; 61 parameters.sandbox_info->target_services;
50 if (!target_services) 62 if (!target_services)
51 return false; 63 return false;
52 char buffer; 64 char buffer;
53 // Ensure RtlGenRandom is warm before the token is lowered; otherwise, 65 // Ensure RtlGenRandom is warm before the token is lowered; otherwise,
54 // base::RandBytes() will CHECK fail when v8 is initialized. 66 // base::RandBytes() will CHECK fail when v8 is initialized.
55 base::RandBytes(&buffer, sizeof(buffer)); 67 base::RandBytes(&buffer, sizeof(buffer));
56 target_services->LowerToken(); 68 target_services->LowerToken();
57 } 69 }
58 #endif 70 #endif
59 71
60 base::RunLoop().Run(); 72 base::RunLoop().Run();
61 73
62 #if defined(LEAK_SANITIZER) 74 #if defined(LEAK_SANITIZER)
63 // Invoke LeakSanitizer before shutting down the utility thread, to avoid 75 // Invoke LeakSanitizer before shutting down the utility thread, to avoid
64 // reporting shutdown-only leaks. 76 // reporting shutdown-only leaks.
65 __lsan_do_leak_check(); 77 __lsan_do_leak_check();
66 #endif 78 #endif
67 79
68 return 0; 80 return 0;
69 } 81 }
70 82
71 } // namespace content 83 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698