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

Side by Side Diff: content/common/mojo/mojo_shell_connection_impl.cc

Issue 1476643002: mustash: Enable connections to mus from the Chrome renderer [take 2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't create a RenderWidgetWindowTreeeClientFactory in tests Created 5 years 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/common/mojo/mojo_shell_connection_impl.h" 5 #include "content/common/mojo/mojo_shell_connection_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/stl_util.h"
9 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
10 #include "mojo/application/public/cpp/application_delegate.h" 11 #include "mojo/application/public/cpp/application_delegate.h"
11 #include "mojo/application/public/cpp/application_impl.h" 12 #include "mojo/application/public/cpp/application_impl.h"
12 #include "mojo/converters/network/network_type_converters.h" 13 #include "mojo/converters/network/network_type_converters.h"
13 #include "mojo/runner/child/runner_connection.h" 14 #include "mojo/runner/child/runner_connection.h"
14 15
15 namespace content { 16 namespace content {
16 namespace { 17 namespace {
17 using MojoShellConnectionPtr = 18 using MojoShellConnectionPtr =
18 base::ThreadLocalPointer<MojoShellConnectionImpl>; 19 base::ThreadLocalPointer<MojoShellConnectionImpl>;
19 20
20 // Env is thread local so that aura may be used on multiple threads. 21 // Env is thread local so that aura may be used on multiple threads.
21 base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr = 22 base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr =
22 LAZY_INSTANCE_INITIALIZER; 23 LAZY_INSTANCE_INITIALIZER;
23 24
24 } // namespace 25 } // namespace
25 26
26 bool IsRunningInMojoShell() { 27 bool IsRunningInMojoShell() {
27 return base::CommandLine::ForCurrentProcess()->HasSwitch( 28 return base::CommandLine::ForCurrentProcess()->HasSwitch(
28 "mojo-platform-channel-handle"); 29 "mojo-platform-channel-handle");
29 } 30 }
30 31
31 // static 32 // static
32 void MojoShellConnectionImpl::Create() { 33 void MojoShellConnectionImpl::Create() {
33 DCHECK(IsRunningInMojoShell()); 34 DCHECK(!lazy_tls_ptr.Pointer()->Get());
34 CreateWithMessagePipe(mojo::ScopedMessagePipeHandle()); 35 MojoShellConnectionImpl* connection = new MojoShellConnectionImpl;
36 lazy_tls_ptr.Pointer()->Set(connection);
35 } 37 }
36 38
37 // static 39 // static
38 void MojoShellConnectionImpl::CreateWithMessagePipe( 40 MojoShellConnectionImpl* MojoShellConnectionImpl::Get() {
41 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get());
42 }
43
44 void MojoShellConnectionImpl::BindToCommandLinePlatformChannel() {
45 DCHECK(IsRunningInMojoShell());
46 if (initialized_)
47 return;
48 WaitForShell(mojo::ScopedMessagePipeHandle());
49 }
50
51 void MojoShellConnectionImpl::BindToMessagePipe(
39 mojo::ScopedMessagePipeHandle handle) { 52 mojo::ScopedMessagePipeHandle handle) {
40 DCHECK(!lazy_tls_ptr.Pointer()->Get()); 53 if (initialized_)
41 MojoShellConnectionImpl* connection = new MojoShellConnectionImpl; 54 return;
42 lazy_tls_ptr.Pointer()->Set(connection); 55 WaitForShell(handle.Pass());
43 connection->WaitForShell(handle.Pass());
44 } 56 }
45 57
46 MojoShellConnectionImpl::MojoShellConnectionImpl() : initialized_(false) {} 58 MojoShellConnectionImpl::MojoShellConnectionImpl() : initialized_(false) {}
47 MojoShellConnectionImpl::~MojoShellConnectionImpl() {} 59 MojoShellConnectionImpl::~MojoShellConnectionImpl() {
60 STLDeleteElements(&listeners_);
61 }
48 62
49 void MojoShellConnectionImpl::WaitForShell( 63 void MojoShellConnectionImpl::WaitForShell(
50 mojo::ScopedMessagePipeHandle handle) { 64 mojo::ScopedMessagePipeHandle handle) {
51 mojo::InterfaceRequest<mojo::Application> application_request; 65 mojo::InterfaceRequest<mojo::Application> application_request;
52 runner_connection_.reset(mojo::runner::RunnerConnection::ConnectToRunner( 66 runner_connection_.reset(mojo::runner::RunnerConnection::ConnectToRunner(
53 &application_request, handle.Pass())); 67 &application_request, handle.Pass()));
54 application_impl_.reset(new mojo::ApplicationImpl( 68 application_impl_.reset(new mojo::ApplicationImpl(
55 this, application_request.Pass())); 69 this, application_request.Pass()));
56 application_impl_->WaitForInitialize(); 70 application_impl_->WaitForInitialize();
57 } 71 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // static 107 // static
94 void MojoShellConnection::Destroy() { 108 void MojoShellConnection::Destroy() {
95 // This joins the shell controller thread. 109 // This joins the shell controller thread.
96 delete Get(); 110 delete Get();
97 lazy_tls_ptr.Pointer()->Set(nullptr); 111 lazy_tls_ptr.Pointer()->Set(nullptr);
98 } 112 }
99 113
100 MojoShellConnection::~MojoShellConnection() {} 114 MojoShellConnection::~MojoShellConnection() {}
101 115
102 } // namespace content 116 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698