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

Side by Side Diff: services/service_manager/tests/connect/connect_test_class_app.cc

Issue 2487573002: Service Manager: Remove ServiceContext* arg from Service::OnStart() (Closed)
Patch Set: rebase 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
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/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "mojo/public/cpp/bindings/binding_set.h" 9 #include "mojo/public/cpp/bindings/binding_set.h"
10 #include "services/service_manager/public/c/main.h" 10 #include "services/service_manager/public/c/main.h"
(...skipping 15 matching lines...) Expand all
26 public InterfaceFactory<test::mojom::ConnectTestService>, 26 public InterfaceFactory<test::mojom::ConnectTestService>,
27 public InterfaceFactory<test::mojom::ClassInterface>, 27 public InterfaceFactory<test::mojom::ClassInterface>,
28 public test::mojom::ConnectTestService, 28 public test::mojom::ConnectTestService,
29 public test::mojom::ClassInterface { 29 public test::mojom::ClassInterface {
30 public: 30 public:
31 ConnectTestClassApp() {} 31 ConnectTestClassApp() {}
32 ~ConnectTestClassApp() override {} 32 ~ConnectTestClassApp() override {}
33 33
34 private: 34 private:
35 // service_manager::Service: 35 // service_manager::Service:
36 void OnStart(ServiceContext* context) override {
37 context_ = context;
38 }
39
40 bool OnConnect(const ServiceInfo& remote_info, 36 bool OnConnect(const ServiceInfo& remote_info,
41 InterfaceRegistry* registry) override { 37 InterfaceRegistry* registry) override {
42 registry->AddInterface<test::mojom::ConnectTestService>(this); 38 registry->AddInterface<test::mojom::ConnectTestService>(this);
43 registry->AddInterface<test::mojom::ClassInterface>(this); 39 registry->AddInterface<test::mojom::ClassInterface>(this);
44 inbound_connections_.insert(registry); 40 inbound_connections_.insert(registry);
45 registry->AddConnectionLostClosure( 41 registry->AddConnectionLostClosure(
46 base::Bind(&ConnectTestClassApp::OnConnectionError, 42 base::Bind(&ConnectTestClassApp::OnConnectionError,
47 base::Unretained(this), registry)); 43 base::Unretained(this), registry));
48 return true; 44 return true;
49 } 45 }
50 46
51 // InterfaceFactory<test::mojom::ConnectTestService>: 47 // InterfaceFactory<test::mojom::ConnectTestService>:
52 void Create(const Identity& remote_identity, 48 void Create(const Identity& remote_identity,
53 test::mojom::ConnectTestServiceRequest request) override { 49 test::mojom::ConnectTestServiceRequest request) override {
54 bindings_.AddBinding(this, std::move(request)); 50 bindings_.AddBinding(this, std::move(request));
55 } 51 }
56 52
57 // InterfaceFactory<test::mojom::ClassInterface>: 53 // InterfaceFactory<test::mojom::ClassInterface>:
58 void Create(const Identity& remote_identity, 54 void Create(const Identity& remote_identity,
59 test::mojom::ClassInterfaceRequest request) override { 55 test::mojom::ClassInterfaceRequest request) override {
60 class_interface_bindings_.AddBinding(this, std::move(request)); 56 class_interface_bindings_.AddBinding(this, std::move(request));
61 } 57 }
62 58
63 // test::mojom::ConnectTestService: 59 // test::mojom::ConnectTestService:
64 void GetTitle(const GetTitleCallback& callback) override { 60 void GetTitle(const GetTitleCallback& callback) override {
65 callback.Run("CLASS APP"); 61 callback.Run("CLASS APP");
66 } 62 }
67 void GetInstance(const GetInstanceCallback& callback) override { 63 void GetInstance(const GetInstanceCallback& callback) override {
68 callback.Run(context_->identity().instance()); 64 callback.Run(context()->identity().instance());
69 } 65 }
70 66
71 // test::mojom::ClassInterface: 67 // test::mojom::ClassInterface:
72 void Ping(const PingCallback& callback) override { 68 void Ping(const PingCallback& callback) override {
73 callback.Run("PONG"); 69 callback.Run("PONG");
74 } 70 }
75 71
76 void OnConnectionError(InterfaceRegistry* registry) { 72 void OnConnectionError(InterfaceRegistry* registry) {
77 auto it = inbound_connections_.find(registry); 73 auto it = inbound_connections_.find(registry);
78 DCHECK(it != inbound_connections_.end()); 74 DCHECK(it != inbound_connections_.end());
79 inbound_connections_.erase(it); 75 inbound_connections_.erase(it);
80 if (inbound_connections_.empty()) 76 if (inbound_connections_.empty())
81 context_->QuitNow(); 77 context()->QuitNow();
82 } 78 }
83 79
84 ServiceContext* context_ = nullptr;
85 std::set<InterfaceRegistry*> inbound_connections_; 80 std::set<InterfaceRegistry*> inbound_connections_;
86 mojo::BindingSet<test::mojom::ConnectTestService> bindings_; 81 mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
87 mojo::BindingSet<test::mojom::ClassInterface> class_interface_bindings_; 82 mojo::BindingSet<test::mojom::ClassInterface> class_interface_bindings_;
88 83
89 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp); 84 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp);
90 }; 85 };
91 86
92 } // namespace service_manager 87 } // namespace service_manager
93 88
94 MojoResult ServiceMain(MojoHandle service_request_handle) { 89 MojoResult ServiceMain(MojoHandle service_request_handle) {
95 service_manager::ServiceRunner runner( 90 service_manager::ServiceRunner runner(
96 new service_manager::ConnectTestClassApp); 91 new service_manager::ConnectTestClassApp);
97 return runner.Run(service_request_handle); 92 return runner.Run(service_request_handle);
98 } 93 }
OLDNEW
« no previous file with comments | « services/service_manager/tests/connect/connect_test_app.cc ('k') | services/service_manager/tests/connect/connect_test_exe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698