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

Side by Side Diff: chrome/app/mash/mash_runner.cc

Issue 2645973006: [Service Manager] Get rid of dynamic service discovery (Closed)
Patch Set: . Created 3 years, 10 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 | « chrome/app/mash/DEPS ('k') | chrome/browser/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string>
8
7 #include "base/at_exit.h" 9 #include "base/at_exit.h"
8 #include "base/base_paths.h" 10 #include "base/base_paths.h"
9 #include "base/base_switches.h" 11 #include "base/base_switches.h"
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/debug/debugger.h" 14 #include "base/debug/debugger.h"
15 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
14 #include "base/i18n/icu_util.h" 17 #include "base/i18n/icu_util.h"
18 #include "base/json/json_reader.h"
15 #include "base/logging.h" 19 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
17 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h" 22 #include "base/path_service.h"
19 #include "base/process/launch.h" 23 #include "base/process/launch.h"
20 #include "base/process/process.h" 24 #include "base/process/process.h"
21 #include "base/run_loop.h" 25 #include "base/run_loop.h"
22 #include "base/sys_info.h" 26 #include "base/sys_info.h"
23 #include "base/task_scheduler/task_scheduler.h" 27 #include "base/task_scheduler/task_scheduler.h"
24 #include "base/threading/sequenced_worker_pool.h" 28 #include "base/threading/sequenced_worker_pool.h"
29 #include "base/threading/thread.h"
25 #include "base/trace_event/trace_event.h" 30 #include "base/trace_event/trace_event.h"
26 #include "components/tracing/common/trace_to_console.h" 31 #include "components/tracing/common/trace_to_console.h"
27 #include "components/tracing/common/tracing_switches.h" 32 #include "components/tracing/common/tracing_switches.h"
28 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
29 #include "content/public/common/service_names.mojom.h" 34 #include "content/public/common/service_names.mojom.h"
30 #include "mash/package/mash_packaged_service.h" 35 #include "mash/package/mash_packaged_service.h"
31 #include "mash/session/public/interfaces/constants.mojom.h" 36 #include "mash/session/public/interfaces/constants.mojom.h"
37 #include "mojo/edk/embedder/embedder.h"
38 #include "mojo/edk/embedder/scoped_ipc_support.h"
32 #include "mojo/public/cpp/bindings/binding_set.h" 39 #include "mojo/public/cpp/bindings/binding_set.h"
33 #include "services/catalog/public/interfaces/catalog.mojom.h" 40 #include "services/catalog/public/interfaces/catalog.mojom.h"
34 #include "services/catalog/public/interfaces/constants.mojom.h" 41 #include "services/catalog/public/interfaces/constants.mojom.h"
35 #include "services/service_manager/background/background_service_manager.h" 42 #include "services/service_manager/background/background_service_manager.h"
36 #include "services/service_manager/public/cpp/connector.h" 43 #include "services/service_manager/public/cpp/connector.h"
37 #include "services/service_manager/public/cpp/identity.h" 44 #include "services/service_manager/public/cpp/identity.h"
38 #include "services/service_manager/public/cpp/service.h" 45 #include "services/service_manager/public/cpp/service.h"
39 #include "services/service_manager/public/cpp/service_context.h" 46 #include "services/service_manager/public/cpp/service_context.h"
40 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h" 47 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h"
41 #include "services/service_manager/public/interfaces/service_factory.mojom.h" 48 #include "services/service_manager/public/interfaces/service_factory.mojom.h"
(...skipping 12 matching lines...) Expand all
54 61
55 using service_manager::mojom::ServiceFactory; 62 using service_manager::mojom::ServiceFactory;
56 63
57 namespace { 64 namespace {
58 65
59 // kProcessType used to identify child processes. 66 // kProcessType used to identify child processes.
60 const char* kMashChild = "mash-child"; 67 const char* kMashChild = "mash-child";
61 68
62 const char kChromeMashServiceName[] = "chrome_mash"; 69 const char kChromeMashServiceName[] = "chrome_mash";
63 70
64 const char kChromeContentBrowserPackageName[] = "chrome_content_browser"; 71 const base::FilePath::CharType kChromeMashCatalogFilename[] =
65 const char kChromeContentGpuPackageName[] = "chrome_content_gpu"; 72 FILE_PATH_LITERAL("chrome_mash_catalog.json");
66 const char kChromeContentRendererPackageName[] = "chrome_content_renderer";
67 const char kChromeContentUtilityPackageName[] = "chrome_content_utility";
68
69 const char kPackagesPath[] = "Packages";
70 const char kManifestFilename[] = "manifest.json";
71
72 base::FilePath GetPackageManifestPath(const std::string& package_name) {
73 base::FilePath exe = base::CommandLine::ForCurrentProcess()->GetProgram();
74 return exe.DirName().AppendASCII(kPackagesPath).AppendASCII(package_name)
75 .AppendASCII(kManifestFilename);
76 }
77 73
78 bool IsChild() { 74 bool IsChild() {
79 return base::CommandLine::ForCurrentProcess()->HasSwitch( 75 return base::CommandLine::ForCurrentProcess()->HasSwitch(
80 switches::kProcessType) && 76 switches::kProcessType) &&
81 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 77 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
82 switches::kProcessType) == kMashChild; 78 switches::kProcessType) == kMashChild;
83 } 79 }
84 80
85 void InitializeResources() { 81 void InitializeResources() {
86 ui::RegisterPathProvider(); 82 ui::RegisterPathProvider();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 161
166 if (IsChild()) 162 if (IsChild())
167 return RunChild(); 163 return RunChild();
168 RunMain(); 164 RunMain();
169 return 0; 165 return 0;
170 } 166 }
171 167
172 void MashRunner::RunMain() { 168 void MashRunner::RunMain() {
173 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); 169 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
174 170
171 mojo::edk::Init();
172
173 base::Thread ipc_thread("IPC thread");
174 ipc_thread.StartWithOptions(
175 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
176 mojo::edk::ScopedIPCSupport ipc_support(
177 ipc_thread.task_runner(),
178 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST);
179
180 std::string catalog_contents;
181 base::FilePath exe_path;
182 base::PathService::Get(base::DIR_EXE, &exe_path);
183 base::FilePath catalog_path = exe_path.Append(kChromeMashCatalogFilename);
184 bool result = base::ReadFileToString(catalog_path, &catalog_contents);
185 DCHECK(result);
186 std::unique_ptr<base::Value> manifest_value =
187 base::JSONReader::Read(catalog_contents);
188 DCHECK(manifest_value);
189
175 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we 190 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we
176 // shouldn't we using context as it has a lot of stuff we don't really want 191 // shouldn't we using context as it has a lot of stuff we don't really want
177 // in chrome. 192 // in chrome.
178 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; 193 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate;
179 service_manager::BackgroundServiceManager background_service_manager; 194 service_manager::BackgroundServiceManager background_service_manager(
180 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> 195 &service_process_launcher_delegate, std::move(manifest_value));
181 init_params(new service_manager::BackgroundServiceManager::InitParams); 196 service_manager::mojom::ServicePtr service;
182 init_params->service_process_launcher_delegate =
183 &service_process_launcher_delegate;
184 background_service_manager.Init(std::move(init_params));
185 context_.reset(new service_manager::ServiceContext( 197 context_.reset(new service_manager::ServiceContext(
186 base::MakeUnique<mash::MashPackagedService>(), 198 base::MakeUnique<mash::MashPackagedService>(),
187 background_service_manager.CreateServiceRequest(kChromeMashServiceName))); 199 service_manager::mojom::ServiceRequest(&service)));
188 200 background_service_manager.RegisterService(
189 // We need to send a sync messages to the Catalog, so we wait for a completed 201 service_manager::Identity(
190 // connection first. 202 kChromeMashServiceName, service_manager::mojom::kRootUserID),
191 std::unique_ptr<service_manager::Connection> catalog_connection = 203 std::move(service), nullptr);
192 context_->connector()->Connect(catalog::mojom::kServiceName);
193 {
194 base::RunLoop run_loop;
195 catalog_connection->AddConnectionCompletedClosure(run_loop.QuitClosure());
196 run_loop.Run();
197 }
198
199 // Synchronously override manifests needed for content process services.
200 catalog::mojom::CatalogControlPtr catalog_control;
201 catalog_connection->GetInterface(&catalog_control);
202 CHECK(catalog_control->OverrideManifestPath(
203 content::mojom::kBrowserServiceName,
204 GetPackageManifestPath(kChromeContentBrowserPackageName)));
205 CHECK(catalog_control->OverrideManifestPath(
206 content::mojom::kGpuServiceName,
207 GetPackageManifestPath(kChromeContentGpuPackageName)));
208 CHECK(catalog_control->OverrideManifestPath(
209 content::mojom::kRendererServiceName,
210 GetPackageManifestPath(kChromeContentRendererPackageName)));
211 CHECK(catalog_control->OverrideManifestPath(
212 content::mojom::kUtilityServiceName,
213 GetPackageManifestPath(kChromeContentUtilityPackageName)));
214 204
215 // Ping mash_session to ensure an instance is brought up 205 // Ping mash_session to ensure an instance is brought up
216 context_->connector()->Connect(mash::session::mojom::kServiceName); 206 context_->connector()->Connect(mash::session::mojom::kServiceName);
217 base::RunLoop().Run(); 207 base::RunLoop().Run();
218 208
219 base::TaskScheduler::GetInstance()->Shutdown(); 209 base::TaskScheduler::GetInstance()->Shutdown();
220 } 210 }
221 211
222 int MashRunner::RunChild() { 212 int MashRunner::RunChild() {
223 service_manager::WaitForDebuggerIfNecessary(); 213 service_manager::WaitForDebuggerIfNecessary();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { 284 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) {
295 return; 285 return;
296 } 286 }
297 287
298 // Include the pid as logging may not have been initialized yet (the pid 288 // Include the pid as logging may not have been initialized yet (the pid
299 // printed out by logging is wrong). 289 // printed out by logging is wrong).
300 LOG(WARNING) << "waiting for debugger to attach for service " << service_name 290 LOG(WARNING) << "waiting for debugger to attach for service " << service_name
301 << " pid=" << base::Process::Current().Pid(); 291 << " pid=" << base::Process::Current().Pid();
302 base::debug::WaitForDebugger(120, true); 292 base::debug::WaitForDebugger(120, true);
303 } 293 }
OLDNEW
« no previous file with comments | « chrome/app/mash/DEPS ('k') | chrome/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698