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

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

Issue 1297953004: Support mojo applications in GPU process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase only Created 5 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 | « content/browser/gpu/gpu_process_host.cc ('k') | content/common/gpu/gpu_process_launch_causes.h » ('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 "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "content/browser/gpu/gpu_process_host.h"
13 #include "content/common/gpu/gpu_process_launch_causes.h"
12 #include "content/common/process_control.mojom.h" 14 #include "content/common/process_control.mojom.h"
13 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/utility_process_host.h" 17 #include "content/public/browser/utility_process_host.h"
16 #include "content/public/browser/utility_process_host_client.h" 18 #include "content/public/browser/utility_process_host_client.h"
17 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
18 #include "content/public/common/service_registry.h" 20 #include "content/public/common/service_registry.h"
19 #include "mojo/application/public/cpp/application_delegate.h" 21 #include "mojo/application/public/cpp/application_delegate.h"
20 #include "mojo/common/url_type_converters.h" 22 #include "mojo/common/url_type_converters.h"
21 #include "mojo/package_manager/package_manager_impl.h" 23 #include "mojo/package_manager/package_manager_impl.h"
22 #include "mojo/shell/application_loader.h" 24 #include "mojo/shell/application_loader.h"
23 #include "mojo/shell/connect_to_application_params.h" 25 #include "mojo/shell/connect_to_application_params.h"
24 #include "mojo/shell/identity.h" 26 #include "mojo/shell/identity.h"
25 #include "mojo/shell/static_application_loader.h" 27 #include "mojo/shell/static_application_loader.h"
26 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" 28 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
27 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h" 29 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h"
28 30
29 #if defined(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) 31 #if defined(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
30 #include "media/mojo/services/mojo_media_application.h" 32 #include "media/mojo/services/mojo_media_application.h"
31 #endif 33 #endif
32 34
33 namespace content { 35 namespace content {
34 36
35 namespace { 37 namespace {
36 38
37 // An extra set of apps to register on initialization, if set by a test. 39 // An extra set of apps to register on initialization, if set by a test.
38 const MojoShellContext::StaticApplicationMap* g_applications_for_test; 40 const MojoShellContext::StaticApplicationMap* g_applications_for_test;
39 41
40 void StartProcessOnIOThread(mojo::InterfaceRequest<ProcessControl> request, 42 void StartUtilityProcessOnIOThread(
41 const base::string16& process_name, 43 mojo::InterfaceRequest<ProcessControl> request,
42 bool use_sandbox) { 44 const base::string16& process_name,
45 bool use_sandbox) {
43 UtilityProcessHost* process_host = 46 UtilityProcessHost* process_host =
44 UtilityProcessHost::Create(nullptr, nullptr); 47 UtilityProcessHost::Create(nullptr, nullptr);
45 process_host->SetName(process_name); 48 process_host->SetName(process_name);
46 if (!use_sandbox) 49 if (!use_sandbox)
47 process_host->DisableSandbox(); 50 process_host->DisableSandbox();
48 process_host->StartMojoMode(); 51 process_host->StartMojoMode();
49 52
50 ServiceRegistry* services = process_host->GetServiceRegistry(); 53 ServiceRegistry* services = process_host->GetServiceRegistry();
51 services->ConnectToRemoteService(request.Pass()); 54 services->ConnectToRemoteService(request.Pass());
52 } 55 }
(...skipping 28 matching lines...) Expand all
81 : process_name_(process_name), use_sandbox_(use_sandbox) {} 84 : process_name_(process_name), use_sandbox_(use_sandbox) {}
82 ~UtilityProcessLoader() override {} 85 ~UtilityProcessLoader() override {}
83 86
84 private: 87 private:
85 // mojo::shell::ApplicationLoader: 88 // mojo::shell::ApplicationLoader:
86 void Load( 89 void Load(
87 const GURL& url, 90 const GURL& url,
88 mojo::InterfaceRequest<mojo::Application> application_request) override { 91 mojo::InterfaceRequest<mojo::Application> application_request) override {
89 ProcessControlPtr process_control; 92 ProcessControlPtr process_control;
90 auto process_request = mojo::GetProxy(&process_control); 93 auto process_request = mojo::GetProxy(&process_control);
91 BrowserThread::PostTask( 94 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
92 BrowserThread::IO, FROM_HERE, 95 base::Bind(&StartUtilityProcessOnIOThread,
93 base::Bind(&StartProcessOnIOThread, base::Passed(&process_request), 96 base::Passed(&process_request),
94 process_name_, use_sandbox_)); 97 process_name_, use_sandbox_));
95 process_control->LoadApplication(url.spec(), application_request.Pass(), 98 process_control->LoadApplication(url.spec(), application_request.Pass(),
96 base::Bind(&OnApplicationLoaded, url)); 99 base::Bind(&OnApplicationLoaded, url));
97 } 100 }
98 101
99 const base::string16 process_name_; 102 const base::string16 process_name_;
100 const bool use_sandbox_; 103 const bool use_sandbox_;
101 104
102 DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader); 105 DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader);
103 }; 106 };
104 107
108 // Request ProcessControl from GPU process host. Must be called on IO thread.
109 void RequestGpuProcessControl(mojo::InterfaceRequest<ProcessControl> request) {
110 BrowserChildProcessHostDelegate* process_host =
111 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
112 CAUSE_FOR_GPU_LAUNCH_MOJO_SETUP);
113 if (!process_host) {
114 DLOG(ERROR) << "GPU process host not available.";
115 return;
116 }
117
118 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual
119 // process is dead. In that case, |request| will be dropped and application
120 // load requests through ProcessControl will also fail. Make sure we handle
121 // these cases correctly.
122 process_host->GetServiceRegistry()->ConnectToRemoteService(request.Pass());
123 }
124
125 // Forwards the load request to the GPU process.
126 class GpuProcessLoader : public mojo::shell::ApplicationLoader {
127 public:
128 GpuProcessLoader() {}
129 ~GpuProcessLoader() override {}
130
131 private:
132 // mojo::shell::ApplicationLoader:
133 void Load(
134 const GURL& url,
135 mojo::InterfaceRequest<mojo::Application> application_request) override {
136 ProcessControlPtr process_control;
137 auto process_request = mojo::GetProxy(&process_control);
138 BrowserThread::PostTask(
139 BrowserThread::IO, FROM_HERE,
140 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request)));
141 process_control->LoadApplication(url.spec(), application_request.Pass(),
142 base::Bind(&OnApplicationLoaded, url));
143 }
144
145 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader);
146 };
147
105 } // namespace 148 } // namespace
106 149
107 // Thread-safe proxy providing access to the shell context from any thread. 150 // Thread-safe proxy providing access to the shell context from any thread.
108 class MojoShellContext::Proxy { 151 class MojoShellContext::Proxy {
109 public: 152 public:
110 Proxy(MojoShellContext* shell_context) 153 Proxy(MojoShellContext* shell_context)
111 : shell_context_(shell_context), 154 : shell_context_(shell_context),
112 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 155 task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
113 156
114 ~Proxy() {} 157 ~Proxy() {}
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 mojo::shell::GetPermissiveCapabilityFilter())); 285 mojo::shell::GetPermissiveCapabilityFilter()));
243 params->SetTarget(mojo::shell::Identity(url, std::string(), filter)); 286 params->SetTarget(mojo::shell::Identity(url, std::string(), filter));
244 params->set_services(request.Pass()); 287 params->set_services(request.Pass());
245 params->set_exposed_services(exposed_services.Pass()); 288 params->set_exposed_services(exposed_services.Pass());
246 params->set_on_application_end(base::Bind(&base::DoNothing)); 289 params->set_on_application_end(base::Bind(&base::DoNothing));
247 params->set_connect_callback(callback); 290 params->set_connect_callback(callback);
248 application_manager_->ConnectToApplication(params.Pass()); 291 application_manager_->ConnectToApplication(params.Pass());
249 } 292 }
250 293
251 } // namespace content 294 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host.cc ('k') | content/common/gpu/gpu_process_launch_causes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698