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

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

Issue 2138263002: Revert of Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 base::LazyInstance<std::unique_ptr<shell::Connector>>::Leaky 52 using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>;
53 g_io_thread_connector = LAZY_INSTANCE_INITIALIZER;
54 53
55 void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); } 54 base::LazyInstance<ConnectorPtr>::Leaky io_connector_tls_ptr =
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 }
56 66
57 void StartUtilityProcessOnIOThread( 67 void StartUtilityProcessOnIOThread(
58 mojo::InterfaceRequest<mojom::ProcessControl> request, 68 mojo::InterfaceRequest<mojom::ProcessControl> request,
59 const base::string16& process_name, 69 const base::string16& process_name,
60 bool use_sandbox) { 70 bool use_sandbox) {
61 UtilityProcessHost* process_host = 71 UtilityProcessHost* process_host =
62 UtilityProcessHost::Create(nullptr, nullptr); 72 UtilityProcessHost::Create(nullptr, nullptr);
63 process_host->SetName(process_name); 73 process_host->SetName(process_name);
64 if (!use_sandbox) 74 if (!use_sandbox)
65 process_host->DisableSandbox(); 75 process_host->DisableSandbox();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 shell::mojom::ServiceRequest request; 265 shell::mojom::ServiceRequest request;
256 if (shell::ShellIsRemote()) { 266 if (shell::ShellIsRemote()) {
257 mojo::edk::SetParentPipeHandleFromCommandLine(); 267 mojo::edk::SetParentPipeHandleFromCommandLine();
258 request = shell::GetServiceRequestFromCommandLine(); 268 request = shell::GetServiceRequestFromCommandLine();
259 } else { 269 } else {
260 service_manager_.reset(new shell::ServiceManager( 270 service_manager_.reset(new shell::ServiceManager(
261 std::move(native_runner_factory), catalog_->TakeService())); 271 std::move(native_runner_factory), catalog_->TakeService()));
262 request = 272 request =
263 service_manager_->StartEmbedderService(kBrowserMojoApplicationName); 273 service_manager_->StartEmbedderService(kBrowserMojoApplicationName);
264 } 274 }
265 MojoShellConnection::SetForProcess(MojoShellConnection::Create( 275 MojoShellConnection::SetForProcess(
266 std::move(request), 276 MojoShellConnection::Create(std::move(request)));
267 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); 277
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)));
268 283
269 ContentBrowserClient::StaticMojoApplicationMap apps; 284 ContentBrowserClient::StaticMojoApplicationMap apps;
270 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 285 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
271 for (const auto& entry : apps) { 286 for (const auto& entry : apps) {
272 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, 287 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first,
273 entry.second); 288 entry.second);
274 } 289 }
275 290
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
283 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; 291 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps;
284 GetContentClient() 292 GetContentClient()
285 ->browser() 293 ->browser()
286 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); 294 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps);
287 for (const auto& app : sandboxed_apps) { 295 for (const auto& app : sandboxed_apps) {
288 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( 296 MojoShellConnection::GetForProcess()->AddServiceRequestHandler(
289 app.first, 297 app.first,
290 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, 298 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second,
291 true /* use_sandbox */)); 299 true /* use_sandbox */));
292 } 300 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 shell::mojom::InterfaceProviderPtr exposed_services, 333 shell::mojom::InterfaceProviderPtr exposed_services,
326 const shell::mojom::Connector::ConnectCallback& callback) { 334 const shell::mojom::Connector::ConnectCallback& callback) {
327 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, 335 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name,
328 std::move(request), 336 std::move(request),
329 std::move(exposed_services), callback); 337 std::move(exposed_services), callback);
330 } 338 }
331 339
332 // static 340 // static
333 shell::Connector* MojoShellContext::GetConnectorForIOThread() { 341 shell::Connector* MojoShellContext::GetConnectorForIOThread() {
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
335 return g_io_thread_connector.Get().get(); 343 return io_connector_tls_ptr.Pointer()->Get();
336 } 344 }
337 345
338 void MojoShellContext::ConnectToApplicationOnOwnThread( 346 void MojoShellContext::ConnectToApplicationOnOwnThread(
339 const std::string& user_id, 347 const std::string& user_id,
340 const std::string& name, 348 const std::string& name,
341 const std::string& requestor_name, 349 const std::string& requestor_name,
342 shell::mojom::InterfaceProviderRequest request, 350 shell::mojom::InterfaceProviderRequest request,
343 shell::mojom::InterfaceProviderPtr exposed_services, 351 shell::mojom::InterfaceProviderPtr exposed_services,
344 const shell::mojom::Connector::ConnectCallback& callback) { 352 const shell::mojom::Connector::ConnectCallback& callback) {
345 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); 353 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams);
346 shell::Identity source_id(requestor_name, user_id); 354 shell::Identity source_id(requestor_name, user_id);
347 params->set_source(source_id); 355 params->set_source(source_id);
348 params->set_target(shell::Identity(name, user_id)); 356 params->set_target(shell::Identity(name, user_id));
349 params->set_remote_interfaces(std::move(request)); 357 params->set_remote_interfaces(std::move(request));
350 params->set_local_interfaces(std::move(exposed_services)); 358 params->set_local_interfaces(std::move(exposed_services));
351 params->set_connect_callback(callback); 359 params->set_connect_callback(callback);
352 service_manager_->Connect(std::move(params)); 360 service_manager_->Connect(std::move(params));
353 } 361 }
354 362
355 } // namespace content 363 } // 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