| 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 <unordered_map> | 7 #include <unordered_map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "services/shell/public/interfaces/connector.mojom.h" | 41 #include "services/shell/public/interfaces/connector.mojom.h" |
| 42 #include "services/shell/public/interfaces/shell_client.mojom.h" | 42 #include "services/shell/public/interfaces/shell_client.mojom.h" |
| 43 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" | 43 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" |
| 44 #include "services/shell/runner/host/in_process_native_runner.h" | 44 #include "services/shell/runner/host/in_process_native_runner.h" |
| 45 #include "services/user/public/cpp/constants.h" | 45 #include "services/user/public/cpp/constants.h" |
| 46 | 46 |
| 47 namespace content { | 47 namespace content { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // An extra set of apps to register on initialization, if set by a test. | |
| 52 const MojoShellContext::StaticApplicationMap* g_applications_for_test; | |
| 53 | |
| 54 void StartUtilityProcessOnIOThread( | 51 void StartUtilityProcessOnIOThread( |
| 55 mojo::InterfaceRequest<mojom::ProcessControl> request, | 52 mojo::InterfaceRequest<mojom::ProcessControl> request, |
| 56 const base::string16& process_name, | 53 const base::string16& process_name, |
| 57 bool use_sandbox) { | 54 bool use_sandbox) { |
| 58 UtilityProcessHost* process_host = | 55 UtilityProcessHost* process_host = |
| 59 UtilityProcessHost::Create(nullptr, nullptr); | 56 UtilityProcessHost::Create(nullptr, nullptr); |
| 60 process_host->SetName(process_name); | 57 process_host->SetName(process_name); |
| 61 if (!use_sandbox) | 58 if (!use_sandbox) |
| 62 process_host->DisableSandbox(); | 59 process_host->DisableSandbox(); |
| 63 process_host->Start(); | 60 process_host->Start(); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 212 |
| 216 std::unique_ptr<shell::ShellClient> client_; | 213 std::unique_ptr<shell::ShellClient> client_; |
| 217 | 214 |
| 218 DISALLOW_COPY_AND_ASSIGN(ShellConnectionListener); | 215 DISALLOW_COPY_AND_ASSIGN(ShellConnectionListener); |
| 219 }; | 216 }; |
| 220 | 217 |
| 221 // static | 218 // static |
| 222 base::LazyInstance<std::unique_ptr<MojoShellContext::Proxy>> | 219 base::LazyInstance<std::unique_ptr<MojoShellContext::Proxy>> |
| 223 MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER; | 220 MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER; |
| 224 | 221 |
| 225 void MojoShellContext::SetApplicationsForTest( | |
| 226 const StaticApplicationMap* apps) { | |
| 227 g_applications_for_test = apps; | |
| 228 } | |
| 229 | |
| 230 MojoShellContext::MojoShellContext() { | 222 MojoShellContext::MojoShellContext() { |
| 231 proxy_.Get().reset(new Proxy(this)); | 223 proxy_.Get().reset(new Proxy(this)); |
| 232 | 224 |
| 233 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = | 225 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = |
| 234 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); | 226 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); |
| 235 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory( | 227 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory( |
| 236 new shell::InProcessNativeRunnerFactory( | 228 new shell::InProcessNativeRunnerFactory( |
| 237 BrowserThread::GetBlockingPool())); | 229 BrowserThread::GetBlockingPool())); |
| 238 | 230 |
| 239 manifest_provider_.reset(new BuiltinManifestProvider); | 231 manifest_provider_.reset(new BuiltinManifestProvider); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 253 shell_.reset(new shell::Shell(std::move(native_runner_factory), | 245 shell_.reset(new shell::Shell(std::move(native_runner_factory), |
| 254 catalog_->TakeShellClient())); | 246 catalog_->TakeShellClient())); |
| 255 MojoShellConnection::Create( | 247 MojoShellConnection::Create( |
| 256 shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName), | 248 shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName), |
| 257 false /* is_external */); | 249 false /* is_external */); |
| 258 } | 250 } |
| 259 | 251 |
| 260 std::unique_ptr<BrowserShellConnection> browser_shell_connection( | 252 std::unique_ptr<BrowserShellConnection> browser_shell_connection( |
| 261 new BrowserShellConnection); | 253 new BrowserShellConnection); |
| 262 | 254 |
| 263 StaticApplicationMap apps; | 255 ContentBrowserClient::StaticMojoApplicationMap apps; |
| 264 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 256 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
| 265 if (g_applications_for_test) { | |
| 266 // Add testing apps to the map, potentially overwriting whatever the | |
| 267 // browser client registered. | |
| 268 for (const auto& entry : *g_applications_for_test) | |
| 269 apps[entry.first] = entry.second; | |
| 270 } | |
| 271 for (const auto& entry : apps) { | 257 for (const auto& entry : apps) { |
| 272 browser_shell_connection->AddEmbeddedApplication( | 258 browser_shell_connection->AddEmbeddedApplication( |
| 273 entry.first, entry.second, nullptr); | 259 entry.first, entry.second.application_factory, |
| 260 entry.second.application_task_runner); |
| 274 } | 261 } |
| 275 | 262 |
| 276 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; | 263 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; |
| 277 GetContentClient() | 264 GetContentClient() |
| 278 ->browser() | 265 ->browser() |
| 279 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); | 266 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); |
| 280 for (const auto& app : sandboxed_apps) { | 267 for (const auto& app : sandboxed_apps) { |
| 281 browser_shell_connection->AddShellClientRequestHandler( | 268 browser_shell_connection->AddShellClientRequestHandler( |
| 282 app.first, | 269 app.first, |
| 283 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, | 270 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 shell::Identity source_id(requestor_name, user_id); | 324 shell::Identity source_id(requestor_name, user_id); |
| 338 params->set_source(source_id); | 325 params->set_source(source_id); |
| 339 params->set_target(shell::Identity(name, user_id)); | 326 params->set_target(shell::Identity(name, user_id)); |
| 340 params->set_remote_interfaces(std::move(request)); | 327 params->set_remote_interfaces(std::move(request)); |
| 341 params->set_local_interfaces(std::move(exposed_services)); | 328 params->set_local_interfaces(std::move(exposed_services)); |
| 342 params->set_connect_callback(callback); | 329 params->set_connect_callback(callback); |
| 343 shell_->Connect(std::move(params)); | 330 shell_->Connect(std::move(params)); |
| 344 } | 331 } |
| 345 | 332 |
| 346 } // namespace content | 333 } // namespace content |
| OLD | NEW |