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

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

Issue 1793793002: Remove ShellConnection::WaitForInitialize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix mus views tests Created 4 years, 9 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/common/mojo/mojo_shell_connection_impl.h" 5 #include "content/common/mojo/mojo_shell_connection_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 // static 43 // static
44 void MojoShellConnectionImpl::Create( 44 void MojoShellConnectionImpl::Create(
45 mojo::shell::mojom::ShellClientRequest request) { 45 mojo::shell::mojom::ShellClientRequest request) {
46 DCHECK(!lazy_tls_ptr.Pointer()->Get()); 46 DCHECK(!lazy_tls_ptr.Pointer()->Get());
47 MojoShellConnectionImpl* connection = 47 MojoShellConnectionImpl* connection =
48 new MojoShellConnectionImpl(false /* external */); 48 new MojoShellConnectionImpl(false /* external */);
49 lazy_tls_ptr.Pointer()->Set(connection); 49 lazy_tls_ptr.Pointer()->Set(connection);
50 50
51 connection->shell_connection_.reset( 51 connection->shell_connection_.reset(new mojo::ShellConnection(connection));
52 new mojo::ShellConnection(connection, std::move(request))); 52 connection->shell_connection_->BindToRequest(std::move(request));
Ben Goodger (Google) 2016/03/13 04:16:24 How is this different than just passing request th
Ken Rockot(use gerrit already) 2016/03/13 16:14:25 Oops, it's not. Fixed
53 connection->shell_connection_->WaitForInitialize();
54 } 53 }
55 54
56 // static 55 // static
57 MojoShellConnectionImpl* MojoShellConnectionImpl::Get() { 56 MojoShellConnectionImpl* MojoShellConnectionImpl::Get() {
58 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get()); 57 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get());
59 } 58 }
60 59
61 void MojoShellConnectionImpl::BindToCommandLinePlatformChannel() { 60 void MojoShellConnectionImpl::Connect(
62 DCHECK(IsRunningInMojoShell()); 61 mojo::shell::mojom::ShellClientFactoryRequest request) {
63 if (initialized_) 62 DCHECK(IsRunningInMojoShell() || request.is_pending());
64 return; 63 DCHECK(!shell_connection_);
65 WaitForShell(mojo::ScopedMessagePipeHandle());
66 }
67 64
68 void MojoShellConnectionImpl::BindToMessagePipe( 65 shell_connection_.reset(new mojo::ShellConnection(this));
69 mojo::ScopedMessagePipeHandle handle) { 66 runner_connection_ = mojo::shell::RunnerConnection::Create(
70 if (initialized_) 67 shell_connection_.get(), std::move(request), false /* exit_on_error */);
71 return; 68 if (!runner_connection_) {
72 WaitForShell(std::move(handle)); 69 delete this;
70 lazy_tls_ptr.Pointer()->Set(nullptr);
71 }
73 } 72 }
74 73
75 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) : 74 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) :
76 external_(external), initialized_(false) {} 75 external_(external) {}
77 76
78 MojoShellConnectionImpl::~MojoShellConnectionImpl() { 77 MojoShellConnectionImpl::~MojoShellConnectionImpl() {
79 STLDeleteElements(&listeners_); 78 STLDeleteElements(&listeners_);
80 } 79 }
81 80
82 void MojoShellConnectionImpl::WaitForShell(
83 mojo::ScopedMessagePipeHandle handle) {
84 mojo::shell::mojom::ShellClientRequest request;
85 runner_connection_.reset(mojo::shell::RunnerConnection::ConnectToRunner(
86 &request, std::move(handle), false /* exit_on_error */));
87 if (!runner_connection_) {
88 DLOG(ERROR) << "Unable to connect to the Mojo shell.";
89 delete this;
90 lazy_tls_ptr.Pointer()->Set(nullptr);
91 return;
92 }
93 shell_connection_.reset(new mojo::ShellConnection(this, std::move(request)));
94 shell_connection_->WaitForInitialize();
95 }
96
97 void MojoShellConnectionImpl::Initialize(mojo::Connector* connector, 81 void MojoShellConnectionImpl::Initialize(mojo::Connector* connector,
98 const mojo::Identity& identity, 82 const mojo::Identity& identity,
99 uint32_t id) { 83 uint32_t id) {
100 initialized_ = true;
101 } 84 }
102 85
103 bool MojoShellConnectionImpl::AcceptConnection(mojo::Connection* connection) { 86 bool MojoShellConnectionImpl::AcceptConnection(mojo::Connection* connection) {
104 bool found = false; 87 bool found = false;
105 for (auto listener : listeners_) 88 for (auto listener : listeners_)
106 found |= listener->AcceptConnection(connection); 89 found |= listener->AcceptConnection(connection);
107 return found; 90 return found;
108 } 91 }
109 92
110 mojo::Connector* MojoShellConnectionImpl::GetConnector() { 93 mojo::Connector* MojoShellConnectionImpl::GetConnector() {
111 DCHECK(initialized_); 94 DCHECK(shell_connection_);
112 return shell_connection_->connector(); 95 return shell_connection_->connector();
113 } 96 }
114 97
115 bool MojoShellConnectionImpl::UsingExternalShell() const { 98 bool MojoShellConnectionImpl::UsingExternalShell() const {
116 return external_; 99 return external_;
117 } 100 }
118 101
119 void MojoShellConnectionImpl::AddListener(Listener* listener) { 102 void MojoShellConnectionImpl::AddListener(Listener* listener) {
120 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener) == 103 DCHECK(std::find(listeners_.begin(), listeners_.end(), listener) ==
121 listeners_.end()); 104 listeners_.end());
(...skipping 14 matching lines...) Expand all
136 // static 119 // static
137 void MojoShellConnection::Destroy() { 120 void MojoShellConnection::Destroy() {
138 // This joins the shell controller thread. 121 // This joins the shell controller thread.
139 delete Get(); 122 delete Get();
140 lazy_tls_ptr.Pointer()->Set(nullptr); 123 lazy_tls_ptr.Pointer()->Set(nullptr);
141 } 124 }
142 125
143 MojoShellConnection::~MojoShellConnection() {} 126 MojoShellConnection::~MojoShellConnection() {}
144 127
145 } // namespace content 128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698