Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(863)

Side by Side Diff: content/browser/mojo/mojo_shell_context.cc

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "services/shell/public/interfaces/service.mojom.h" 42 #include "services/shell/public/interfaces/service.mojom.h"
43 #include "services/shell/public/interfaces/service_factory.mojom.h" 43 #include "services/shell/public/interfaces/service_factory.mojom.h"
44 #include "services/shell/runner/common/client_util.h" 44 #include "services/shell/runner/common/client_util.h"
45 #include "services/shell/runner/host/in_process_native_runner.h" 45 #include "services/shell/runner/host/in_process_native_runner.h"
46 #include "services/user/public/cpp/constants.h" 46 #include "services/user/public/cpp/constants.h"
47 47
48 namespace content { 48 namespace content {
49 49
50 namespace { 50 namespace {
51 51
52 using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>; 52 base::LazyInstance<std::unique_ptr<shell::Connector>>::Leaky
53 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER;
53 54
54 base::LazyInstance<ConnectorPtr>::Leaky io_connector_tls_ptr = 55 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); }
55 LAZY_INSTANCE_INITIALIZER;
56
57 void SetConnectorOnIOThread(std::unique_ptr<shell::Connector> connector) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
59 io_connector_tls_ptr.Pointer()->Set(connector.release());
60 }
61
62 void DestroyConnectorOnIOThread() {
63 delete MojoShellContext::GetConnectorForIOThread();
64 io_connector_tls_ptr.Pointer()->Set(nullptr);
65 }
66 56
67 void StartUtilityProcessOnIOThread( 57 void StartUtilityProcessOnIOThread(
68 mojo::InterfaceRequest<mojom::ProcessControl> request, 58 mojo::InterfaceRequest<mojom::ProcessControl> request,
69 const base::string16& process_name, 59 const base::string16& process_name,
70 bool use_sandbox) { 60 bool use_sandbox) {
71 UtilityProcessHost* process_host = 61 UtilityProcessHost* process_host =
72 UtilityProcessHost::Create(nullptr, nullptr); 62 UtilityProcessHost::Create(nullptr, nullptr);
73 process_host->SetName(process_name); 63 process_host->SetName(process_name);
74 if (!use_sandbox) 64 if (!use_sandbox)
75 process_host->DisableSandbox(); 65 process_host->DisableSandbox();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 shell::mojom::ServiceRequest request; 255 shell::mojom::ServiceRequest request;
266 if (shell::ShellIsRemote()) { 256 if (shell::ShellIsRemote()) {
267 mojo::edk::SetParentPipeHandleFromCommandLine(); 257 mojo::edk::SetParentPipeHandleFromCommandLine();
268 request = shell::GetServiceRequestFromCommandLine(); 258 request = shell::GetServiceRequestFromCommandLine();
269 } else { 259 } else {
270 service_manager_.reset(new shell::ServiceManager( 260 service_manager_.reset(new shell::ServiceManager(
271 std::move(native_runner_factory), catalog_->TakeService())); 261 std::move(native_runner_factory), catalog_->TakeService()));
272 request = 262 request =
273 service_manager_->StartEmbedderService(kBrowserMojoApplicationName); 263 service_manager_->StartEmbedderService(kBrowserMojoApplicationName);
274 } 264 }
275 MojoShellConnection::SetForProcess( 265 MojoShellConnection::SetForProcess(MojoShellConnection::Create(
276 MojoShellConnection::Create(std::move(request))); 266 std::move(request),
277 267 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
278 std::unique_ptr<shell::Connector> io_connector =
279 MojoShellConnection::GetForProcess()->GetConnector()->Clone();
280 BrowserThread::PostTask(
281 BrowserThread::IO, FROM_HERE,
282 base::Bind(&SetConnectorOnIOThread, base::Passed(&io_connector)));
283 268
284 ContentBrowserClient::StaticMojoApplicationMap apps; 269 ContentBrowserClient::StaticMojoApplicationMap apps;
285 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 270 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
286 for (const auto& entry : apps) { 271 for (const auto& entry : apps) {
287 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, 272 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first,
288 entry.second); 273 entry.second);
289 } 274 }
290 275
276 // This is safe to assign directly from any thread, because MojoShellContext
277 // must be constructed before anyone can call GetConnectorForIOThread().
278 g_io_thread_connector.Get() =
279 MojoShellConnection::GetForProcess()->GetConnector()->Clone();
280
281 MojoShellConnection::GetForProcess()->Start();
282
291 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; 283 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps;
292 GetContentClient() 284 GetContentClient()
293 ->browser() 285 ->browser()
294 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); 286 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps);
295 for (const auto& app : sandboxed_apps) { 287 for (const auto& app : sandboxed_apps) {
296 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( 288 MojoShellConnection::GetForProcess()->AddServiceRequestHandler(
297 app.first, 289 app.first,
298 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, 290 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second,
299 true /* use_sandbox */)); 291 true /* use_sandbox */));
300 } 292 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 shell::mojom::InterfaceProviderPtr exposed_services, 325 shell::mojom::InterfaceProviderPtr exposed_services,
334 const shell::mojom::Connector::ConnectCallback& callback) { 326 const shell::mojom::Connector::ConnectCallback& callback) {
335 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, 327 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name,
336 std::move(request), 328 std::move(request),
337 std::move(exposed_services), callback); 329 std::move(exposed_services), callback);
338 } 330 }
339 331
340 // static 332 // static
341 shell::Connector* MojoShellContext::GetConnectorForIOThread() { 333 shell::Connector* MojoShellContext::GetConnectorForIOThread() {
342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
343 return io_connector_tls_ptr.Pointer()->Get(); 335 return g_io_thread_connector.Get().get();
344 } 336 }
345 337
346 void MojoShellContext::ConnectToApplicationOnOwnThread( 338 void MojoShellContext::ConnectToApplicationOnOwnThread(
347 const std::string& user_id, 339 const std::string& user_id,
348 const std::string& name, 340 const std::string& name,
349 const std::string& requestor_name, 341 const std::string& requestor_name,
350 shell::mojom::InterfaceProviderRequest request, 342 shell::mojom::InterfaceProviderRequest request,
351 shell::mojom::InterfaceProviderPtr exposed_services, 343 shell::mojom::InterfaceProviderPtr exposed_services,
352 const shell::mojom::Connector::ConnectCallback& callback) { 344 const shell::mojom::Connector::ConnectCallback& callback) {
353 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); 345 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams);
354 shell::Identity source_id(requestor_name, user_id); 346 shell::Identity source_id(requestor_name, user_id);
355 params->set_source(source_id); 347 params->set_source(source_id);
356 params->set_target(shell::Identity(name, user_id)); 348 params->set_target(shell::Identity(name, user_id));
357 params->set_remote_interfaces(std::move(request)); 349 params->set_remote_interfaces(std::move(request));
358 params->set_local_interfaces(std::move(exposed_services)); 350 params->set_local_interfaces(std::move(exposed_services));
359 params->set_connect_callback(callback); 351 params->set_connect_callback(callback);
360 service_manager_->Connect(std::move(params)); 352 service_manager_->Connect(std::move(params));
361 } 353 }
362 354
363 } // namespace content 355 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/mojo_child_connection.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698