| 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" |
| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 g_applications_for_test = apps; | 200 g_applications_for_test = apps; |
| 195 } | 201 } |
| 196 | 202 |
| 197 MojoShellContext::MojoShellContext() { | 203 MojoShellContext::MojoShellContext() { |
| 198 proxy_.Get().reset(new Proxy(this)); | 204 proxy_.Get().reset(new Proxy(this)); |
| 199 | 205 |
| 200 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = | 206 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = |
| 201 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); | 207 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); |
| 202 bool register_mojo_url_schemes = false; | 208 bool register_mojo_url_schemes = false; |
| 203 | 209 |
| 210 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( |
| 211 new mojo::shell::InProcessNativeRunnerFactory( |
| 212 BrowserThread::GetBlockingPool())); |
| 204 application_manager_.reset(new mojo::shell::ApplicationManager( | 213 application_manager_.reset(new mojo::shell::ApplicationManager( |
| 205 nullptr, file_task_runner.get(), register_mojo_url_schemes, nullptr)); | 214 std::move(native_runner_factory), file_task_runner.get(), |
| 215 register_mojo_url_schemes, nullptr)); |
| 206 | 216 |
| 207 application_manager_->set_default_loader( | 217 application_manager_->set_default_loader( |
| 208 scoped_ptr<mojo::shell::ApplicationLoader>(new DefaultApplicationLoader)); | 218 scoped_ptr<mojo::shell::ApplicationLoader>(new DefaultApplicationLoader)); |
| 209 | 219 |
| 210 StaticApplicationMap apps; | 220 StaticApplicationMap apps; |
| 211 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 221 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
| 212 if (g_applications_for_test) { | 222 if (g_applications_for_test) { |
| 213 // Add testing apps to the map, potentially overwriting whatever the | 223 // Add testing apps to the map, potentially overwriting whatever the |
| 214 // browser client registered. | 224 // browser client registered. |
| 215 for (const auto& entry : *g_applications_for_test) | 225 for (const auto& entry : *g_applications_for_test) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 242 scoped_ptr<mojo::shell::ApplicationLoader>( | 252 scoped_ptr<mojo::shell::ApplicationLoader>( |
| 243 new UtilityProcessLoader(app.second, false /* use_sandbox */)), | 253 new UtilityProcessLoader(app.second, false /* use_sandbox */)), |
| 244 app.first); | 254 app.first); |
| 245 } | 255 } |
| 246 | 256 |
| 247 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 257 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 248 application_manager_->SetLoaderForURL( | 258 application_manager_->SetLoaderForURL( |
| 249 scoped_ptr<mojo::shell::ApplicationLoader>(new GpuProcessLoader()), | 259 scoped_ptr<mojo::shell::ApplicationLoader>(new GpuProcessLoader()), |
| 250 GURL("mojo:media")); | 260 GURL("mojo:media")); |
| 251 #endif | 261 #endif |
| 262 |
| 263 if (!IsRunningInMojoShell()) { |
| 264 MojoShellConnectionImpl::Create( |
| 265 application_manager_->InitInstanceForEmbedder(GURL(kBrowserAppUrl))); |
| 266 } |
| 252 } | 267 } |
| 253 | 268 |
| 254 MojoShellContext::~MojoShellContext() { | 269 MojoShellContext::~MojoShellContext() { |
| 270 if (!IsRunningInMojoShell()) |
| 271 MojoShellConnectionImpl::Destroy(); |
| 255 } | 272 } |
| 256 | 273 |
| 257 // static | 274 // static |
| 258 void MojoShellContext::ConnectToApplication( | 275 void MojoShellContext::ConnectToApplication( |
| 259 const GURL& url, | 276 const GURL& url, |
| 260 const GURL& requestor_url, | 277 const GURL& requestor_url, |
| 261 mojo::shell::mojom::InterfaceProviderRequest request, | 278 mojo::shell::mojom::InterfaceProviderRequest request, |
| 262 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 279 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 263 const mojo::shell::mojom::Connector::ConnectCallback& callback) { | 280 const mojo::shell::mojom::Connector::ConnectCallback& callback) { |
| 264 proxy_.Get()->ConnectToApplication(url, requestor_url, std::move(request), | 281 proxy_.Get()->ConnectToApplication(url, requestor_url, std::move(request), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 282 params->set_source(source_id); | 299 params->set_source(source_id); |
| 283 params->set_target(mojo::shell::Identity( | 300 params->set_target(mojo::shell::Identity( |
| 284 url, std::string(), mojo::shell::mojom::Connector::kUserRoot)); | 301 url, std::string(), mojo::shell::mojom::Connector::kUserRoot)); |
| 285 params->set_remote_interfaces(std::move(request)); | 302 params->set_remote_interfaces(std::move(request)); |
| 286 params->set_local_interfaces(std::move(exposed_services)); | 303 params->set_local_interfaces(std::move(exposed_services)); |
| 287 params->set_connect_callback(callback); | 304 params->set_connect_callback(callback); |
| 288 application_manager_->Connect(std::move(params)); | 305 application_manager_->Connect(std::move(params)); |
| 289 } | 306 } |
| 290 | 307 |
| 291 } // namespace content | 308 } // namespace content |
| OLD | NEW |