| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "components/profile_service/profile_app.h" | 17 #include "components/profile_service/profile_app.h" |
| 17 #include "content/browser/gpu/gpu_process_host.h" | 18 #include "content/browser/gpu/gpu_process_host.h" |
| 18 #include "content/browser/mojo/constants.h" | 19 #include "content/browser/mojo/constants.h" |
| 19 #include "content/common/gpu_process_launch_causes.h" | 20 #include "content/common/gpu_process_launch_causes.h" |
| 20 #include "content/common/mojo/current_thread_loader.h" | 21 #include "content/common/mojo/current_thread_loader.h" |
| 21 #include "content/common/mojo/mojo_shell_connection_impl.h" | 22 #include "content/common/mojo/mojo_shell_connection_impl.h" |
| 22 #include "content/common/mojo/static_loader.h" | 23 #include "content/common/mojo/static_loader.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 229 } |
| 229 | 230 |
| 230 private: | 231 private: |
| 231 MojoShellContext* shell_context_; | 232 MojoShellContext* shell_context_; |
| 232 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 233 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 233 | 234 |
| 234 DISALLOW_COPY_AND_ASSIGN(Proxy); | 235 DISALLOW_COPY_AND_ASSIGN(Proxy); |
| 235 }; | 236 }; |
| 236 | 237 |
| 237 // static | 238 // static |
| 238 base::LazyInstance<scoped_ptr<MojoShellContext::Proxy>> | 239 base::LazyInstance<std::unique_ptr<MojoShellContext::Proxy>> |
| 239 MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER; | 240 MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER; |
| 240 | 241 |
| 241 void MojoShellContext::SetApplicationsForTest( | 242 void MojoShellContext::SetApplicationsForTest( |
| 242 const StaticApplicationMap* apps) { | 243 const StaticApplicationMap* apps) { |
| 243 g_applications_for_test = apps; | 244 g_applications_for_test = apps; |
| 244 } | 245 } |
| 245 | 246 |
| 246 MojoShellContext::MojoShellContext( | 247 MojoShellContext::MojoShellContext( |
| 247 scoped_refptr<base::SingleThreadTaskRunner> file_thread, | 248 scoped_refptr<base::SingleThreadTaskRunner> file_thread, |
| 248 scoped_refptr<base::SingleThreadTaskRunner> db_thread) { | 249 scoped_refptr<base::SingleThreadTaskRunner> db_thread) { |
| 249 proxy_.Get().reset(new Proxy(this)); | 250 proxy_.Get().reset(new Proxy(this)); |
| 250 | 251 |
| 251 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = | 252 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = |
| 252 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); | 253 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); |
| 253 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( | 254 std::unique_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( |
| 254 new mojo::shell::InProcessNativeRunnerFactory( | 255 new mojo::shell::InProcessNativeRunnerFactory( |
| 255 BrowserThread::GetBlockingPool())); | 256 BrowserThread::GetBlockingPool())); |
| 256 manifest_provider_.reset(new BuiltinManifestProvider); | 257 manifest_provider_.reset(new BuiltinManifestProvider); |
| 257 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr, | 258 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr, |
| 258 manifest_provider_.get())); | 259 manifest_provider_.get())); |
| 259 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), | 260 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), |
| 260 catalog_->TakeShellClient())); | 261 catalog_->TakeShellClient())); |
| 261 shell_->set_default_loader( | 262 shell_->set_default_loader( |
| 262 scoped_ptr<mojo::shell::Loader>(new DefaultLoader)); | 263 std::unique_ptr<mojo::shell::Loader>(new DefaultLoader)); |
| 263 | 264 |
| 264 StaticApplicationMap apps; | 265 StaticApplicationMap apps; |
| 265 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 266 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
| 266 if (g_applications_for_test) { | 267 if (g_applications_for_test) { |
| 267 // Add testing apps to the map, potentially overwriting whatever the | 268 // Add testing apps to the map, potentially overwriting whatever the |
| 268 // browser client registered. | 269 // browser client registered. |
| 269 for (const auto& entry : *g_applications_for_test) | 270 for (const auto& entry : *g_applications_for_test) |
| 270 apps[entry.first] = entry.second; | 271 apps[entry.first] = entry.second; |
| 271 } | 272 } |
| 272 for (const auto& entry : apps) { | 273 for (const auto& entry : apps) { |
| 273 shell_->SetLoaderForName( | 274 shell_->SetLoaderForName(base::WrapUnique(new StaticLoader(entry.second)), |
| 274 make_scoped_ptr(new StaticLoader(entry.second)), entry.first); | 275 entry.first); |
| 275 } | 276 } |
| 276 | 277 |
| 277 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; | 278 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; |
| 278 GetContentClient() | 279 GetContentClient() |
| 279 ->browser() | 280 ->browser() |
| 280 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); | 281 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); |
| 281 for (const auto& app : sandboxed_apps) { | 282 for (const auto& app : sandboxed_apps) { |
| 282 shell_->SetLoaderForName( | 283 shell_->SetLoaderForName(base::WrapUnique(new UtilityProcessLoader( |
| 283 make_scoped_ptr( | 284 app.second, true /* use_sandbox */)), |
| 284 new UtilityProcessLoader(app.second, true /* use_sandbox */)), | 285 app.first); |
| 285 app.first); | |
| 286 } | 286 } |
| 287 | 287 |
| 288 ContentBrowserClient::OutOfProcessMojoApplicationMap unsandboxed_apps; | 288 ContentBrowserClient::OutOfProcessMojoApplicationMap unsandboxed_apps; |
| 289 GetContentClient() | 289 GetContentClient() |
| 290 ->browser() | 290 ->browser() |
| 291 ->RegisterUnsandboxedOutOfProcessMojoApplications(&unsandboxed_apps); | 291 ->RegisterUnsandboxedOutOfProcessMojoApplications(&unsandboxed_apps); |
| 292 for (const auto& app : unsandboxed_apps) { | 292 for (const auto& app : unsandboxed_apps) { |
| 293 shell_->SetLoaderForName( | 293 shell_->SetLoaderForName(base::WrapUnique(new UtilityProcessLoader( |
| 294 make_scoped_ptr( | 294 app.second, false /* use_sandbox */)), |
| 295 new UtilityProcessLoader(app.second, false /* use_sandbox */)), | 295 app.first); |
| 296 app.first); | |
| 297 } | 296 } |
| 298 | 297 |
| 299 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 298 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 300 shell_->SetLoaderForName(make_scoped_ptr(new GpuProcessLoader), "mojo:media"); | 299 shell_->SetLoaderForName(base::WrapUnique(new GpuProcessLoader), |
| 300 "mojo:media"); |
| 301 #endif | 301 #endif |
| 302 | 302 |
| 303 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 303 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 304 switches::kMojoLocalStorage)) { | 304 switches::kMojoLocalStorage)) { |
| 305 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = | 305 base::Callback<std::unique_ptr<mojo::ShellClient>()> profile_callback = |
| 306 base::Bind(&profile::CreateProfileApp, file_thread, db_thread); | 306 base::Bind(&profile::CreateProfileApp, file_thread, db_thread); |
| 307 shell_->SetLoaderForName( | 307 shell_->SetLoaderForName( |
| 308 make_scoped_ptr(new CurrentThreadLoader(profile_callback)), | 308 base::WrapUnique(new CurrentThreadLoader(profile_callback)), |
| 309 "mojo:profile"); | 309 "mojo:profile"); |
| 310 } | 310 } |
| 311 | 311 |
| 312 if (!IsRunningInMojoShell()) { | 312 if (!IsRunningInMojoShell()) { |
| 313 MojoShellConnection::Create( | 313 MojoShellConnection::Create( |
| 314 shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName), | 314 shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName), |
| 315 false /* is_external */); | 315 false /* is_external */); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 334 std::move(exposed_services), callback); | 334 std::move(exposed_services), callback); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void MojoShellContext::ConnectToApplicationOnOwnThread( | 337 void MojoShellContext::ConnectToApplicationOnOwnThread( |
| 338 const std::string& user_id, | 338 const std::string& user_id, |
| 339 const std::string& name, | 339 const std::string& name, |
| 340 const std::string& requestor_name, | 340 const std::string& requestor_name, |
| 341 mojo::shell::mojom::InterfaceProviderRequest request, | 341 mojo::shell::mojom::InterfaceProviderRequest request, |
| 342 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 342 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 343 const mojo::shell::mojom::Connector::ConnectCallback& callback) { | 343 const mojo::shell::mojom::Connector::ConnectCallback& callback) { |
| 344 scoped_ptr<mojo::shell::ConnectParams> params(new mojo::shell::ConnectParams); | 344 std::unique_ptr<mojo::shell::ConnectParams> params( |
| 345 new mojo::shell::ConnectParams); |
| 345 mojo::Identity source_id(requestor_name, user_id); | 346 mojo::Identity source_id(requestor_name, user_id); |
| 346 params->set_source(source_id); | 347 params->set_source(source_id); |
| 347 params->set_target(mojo::Identity(name, user_id)); | 348 params->set_target(mojo::Identity(name, user_id)); |
| 348 params->set_remote_interfaces(std::move(request)); | 349 params->set_remote_interfaces(std::move(request)); |
| 349 params->set_local_interfaces(std::move(exposed_services)); | 350 params->set_local_interfaces(std::move(exposed_services)); |
| 350 params->set_connect_callback(callback); | 351 params->set_connect_callback(callback); |
| 351 shell_->Connect(std::move(params)); | 352 shell_->Connect(std::move(params)); |
| 352 } | 353 } |
| 353 | 354 |
| 354 } // namespace content | 355 } // namespace content |
| OLD | NEW |