| OLD | NEW |
| 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 Loading... |
| 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_NO_LAUNCH); |
| 113 if (!process_host) { |
| 114 LOG(ERROR) << "GPU process host not available."; |
| 115 return; |
| 116 } |
| 117 |
| 118 ServiceRegistry* service_registry = process_host->GetServiceRegistry(); |
| 119 if (!service_registry) { |
| 120 LOG(ERROR) << "ServiceRegistry not available in GPU process host."; |
| 121 return; |
| 122 } |
| 123 |
| 124 service_registry->ConnectToRemoteService(request.Pass()); |
| 125 } |
| 126 |
| 127 // Forwards the load request to the GPU process. |
| 128 class GpuProcessLoader : public mojo::shell::ApplicationLoader { |
| 129 public: |
| 130 GpuProcessLoader() {} |
| 131 ~GpuProcessLoader() override {} |
| 132 |
| 133 private: |
| 134 // mojo::shell::ApplicationLoader: |
| 135 void Load( |
| 136 const GURL& url, |
| 137 mojo::InterfaceRequest<mojo::Application> application_request) override { |
| 138 ProcessControlPtr process_control; |
| 139 auto process_request = mojo::GetProxy(&process_control); |
| 140 BrowserThread::PostTask( |
| 141 BrowserThread::IO, FROM_HERE, |
| 142 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
| 143 process_control->LoadApplication(url.spec(), application_request.Pass(), |
| 144 base::Bind(&OnApplicationLoaded, url)); |
| 145 } |
| 146 |
| 147 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); |
| 148 }; |
| 149 |
| 105 } // namespace | 150 } // namespace |
| 106 | 151 |
| 107 // Thread-safe proxy providing access to the shell context from any thread. | 152 // Thread-safe proxy providing access to the shell context from any thread. |
| 108 class MojoShellContext::Proxy { | 153 class MojoShellContext::Proxy { |
| 109 public: | 154 public: |
| 110 Proxy(MojoShellContext* shell_context) | 155 Proxy(MojoShellContext* shell_context) |
| 111 : shell_context_(shell_context), | 156 : shell_context_(shell_context), |
| 112 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 157 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 113 | 158 |
| 114 ~Proxy() {} | 159 ~Proxy() {} |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 mojo::shell::GetPermissiveCapabilityFilter())); | 287 mojo::shell::GetPermissiveCapabilityFilter())); |
| 243 params->SetTarget(mojo::shell::Identity(url, std::string(), filter)); | 288 params->SetTarget(mojo::shell::Identity(url, std::string(), filter)); |
| 244 params->set_services(request.Pass()); | 289 params->set_services(request.Pass()); |
| 245 params->set_exposed_services(exposed_services.Pass()); | 290 params->set_exposed_services(exposed_services.Pass()); |
| 246 params->set_on_application_end(base::Bind(&base::DoNothing)); | 291 params->set_on_application_end(base::Bind(&base::DoNothing)); |
| 247 params->set_connect_callback(callback); | 292 params->set_connect_callback(callback); |
| 248 application_manager_->ConnectToApplication(params.Pass()); | 293 application_manager_->ConnectToApplication(params.Pass()); |
| 249 } | 294 } |
| 250 | 295 |
| 251 } // namespace content | 296 } // namespace content |
| OLD | NEW |