| 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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/i18n/icu_util.h" | 12 #include "base/i18n/icu_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/task_scheduler/task_scheduler.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 19 #include "components/tracing/common/trace_to_console.h" | 21 #include "components/tracing/common/trace_to_console.h" |
| 20 #include "components/tracing/common/tracing_switches.h" | 22 #include "components/tracing/common/tracing_switches.h" |
| 21 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/common/service_names.mojom.h" | 24 #include "content/public/common/service_names.mojom.h" |
| 23 #include "mash/package/mash_packaged_service.h" | 25 #include "mash/package/mash_packaged_service.h" |
| 24 #include "mojo/public/cpp/bindings/binding_set.h" | 26 #include "mojo/public/cpp/bindings/binding_set.h" |
| 25 #include "services/catalog/public/interfaces/catalog.mojom.h" | 27 #include "services/catalog/public/interfaces/catalog.mojom.h" |
| 26 #include "services/catalog/public/interfaces/constants.mojom.h" | 28 #include "services/catalog/public/interfaces/constants.mojom.h" |
| 27 #include "services/service_manager/background/background_service_manager.h" | 29 #include "services/service_manager/background/background_service_manager.h" |
| 28 #include "services/service_manager/native_runner_delegate.h" | 30 #include "services/service_manager/native_runner_delegate.h" |
| 29 #include "services/service_manager/public/cpp/connector.h" | 31 #include "services/service_manager/public/cpp/connector.h" |
| 30 #include "services/service_manager/public/cpp/identity.h" | 32 #include "services/service_manager/public/cpp/identity.h" |
| 31 #include "services/service_manager/public/cpp/service.h" | 33 #include "services/service_manager/public/cpp/service.h" |
| 32 #include "services/service_manager/public/cpp/service_context.h" | 34 #include "services/service_manager/public/cpp/service_context.h" |
| 33 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 35 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
| 34 #include "services/service_manager/runner/common/switches.h" | 36 #include "services/service_manager/runner/common/switches.h" |
| 35 #include "services/service_manager/runner/host/child_process.h" | 37 #include "services/service_manager/runner/host/child_process.h" |
| 36 #include "services/service_manager/runner/host/child_process_base.h" | 38 #include "services/service_manager/runner/host/child_process_base.h" |
| 37 #include "services/service_manager/runner/init.h" | 39 #include "services/service_manager/runner/init.h" |
| 40 #include "services/service_manager/standalone/context.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/base/ui_base_paths.h" | 42 #include "ui/base/ui_base_paths.h" |
| 40 #include "ui/base/ui_base_switches.h" | 43 #include "ui/base/ui_base_switches.h" |
| 41 | 44 |
| 42 using service_manager::mojom::ServiceFactory; | 45 using service_manager::mojom::ServiceFactory; |
| 43 | 46 |
| 44 namespace { | 47 namespace { |
| 45 | 48 |
| 46 // kProcessType used to identify child processes. | 49 // kProcessType used to identify child processes. |
| 47 const char* kMashChild = "mash-child"; | 50 const char* kMashChild = "mash-child"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 MashRunner::~MashRunner() {} | 123 MashRunner::~MashRunner() {} |
| 121 | 124 |
| 122 int MashRunner::Run() { | 125 int MashRunner::Run() { |
| 123 if (IsChild()) | 126 if (IsChild()) |
| 124 return RunChild(); | 127 return RunChild(); |
| 125 RunMain(); | 128 RunMain(); |
| 126 return 0; | 129 return 0; |
| 127 } | 130 } |
| 128 | 131 |
| 129 void MashRunner::RunMain() { | 132 void MashRunner::RunMain() { |
| 133 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( |
| 134 service_manager::kThreadPoolMaxThreads); |
| 135 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
| 136 |
| 130 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we | 137 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we |
| 131 // shouldn't we using context as it has a lot of stuff we don't really want | 138 // shouldn't we using context as it has a lot of stuff we don't really want |
| 132 // in chrome. | 139 // in chrome. |
| 133 NativeRunnerDelegateImpl native_runner_delegate; | 140 NativeRunnerDelegateImpl native_runner_delegate; |
| 134 service_manager::BackgroundServiceManager background_service_manager; | 141 service_manager::BackgroundServiceManager background_service_manager; |
| 135 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> | 142 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> |
| 136 init_params(new service_manager::BackgroundServiceManager::InitParams); | 143 init_params(new service_manager::BackgroundServiceManager::InitParams); |
| 137 init_params->native_runner_delegate = &native_runner_delegate; | 144 init_params->native_runner_delegate = &native_runner_delegate; |
| 138 background_service_manager.Init(std::move(init_params)); | 145 background_service_manager.Init(std::move(init_params)); |
| 139 context_.reset(new service_manager::ServiceContext( | 146 context_.reset(new service_manager::ServiceContext( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 162 CHECK(catalog_control->OverrideManifestPath( | 169 CHECK(catalog_control->OverrideManifestPath( |
| 163 content::mojom::kRendererServiceName, | 170 content::mojom::kRendererServiceName, |
| 164 GetPackageManifestPath(kChromeContentRendererPackageName))); | 171 GetPackageManifestPath(kChromeContentRendererPackageName))); |
| 165 CHECK(catalog_control->OverrideManifestPath( | 172 CHECK(catalog_control->OverrideManifestPath( |
| 166 content::mojom::kUtilityServiceName, | 173 content::mojom::kUtilityServiceName, |
| 167 GetPackageManifestPath(kChromeContentUtilityPackageName))); | 174 GetPackageManifestPath(kChromeContentUtilityPackageName))); |
| 168 | 175 |
| 169 // Ping mash_session to ensure an instance is brought up | 176 // Ping mash_session to ensure an instance is brought up |
| 170 context_->connector()->Connect("mash_session"); | 177 context_->connector()->Connect("mash_session"); |
| 171 base::RunLoop().Run(); | 178 base::RunLoop().Run(); |
| 179 |
| 180 base::TaskScheduler::GetInstance()->Shutdown(); |
| 172 } | 181 } |
| 173 | 182 |
| 174 int MashRunner::RunChild() { | 183 int MashRunner::RunChild() { |
| 184 // TODO(fdoray): Add TaskScheduler initialization code in |
| 185 // service_manager::ServiceRunner. TaskScheduler can't be initialized here |
| 186 // because it wouldn't be visible to the service's dynamic library. |
| 187 // https://crbug.com/664996 |
| 188 |
| 175 base::FilePath path = | 189 base::FilePath path = |
| 176 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 190 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 177 switches::kChildProcess); | 191 switches::kChildProcess); |
| 178 if (base::PathExists(path)) | 192 if (base::PathExists(path)) |
| 179 return service_manager::ChildProcessMain(); | 193 return service_manager::ChildProcessMain(); |
| 180 | 194 |
| 181 // If the path doesn't exist - try launching this as a packaged service. | 195 // If the path doesn't exist - try launching this as a packaged service. |
| 182 base::i18n::InitializeICU(); | 196 base::i18n::InitializeICU(); |
| 183 InitializeResources(); | 197 InitializeResources(); |
| 184 service_manager::ChildProcessMainWithCallback( | 198 service_manager::ChildProcessMainWithCallback( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 base::trace_event::TraceConfig trace_config = | 232 base::trace_event::TraceConfig trace_config = |
| 219 tracing::GetConfigForTraceToConsole(); | 233 tracing::GetConfigForTraceToConsole(); |
| 220 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 234 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 221 trace_config, | 235 trace_config, |
| 222 base::trace_event::TraceLog::RECORDING_MODE); | 236 base::trace_event::TraceLog::RECORDING_MODE); |
| 223 } | 237 } |
| 224 | 238 |
| 225 MashRunner mash_runner; | 239 MashRunner mash_runner; |
| 226 return mash_runner.Run(); | 240 return mash_runner.Run(); |
| 227 } | 241 } |
| OLD | NEW |