OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/app/mash/mash_runner.h" | 5 #include "chrome/app/mash/mash_runner.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/debugger.h" | 12 #include "base/debug/debugger.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/i18n/icu_util.h" | 14 #include "base/i18n/icu_util.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/process/launch.h" | 19 #include "base/process/launch.h" |
20 #include "base/process/process.h" | 20 #include "base/process/process.h" |
21 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 22 #include "base/sys_info.h" |
22 #include "base/task_scheduler/task_scheduler.h" | 23 #include "base/task_scheduler/task_scheduler.h" |
23 #include "base/threading/sequenced_worker_pool.h" | 24 #include "base/threading/sequenced_worker_pool.h" |
24 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
25 #include "components/tracing/common/trace_to_console.h" | 26 #include "components/tracing/common/trace_to_console.h" |
26 #include "components/tracing/common/tracing_switches.h" | 27 #include "components/tracing/common/tracing_switches.h" |
27 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
28 #include "content/public/common/service_names.mojom.h" | 29 #include "content/public/common/service_names.mojom.h" |
29 #include "mash/package/mash_packaged_service.h" | 30 #include "mash/package/mash_packaged_service.h" |
30 #include "mash/session/public/interfaces/constants.mojom.h" | 31 #include "mash/session/public/interfaces/constants.mojom.h" |
31 #include "mojo/public/cpp/bindings/binding_set.h" | 32 #include "mojo/public/cpp/bindings/binding_set.h" |
32 #include "services/catalog/public/interfaces/catalog.mojom.h" | 33 #include "services/catalog/public/interfaces/catalog.mojom.h" |
33 #include "services/catalog/public/interfaces/constants.mojom.h" | 34 #include "services/catalog/public/interfaces/constants.mojom.h" |
34 #include "services/service_manager/background/background_service_manager.h" | 35 #include "services/service_manager/background/background_service_manager.h" |
35 #include "services/service_manager/public/cpp/connector.h" | 36 #include "services/service_manager/public/cpp/connector.h" |
36 #include "services/service_manager/public/cpp/identity.h" | 37 #include "services/service_manager/public/cpp/identity.h" |
37 #include "services/service_manager/public/cpp/service.h" | 38 #include "services/service_manager/public/cpp/service.h" |
38 #include "services/service_manager/public/cpp/service_context.h" | 39 #include "services/service_manager/public/cpp/service_context.h" |
39 #include "services/service_manager/public/cpp/standalone_service/standalone_serv
ice.h" | 40 #include "services/service_manager/public/cpp/standalone_service/standalone_serv
ice.h" |
40 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 41 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
41 #include "services/service_manager/runner/common/client_util.h" | 42 #include "services/service_manager/runner/common/client_util.h" |
42 #include "services/service_manager/runner/common/switches.h" | 43 #include "services/service_manager/runner/common/switches.h" |
43 #include "services/service_manager/runner/init.h" | 44 #include "services/service_manager/runner/init.h" |
44 #include "services/service_manager/standalone/context.h" | |
45 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
46 #include "ui/base/ui_base_paths.h" | 46 #include "ui/base/ui_base_paths.h" |
47 #include "ui/base/ui_base_switches.h" | 47 #include "ui/base/ui_base_switches.h" |
48 | 48 |
49 using service_manager::mojom::ServiceFactory; | 49 using service_manager::mojom::ServiceFactory; |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
53 // kProcessType used to identify child processes. | 53 // kProcessType used to identify child processes. |
54 const char* kMashChild = "mash-child"; | 54 const char* kMashChild = "mash-child"; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); | 127 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); |
128 }; | 128 }; |
129 | 129 |
130 } // namespace | 130 } // namespace |
131 | 131 |
132 MashRunner::MashRunner() {} | 132 MashRunner::MashRunner() {} |
133 | 133 |
134 MashRunner::~MashRunner() {} | 134 MashRunner::~MashRunner() {} |
135 | 135 |
136 int MashRunner::Run() { | 136 int MashRunner::Run() { |
| 137 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( |
| 138 base::SysInfo::NumberOfProcessors()); |
| 139 |
137 if (IsChild()) | 140 if (IsChild()) |
138 return RunChild(); | 141 return RunChild(); |
139 RunMain(); | 142 RunMain(); |
140 return 0; | 143 return 0; |
141 } | 144 } |
142 | 145 |
143 void MashRunner::RunMain() { | 146 void MashRunner::RunMain() { |
144 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( | |
145 service_manager::kThreadPoolMaxThreads); | |
146 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | 147 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
147 | 148 |
148 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we | 149 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we |
149 // shouldn't we using context as it has a lot of stuff we don't really want | 150 // shouldn't we using context as it has a lot of stuff we don't really want |
150 // in chrome. | 151 // in chrome. |
151 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; | 152 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; |
152 service_manager::BackgroundServiceManager background_service_manager; | 153 service_manager::BackgroundServiceManager background_service_manager; |
153 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> | 154 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> |
154 init_params(new service_manager::BackgroundServiceManager::InitParams); | 155 init_params(new service_manager::BackgroundServiceManager::InitParams); |
155 init_params->service_process_launcher_delegate = | 156 init_params->service_process_launcher_delegate = |
(...skipping 30 matching lines...) Expand all Loading... |
186 GetPackageManifestPath(kChromeContentUtilityPackageName))); | 187 GetPackageManifestPath(kChromeContentUtilityPackageName))); |
187 | 188 |
188 // Ping mash_session to ensure an instance is brought up | 189 // Ping mash_session to ensure an instance is brought up |
189 context_->connector()->Connect(mash::session::mojom::kServiceName); | 190 context_->connector()->Connect(mash::session::mojom::kServiceName); |
190 base::RunLoop().Run(); | 191 base::RunLoop().Run(); |
191 | 192 |
192 base::TaskScheduler::GetInstance()->Shutdown(); | 193 base::TaskScheduler::GetInstance()->Shutdown(); |
193 } | 194 } |
194 | 195 |
195 int MashRunner::RunChild() { | 196 int MashRunner::RunChild() { |
196 // TODO(fdoray): Add TaskScheduler initialization code in | |
197 // service_manager::ServiceRunner. TaskScheduler can't be initialized here | |
198 // because it wouldn't be visible to the service's dynamic library. | |
199 // https://crbug.com/664996 | |
200 | |
201 service_manager::WaitForDebuggerIfNecessary(); | 197 service_manager::WaitForDebuggerIfNecessary(); |
202 | 198 |
203 base::i18n::InitializeICU(); | 199 base::i18n::InitializeICU(); |
204 InitializeResources(); | 200 InitializeResources(); |
205 service_manager::RunStandaloneService( | 201 service_manager::RunStandaloneService( |
206 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 202 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
207 return 0; | 203 return 0; |
208 } | 204 } |
209 | 205 |
210 void MashRunner::StartChildApp( | 206 void MashRunner::StartChildApp( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { | 255 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { |
260 return; | 256 return; |
261 } | 257 } |
262 | 258 |
263 // Include the pid as logging may not have been initialized yet (the pid | 259 // Include the pid as logging may not have been initialized yet (the pid |
264 // printed out by logging is wrong). | 260 // printed out by logging is wrong). |
265 LOG(WARNING) << "waiting for debugger to attach for service " << service_name | 261 LOG(WARNING) << "waiting for debugger to attach for service " << service_name |
266 << " pid=" << base::Process::Current().Pid(); | 262 << " pid=" << base::Process::Current().Pid(); |
267 base::debug::WaitForDebugger(120, true); | 263 base::debug::WaitForDebugger(120, true); |
268 } | 264 } |
OLD | NEW |