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