| 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 <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" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 // The default loader to use for all applications. This does nothing but drop | 60 // The default loader to use for all applications. This does nothing but drop |
| 61 // the Application request. | 61 // the Application request. |
| 62 class DefaultApplicationLoader : public mojo::shell::ApplicationLoader { | 62 class DefaultApplicationLoader : public mojo::shell::ApplicationLoader { |
| 63 public: | 63 public: |
| 64 DefaultApplicationLoader() {} | 64 DefaultApplicationLoader() {} |
| 65 ~DefaultApplicationLoader() override {} | 65 ~DefaultApplicationLoader() override {} |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 // mojo::shell::ApplicationLoader: | 68 // mojo::shell::ApplicationLoader: |
| 69 void Load( | 69 void Load(const GURL& url, |
| 70 const GURL& url, | 70 mojo::InterfaceRequest<mojo::shell::mojom::Application> request) |
| 71 mojo::InterfaceRequest<mojo::Application> application_request) override {} | 71 override {} |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(DefaultApplicationLoader); | 73 DISALLOW_COPY_AND_ASSIGN(DefaultApplicationLoader); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // This launches a utility process and forwards the Load request the | 76 // This launches a utility process and forwards the Load request the |
| 77 // ProcessControl service there. The utility process is sandboxed iff | 77 // ProcessControl service there. The utility process is sandboxed iff |
| 78 // |use_sandbox| is true. | 78 // |use_sandbox| is true. |
| 79 class UtilityProcessLoader : public mojo::shell::ApplicationLoader { | 79 class UtilityProcessLoader : public mojo::shell::ApplicationLoader { |
| 80 public: | 80 public: |
| 81 UtilityProcessLoader(const base::string16& process_name, bool use_sandbox) | 81 UtilityProcessLoader(const base::string16& process_name, bool use_sandbox) |
| 82 : process_name_(process_name), use_sandbox_(use_sandbox) {} | 82 : process_name_(process_name), use_sandbox_(use_sandbox) {} |
| 83 ~UtilityProcessLoader() override {} | 83 ~UtilityProcessLoader() override {} |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 // mojo::shell::ApplicationLoader: | 86 // mojo::shell::ApplicationLoader: |
| 87 void Load( | 87 void Load(const GURL& url, |
| 88 const GURL& url, | 88 mojo::InterfaceRequest<mojo::shell::mojom::Application> request) |
| 89 mojo::InterfaceRequest<mojo::Application> application_request) override { | 89 override { |
| 90 ProcessControlPtr process_control; | 90 ProcessControlPtr process_control; |
| 91 auto process_request = mojo::GetProxy(&process_control); | 91 auto process_request = mojo::GetProxy(&process_control); |
| 92 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 92 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 93 base::Bind(&StartUtilityProcessOnIOThread, | 93 base::Bind(&StartUtilityProcessOnIOThread, |
| 94 base::Passed(&process_request), | 94 base::Passed(&process_request), |
| 95 process_name_, use_sandbox_)); | 95 process_name_, use_sandbox_)); |
| 96 process_control->LoadApplication(url.spec(), std::move(application_request), | 96 process_control->LoadApplication(url.spec(), std::move(request), |
| 97 base::Bind(&OnApplicationLoaded, url)); | 97 base::Bind(&OnApplicationLoaded, url)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 const base::string16 process_name_; | 100 const base::string16 process_name_; |
| 101 const bool use_sandbox_; | 101 const bool use_sandbox_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader); | 103 DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Request ProcessControl from GPU process host. Must be called on IO thread. | 106 // Request ProcessControl from GPU process host. Must be called on IO thread. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Forwards the load request to the GPU process. | 124 // Forwards the load request to the GPU process. |
| 125 class GpuProcessLoader : public mojo::shell::ApplicationLoader { | 125 class GpuProcessLoader : public mojo::shell::ApplicationLoader { |
| 126 public: | 126 public: |
| 127 GpuProcessLoader() {} | 127 GpuProcessLoader() {} |
| 128 ~GpuProcessLoader() override {} | 128 ~GpuProcessLoader() override {} |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 // mojo::shell::ApplicationLoader: | 131 // mojo::shell::ApplicationLoader: |
| 132 void Load( | 132 void Load(const GURL& url, |
| 133 const GURL& url, | 133 mojo::InterfaceRequest<mojo::shell::mojom::Application> request) |
| 134 mojo::InterfaceRequest<mojo::Application> application_request) override { | 134 override { |
| 135 ProcessControlPtr process_control; | 135 ProcessControlPtr process_control; |
| 136 auto process_request = mojo::GetProxy(&process_control); | 136 auto process_request = mojo::GetProxy(&process_control); |
| 137 BrowserThread::PostTask( | 137 BrowserThread::PostTask( |
| 138 BrowserThread::IO, FROM_HERE, | 138 BrowserThread::IO, FROM_HERE, |
| 139 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); | 139 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
| 140 process_control->LoadApplication(url.spec(), std::move(application_request), | 140 process_control->LoadApplication(url.spec(), std::move(request), |
| 141 base::Bind(&OnApplicationLoaded, url)); | 141 base::Bind(&OnApplicationLoaded, url)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); | 144 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 } // namespace | 147 } // namespace |
| 148 | 148 |
| 149 // Thread-safe proxy providing access to the shell context from any thread. | 149 // Thread-safe proxy providing access to the shell context from any thread. |
| 150 class MojoShellContext::Proxy { | 150 class MojoShellContext::Proxy { |
| 151 public: | 151 public: |
| 152 Proxy(MojoShellContext* shell_context) | 152 Proxy(MojoShellContext* shell_context) |
| 153 : shell_context_(shell_context), | 153 : shell_context_(shell_context), |
| 154 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 154 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 155 | 155 |
| 156 ~Proxy() {} | 156 ~Proxy() {} |
| 157 | 157 |
| 158 void ConnectToApplication( | 158 void ConnectToApplication( |
| 159 const GURL& url, | 159 const GURL& url, |
| 160 const GURL& requestor_url, | 160 const GURL& requestor_url, |
| 161 mojo::InterfaceRequest<mojo::ServiceProvider> request, | 161 mojo::InterfaceRequest<mojo::ServiceProvider> request, |
| 162 mojo::ServiceProviderPtr exposed_services, | 162 mojo::ServiceProviderPtr exposed_services, |
| 163 const mojo::shell::CapabilityFilter& filter, | 163 const mojo::shell::CapabilityFilter& filter, |
| 164 const mojo::Shell::ConnectToApplicationCallback& callback) { | 164 const mojo::shell::mojom::Shell::ConnectToApplicationCallback& callback) { |
| 165 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { | 165 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { |
| 166 if (shell_context_) { | 166 if (shell_context_) { |
| 167 shell_context_->ConnectToApplicationOnOwnThread( | 167 shell_context_->ConnectToApplicationOnOwnThread( |
| 168 url, requestor_url, std::move(request), std::move(exposed_services), | 168 url, requestor_url, std::move(request), std::move(exposed_services), |
| 169 filter, callback); | 169 filter, callback); |
| 170 } | 170 } |
| 171 } else { | 171 } else { |
| 172 // |shell_context_| outlives the main MessageLoop, so it's safe for it to | 172 // |shell_context_| outlives the main MessageLoop, so it's safe for it to |
| 173 // be unretained here. | 173 // be unretained here. |
| 174 task_runner_->PostTask( | 174 task_runner_->PostTask( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 MojoShellContext::~MojoShellContext() { | 256 MojoShellContext::~MojoShellContext() { |
| 257 } | 257 } |
| 258 | 258 |
| 259 // static | 259 // static |
| 260 void MojoShellContext::ConnectToApplication( | 260 void MojoShellContext::ConnectToApplication( |
| 261 const GURL& url, | 261 const GURL& url, |
| 262 const GURL& requestor_url, | 262 const GURL& requestor_url, |
| 263 mojo::InterfaceRequest<mojo::ServiceProvider> request, | 263 mojo::InterfaceRequest<mojo::ServiceProvider> request, |
| 264 mojo::ServiceProviderPtr exposed_services, | 264 mojo::ServiceProviderPtr exposed_services, |
| 265 const mojo::shell::CapabilityFilter& filter, | 265 const mojo::shell::CapabilityFilter& filter, |
| 266 const mojo::Shell::ConnectToApplicationCallback& callback) { | 266 const mojo::shell::mojom::Shell::ConnectToApplicationCallback& callback) { |
| 267 proxy_.Get()->ConnectToApplication(url, requestor_url, std::move(request), | 267 proxy_.Get()->ConnectToApplication(url, requestor_url, std::move(request), |
| 268 std::move(exposed_services), filter, | 268 std::move(exposed_services), filter, |
| 269 callback); | 269 callback); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void MojoShellContext::ConnectToApplicationOnOwnThread( | 272 void MojoShellContext::ConnectToApplicationOnOwnThread( |
| 273 const GURL& url, | 273 const GURL& url, |
| 274 const GURL& requestor_url, | 274 const GURL& requestor_url, |
| 275 mojo::InterfaceRequest<mojo::ServiceProvider> request, | 275 mojo::InterfaceRequest<mojo::ServiceProvider> request, |
| 276 mojo::ServiceProviderPtr exposed_services, | 276 mojo::ServiceProviderPtr exposed_services, |
| 277 const mojo::shell::CapabilityFilter& filter, | 277 const mojo::shell::CapabilityFilter& filter, |
| 278 const mojo::Shell::ConnectToApplicationCallback& callback) { | 278 const mojo::shell::mojom::Shell::ConnectToApplicationCallback& callback) { |
| 279 scoped_ptr<mojo::shell::ConnectToApplicationParams> params( | 279 scoped_ptr<mojo::shell::ConnectToApplicationParams> params( |
| 280 new mojo::shell::ConnectToApplicationParams); | 280 new mojo::shell::ConnectToApplicationParams); |
| 281 params->set_source( | 281 params->set_source( |
| 282 mojo::shell::Identity(requestor_url, std::string(), | 282 mojo::shell::Identity(requestor_url, std::string(), |
| 283 mojo::shell::GetPermissiveCapabilityFilter())); | 283 mojo::shell::GetPermissiveCapabilityFilter())); |
| 284 params->SetTarget(mojo::shell::Identity(url, std::string(), filter)); | 284 params->SetTarget(mojo::shell::Identity(url, std::string(), filter)); |
| 285 params->set_services(std::move(request)); | 285 params->set_services(std::move(request)); |
| 286 params->set_exposed_services(std::move(exposed_services)); | 286 params->set_exposed_services(std::move(exposed_services)); |
| 287 params->set_on_application_end(base::Bind(&base::DoNothing)); | 287 params->set_on_application_end(base::Bind(&base::DoNothing)); |
| 288 params->set_connect_callback(callback); | 288 params->set_connect_callback(callback); |
| 289 application_manager_->ConnectToApplication(std::move(params)); | 289 application_manager_->ConnectToApplication(std::move(params)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace content | 292 } // namespace content |
| OLD | NEW |