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

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

Issue 2804373002: Eliminate Connector::Connect(), Connection, etc. (Closed)
Patch Set: . Created 3 years, 8 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/cpp/bindings/binding_set.h" 7 #include "mojo/public/cpp/bindings/binding_set.h"
8 #include "services/service_manager/public/c/main.h" 8 #include "services/service_manager/public/c/main.h"
9 #include "services/service_manager/public/cpp/binder_registry.h"
9 #include "services/service_manager/public/cpp/connector.h" 10 #include "services/service_manager/public/cpp/connector.h"
10 #include "services/service_manager/public/cpp/interface_factory.h" 11 #include "services/service_manager/public/cpp/interface_factory.h"
11 #include "services/service_manager/public/cpp/interface_registry.h"
12 #include "services/service_manager/public/cpp/service.h" 12 #include "services/service_manager/public/cpp/service.h"
13 #include "services/service_manager/public/cpp/service_context.h" 13 #include "services/service_manager/public/cpp/service_context.h"
14 #include "services/service_manager/public/cpp/service_runner.h" 14 #include "services/service_manager/public/cpp/service_runner.h"
15 #include "services/service_manager/tests/shutdown/shutdown_unittest.mojom.h" 15 #include "services/service_manager/tests/shutdown/shutdown_unittest.mojom.h"
16 16
17 namespace service_manager { 17 namespace service_manager {
18 18
19 class ShutdownClientApp 19 class ShutdownClientApp
20 : public Service, 20 : public Service,
21 public InterfaceFactory<mojom::ShutdownTestClientController>, 21 public InterfaceFactory<mojom::ShutdownTestClientController>,
22 public mojom::ShutdownTestClientController, 22 public mojom::ShutdownTestClientController,
23 public mojom::ShutdownTestClient { 23 public mojom::ShutdownTestClient {
24 public: 24 public:
25 ShutdownClientApp() {} 25 ShutdownClientApp() {
26 registry_.AddInterface<mojom::ShutdownTestClientController>(this);
27 }
26 ~ShutdownClientApp() override {} 28 ~ShutdownClientApp() override {}
27 29
28 private: 30 private:
29 // service_manager::Service: 31 // service_manager::Service:
30 bool OnConnect(const ServiceInfo& remote_info, 32 void OnBindInterface(const ServiceInfo& source_info,
31 InterfaceRegistry* registry) override { 33 const std::string& interface_name,
32 registry->AddInterface<mojom::ShutdownTestClientController>(this); 34 mojo::ScopedMessagePipeHandle interface_pipe) override {
33 return true; 35 registry_.BindInterface(source_info.identity, interface_name,
36 std::move(interface_pipe));
34 } 37 }
35 38
36 // InterfaceFactory<mojom::ShutdownTestClientController>: 39 // InterfaceFactory<mojom::ShutdownTestClientController>:
37 void Create(const Identity& remote_identity, 40 void Create(const Identity& remote_identity,
38 mojom::ShutdownTestClientControllerRequest request) override { 41 mojom::ShutdownTestClientControllerRequest request) override {
39 bindings_.AddBinding(this, std::move(request)); 42 bindings_.AddBinding(this, std::move(request));
40 } 43 }
41 44
42 // mojom::ShutdownTestClientController: 45 // mojom::ShutdownTestClientController:
43 void ConnectAndWait(const ConnectAndWaitCallback& callback) override { 46 void ConnectAndWait(const ConnectAndWaitCallback& callback) override {
44 mojom::ShutdownTestServicePtr service; 47 mojom::ShutdownTestServicePtr service;
45 context()->connector()->BindInterface("shutdown_service", &service); 48 context()->connector()->BindInterface("shutdown_service", &service);
46 49
47 mojo::Binding<mojom::ShutdownTestClient> client_binding(this); 50 mojo::Binding<mojom::ShutdownTestClient> client_binding(this);
48 51
49 mojom::ShutdownTestClientPtr client_ptr = 52 mojom::ShutdownTestClientPtr client_ptr =
50 client_binding.CreateInterfacePtrAndBind(); 53 client_binding.CreateInterfacePtrAndBind();
51 54
52 service->SetClient(std::move(client_ptr)); 55 service->SetClient(std::move(client_ptr));
53 56
54 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( 57 base::MessageLoop::ScopedNestableTaskAllower nestable_allower(
55 base::MessageLoop::current()); 58 base::MessageLoop::current());
56 base::RunLoop run_loop; 59 base::RunLoop run_loop;
57 client_binding.set_connection_error_handler(run_loop.QuitClosure()); 60 client_binding.set_connection_error_handler(run_loop.QuitClosure());
58 run_loop.Run(); 61 run_loop.Run();
59 62
60 callback.Run(); 63 callback.Run();
61 } 64 }
62 65
66 BinderRegistry registry_;
63 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_; 67 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_;
64 68
65 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp); 69 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp);
66 }; 70 };
67 71
68 } // namespace service_manager 72 } // namespace service_manager
69 73
70 MojoResult ServiceMain(MojoHandle service_request_handle) { 74 MojoResult ServiceMain(MojoHandle service_request_handle) {
71 service_manager::ServiceRunner runner(new service_manager::ShutdownClientApp); 75 service_manager::ServiceRunner runner(new service_manager::ShutdownClientApp);
72 return runner.Run(service_request_handle); 76 return runner.Run(service_request_handle);
73 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698