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/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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 MashRunner::~MashRunner() {} | 122 MashRunner::~MashRunner() {} |
| 121 | 123 |
| 122 int MashRunner::Run() { | 124 int MashRunner::Run() { |
| 123 if (IsChild()) | 125 if (IsChild()) |
| 124 return RunChild(); | 126 return RunChild(); |
| 125 RunMain(); | 127 RunMain(); |
| 126 return 0; | 128 return 0; |
| 127 } | 129 } |
| 128 | 130 |
| 129 void MashRunner::RunMain() { | 131 void MashRunner::RunMain() { |
| 132 constexpr int kNumThreads = 3; | |
|
sky
2016/11/23 21:47:35
Where does the 3 come from? Is there a constant el
fdoray
2016/11/23 21:53:43
From the SequencedWorkerPool that TaskScheduler re
| |
| 133 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(kNumThreads); | |
| 134 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | |
| 135 | |
| 130 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we | 136 // 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 | 137 // shouldn't we using context as it has a lot of stuff we don't really want |
| 132 // in chrome. | 138 // in chrome. |
| 133 NativeRunnerDelegateImpl native_runner_delegate; | 139 NativeRunnerDelegateImpl native_runner_delegate; |
| 134 service_manager::BackgroundServiceManager background_service_manager; | 140 service_manager::BackgroundServiceManager background_service_manager; |
| 135 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> | 141 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> |
| 136 init_params(new service_manager::BackgroundServiceManager::InitParams); | 142 init_params(new service_manager::BackgroundServiceManager::InitParams); |
| 137 init_params->native_runner_delegate = &native_runner_delegate; | 143 init_params->native_runner_delegate = &native_runner_delegate; |
| 138 background_service_manager.Init(std::move(init_params)); | 144 background_service_manager.Init(std::move(init_params)); |
| 139 context_.reset(new service_manager::ServiceContext( | 145 context_.reset(new service_manager::ServiceContext( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 162 CHECK(catalog_control->OverrideManifestPath( | 168 CHECK(catalog_control->OverrideManifestPath( |
| 163 content::mojom::kRendererServiceName, | 169 content::mojom::kRendererServiceName, |
| 164 GetPackageManifestPath(kChromeContentRendererPackageName))); | 170 GetPackageManifestPath(kChromeContentRendererPackageName))); |
| 165 CHECK(catalog_control->OverrideManifestPath( | 171 CHECK(catalog_control->OverrideManifestPath( |
| 166 content::mojom::kUtilityServiceName, | 172 content::mojom::kUtilityServiceName, |
| 167 GetPackageManifestPath(kChromeContentUtilityPackageName))); | 173 GetPackageManifestPath(kChromeContentUtilityPackageName))); |
| 168 | 174 |
| 169 // Ping mash_session to ensure an instance is brought up | 175 // Ping mash_session to ensure an instance is brought up |
| 170 context_->connector()->Connect("mash_session"); | 176 context_->connector()->Connect("mash_session"); |
| 171 base::RunLoop().Run(); | 177 base::RunLoop().Run(); |
| 178 | |
| 179 base::TaskScheduler::GetInstance()->Shutdown(); | |
| 172 } | 180 } |
| 173 | 181 |
| 174 int MashRunner::RunChild() { | 182 int MashRunner::RunChild() { |
| 183 // TODO(fdoray): Add TaskScheduler initialization code in | |
| 184 // service_manager::ServiceRunner. TaskScheduler can't be initialized here | |
| 185 // because it wouldn't be visible to the service's dynamic library. | |
| 186 // https://crbug.com/664996 | |
| 187 | |
| 175 base::FilePath path = | 188 base::FilePath path = |
| 176 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 189 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 177 switches::kChildProcess); | 190 switches::kChildProcess); |
| 178 if (base::PathExists(path)) | 191 if (base::PathExists(path)) |
| 179 return service_manager::ChildProcessMain(); | 192 return service_manager::ChildProcessMain(); |
| 180 | 193 |
| 181 // If the path doesn't exist - try launching this as a packaged service. | 194 // If the path doesn't exist - try launching this as a packaged service. |
| 182 base::i18n::InitializeICU(); | 195 base::i18n::InitializeICU(); |
| 183 InitializeResources(); | 196 InitializeResources(); |
| 184 service_manager::ChildProcessMainWithCallback( | 197 service_manager::ChildProcessMainWithCallback( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 base::trace_event::TraceConfig trace_config = | 231 base::trace_event::TraceConfig trace_config = |
| 219 tracing::GetConfigForTraceToConsole(); | 232 tracing::GetConfigForTraceToConsole(); |
| 220 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 233 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 221 trace_config, | 234 trace_config, |
| 222 base::trace_event::TraceLog::RECORDING_MODE); | 235 base::trace_event::TraceLog::RECORDING_MODE); |
| 223 } | 236 } |
| 224 | 237 |
| 225 MashRunner mash_runner; | 238 MashRunner mash_runner; |
| 226 return mash_runner.Run(); | 239 return mash_runner.Run(); |
| 227 } | 240 } |
| OLD | NEW |