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

Side by Side Diff: content/browser/mojo/mojo_shell_context.cc

Issue 1828733004: Load application manifests from resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « content/browser/mojo/mojo_shell_context.h ('k') | content/content.gyp » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/mojo/mojo_shell_context.h" 5 #include "content/browser/mojo/mojo_shell_context.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "components/profile_service/profile_app.h" 16 #include "components/profile_service/profile_app.h"
17 #include "content/browser/gpu/gpu_process_host.h" 17 #include "content/browser/gpu/gpu_process_host.h"
18 #include "content/browser/mojo/constants.h"
18 #include "content/common/gpu_process_launch_causes.h" 19 #include "content/common/gpu_process_launch_causes.h"
19 #include "content/common/mojo/current_thread_loader.h" 20 #include "content/common/mojo/current_thread_loader.h"
20 #include "content/common/mojo/mojo_shell_connection_impl.h" 21 #include "content/common/mojo/mojo_shell_connection_impl.h"
21 #include "content/common/mojo/static_loader.h" 22 #include "content/common/mojo/static_loader.h"
22 #include "content/common/process_control.mojom.h" 23 #include "content/common/process_control.mojom.h"
24 #include "content/grit/content_resources.h"
23 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/content_browser_client.h" 26 #include "content/public/browser/content_browser_client.h"
25 #include "content/public/browser/utility_process_host.h" 27 #include "content/public/browser/utility_process_host.h"
26 #include "content/public/browser/utility_process_host_client.h" 28 #include "content/public/browser/utility_process_host_client.h"
27 #include "content/public/common/content_client.h" 29 #include "content/public/common/content_client.h"
28 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
29 #include "content/public/common/service_registry.h" 31 #include "content/public/common/service_registry.h"
30 #include "mojo/public/cpp/bindings/interface_request.h" 32 #include "mojo/public/cpp/bindings/interface_request.h"
31 #include "mojo/public/cpp/bindings/string.h" 33 #include "mojo/public/cpp/bindings/string.h"
32 #include "mojo/services/catalog/factory.h" 34 #include "mojo/services/catalog/factory.h"
35 #include "mojo/services/catalog/manifest_provider.h"
33 #include "mojo/services/catalog/store.h" 36 #include "mojo/services/catalog/store.h"
34 #include "mojo/shell/connect_params.h" 37 #include "mojo/shell/connect_params.h"
35 #include "mojo/shell/loader.h" 38 #include "mojo/shell/loader.h"
36 #include "mojo/shell/native_runner.h" 39 #include "mojo/shell/native_runner.h"
37 #include "mojo/shell/public/cpp/identity.h" 40 #include "mojo/shell/public/cpp/identity.h"
38 #include "mojo/shell/public/cpp/shell_client.h" 41 #include "mojo/shell/public/cpp/shell_client.h"
39 #include "mojo/shell/public/interfaces/connector.mojom.h" 42 #include "mojo/shell/public/interfaces/connector.mojom.h"
40 #include "mojo/shell/runner/host/in_process_native_runner.h" 43 #include "mojo/shell/runner/host/in_process_native_runner.h"
41 44
42 namespace content { 45 namespace content {
43 46
44 namespace { 47 namespace {
45 48
46 const char kBrowserAppName[] = "exe:chrome";
47
48 // An extra set of apps to register on initialization, if set by a test. 49 // An extra set of apps to register on initialization, if set by a test.
49 const MojoShellContext::StaticApplicationMap* g_applications_for_test; 50 const MojoShellContext::StaticApplicationMap* g_applications_for_test;
50 51
51 void StartUtilityProcessOnIOThread( 52 void StartUtilityProcessOnIOThread(
52 mojo::InterfaceRequest<mojom::ProcessControl> request, 53 mojo::InterfaceRequest<mojom::ProcessControl> request,
53 const base::string16& process_name, 54 const base::string16& process_name,
54 bool use_sandbox) { 55 bool use_sandbox) {
55 UtilityProcessHost* process_host = 56 UtilityProcessHost* process_host =
56 UtilityProcessHost::Create(nullptr, nullptr); 57 UtilityProcessHost::Create(nullptr, nullptr);
57 process_host->SetName(process_name); 58 process_host->SetName(process_name);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 BrowserThread::PostTask( 149 BrowserThread::PostTask(
149 BrowserThread::IO, FROM_HERE, 150 BrowserThread::IO, FROM_HERE,
150 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); 151 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request)));
151 process_control->LoadApplication(name, std::move(request), 152 process_control->LoadApplication(name, std::move(request),
152 base::Bind(&OnApplicationLoaded, name)); 153 base::Bind(&OnApplicationLoaded, name));
153 } 154 }
154 155
155 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); 156 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader);
156 }; 157 };
157 158
159 std::string GetStringResource(int id) {
160 return GetContentClient()->GetDataResource(
161 id, ui::ScaleFactor::SCALE_FACTOR_NONE).as_string();
162 }
163
158 } // namespace 164 } // namespace
159 165
166 // A ManifestProvider which resolves application names to builtin manifest
167 // resources for the catalog service to consume.
168 class MojoShellContext::BuiltinManifestProvider
169 : public catalog::ManifestProvider {
170 public:
171 BuiltinManifestProvider() {}
172 ~BuiltinManifestProvider() override {}
173
174 private:
175 // catalog::ManifestProvider:
176 bool GetApplicationManifest(const base::StringPiece& name,
177 std::string* manifest_contents) override {
178 if (name == "mojo:catalog") {
179 *manifest_contents = GetStringResource(IDR_MOJO_CATALOG_MANIFEST);
180 return true;
181 } else if (name == kBrowserMojoApplicationName) {
182 *manifest_contents = GetStringResource(IDR_MOJO_CONTENT_BROWSER_MANIFEST);
183 return true;
184 } else if (name == kRendererMojoApplicationName) {
185 *manifest_contents =
186 GetStringResource(IDR_MOJO_CONTENT_RENDERER_MANIFEST);
187 return true;
188 }
189
190 return false;
191 }
192
193 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider);
194 };
195
160 // Thread-safe proxy providing access to the shell context from any thread. 196 // Thread-safe proxy providing access to the shell context from any thread.
161 class MojoShellContext::Proxy { 197 class MojoShellContext::Proxy {
162 public: 198 public:
163 Proxy(MojoShellContext* shell_context) 199 Proxy(MojoShellContext* shell_context)
164 : shell_context_(shell_context), 200 : shell_context_(shell_context),
165 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 201 task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
166 202
167 ~Proxy() {} 203 ~Proxy() {}
168 204
169 void ConnectToApplication( 205 void ConnectToApplication(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 MojoShellContext::MojoShellContext( 246 MojoShellContext::MojoShellContext(
211 scoped_refptr<base::SingleThreadTaskRunner> file_thread, 247 scoped_refptr<base::SingleThreadTaskRunner> file_thread,
212 scoped_refptr<base::SingleThreadTaskRunner> db_thread) { 248 scoped_refptr<base::SingleThreadTaskRunner> db_thread) {
213 proxy_.Get().reset(new Proxy(this)); 249 proxy_.Get().reset(new Proxy(this));
214 250
215 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = 251 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
216 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 252 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
217 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( 253 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory(
218 new mojo::shell::InProcessNativeRunnerFactory( 254 new mojo::shell::InProcessNativeRunnerFactory(
219 BrowserThread::GetBlockingPool())); 255 BrowserThread::GetBlockingPool()));
220 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr)); 256 manifest_provider_.reset(new BuiltinManifestProvider);
257 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr,
258 manifest_provider_.get()));
221 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), 259 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory),
222 catalog_->TakeShellClient())); 260 catalog_->TakeShellClient()));
223
224 shell_->set_default_loader( 261 shell_->set_default_loader(
225 scoped_ptr<mojo::shell::Loader>(new DefaultLoader)); 262 scoped_ptr<mojo::shell::Loader>(new DefaultLoader));
226 263
227 StaticApplicationMap apps; 264 StaticApplicationMap apps;
228 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 265 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
229 if (g_applications_for_test) { 266 if (g_applications_for_test) {
230 // Add testing apps to the map, potentially overwriting whatever the 267 // Add testing apps to the map, potentially overwriting whatever the
231 // browser client registered. 268 // browser client registered.
232 for (const auto& entry : *g_applications_for_test) 269 for (const auto& entry : *g_applications_for_test)
233 apps[entry.first] = entry.second; 270 apps[entry.first] = entry.second;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 303 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
267 switches::kMojoLocalStorage)) { 304 switches::kMojoLocalStorage)) {
268 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = 305 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback =
269 base::Bind(&profile::CreateProfileApp, file_thread, db_thread); 306 base::Bind(&profile::CreateProfileApp, file_thread, db_thread);
270 shell_->SetLoaderForName( 307 shell_->SetLoaderForName(
271 make_scoped_ptr(new CurrentThreadLoader(profile_callback)), 308 make_scoped_ptr(new CurrentThreadLoader(profile_callback)),
272 "mojo:profile"); 309 "mojo:profile");
273 } 310 }
274 311
275 if (!IsRunningInMojoShell()) { 312 if (!IsRunningInMojoShell()) {
276 const bool is_external = false;
277 MojoShellConnection::Create( 313 MojoShellConnection::Create(
278 shell_->InitInstanceForEmbedder(kBrowserAppName), is_external); 314 shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName),
315 false /* is_external */);
279 } 316 }
280 } 317 }
281 318
282 MojoShellContext::~MojoShellContext() { 319 MojoShellContext::~MojoShellContext() {
283 if (!IsRunningInMojoShell()) 320 if (!IsRunningInMojoShell())
284 MojoShellConnectionImpl::Destroy(); 321 MojoShellConnectionImpl::Destroy();
285 } 322 }
286 323
287 // static 324 // static
288 void MojoShellContext::ConnectToApplication( 325 void MojoShellContext::ConnectToApplication(
(...skipping 19 matching lines...) Expand all
308 mojo::Identity source_id(requestor_name, user_id); 345 mojo::Identity source_id(requestor_name, user_id);
309 params->set_source(source_id); 346 params->set_source(source_id);
310 params->set_target(mojo::Identity(name, user_id)); 347 params->set_target(mojo::Identity(name, user_id));
311 params->set_remote_interfaces(std::move(request)); 348 params->set_remote_interfaces(std::move(request));
312 params->set_local_interfaces(std::move(exposed_services)); 349 params->set_local_interfaces(std::move(exposed_services));
313 params->set_connect_callback(callback); 350 params->set_connect_callback(callback);
314 shell_->Connect(std::move(params)); 351 shell_->Connect(std::move(params));
315 } 352 }
316 353
317 } // namespace content 354 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/mojo_shell_context.h ('k') | content/content.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698