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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 base::LazyInstance<ConnectorPtr>::Leaky io_connector_tls_ptr = | 54 base::LazyInstance<ConnectorPtr>::Leaky io_connector_tls_ptr = |
55 LAZY_INSTANCE_INITIALIZER; | 55 LAZY_INSTANCE_INITIALIZER; |
56 | 56 |
57 void SetConnectorOnIOThread(std::unique_ptr<shell::Connector> connector) { | 57 void SetConnectorOnIOThread(std::unique_ptr<shell::Connector> connector) { |
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
59 io_connector_tls_ptr.Pointer()->Set(connector.release()); | 59 io_connector_tls_ptr.Pointer()->Set(connector.release()); |
60 } | 60 } |
61 | 61 |
62 void DestroyConnectorOnIOThread() { | 62 void DestroyConnectorOnIOThread() { |
63 delete MojoShellContext::GetConnectorForIOThread(); | 63 delete ShellContext::GetConnectorForIOThread(); |
64 io_connector_tls_ptr.Pointer()->Set(nullptr); | 64 io_connector_tls_ptr.Pointer()->Set(nullptr); |
65 } | 65 } |
66 | 66 |
67 void StartUtilityProcessOnIOThread( | 67 void StartUtilityProcessOnIOThread( |
68 mojo::InterfaceRequest<mojom::ProcessControl> request, | 68 mojo::InterfaceRequest<mojom::ProcessControl> request, |
69 const base::string16& process_name, | 69 const base::string16& process_name, |
70 bool use_sandbox) { | 70 bool use_sandbox) { |
71 UtilityProcessHost* process_host = | 71 UtilityProcessHost* process_host = |
72 UtilityProcessHost::Create(nullptr, nullptr); | 72 UtilityProcessHost::Create(nullptr, nullptr); |
73 process_host->SetName(process_name); | 73 process_host->SetName(process_name); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 const std::string& name, | 329 const std::string& name, |
330 const std::string& requestor_name, | 330 const std::string& requestor_name, |
331 shell::mojom::InterfaceProviderRequest request, | 331 shell::mojom::InterfaceProviderRequest request, |
332 shell::mojom::InterfaceProviderPtr exposed_services, | 332 shell::mojom::InterfaceProviderPtr exposed_services, |
333 const shell::mojom::Connector::ConnectCallback& callback) { | 333 const shell::mojom::Connector::ConnectCallback& callback) { |
334 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, | 334 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, |
335 std::move(request), | 335 std::move(request), |
336 std::move(exposed_services), callback); | 336 std::move(exposed_services), callback); |
337 } | 337 } |
338 | 338 |
339 // static | |
340 shell::Connector* MojoShellContext::GetConnectorForIOThread() { | |
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
342 return io_connector_tls_ptr.Pointer()->Get(); | |
343 } | |
344 | |
345 void MojoShellContext::ConnectToApplicationOnOwnThread( | 339 void MojoShellContext::ConnectToApplicationOnOwnThread( |
346 const std::string& user_id, | 340 const std::string& user_id, |
347 const std::string& name, | 341 const std::string& name, |
348 const std::string& requestor_name, | 342 const std::string& requestor_name, |
349 shell::mojom::InterfaceProviderRequest request, | 343 shell::mojom::InterfaceProviderRequest request, |
350 shell::mojom::InterfaceProviderPtr exposed_services, | 344 shell::mojom::InterfaceProviderPtr exposed_services, |
351 const shell::mojom::Connector::ConnectCallback& callback) { | 345 const shell::mojom::Connector::ConnectCallback& callback) { |
352 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); | 346 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); |
353 shell::Identity source_id(requestor_name, user_id); | 347 shell::Identity source_id(requestor_name, user_id); |
354 params->set_source(source_id); | 348 params->set_source(source_id); |
355 params->set_target(shell::Identity(name, user_id)); | 349 params->set_target(shell::Identity(name, user_id)); |
356 params->set_remote_interfaces(std::move(request)); | 350 params->set_remote_interfaces(std::move(request)); |
357 params->set_local_interfaces(std::move(exposed_services)); | 351 params->set_local_interfaces(std::move(exposed_services)); |
358 params->set_connect_callback(callback); | 352 params->set_connect_callback(callback); |
359 shell_->Connect(std::move(params)); | 353 shell_->Connect(std::move(params)); |
360 } | 354 } |
361 | 355 |
| 356 // static |
| 357 std::unique_ptr<ShellContext> ShellContext::Create() { |
| 358 return base::WrapUnique(new MojoShellContext); |
| 359 } |
| 360 |
| 361 // static |
| 362 shell::Connector* ShellContext::GetConnectorForIOThread() { |
| 363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 364 return io_connector_tls_ptr.Pointer()->Get(); |
| 365 } |
| 366 |
| 367 |
362 } // namespace content | 368 } // namespace content |
OLD | NEW |