Chromium Code Reviews| 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 "services/service_manager/standalone/context.h" |
|
fdoray
2017/01/11 14:29:51
services/service_manager/standalone/context.h is n
kylechar
2017/01/11 16:16:20
Done.
| |
| 45 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
| 46 #include "ui/base/ui_base_paths.h" | 47 #include "ui/base/ui_base_paths.h" |
| 47 #include "ui/base/ui_base_switches.h" | 48 #include "ui/base/ui_base_switches.h" |
| 48 | 49 |
| 49 using service_manager::mojom::ServiceFactory; | 50 using service_manager::mojom::ServiceFactory; |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 // kProcessType used to identify child processes. | 54 // kProcessType used to identify child processes. |
| 54 const char* kMashChild = "mash-child"; | 55 const char* kMashChild = "mash-child"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); | 128 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 } // namespace | 131 } // namespace |
| 131 | 132 |
| 132 MashRunner::MashRunner() {} | 133 MashRunner::MashRunner() {} |
| 133 | 134 |
| 134 MashRunner::~MashRunner() {} | 135 MashRunner::~MashRunner() {} |
| 135 | 136 |
| 136 int MashRunner::Run() { | 137 int MashRunner::Run() { |
| 138 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( | |
| 139 base::SysInfo::NumberOfProcessors()); | |
| 140 | |
| 137 if (IsChild()) | 141 if (IsChild()) |
| 138 return RunChild(); | 142 return RunChild(); |
| 139 RunMain(); | 143 RunMain(); |
| 140 return 0; | 144 return 0; |
| 141 } | 145 } |
| 142 | 146 |
| 143 void MashRunner::RunMain() { | 147 void MashRunner::RunMain() { |
| 144 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( | |
| 145 service_manager::kThreadPoolMaxThreads); | |
| 146 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | 148 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
| 147 | 149 |
| 148 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we | 150 // 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 | 151 // shouldn't we using context as it has a lot of stuff we don't really want |
| 150 // in chrome. | 152 // in chrome. |
| 151 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; | 153 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; |
| 152 service_manager::BackgroundServiceManager background_service_manager; | 154 service_manager::BackgroundServiceManager background_service_manager; |
| 153 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> | 155 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> |
| 154 init_params(new service_manager::BackgroundServiceManager::InitParams); | 156 init_params(new service_manager::BackgroundServiceManager::InitParams); |
| 155 init_params->service_process_launcher_delegate = | 157 init_params->service_process_launcher_delegate = |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 186 GetPackageManifestPath(kChromeContentUtilityPackageName))); | 188 GetPackageManifestPath(kChromeContentUtilityPackageName))); |
| 187 | 189 |
| 188 // Ping mash_session to ensure an instance is brought up | 190 // Ping mash_session to ensure an instance is brought up |
| 189 context_->connector()->Connect(mash::session::mojom::kServiceName); | 191 context_->connector()->Connect(mash::session::mojom::kServiceName); |
| 190 base::RunLoop().Run(); | 192 base::RunLoop().Run(); |
| 191 | 193 |
| 192 base::TaskScheduler::GetInstance()->Shutdown(); | 194 base::TaskScheduler::GetInstance()->Shutdown(); |
| 193 } | 195 } |
| 194 | 196 |
| 195 int MashRunner::RunChild() { | 197 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(); | 198 service_manager::WaitForDebuggerIfNecessary(); |
| 202 | 199 |
| 203 base::i18n::InitializeICU(); | 200 base::i18n::InitializeICU(); |
| 204 InitializeResources(); | 201 InitializeResources(); |
| 205 service_manager::RunStandaloneService( | 202 service_manager::RunStandaloneService( |
| 206 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 203 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
| 207 return 0; | 204 return 0; |
| 208 } | 205 } |
| 209 | 206 |
| 210 void MashRunner::StartChildApp( | 207 void MashRunner::StartChildApp( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { | 256 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { |
| 260 return; | 257 return; |
| 261 } | 258 } |
| 262 | 259 |
| 263 // Include the pid as logging may not have been initialized yet (the pid | 260 // Include the pid as logging may not have been initialized yet (the pid |
| 264 // printed out by logging is wrong). | 261 // printed out by logging is wrong). |
| 265 LOG(WARNING) << "waiting for debugger to attach for service " << service_name | 262 LOG(WARNING) << "waiting for debugger to attach for service " << service_name |
| 266 << " pid=" << base::Process::Current().Pid(); | 263 << " pid=" << base::Process::Current().Pid(); |
| 267 base::debug::WaitForDebugger(120, true); | 264 base::debug::WaitForDebugger(120, true); |
| 268 } | 265 } |
| OLD | NEW |