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

Side by Side Diff: services/shell/tests/shutdown/shutdown_client_app.cc

Issue 2179023004: Make Service own ServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "mojo/public/c/system/main.h" 7 #include "mojo/public/c/system/main.h"
8 #include "mojo/public/cpp/bindings/binding_set.h" 8 #include "mojo/public/cpp/bindings/binding_set.h"
9 #include "services/shell/public/cpp/connector.h" 9 #include "services/shell/public/cpp/connector.h"
10 #include "services/shell/public/cpp/interface_factory.h" 10 #include "services/shell/public/cpp/interface_factory.h"
11 #include "services/shell/public/cpp/service.h" 11 #include "services/shell/public/cpp/service.h"
12 #include "services/shell/public/cpp/service_runner.h" 12 #include "services/shell/public/cpp/service_runner.h"
13 #include "services/shell/tests/shutdown/shutdown_unittest.mojom.h" 13 #include "services/shell/tests/shutdown/shutdown_unittest.mojom.h"
14 14
15 namespace shell { 15 namespace shell {
16 16
17 class ShutdownClientApp 17 class ShutdownClientApp
18 : public Service, 18 : public Service,
19 public InterfaceFactory<mojom::ShutdownTestClientController>, 19 public InterfaceFactory<mojom::ShutdownTestClientController>,
20 public mojom::ShutdownTestClientController, 20 public mojom::ShutdownTestClientController,
21 public mojom::ShutdownTestClient { 21 public mojom::ShutdownTestClient {
22 public: 22 public:
23 ShutdownClientApp() {} 23 ShutdownClientApp() {}
24 ~ShutdownClientApp() override {} 24 ~ShutdownClientApp() override {}
25 25
26 private: 26 private:
27 // shell::Service: 27 // shell::Service:
28 void OnStart(Connector* connector, const Identity& identity,
29 uint32_t id) override {
30 connector_ = connector;
31 }
32
33 bool OnConnect(Connection* connection) override { 28 bool OnConnect(Connection* connection) override {
34 connection->AddInterface<mojom::ShutdownTestClientController>(this); 29 connection->AddInterface<mojom::ShutdownTestClientController>(this);
35 return true; 30 return true;
36 } 31 }
37 32
38 // InterfaceFactory<mojom::ShutdownTestClientController>: 33 // InterfaceFactory<mojom::ShutdownTestClientController>:
39 void Create(const Identity& remote_identity, 34 void Create(const Identity& remote_identity,
40 mojom::ShutdownTestClientControllerRequest request) override { 35 mojom::ShutdownTestClientControllerRequest request) override {
41 bindings_.AddBinding(this, std::move(request)); 36 bindings_.AddBinding(this, std::move(request));
42 } 37 }
43 38
44 // mojom::ShutdownTestClientController: 39 // mojom::ShutdownTestClientController:
45 void ConnectAndWait(const ConnectAndWaitCallback& callback) override { 40 void ConnectAndWait(const ConnectAndWaitCallback& callback) override {
46 mojom::ShutdownTestServicePtr service; 41 mojom::ShutdownTestServicePtr service;
47 connector_->ConnectToInterface("mojo:shutdown_service", &service); 42 connector()->ConnectToInterface("mojo:shutdown_service",
43 &service);
48 44
49 mojo::Binding<mojom::ShutdownTestClient> client_binding(this); 45 mojo::Binding<mojom::ShutdownTestClient> client_binding(this);
50 46
51 mojom::ShutdownTestClientPtr client_ptr = 47 mojom::ShutdownTestClientPtr client_ptr =
52 client_binding.CreateInterfacePtrAndBind(); 48 client_binding.CreateInterfacePtrAndBind();
53 49
54 service->SetClient(std::move(client_ptr)); 50 service->SetClient(std::move(client_ptr));
55 51
56 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( 52 base::MessageLoop::ScopedNestableTaskAllower nestable_allower(
57 base::MessageLoop::current()); 53 base::MessageLoop::current());
58 base::RunLoop run_loop; 54 base::RunLoop run_loop;
59 client_binding.set_connection_error_handler(run_loop.QuitClosure()); 55 client_binding.set_connection_error_handler(run_loop.QuitClosure());
60 run_loop.Run(); 56 run_loop.Run();
61 57
62 callback.Run(); 58 callback.Run();
63 } 59 }
64 60
65 Connector* connector_ = nullptr;
66 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_; 61 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_;
67 62
68 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp); 63 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp);
69 }; 64 };
70 65
71 } // namespace shell 66 } // namespace shell
72 67
73 68
74 MojoResult MojoMain(MojoHandle shell_handle) { 69 MojoResult MojoMain(MojoHandle shell_handle) {
75 return shell::ServiceRunner(new shell::ShutdownClientApp) 70 return shell::ServiceRunner(new shell::ShutdownClientApp)
76 .Run(shell_handle); 71 .Run(shell_handle);
77 } 72 }
OLDNEW
« no previous file with comments | « services/shell/tests/shell/target.cc ('k') | services/shell/tests/shutdown/shutdown_service_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698