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

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

Issue 1738663002: Hook embedded shell up to MojoShellConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 9 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
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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "content/browser/gpu/gpu_process_host.h" 14 #include "content/browser/gpu/gpu_process_host.h"
15 #include "content/common/gpu/gpu_process_launch_causes.h" 15 #include "content/common/gpu/gpu_process_launch_causes.h"
16 #include "content/common/mojo/mojo_shell_connection_impl.h"
16 #include "content/common/mojo/static_application_loader.h" 17 #include "content/common/mojo/static_application_loader.h"
17 #include "content/common/process_control.mojom.h" 18 #include "content/common/process_control.mojom.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/content_browser_client.h" 20 #include "content/public/browser/content_browser_client.h"
20 #include "content/public/browser/utility_process_host.h" 21 #include "content/public/browser/utility_process_host.h"
21 #include "content/public/browser/utility_process_host_client.h" 22 #include "content/public/browser/utility_process_host_client.h"
22 #include "content/public/common/content_client.h" 23 #include "content/public/common/content_client.h"
23 #include "content/public/common/service_registry.h" 24 #include "content/public/common/service_registry.h"
24 #include "mojo/common/url_type_converters.h" 25 #include "mojo/common/url_type_converters.h"
25 #include "mojo/public/cpp/bindings/interface_request.h" 26 #include "mojo/public/cpp/bindings/interface_request.h"
26 #include "mojo/public/cpp/bindings/string.h" 27 #include "mojo/public/cpp/bindings/string.h"
27 #include "mojo/shell/application_loader.h" 28 #include "mojo/shell/application_loader.h"
28 #include "mojo/shell/connect_params.h" 29 #include "mojo/shell/connect_params.h"
29 #include "mojo/shell/identity.h" 30 #include "mojo/shell/identity.h"
31 #include "mojo/shell/native_runner.h"
30 #include "mojo/shell/public/cpp/shell_client.h" 32 #include "mojo/shell/public/cpp/shell_client.h"
33 #include "mojo/shell/public/interfaces/shell.mojom.h"
34 #include "mojo/shell/runner/host/in_process_native_runner.h"
31 35
32 namespace content { 36 namespace content {
33 37
34 namespace { 38 namespace {
35 39
40 const char kBrowserAppUrl[] = "exe:chrome";
41
36 // An extra set of apps to register on initialization, if set by a test. 42 // An extra set of apps to register on initialization, if set by a test.
37 const MojoShellContext::StaticApplicationMap* g_applications_for_test; 43 const MojoShellContext::StaticApplicationMap* g_applications_for_test;
38 44
39 void StartUtilityProcessOnIOThread( 45 void StartUtilityProcessOnIOThread(
40 mojo::InterfaceRequest<ProcessControl> request, 46 mojo::InterfaceRequest<ProcessControl> request,
41 const base::string16& process_name, 47 const base::string16& process_name,
42 bool use_sandbox) { 48 bool use_sandbox) {
43 UtilityProcessHost* process_host = 49 UtilityProcessHost* process_host =
44 UtilityProcessHost::Create(nullptr, nullptr); 50 UtilityProcessHost::Create(nullptr, nullptr);
45 process_host->SetName(process_name); 51 process_host->SetName(process_name);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 g_applications_for_test = apps; 201 g_applications_for_test = apps;
196 } 202 }
197 203
198 MojoShellContext::MojoShellContext() { 204 MojoShellContext::MojoShellContext() {
199 proxy_.Get().reset(new Proxy(this)); 205 proxy_.Get().reset(new Proxy(this));
200 206
201 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = 207 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
202 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 208 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
203 bool register_mojo_url_schemes = false; 209 bool register_mojo_url_schemes = false;
204 210
211 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory(
212 new mojo::shell::InProcessNativeRunnerFactory(
213 BrowserThread::GetBlockingPool()));
205 application_manager_.reset(new mojo::shell::ApplicationManager( 214 application_manager_.reset(new mojo::shell::ApplicationManager(
206 nullptr, file_task_runner.get(), register_mojo_url_schemes)); 215 std::move(native_runner_factory), file_task_runner.get(),
216 register_mojo_url_schemes));
207 217
208 application_manager_->set_default_loader( 218 application_manager_->set_default_loader(
209 scoped_ptr<mojo::shell::ApplicationLoader>(new DefaultApplicationLoader)); 219 scoped_ptr<mojo::shell::ApplicationLoader>(new DefaultApplicationLoader));
210 220
211 StaticApplicationMap apps; 221 StaticApplicationMap apps;
212 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 222 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
213 if (g_applications_for_test) { 223 if (g_applications_for_test) {
214 // Add testing apps to the map, potentially overwriting whatever the 224 // Add testing apps to the map, potentially overwriting whatever the
215 // browser client registered. 225 // browser client registered.
216 for (const auto& entry : *g_applications_for_test) 226 for (const auto& entry : *g_applications_for_test)
(...skipping 26 matching lines...) Expand all
243 scoped_ptr<mojo::shell::ApplicationLoader>( 253 scoped_ptr<mojo::shell::ApplicationLoader>(
244 new UtilityProcessLoader(app.second, false /* use_sandbox */)), 254 new UtilityProcessLoader(app.second, false /* use_sandbox */)),
245 app.first); 255 app.first);
246 } 256 }
247 257
248 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 258 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
249 application_manager_->SetLoaderForURL( 259 application_manager_->SetLoaderForURL(
250 scoped_ptr<mojo::shell::ApplicationLoader>(new GpuProcessLoader()), 260 scoped_ptr<mojo::shell::ApplicationLoader>(new GpuProcessLoader()),
251 GURL("mojo:media")); 261 GURL("mojo:media"));
252 #endif 262 #endif
263
264 if (!IsRunningInMojoShell()) {
265 scoped_ptr<mojo::shell::ConnectParams> params(
266 new mojo::shell::ConnectParams);
Ben Goodger (Google) 2016/02/25 03:02:58 you must always set a source.
Ken Rockot(use gerrit already) 2016/02/25 04:42:05 Ah right, so it doesn't even really make sense to
267 params->set_target(
268 mojo::shell::Identity(GURL(kBrowserAppUrl), std::string(),
269 mojo::shell::mojom::Shell::kUserRoot,
270 mojo::shell::GetPermissiveCapabilityFilter()));
271
272 MojoShellConnectionImpl::Create(
273 application_manager_->CreateInstanceForURL(std::move(params)));
274 }
253 } 275 }
254 276
255 MojoShellContext::~MojoShellContext() { 277 MojoShellContext::~MojoShellContext() {
256 } 278 }
257 279
258 // static 280 // static
259 void MojoShellContext::ConnectToApplication( 281 void MojoShellContext::ConnectToApplication(
260 const GURL& url, 282 const GURL& url,
261 const GURL& requestor_url, 283 const GURL& requestor_url,
262 mojo::shell::mojom::InterfaceProviderRequest request, 284 mojo::shell::mojom::InterfaceProviderRequest request,
(...skipping 20 matching lines...) Expand all
283 mojo::shell::GetPermissiveCapabilityFilter())); 305 mojo::shell::GetPermissiveCapabilityFilter()));
284 params->set_target(mojo::shell::Identity( 306 params->set_target(mojo::shell::Identity(
285 url, std::string(), mojo::shell::mojom::Shell::kUserRoot, filter)); 307 url, std::string(), mojo::shell::mojom::Shell::kUserRoot, filter));
286 params->set_remote_interfaces(std::move(request)); 308 params->set_remote_interfaces(std::move(request));
287 params->set_local_interfaces(std::move(exposed_services)); 309 params->set_local_interfaces(std::move(exposed_services));
288 params->set_connect_callback(callback); 310 params->set_connect_callback(callback);
289 application_manager_->Connect(std::move(params)); 311 application_manager_->Connect(std::move(params));
290 } 312 }
291 313
292 } // namespace content 314 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698