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

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

Issue 2118083002: ShellClient -> Service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mus2
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
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/common/process_control.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
11 #include "content/common/mojo/embedded_application_runner.h" 11 #include "content/common/mojo/embedded_application_runner.h"
12 #include "services/shell/public/cpp/shell_client.h" 12 #include "services/shell/public/cpp/service.h"
13 #include "services/shell/public/cpp/shell_connection.h" 13 #include "services/shell/public/cpp/shell_connection.h"
14 #include "services/shell/runner/common/client_util.h" 14 #include "services/shell/runner/common/client_util.h"
15 15
16 namespace content { 16 namespace content {
17 namespace { 17 namespace {
18 18
19 using MojoShellConnectionPtr = 19 using MojoShellConnectionPtr =
20 base::ThreadLocalPointer<MojoShellConnection>; 20 base::ThreadLocalPointer<MojoShellConnection>;
21 21
22 // Env is thread local so that aura may be used on multiple threads. 22 // Env is thread local so that aura may be used on multiple threads.
(...skipping 27 matching lines...) Expand all
50 } 50 }
51 51
52 // static 52 // static
53 void MojoShellConnection::SetFactoryForTest(Factory* factory) { 53 void MojoShellConnection::SetFactoryForTest(Factory* factory) {
54 DCHECK(!lazy_tls_ptr.Pointer()->Get()); 54 DCHECK(!lazy_tls_ptr.Pointer()->Get());
55 mojo_shell_connection_factory = factory; 55 mojo_shell_connection_factory = factory;
56 } 56 }
57 57
58 // static 58 // static
59 std::unique_ptr<MojoShellConnection> MojoShellConnection::Create( 59 std::unique_ptr<MojoShellConnection> MojoShellConnection::Create(
60 shell::mojom::ShellClientRequest request) { 60 shell::mojom::ServiceRequest request) {
61 if (mojo_shell_connection_factory) 61 if (mojo_shell_connection_factory)
62 return mojo_shell_connection_factory->Run(); 62 return mojo_shell_connection_factory->Run();
63 return base::WrapUnique(new MojoShellConnectionImpl(std::move(request))); 63 return base::WrapUnique(new MojoShellConnectionImpl(std::move(request)));
64 } 64 }
65 65
66 MojoShellConnection::~MojoShellConnection() {} 66 MojoShellConnection::~MojoShellConnection() {}
67 67
68 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
69 // MojoShellConnectionImpl, public: 69 // MojoShellConnectionImpl, public:
70 70
71 MojoShellConnectionImpl::MojoShellConnectionImpl( 71 MojoShellConnectionImpl::MojoShellConnectionImpl(
72 shell::mojom::ShellClientRequest request) 72 shell::mojom::ServiceRequest request)
73 : shell_connection_(new shell::ShellConnection(this, std::move(request))) {} 73 : shell_connection_(new shell::ShellConnection(this, std::move(request))) {}
74 74
75 MojoShellConnectionImpl::~MojoShellConnectionImpl() {} 75 MojoShellConnectionImpl::~MojoShellConnectionImpl() {}
76 76
77 //////////////////////////////////////////////////////////////////////////////// 77 ////////////////////////////////////////////////////////////////////////////////
78 // MojoShellConnectionImpl, shell::ShellClient implementation: 78 // MojoShellConnectionImpl, shell::Service implementation:
79 79
80 void MojoShellConnectionImpl::Initialize(shell::Connector* connector, 80 void MojoShellConnectionImpl::OnStart(shell::Connector* connector,
81 const shell::Identity& identity, 81 const shell::Identity& identity,
82 uint32_t id) { 82 uint32_t id) {
83 for (auto& client : embedded_shell_clients_) 83 for (auto& client : embedded_services_)
84 client->Initialize(connector, identity, id); 84 client->OnStart(connector, identity, id);
85 } 85 }
86 86
87 bool MojoShellConnectionImpl::AcceptConnection(shell::Connection* connection) { 87 bool MojoShellConnectionImpl::OnConnect(shell::Connection* connection) {
88 std::string remote_app = connection->GetRemoteIdentity().name(); 88 std::string remote_app = connection->GetRemoteIdentity().name();
89 if (remote_app == "mojo:shell") { 89 if (remote_app == "mojo:shell") {
90 // Only expose the SCF interface to the shell. 90 // Only expose the SCF interface to the shell.
91 connection->AddInterface<shell::mojom::ShellClientFactory>(this); 91 connection->AddInterface<shell::mojom::ServiceFactory>(this);
92 return true; 92 return true;
93 } 93 }
94 94
95 bool accept = false; 95 bool accept = false;
96 for (auto& client : embedded_shell_clients_) 96 for (auto& client : embedded_services_)
97 accept |= client->AcceptConnection(connection); 97 accept |= client->OnConnect(connection);
98 98
99 // Reject all other connections to this application. 99 // Reject all other connections to this application.
100 return accept; 100 return accept;
101 } 101 }
102 102
103 shell::InterfaceRegistry* 103 shell::InterfaceRegistry*
104 MojoShellConnectionImpl::GetInterfaceRegistryForConnection() { 104 MojoShellConnectionImpl::GetInterfaceRegistryForConnection() {
105 // TODO(beng): This is really horrible since obviously subject to issues 105 // TODO(beng): This is really horrible since obviously subject to issues
106 // of ordering, but is no more horrible than this API is in general. 106 // of ordering, but is no more horrible than this API is in general.
107 shell::InterfaceRegistry* registry = nullptr; 107 shell::InterfaceRegistry* registry = nullptr;
108 for (auto& client : embedded_shell_clients_) { 108 for (auto& client : embedded_services_) {
109 registry = client->GetInterfaceRegistryForConnection(); 109 registry = client->GetInterfaceRegistryForConnection();
110 if (registry) 110 if (registry)
111 return registry; 111 return registry;
112 } 112 }
113 return nullptr; 113 return nullptr;
114 } 114 }
115 115
116 shell::InterfaceProvider* 116 shell::InterfaceProvider*
117 MojoShellConnectionImpl::GetInterfaceProviderForConnection() { 117 MojoShellConnectionImpl::GetInterfaceProviderForConnection() {
118 // TODO(beng): This is really horrible since obviously subject to issues 118 // TODO(beng): This is really horrible since obviously subject to issues
119 // of ordering, but is no more horrible than this API is in general. 119 // of ordering, but is no more horrible than this API is in general.
120 shell::InterfaceProvider* provider = nullptr; 120 shell::InterfaceProvider* provider = nullptr;
121 for (auto& client : embedded_shell_clients_) { 121 for (auto& client : embedded_services_) {
122 provider = client->GetInterfaceProviderForConnection(); 122 provider = client->GetInterfaceProviderForConnection();
123 if (provider) 123 if (provider)
124 return provider; 124 return provider;
125 } 125 }
126 return nullptr; 126 return nullptr;
127 } 127 }
128 128
129 //////////////////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////////////////
130 // MojoShellConnectionImpl, 130 // MojoShellConnectionImpl,
131 // shell::InterfaceFactory<shell::mojom::ShellClientFactory> implementation: 131 // shell::InterfaceFactory<shell::mojom::ServiceFactory> implementation:
132 132
133 void MojoShellConnectionImpl::Create( 133 void MojoShellConnectionImpl::Create(
134 shell::Connection* connection, 134 shell::Connection* connection,
135 shell::mojom::ShellClientFactoryRequest request) { 135 shell::mojom::ServiceFactoryRequest request) {
136 factory_bindings_.AddBinding(this, std::move(request)); 136 factory_bindings_.AddBinding(this, std::move(request));
137 } 137 }
138 138
139 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
140 // MojoShellConnectionImpl, shell::mojom::ShellClientFactory implementation: 140 // MojoShellConnectionImpl, shell::mojom::ServiceFactory implementation:
141 141
142 void MojoShellConnectionImpl::CreateShellClient( 142 void MojoShellConnectionImpl::CreateService(
143 shell::mojom::ShellClientRequest request, 143 shell::mojom::ServiceRequest request,
144 const mojo::String& name) { 144 const mojo::String& name) {
145 auto it = request_handlers_.find(name); 145 auto it = request_handlers_.find(name);
146 if (it != request_handlers_.end()) 146 if (it != request_handlers_.end())
147 it->second.Run(std::move(request)); 147 it->second.Run(std::move(request));
148 } 148 }
149 149
150 //////////////////////////////////////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////////////////
151 // MojoShellConnectionImpl, MojoShellConnection implementation: 151 // MojoShellConnectionImpl, MojoShellConnection implementation:
152 152
153 shell::ShellConnection* MojoShellConnectionImpl::GetShellConnection() { 153 shell::ShellConnection* MojoShellConnectionImpl::GetShellConnection() {
154 return shell_connection_.get(); 154 return shell_connection_.get();
155 } 155 }
156 156
157 shell::Connector* MojoShellConnectionImpl::GetConnector() { 157 shell::Connector* MojoShellConnectionImpl::GetConnector() {
158 DCHECK(shell_connection_); 158 DCHECK(shell_connection_);
159 return shell_connection_->connector(); 159 return shell_connection_->connector();
160 } 160 }
161 161
162 const shell::Identity& MojoShellConnectionImpl::GetIdentity() const { 162 const shell::Identity& MojoShellConnectionImpl::GetIdentity() const {
163 DCHECK(shell_connection_); 163 DCHECK(shell_connection_);
164 return shell_connection_->identity(); 164 return shell_connection_->identity();
165 } 165 }
166 166
167 void MojoShellConnectionImpl::SetConnectionLostClosure( 167 void MojoShellConnectionImpl::SetConnectionLostClosure(
168 const base::Closure& closure) { 168 const base::Closure& closure) {
169 shell_connection_->SetConnectionLostClosure(closure); 169 shell_connection_->SetConnectionLostClosure(closure);
170 } 170 }
171 171
172 void MojoShellConnectionImpl::AddEmbeddedShellClient( 172 void MojoShellConnectionImpl::MergeService(
173 std::unique_ptr<shell::ShellClient> shell_client) { 173 std::unique_ptr<shell::Service> service) {
174 embedded_shell_clients_.push_back(shell_client.get()); 174 embedded_services_.push_back(service.get());
175 owned_shell_clients_.push_back(std::move(shell_client)); 175 owned_services_.push_back(std::move(service));
176 } 176 }
177 177
178 void MojoShellConnectionImpl::AddEmbeddedShellClient( 178 void MojoShellConnectionImpl::MergeService(
179 shell::ShellClient* shell_client) { 179 shell::Service* service) {
180 embedded_shell_clients_.push_back(shell_client); 180 embedded_services_.push_back(service);
181 } 181 }
182 182
183 void MojoShellConnectionImpl::AddEmbeddedService( 183 void MojoShellConnectionImpl::AddEmbeddedService(
184 const std::string& name, 184 const std::string& name,
185 const MojoApplicationInfo& info) { 185 const MojoApplicationInfo& info) {
186 std::unique_ptr<EmbeddedApplicationRunner> app( 186 std::unique_ptr<EmbeddedApplicationRunner> app(
187 new EmbeddedApplicationRunner(name, info)); 187 new EmbeddedApplicationRunner(name, info));
188 AddShellClientRequestHandler( 188 AddServiceRequestHandler(
189 name, base::Bind(&EmbeddedApplicationRunner::BindShellClientRequest, 189 name, base::Bind(&EmbeddedApplicationRunner::BindServiceRequest,
190 base::Unretained(app.get()))); 190 base::Unretained(app.get())));
191 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); 191 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app)));
192 DCHECK(result.second); 192 DCHECK(result.second);
193 } 193 }
194 194
195 void MojoShellConnectionImpl::AddShellClientRequestHandler( 195 void MojoShellConnectionImpl::AddServiceRequestHandler(
196 const std::string& name, 196 const std::string& name,
197 const ShellClientRequestHandler& handler) { 197 const ServiceRequestHandler& handler) {
198 auto result = request_handlers_.insert(std::make_pair(name, handler)); 198 auto result = request_handlers_.insert(std::make_pair(name, handler));
199 DCHECK(result.second); 199 DCHECK(result.second);
200 } 200 }
201 201
202 } // namespace content 202 } // namespace content
OLDNEW
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/common/process_control.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698