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

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

Issue 2389133008: Mash: Replaces "exe:chrome" with "service:content_browser" (Closed)
Patch Set: Created 4 years, 2 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/chrome_mash_manifest.json ('k') | chrome/app/mojo/OWNERS » ('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 "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/barrier_closure.h"
8 #include "base/bind.h" 9 #include "base/bind.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/debug/debugger.h" 11 #include "base/debug/debugger.h"
11 #include "base/i18n/icu_util.h" 12 #include "base/i18n/icu_util.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/process/launch.h" 16 #include "base/process/launch.h"
16 #include "base/run_loop.h" 17 #include "base/run_loop.h"
17 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
18 #include "components/tracing/common/trace_to_console.h" 19 #include "components/tracing/common/trace_to_console.h"
19 #include "components/tracing/common/tracing_switches.h" 20 #include "components/tracing/common/tracing_switches.h"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
22 #include "content/public/common/service_names.h"
21 #include "mash/package/mash_packaged_service.h" 23 #include "mash/package/mash_packaged_service.h"
22 #include "mojo/public/cpp/bindings/binding_set.h" 24 #include "mojo/public/cpp/bindings/binding_set.h"
25 #include "services/catalog/public/interfaces/catalog.mojom.h"
23 #include "services/shell/background/background_shell.h" 26 #include "services/shell/background/background_shell.h"
24 #include "services/shell/native_runner_delegate.h" 27 #include "services/shell/native_runner_delegate.h"
25 #include "services/shell/public/cpp/connector.h" 28 #include "services/shell/public/cpp/connector.h"
26 #include "services/shell/public/cpp/identity.h" 29 #include "services/shell/public/cpp/identity.h"
27 #include "services/shell/public/cpp/service.h" 30 #include "services/shell/public/cpp/service.h"
28 #include "services/shell/public/cpp/service_context.h" 31 #include "services/shell/public/cpp/service_context.h"
29 #include "services/shell/public/interfaces/service_factory.mojom.h" 32 #include "services/shell/public/interfaces/service_factory.mojom.h"
30 #include "services/shell/runner/common/switches.h" 33 #include "services/shell/runner/common/switches.h"
31 #include "services/shell/runner/host/child_process_base.h" 34 #include "services/shell/runner/host/child_process_base.h"
32 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/base/ui_base_paths.h" 36 #include "ui/base/ui_base_paths.h"
34 #include "ui/base/ui_base_switches.h" 37 #include "ui/base/ui_base_switches.h"
35 38
36 using shell::mojom::ServiceFactory; 39 using shell::mojom::ServiceFactory;
37 40
38 namespace { 41 namespace {
39 42
40 // kProcessType used to identify child processes. 43 // kProcessType used to identify child processes.
41 const char* kMashChild = "mash-child"; 44 const char* kMashChild = "mash-child";
42 45
46 const char kChromeMashServiceName[] = "exe:chrome_mash";
Ben Goodger (Google) 2016/10/06 21:46:26 Can we not use exe: prefixes for synthetic names?
Ken Rockot(use gerrit already) 2016/10/06 22:37:07 Done. This means we don't need the ServiceManagerC
47 const char kChromeMashManifestFilename[] = "chrome_mash_manifest.json";
48
49 const char kChromeMashContentBrowserPackageName[] =
50 "chrome_mash_content_browser";
51 const char kChromeContentGpuPackageName[] = "chrome_content_gpu";
52 const char kChromeContentRendererPackageName[] = "chrome_content_renderer";
53 const char kChromeContentUtilityPackageName[] = "chrome_content_utility";
54
55 const char kPackagesPath[] = "Packages";
56 const char kManifestFilename[] = "manifest.json";
57
58 base::FilePath GetPackageManifestPath(const std::string& package_name) {
59 base::FilePath exe = base::CommandLine::ForCurrentProcess()->GetProgram();
60 return exe.DirName().AppendASCII(kPackagesPath).AppendASCII(package_name)
61 .AppendASCII(kManifestFilename);
62 }
63
43 bool IsChild() { 64 bool IsChild() {
44 return base::CommandLine::ForCurrentProcess()->HasSwitch( 65 return base::CommandLine::ForCurrentProcess()->HasSwitch(
45 switches::kProcessType) && 66 switches::kProcessType) &&
46 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 67 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
47 switches::kProcessType) == kMashChild; 68 switches::kProcessType) == kMashChild;
48 } 69 }
49 70
50 void InitializeResources() { 71 void InitializeResources() {
51 ui::RegisterPathProvider(); 72 ui::RegisterPathProvider();
52 const std::string locale = 73 const std::string locale =
53 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 74 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
54 switches::kLang); 75 switches::kLang);
55 // This loads the Chrome's resources (chrome_100_percent.pak etc.) 76 // This loads the Chrome's resources (chrome_100_percent.pak etc.)
56 ui::ResourceBundle::InitSharedInstanceWithLocale( 77 ui::ResourceBundle::InitSharedInstanceWithLocale(
57 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); 78 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
58 } 79 }
59 80
60 // Convert the command line program from chrome_mash to chrome. This is
61 // necessary as the shell will attempt to start chrome_mash. We want chrome.
62 void ChangeChromeMashToChrome(base::CommandLine* command_line) {
63 base::FilePath exe_path(command_line->GetProgram());
64 #if defined(OS_WIN)
65 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome.exe"));
66 #else
67 exe_path = exe_path.DirName().Append(FILE_PATH_LITERAL("chrome"));
68 #endif
69 command_line->SetProgram(exe_path);
70 }
71
72 class NativeRunnerDelegateImpl : public shell::NativeRunnerDelegate { 81 class NativeRunnerDelegateImpl : public shell::NativeRunnerDelegate {
73 public: 82 public:
74 NativeRunnerDelegateImpl() {} 83 NativeRunnerDelegateImpl() {}
75 ~NativeRunnerDelegateImpl() override {} 84 ~NativeRunnerDelegateImpl() override {}
76 85
77 private: 86 private:
78 // shell::NativeRunnerDelegate: 87 // shell::NativeRunnerDelegate:
79 void AdjustCommandLineArgumentsForTarget( 88 void AdjustCommandLineArgumentsForTarget(
80 const shell::Identity& target, 89 const shell::Identity& target,
81 base::CommandLine* command_line) override { 90 base::CommandLine* command_line) override {
82 if (target.name() != "exe:chrome") { 91 if (target.name() != content::kBrowserMojoApplicationName) {
83 if (target.name() == "exe:chrome_mash") 92 // If running anything other than the browser process, launch a mash
84 ChangeChromeMashToChrome(command_line); 93 // child process. The new process will execute MashRunner::RunChild().
85 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); 94 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild);
86 #if defined(OS_WIN) 95 #if defined(OS_WIN)
87 command_line->AppendArg(switches::kPrefetchArgumentOther); 96 command_line->AppendArg(switches::kPrefetchArgumentOther);
88 #endif 97 #endif
89 return; 98 return;
90 } 99 }
91 100
101 // When launching the browser process, ensure that we don't inherit the
102 // --mash flag so it proceeds with the normal content/browser startup path.
92 base::CommandLine::StringVector argv(command_line->argv()); 103 base::CommandLine::StringVector argv(command_line->argv());
93 auto iter = 104 auto iter =
94 std::find(argv.begin(), argv.end(), FILE_PATH_LITERAL("--mash")); 105 std::find(argv.begin(), argv.end(), FILE_PATH_LITERAL("--mash"));
95 if (iter != argv.end()) 106 if (iter != argv.end())
96 argv.erase(iter); 107 argv.erase(iter);
97 *command_line = base::CommandLine(argv); 108 *command_line = base::CommandLine(argv);
98 } 109 }
99 110
100 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); 111 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl);
101 }; 112 };
(...skipping 17 matching lines...) Expand all
119 // in chrome. 130 // in chrome.
120 NativeRunnerDelegateImpl native_runner_delegate; 131 NativeRunnerDelegateImpl native_runner_delegate;
121 shell::BackgroundShell background_shell; 132 shell::BackgroundShell background_shell;
122 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( 133 std::unique_ptr<shell::BackgroundShell::InitParams> init_params(
123 new shell::BackgroundShell::InitParams); 134 new shell::BackgroundShell::InitParams);
124 init_params->native_runner_delegate = &native_runner_delegate; 135 init_params->native_runner_delegate = &native_runner_delegate;
125 background_shell.Init(std::move(init_params)); 136 background_shell.Init(std::move(init_params));
126 service_.reset(new mash::MashPackagedService); 137 service_.reset(new mash::MashPackagedService);
127 service_->set_context(base::MakeUnique<shell::ServiceContext>( 138 service_->set_context(base::MakeUnique<shell::ServiceContext>(
128 service_.get(), 139 service_.get(),
129 background_shell.CreateServiceRequest("exe:chrome_mash"))); 140 background_shell.CreateServiceRequest(kChromeMashServiceName)));
141
142 // We need to send sync messages to the ServiceManager and Catalog. Wait for
143 // completed connections to them.
144 std::unique_ptr<shell::Connection> service_manager_connection =
145 service_->connector()->Connect("service:shell");
146 std::unique_ptr<shell::Connection> catalog_connection =
147 service_->connector()->Connect("service:catalog");
148 {
149 base::RunLoop run_loop;
150 auto on_connect = base::BarrierClosure(2, run_loop.QuitClosure());
151 service_manager_connection->AddConnectionCompletedClosure(on_connect);
152 catalog_connection->AddConnectionCompletedClosure(on_connect);
153 run_loop.Run();
154 }
155
156 // Synchronously override "service:content_browser" and "exe:chrome_mash" to
157 // resolve to this executable.
158 base::FilePath this_executable =
159 base::CommandLine::ForCurrentProcess()->GetProgram();
160 shell::mojom::ServiceManagerControlPtr service_manager_control;
161 service_manager_connection->GetInterface(&service_manager_control);
162 CHECK(service_manager_control ->OverridePackagePath(
163 content::kBrowserMojoApplicationName, this_executable));
164 CHECK(service_manager_control->OverridePackagePath(
165 kChromeMashServiceName, this_executable));
166
167 // Synchronously override manifests needed for various services.
168 catalog::mojom::CatalogControlPtr catalog_control;
169 catalog_connection->GetInterface(&catalog_control);
170 CHECK(catalog_control->OverrideManifestPath(
171 kChromeMashServiceName,
172 this_executable.DirName().AppendASCII(kChromeMashManifestFilename)));
173 CHECK(catalog_control->OverrideManifestPath(
174 content::kBrowserMojoApplicationName,
175 GetPackageManifestPath(kChromeMashContentBrowserPackageName)));
176 CHECK(catalog_control->OverrideManifestPath(
177 content::kGpuMojoApplicationName,
178 GetPackageManifestPath(kChromeContentGpuPackageName)));
179 CHECK(catalog_control->OverrideManifestPath(
180 content::kRendererMojoApplicationName,
181 GetPackageManifestPath(kChromeContentRendererPackageName)));
182 CHECK(catalog_control->OverrideManifestPath(
183 content::kUtilityMojoApplicationName,
184 GetPackageManifestPath(kChromeContentUtilityPackageName)));
185
186 // Ping mash_session to ensure an instance is brought up
130 service_->connector()->Connect("service:mash_session"); 187 service_->connector()->Connect("service:mash_session");
131 base::RunLoop().Run(); 188 base::RunLoop().Run();
132 } 189 }
133 190
134 void MashRunner::RunChild() { 191 void MashRunner::RunChild() {
135 base::i18n::InitializeICU(); 192 base::i18n::InitializeICU();
136 InitializeResources(); 193 InitializeResources();
137 shell::ChildProcessMainWithCallback( 194 shell::ChildProcessMainWithCallback(
138 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); 195 base::Bind(&MashRunner::StartChildApp, base::Unretained(this)));
139 } 196 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 tracing::GetConfigForTraceToConsole(); 235 tracing::GetConfigForTraceToConsole();
179 base::trace_event::TraceLog::GetInstance()->SetEnabled( 236 base::trace_event::TraceLog::GetInstance()->SetEnabled(
180 trace_config, 237 trace_config,
181 base::trace_event::TraceLog::RECORDING_MODE); 238 base::trace_event::TraceLog::RECORDING_MODE);
182 } 239 }
183 240
184 MashRunner mash_runner; 241 MashRunner mash_runner;
185 mash_runner.Run(); 242 mash_runner.Run();
186 return 0; 243 return 0;
187 } 244 }
OLDNEW
« no previous file with comments | « chrome/app/mash/chrome_mash_manifest.json ('k') | chrome/app/mojo/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698