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

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

Issue 2651953002: Revert of [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
9 #include "base/at_exit.h" 7 #include "base/at_exit.h"
10 #include "base/base_paths.h" 8 #include "base/base_paths.h"
11 #include "base/base_switches.h" 9 #include "base/base_switches.h"
12 #include "base/bind.h" 10 #include "base/bind.h"
13 #include "base/command_line.h" 11 #include "base/command_line.h"
14 #include "base/debug/debugger.h" 12 #include "base/debug/debugger.h"
15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
17 #include "base/i18n/icu_util.h" 14 #include "base/i18n/icu_util.h"
18 #include "base/json/json_reader.h"
19 #include "base/logging.h" 15 #include "base/logging.h"
20 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
21 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
22 #include "base/path_service.h" 18 #include "base/path_service.h"
23 #include "base/process/launch.h" 19 #include "base/process/launch.h"
24 #include "base/process/process.h" 20 #include "base/process/process.h"
25 #include "base/run_loop.h" 21 #include "base/run_loop.h"
26 #include "base/sys_info.h" 22 #include "base/sys_info.h"
27 #include "base/task_scheduler/task_scheduler.h" 23 #include "base/task_scheduler/task_scheduler.h"
28 #include "base/threading/sequenced_worker_pool.h" 24 #include "base/threading/sequenced_worker_pool.h"
29 #include "base/threading/thread.h"
30 #include "base/trace_event/trace_event.h" 25 #include "base/trace_event/trace_event.h"
31 #include "components/tracing/common/trace_to_console.h" 26 #include "components/tracing/common/trace_to_console.h"
32 #include "components/tracing/common/tracing_switches.h" 27 #include "components/tracing/common/tracing_switches.h"
33 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
34 #include "content/public/common/service_names.mojom.h" 29 #include "content/public/common/service_names.mojom.h"
35 #include "mash/package/mash_packaged_service.h" 30 #include "mash/package/mash_packaged_service.h"
36 #include "mash/session/public/interfaces/constants.mojom.h" 31 #include "mash/session/public/interfaces/constants.mojom.h"
37 #include "mojo/edk/embedder/embedder.h"
38 #include "mojo/edk/embedder/scoped_ipc_support.h"
39 #include "mojo/public/cpp/bindings/binding_set.h" 32 #include "mojo/public/cpp/bindings/binding_set.h"
40 #include "services/catalog/public/interfaces/catalog.mojom.h" 33 #include "services/catalog/public/interfaces/catalog.mojom.h"
41 #include "services/catalog/public/interfaces/constants.mojom.h" 34 #include "services/catalog/public/interfaces/constants.mojom.h"
42 #include "services/service_manager/background/background_service_manager.h" 35 #include "services/service_manager/background/background_service_manager.h"
43 #include "services/service_manager/public/cpp/connector.h" 36 #include "services/service_manager/public/cpp/connector.h"
44 #include "services/service_manager/public/cpp/identity.h" 37 #include "services/service_manager/public/cpp/identity.h"
45 #include "services/service_manager/public/cpp/service.h" 38 #include "services/service_manager/public/cpp/service.h"
46 #include "services/service_manager/public/cpp/service_context.h" 39 #include "services/service_manager/public/cpp/service_context.h"
47 #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"
48 #include "services/service_manager/public/interfaces/service_factory.mojom.h" 41 #include "services/service_manager/public/interfaces/service_factory.mojom.h"
(...skipping 12 matching lines...) Expand all
61 54
62 using service_manager::mojom::ServiceFactory; 55 using service_manager::mojom::ServiceFactory;
63 56
64 namespace { 57 namespace {
65 58
66 // kProcessType used to identify child processes. 59 // kProcessType used to identify child processes.
67 const char* kMashChild = "mash-child"; 60 const char* kMashChild = "mash-child";
68 61
69 const char kChromeMashServiceName[] = "chrome_mash"; 62 const char kChromeMashServiceName[] = "chrome_mash";
70 63
71 const base::FilePath::CharType kChromeMashCatalogFilename[] = 64 const char kChromeContentBrowserPackageName[] = "chrome_content_browser";
72 FILE_PATH_LITERAL("chrome_mash_catalog.json"); 65 const char kChromeContentGpuPackageName[] = "chrome_content_gpu";
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 }
73 77
74 bool IsChild() { 78 bool IsChild() {
75 return base::CommandLine::ForCurrentProcess()->HasSwitch( 79 return base::CommandLine::ForCurrentProcess()->HasSwitch(
76 switches::kProcessType) && 80 switches::kProcessType) &&
77 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 81 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
78 switches::kProcessType) == kMashChild; 82 switches::kProcessType) == kMashChild;
79 } 83 }
80 84
81 void InitializeResources() { 85 void InitializeResources() {
82 ui::RegisterPathProvider(); 86 ui::RegisterPathProvider();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 165
162 if (IsChild()) 166 if (IsChild())
163 return RunChild(); 167 return RunChild();
164 RunMain(); 168 RunMain();
165 return 0; 169 return 0;
166 } 170 }
167 171
168 void MashRunner::RunMain() { 172 void MashRunner::RunMain() {
169 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); 173 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
170 174
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
190 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we 175 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we
191 // shouldn't we using context as it has a lot of stuff we don't really want 176 // shouldn't we using context as it has a lot of stuff we don't really want
192 // in chrome. 177 // in chrome.
193 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; 178 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate;
194 service_manager::BackgroundServiceManager background_service_manager( 179 service_manager::BackgroundServiceManager background_service_manager;
195 &service_process_launcher_delegate, std::move(manifest_value)); 180 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams>
196 service_manager::mojom::ServicePtr service; 181 init_params(new service_manager::BackgroundServiceManager::InitParams);
182 init_params->service_process_launcher_delegate =
183 &service_process_launcher_delegate;
184 background_service_manager.Init(std::move(init_params));
197 context_.reset(new service_manager::ServiceContext( 185 context_.reset(new service_manager::ServiceContext(
198 base::MakeUnique<mash::MashPackagedService>(), 186 base::MakeUnique<mash::MashPackagedService>(),
199 service_manager::mojom::ServiceRequest(&service))); 187 background_service_manager.CreateServiceRequest(kChromeMashServiceName)));
200 background_service_manager.RegisterService( 188
201 service_manager::Identity( 189 // We need to send a sync messages to the Catalog, so we wait for a completed
202 kChromeMashServiceName, service_manager::mojom::kRootUserID), 190 // connection first.
203 std::move(service), nullptr); 191 std::unique_ptr<service_manager::Connection> catalog_connection =
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)));
204 214
205 // Ping mash_session to ensure an instance is brought up 215 // Ping mash_session to ensure an instance is brought up
206 context_->connector()->Connect(mash::session::mojom::kServiceName); 216 context_->connector()->Connect(mash::session::mojom::kServiceName);
207 base::RunLoop().Run(); 217 base::RunLoop().Run();
208 218
209 base::TaskScheduler::GetInstance()->Shutdown(); 219 base::TaskScheduler::GetInstance()->Shutdown();
210 } 220 }
211 221
212 int MashRunner::RunChild() { 222 int MashRunner::RunChild() {
213 service_manager::WaitForDebuggerIfNecessary(); 223 service_manager::WaitForDebuggerIfNecessary();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { 294 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) {
285 return; 295 return;
286 } 296 }
287 297
288 // Include the pid as logging may not have been initialized yet (the pid 298 // Include the pid as logging may not have been initialized yet (the pid
289 // printed out by logging is wrong). 299 // printed out by logging is wrong).
290 LOG(WARNING) << "waiting for debugger to attach for service " << service_name 300 LOG(WARNING) << "waiting for debugger to attach for service " << service_name
291 << " pid=" << base::Process::Current().Pid(); 301 << " pid=" << base::Process::Current().Pid();
292 base::debug::WaitForDebugger(120, true); 302 base::debug::WaitForDebugger(120, true);
293 } 303 }
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