Chromium Code Reviews| Index: content/browser/mojo/mojo_shell_context.cc |
| diff --git a/content/browser/mojo/mojo_shell_context.cc b/content/browser/mojo/mojo_shell_context.cc |
| index db77c35f4e5985c85594eab894d91f5e95fae11b..c0eb45d5ba505c1ffc7cd6156ba13b225962014f 100644 |
| --- a/content/browser/mojo/mojo_shell_context.cc |
| +++ b/content/browser/mojo/mojo_shell_context.cc |
| @@ -9,6 +9,8 @@ |
| #include "base/path_service.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/thread_task_runner_handle.h" |
| +#include "content/browser/gpu/gpu_process_host.h" |
| +#include "content/common/gpu/gpu_process_launch_causes.h" |
| #include "content/common/process_control.mojom.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| @@ -37,9 +39,10 @@ namespace { |
| // An extra set of apps to register on initialization, if set by a test. |
| const MojoShellContext::StaticApplicationMap* g_applications_for_test; |
| -void StartProcessOnIOThread(mojo::InterfaceRequest<ProcessControl> request, |
| - const base::string16& process_name, |
| - bool use_sandbox) { |
| +void StartUtilityProcessOnIOThread( |
| + mojo::InterfaceRequest<ProcessControl> request, |
| + const base::string16& process_name, |
| + bool use_sandbox) { |
| UtilityProcessHost* process_host = |
| UtilityProcessHost::Create(nullptr, nullptr); |
| process_host->SetName(process_name); |
| @@ -88,10 +91,10 @@ class UtilityProcessLoader : public mojo::shell::ApplicationLoader { |
| mojo::InterfaceRequest<mojo::Application> application_request) override { |
| ProcessControlPtr process_control; |
| auto process_request = mojo::GetProxy(&process_control); |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, |
| - base::Bind(&StartProcessOnIOThread, base::Passed(&process_request), |
| - process_name_, use_sandbox_)); |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(&StartUtilityProcessOnIOThread, |
| + base::Passed(&process_request), |
| + process_name_, use_sandbox_)); |
| process_control->LoadApplication(url.spec(), application_request.Pass(), |
| base::Bind(&OnApplicationLoaded, url)); |
| } |
| @@ -102,6 +105,48 @@ class UtilityProcessLoader : public mojo::shell::ApplicationLoader { |
| DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader); |
| }; |
| +// Request ProcessControl from GPU process host. Must be called on IO thread. |
| +void RequestGpuProcessControl(mojo::InterfaceRequest<ProcessControl> request) { |
| + BrowserChildProcessHostDelegate* process_host = |
| + GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| + CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH); |
|
piman
2015/10/06 19:59:35
What happens if the GPU process is not launched ye
xhwang
2015/10/07 19:07:58
Great question. If the process is not launched yet
piman
2015/10/08 22:37:02
Yes, this is typically what we do in places we nee
xhwang
2015/10/09 23:36:35
Thanks for all the info! It seems to me in both (1
|
| + if (!process_host) { |
| + LOG(ERROR) << "GPU process host not available."; |
|
piman
2015/10/06 19:59:35
DLOG
xhwang
2015/10/07 19:07:58
Done.
|
| + return; |
| + } |
| + |
| + ServiceRegistry* service_registry = process_host->GetServiceRegistry(); |
| + if (!service_registry) { |
|
piman
2015/10/06 19:59:35
When would this be false?
xhwang
2015/10/07 19:07:58
Done.
|
| + LOG(ERROR) << "ServiceRegistry not available in GPU process host."; |
|
piman
2015/10/06 19:59:35
DLOG
xhwang
2015/10/07 19:07:58
Obsolete now.
|
| + return; |
| + } |
| + |
| + service_registry->ConnectToRemoteService(request.Pass()); |
| +} |
| + |
| +// Forwards the load request to the GPU process. |
| +class GpuProcessLoader : public mojo::shell::ApplicationLoader { |
| + public: |
| + GpuProcessLoader() {} |
| + ~GpuProcessLoader() override {} |
| + |
| + private: |
| + // mojo::shell::ApplicationLoader: |
| + void Load( |
| + const GURL& url, |
| + mojo::InterfaceRequest<mojo::Application> application_request) override { |
| + ProcessControlPtr process_control; |
| + auto process_request = mojo::GetProxy(&process_control); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
| + process_control->LoadApplication(url.spec(), application_request.Pass(), |
| + base::Bind(&OnApplicationLoaded, url)); |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); |
| +}; |
| + |
| } // namespace |
| // Thread-safe proxy providing access to the shell context from any thread. |