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

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

Issue 2500683002: Revert of Service Manager: Remove ServiceContext* arg from Service::OnStart() (Closed)
Patch Set: Created 4 years, 1 month 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 | « services/service_manager/tests/service_manager/target.cc ('k') | services/ui/demo/mus_demo.h » ('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 "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/connector.h" 9 #include "services/service_manager/public/cpp/connector.h"
10 #include "services/service_manager/public/cpp/interface_factory.h" 10 #include "services/service_manager/public/cpp/interface_factory.h"
11 #include "services/service_manager/public/cpp/interface_registry.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 ~ShutdownClientApp() override {} 26 ~ShutdownClientApp() override {}
27 27
28 private: 28 private:
29 // service_manager::Service: 29 // service_manager::Service:
30 void OnStart(ServiceContext* context) override {
31 context_ = context;
32 }
33
30 bool OnConnect(const ServiceInfo& remote_info, 34 bool OnConnect(const ServiceInfo& remote_info,
31 InterfaceRegistry* registry) override { 35 InterfaceRegistry* registry) override {
32 registry->AddInterface<mojom::ShutdownTestClientController>(this); 36 registry->AddInterface<mojom::ShutdownTestClientController>(this);
33 return true; 37 return true;
34 } 38 }
35 39
36 // InterfaceFactory<mojom::ShutdownTestClientController>: 40 // InterfaceFactory<mojom::ShutdownTestClientController>:
37 void Create(const Identity& remote_identity, 41 void Create(const Identity& remote_identity,
38 mojom::ShutdownTestClientControllerRequest request) override { 42 mojom::ShutdownTestClientControllerRequest request) override {
39 bindings_.AddBinding(this, std::move(request)); 43 bindings_.AddBinding(this, std::move(request));
40 } 44 }
41 45
42 // mojom::ShutdownTestClientController: 46 // mojom::ShutdownTestClientController:
43 void ConnectAndWait(const ConnectAndWaitCallback& callback) override { 47 void ConnectAndWait(const ConnectAndWaitCallback& callback) override {
44 mojom::ShutdownTestServicePtr service; 48 mojom::ShutdownTestServicePtr service;
45 context()->connector()->ConnectToInterface( 49 context_->connector()->ConnectToInterface(
46 "service:shutdown_service", &service); 50 "service:shutdown_service", &service);
47 51
48 mojo::Binding<mojom::ShutdownTestClient> client_binding(this); 52 mojo::Binding<mojom::ShutdownTestClient> client_binding(this);
49 53
50 mojom::ShutdownTestClientPtr client_ptr = 54 mojom::ShutdownTestClientPtr client_ptr =
51 client_binding.CreateInterfacePtrAndBind(); 55 client_binding.CreateInterfacePtrAndBind();
52 56
53 service->SetClient(std::move(client_ptr)); 57 service->SetClient(std::move(client_ptr));
54 58
55 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( 59 base::MessageLoop::ScopedNestableTaskAllower nestable_allower(
56 base::MessageLoop::current()); 60 base::MessageLoop::current());
57 base::RunLoop run_loop; 61 base::RunLoop run_loop;
58 client_binding.set_connection_error_handler(run_loop.QuitClosure()); 62 client_binding.set_connection_error_handler(run_loop.QuitClosure());
59 run_loop.Run(); 63 run_loop.Run();
60 64
61 callback.Run(); 65 callback.Run();
62 } 66 }
63 67
68 ServiceContext* context_ = nullptr;
64 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_; 69 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_;
65 70
66 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp); 71 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp);
67 }; 72 };
68 73
69 } // namespace service_manager 74 } // namespace service_manager
70 75
71 MojoResult ServiceMain(MojoHandle service_request_handle) { 76 MojoResult ServiceMain(MojoHandle service_request_handle) {
72 service_manager::ServiceRunner runner(new service_manager::ShutdownClientApp); 77 service_manager::ServiceRunner runner(new service_manager::ShutdownClientApp);
73 return runner.Run(service_request_handle); 78 return runner.Run(service_request_handle);
74 } 79 }
OLDNEW
« no previous file with comments | « services/service_manager/tests/service_manager/target.cc ('k') | services/ui/demo/mus_demo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698