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

Side by Side Diff: services/shell/tests/connect/connect_test_package.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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/threading/simple_thread.h" 15 #include "base/threading/simple_thread.h"
16 #include "mojo/public/c/system/main.h" 16 #include "mojo/public/c/system/main.h"
17 #include "mojo/public/cpp/bindings/binding_set.h" 17 #include "mojo/public/cpp/bindings/binding_set.h"
18 #include "services/shell/public/cpp/application_runner.h" 18 #include "services/shell/public/cpp/application_runner.h"
19 #include "services/shell/public/cpp/connector.h" 19 #include "services/shell/public/cpp/connector.h"
20 #include "services/shell/public/cpp/interface_factory.h" 20 #include "services/shell/public/cpp/interface_factory.h"
21 #include "services/shell/public/cpp/shell_client.h" 21 #include "services/shell/public/cpp/service.h"
22 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" 22 #include "services/shell/public/interfaces/service_factory.mojom.h"
23 #include "services/shell/tests/connect/connect_test.mojom.h" 23 #include "services/shell/tests/connect/connect_test.mojom.h"
24 24
25 // Tests that multiple applications can be packaged in a single Mojo application 25 // Tests that multiple applications can be packaged in a single Mojo application
26 // implementing ShellClientFactory; that these applications can be specified by 26 // implementing ServiceFactory; that these applications can be specified by
27 // the package's manifest and are thus registered with the PackageManager. 27 // the package's manifest and are thus registered with the PackageManager.
28 28
29 namespace shell { 29 namespace shell {
30 30
31 namespace { 31 namespace {
32 32
33 void QuitLoop(base::RunLoop* loop) { 33 void QuitLoop(base::RunLoop* loop) {
34 loop->Quit(); 34 loop->Quit();
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback; 39 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback;
40 40
41 class ProvidedShellClient 41 class ProvidedService
42 : public ShellClient, 42 : public Service,
43 public InterfaceFactory<test::mojom::ConnectTestService>, 43 public InterfaceFactory<test::mojom::ConnectTestService>,
44 public InterfaceFactory<test::mojom::BlockedInterface>, 44 public InterfaceFactory<test::mojom::BlockedInterface>,
45 public InterfaceFactory<test::mojom::UserIdTest>, 45 public InterfaceFactory<test::mojom::UserIdTest>,
46 public test::mojom::ConnectTestService, 46 public test::mojom::ConnectTestService,
47 public test::mojom::BlockedInterface, 47 public test::mojom::BlockedInterface,
48 public test::mojom::UserIdTest, 48 public test::mojom::UserIdTest,
49 public base::SimpleThread { 49 public base::SimpleThread {
50 public: 50 public:
51 ProvidedShellClient(const std::string& title, 51 ProvidedService(const std::string& title,
52 mojom::ShellClientRequest request) 52 mojom::ServiceRequest request)
53 : base::SimpleThread(title), 53 : base::SimpleThread(title),
54 title_(title), 54 title_(title),
55 request_(std::move(request)) { 55 request_(std::move(request)) {
56 Start(); 56 Start();
57 } 57 }
58 ~ProvidedShellClient() override { 58 ~ProvidedService() override {
59 Join(); 59 Join();
60 } 60 }
61 61
62 private: 62 private:
63 // shell::ShellClient: 63 // shell::Service:
64 void Initialize(Connector* connector, const Identity& identity, 64 void OnStart(Connector* connector, const Identity& identity,
65 uint32_t id) override { 65 uint32_t id) override {
66 connector_ = connector; 66 connector_ = connector;
67 identity_ = identity; 67 identity_ = identity;
68 id_ = id; 68 id_ = id;
69 bindings_.set_connection_error_handler( 69 bindings_.set_connection_error_handler(
70 base::Bind(&ProvidedShellClient::OnConnectionError, 70 base::Bind(&ProvidedService::OnConnectionError,
71 base::Unretained(this))); 71 base::Unretained(this)));
72 } 72 }
73 bool AcceptConnection(Connection* connection) override { 73 bool OnConnect(Connection* connection) override {
74 connection->AddInterface<test::mojom::ConnectTestService>(this); 74 connection->AddInterface<test::mojom::ConnectTestService>(this);
75 connection->AddInterface<test::mojom::BlockedInterface>(this); 75 connection->AddInterface<test::mojom::BlockedInterface>(this);
76 connection->AddInterface<test::mojom::UserIdTest>(this); 76 connection->AddInterface<test::mojom::UserIdTest>(this);
77 77
78 uint32_t remote_id = connection->GetRemoteInstanceID(); 78 uint32_t remote_id = connection->GetRemoteInstanceID();
79 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); 79 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New());
80 state->connection_local_name = connection->GetConnectionName(); 80 state->connection_local_name = connection->GetConnectionName();
81 state->connection_remote_name = connection->GetRemoteIdentity().name(); 81 state->connection_remote_name = connection->GetRemoteIdentity().name();
82 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); 82 state->connection_remote_userid = connection->GetRemoteIdentity().user_id();
83 state->connection_remote_id = remote_id; 83 state->connection_remote_id = remote_id;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 void OnConnectionError() { 148 void OnConnectionError() {
149 if (bindings_.empty()) 149 if (bindings_.empty())
150 base::MessageLoop::current()->QuitWhenIdle(); 150 base::MessageLoop::current()->QuitWhenIdle();
151 } 151 }
152 152
153 Connector* connector_ = nullptr; 153 Connector* connector_ = nullptr;
154 Identity identity_; 154 Identity identity_;
155 uint32_t id_ = shell::mojom::kInvalidInstanceID; 155 uint32_t id_ = shell::mojom::kInvalidInstanceID;
156 const std::string title_; 156 const std::string title_;
157 mojom::ShellClientRequest request_; 157 mojom::ServiceRequest request_;
158 test::mojom::ExposedInterfacePtr caller_; 158 test::mojom::ExposedInterfacePtr caller_;
159 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; 159 mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
160 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_; 160 mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_;
161 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_; 161 mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_;
162 162
163 DISALLOW_COPY_AND_ASSIGN(ProvidedShellClient); 163 DISALLOW_COPY_AND_ASSIGN(ProvidedService);
164 }; 164 };
165 165
166 class ConnectTestShellClient 166 class ConnectTestService
167 : public ShellClient, 167 : public Service,
168 public InterfaceFactory<mojom::ShellClientFactory>, 168 public InterfaceFactory<mojom::ServiceFactory>,
169 public InterfaceFactory<test::mojom::ConnectTestService>, 169 public InterfaceFactory<test::mojom::ConnectTestService>,
170 public mojom::ShellClientFactory, 170 public mojom::ServiceFactory,
171 public test::mojom::ConnectTestService { 171 public test::mojom::ConnectTestService {
172 public: 172 public:
173 ConnectTestShellClient() {} 173 ConnectTestService() {}
174 ~ConnectTestShellClient() override {} 174 ~ConnectTestService() override {}
175 175
176 private: 176 private:
177 // shell::ShellClient: 177 // shell::Service:
178 void Initialize(Connector* connector, const Identity& identity, 178 void OnStart(Connector* connector, const Identity& identity,
179 uint32_t id) override { 179 uint32_t id) override {
180 identity_ = identity; 180 identity_ = identity;
181 bindings_.set_connection_error_handler( 181 bindings_.set_connection_error_handler(
182 base::Bind(&ConnectTestShellClient::OnConnectionError, 182 base::Bind(&ConnectTestService::OnConnectionError,
183 base::Unretained(this))); 183 base::Unretained(this)));
184 } 184 }
185 bool AcceptConnection(Connection* connection) override { 185 bool OnConnect(Connection* connection) override {
186 connection->AddInterface<ShellClientFactory>(this); 186 connection->AddInterface<ServiceFactory>(this);
187 connection->AddInterface<test::mojom::ConnectTestService>(this); 187 connection->AddInterface<test::mojom::ConnectTestService>(this);
188 return true; 188 return true;
189 } 189 }
190 190
191 // InterfaceFactory<mojom::ShellClientFactory>: 191 // InterfaceFactory<mojom::ServiceFactory>:
192 void Create(Connection* connection, 192 void Create(Connection* connection,
193 mojom::ShellClientFactoryRequest request) override { 193 mojom::ServiceFactoryRequest request) override {
194 shell_client_factory_bindings_.AddBinding(this, std::move(request)); 194 service_factory_bindings_.AddBinding(this, std::move(request));
195 } 195 }
196 196
197 // InterfaceFactory<test::mojom::ConnectTestService>: 197 // InterfaceFactory<test::mojom::ConnectTestService>:
198 void Create(Connection* connection, 198 void Create(Connection* connection,
199 test::mojom::ConnectTestServiceRequest request) override { 199 test::mojom::ConnectTestServiceRequest request) override {
200 bindings_.AddBinding(this, std::move(request)); 200 bindings_.AddBinding(this, std::move(request));
201 } 201 }
202 202
203 // mojom::ShellClientFactory: 203 // mojom::ServiceFactory:
204 void CreateShellClient(mojom::ShellClientRequest request, 204 void CreateService(mojom::ServiceRequest request,
205 const mojo::String& name) override { 205 const mojo::String& name) override {
206 if (name == "mojo:connect_test_a") 206 if (name == "mojo:connect_test_a")
207 new ProvidedShellClient("A", std::move(request)); 207 new ProvidedService("A", std::move(request));
208 else if (name == "mojo:connect_test_b") 208 else if (name == "mojo:connect_test_b")
209 new ProvidedShellClient("B", std::move(request)); 209 new ProvidedService("B", std::move(request));
210 } 210 }
211 211
212 // test::mojom::ConnectTestService: 212 // test::mojom::ConnectTestService:
213 void GetTitle(const GetTitleCallback& callback) override { 213 void GetTitle(const GetTitleCallback& callback) override {
214 callback.Run("ROOT"); 214 callback.Run("ROOT");
215 } 215 }
216 void GetInstance(const GetInstanceCallback& callback) override { 216 void GetInstance(const GetInstanceCallback& callback) override {
217 callback.Run(identity_.instance()); 217 callback.Run(identity_.instance());
218 } 218 }
219 219
220 void OnConnectionError() { 220 void OnConnectionError() {
221 if (bindings_.empty()) 221 if (bindings_.empty())
222 base::MessageLoop::current()->QuitWhenIdle(); 222 base::MessageLoop::current()->QuitWhenIdle();
223 } 223 }
224 224
225 Identity identity_; 225 Identity identity_;
226 std::vector<std::unique_ptr<ShellClient>> delegates_; 226 std::vector<std::unique_ptr<Service>> delegates_;
227 mojo::BindingSet<mojom::ShellClientFactory> shell_client_factory_bindings_; 227 mojo::BindingSet<mojom::ServiceFactory> service_factory_bindings_;
228 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; 228 mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
229 229
230 DISALLOW_COPY_AND_ASSIGN(ConnectTestShellClient); 230 DISALLOW_COPY_AND_ASSIGN(ConnectTestService);
231 }; 231 };
232 232
233 } // namespace shell 233 } // namespace shell
234 234
235 MojoResult MojoMain(MojoHandle shell_handle) { 235 MojoResult MojoMain(MojoHandle shell_handle) {
236 MojoResult rv = shell::ApplicationRunner(new shell::ConnectTestShellClient) 236 MojoResult rv = shell::ApplicationRunner(new shell::ConnectTestService)
237 .Run(shell_handle); 237 .Run(shell_handle);
238 return rv; 238 return rv;
239 } 239 }
OLDNEW
« no previous file with comments | « services/shell/tests/connect/connect_test_exe.cc ('k') | services/shell/tests/connect/connect_test_singleton_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698