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

Side by Side Diff: services/service_manager/tests/lifecycle/package.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
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 <algorithm> 5 #include <algorithm>
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 22 matching lines...) Expand all
33 service_manager_connection_closed_callback), 33 service_manager_connection_closed_callback),
34 destruct_callback_(destruct_callback) { 34 destruct_callback_(destruct_callback) {
35 bindings_.set_connection_error_handler(base::Bind(&PackagedApp::BindingLost, 35 bindings_.set_connection_error_handler(base::Bind(&PackagedApp::BindingLost,
36 base::Unretained(this))); 36 base::Unretained(this)));
37 } 37 }
38 38
39 ~PackagedApp() override {} 39 ~PackagedApp() override {}
40 40
41 private: 41 private:
42 // service_manager::Service: 42 // service_manager::Service:
43 void OnStart(service_manager::ServiceContext* context) override {
44 context_ = context;
45 }
46
43 bool OnConnect(const service_manager::ServiceInfo& remote_info, 47 bool OnConnect(const service_manager::ServiceInfo& remote_info,
44 service_manager::InterfaceRegistry* registry) override { 48 service_manager::InterfaceRegistry* registry) override {
45 registry->AddInterface<service_manager::test::mojom::LifecycleControl>( 49 registry->AddInterface<service_manager::test::mojom::LifecycleControl>(
46 this); 50 this);
47 return true; 51 return true;
48 } 52 }
49 53
50 // service_manager::InterfaceFactory<LifecycleControl> 54 // service_manager::InterfaceFactory<LifecycleControl>
51 void Create( 55 void Create(
52 const service_manager::Identity& remote_identity, 56 const service_manager::Identity& remote_identity,
(...skipping 14 matching lines...) Expand all
67 } 71 }
68 72
69 void Crash() override { 73 void Crash() override {
70 // When multiple instances are vended from the same package instance, this 74 // When multiple instances are vended from the same package instance, this
71 // will cause all instances to be quit. 75 // will cause all instances to be quit.
72 exit(1); 76 exit(1);
73 } 77 }
74 78
75 void CloseServiceManagerConnection() override { 79 void CloseServiceManagerConnection() override {
76 service_manager_connection_closed_callback_.Run(); 80 service_manager_connection_closed_callback_.Run();
77 context()->QuitNow(); 81 context_->QuitNow();
78 // This only closed our relationship with the service manager, existing 82 // This only closed our relationship with the service manager, existing
79 // |bindings_| 83 // |bindings_|
80 // remain active. 84 // remain active.
81 } 85 }
82 86
83 void BindingLost() { 87 void BindingLost() {
84 if (bindings_.empty()) { 88 if (bindings_.empty()) {
85 // Deletes |this|. 89 // Deletes |this|.
86 destruct_callback_.Run(); 90 destruct_callback_.Run();
87 } 91 }
88 } 92 }
89 93
94 service_manager::ServiceContext* context_;
90 mojo::BindingSet<service_manager::test::mojom::LifecycleControl> bindings_; 95 mojo::BindingSet<service_manager::test::mojom::LifecycleControl> bindings_;
91 96
92 // Run when this object's connection to the service manager is closed. 97 // Run when this object's connection to the service manager is closed.
93 base::Closure service_manager_connection_closed_callback_; 98 base::Closure service_manager_connection_closed_callback_;
94 // Run when this object is destructed. 99 // Run when this object is destructed.
95 base::Closure destruct_callback_; 100 base::Closure destruct_callback_;
96 101
97 DISALLOW_COPY_AND_ASSIGN(PackagedApp); 102 DISALLOW_COPY_AND_ASSIGN(PackagedApp);
98 }; 103 };
99 104
100 class Package : public service_manager::Service, 105 class Package : public service_manager::Service,
101 public service_manager::InterfaceFactory< 106 public service_manager::InterfaceFactory<
102 service_manager::mojom::ServiceFactory>, 107 service_manager::mojom::ServiceFactory>,
103 public service_manager::mojom::ServiceFactory { 108 public service_manager::mojom::ServiceFactory {
104 public: 109 public:
105 Package() {} 110 Package() {}
106 ~Package() override {} 111 ~Package() override {}
107 112
108 private: 113 private:
109 // service_manager::Service: 114 // service_manager::Service:
110 void OnStart() override { app_client_.OnStart(); } 115 void OnStart(service_manager::ServiceContext* context) override {
116 app_client_.OnStart(context);
117 }
111 118
112 bool OnConnect(const service_manager::ServiceInfo& remote_info, 119 bool OnConnect(const service_manager::ServiceInfo& remote_info,
113 service_manager::InterfaceRegistry* registry) override { 120 service_manager::InterfaceRegistry* registry) override {
114 registry->AddInterface<service_manager::mojom::ServiceFactory>(this); 121 registry->AddInterface<service_manager::mojom::ServiceFactory>(this);
115 return app_client_.OnConnect(remote_info, registry); 122 return app_client_.OnConnect(remote_info, registry);
116 } 123 }
117 124
118 // service_manager::InterfaceFactory<service_manager::mojom::ServiceFactory>: 125 // service_manager::InterfaceFactory<service_manager::mojom::ServiceFactory>:
119 void Create(const service_manager::Identity& remote_identity, 126 void Create(const service_manager::Identity& remote_identity,
120 service_manager::mojom::ServiceFactoryRequest request) override { 127 service_manager::mojom::ServiceFactoryRequest request) override {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 177
171 DISALLOW_COPY_AND_ASSIGN(Package); 178 DISALLOW_COPY_AND_ASSIGN(Package);
172 }; 179 };
173 180
174 } // namespace 181 } // namespace
175 182
176 MojoResult ServiceMain(MojoHandle service_request_handle) { 183 MojoResult ServiceMain(MojoHandle service_request_handle) {
177 service_manager::ServiceRunner runner(new Package); 184 service_manager::ServiceRunner runner(new Package);
178 return runner.Run(service_request_handle); 185 return runner.Run(service_request_handle);
179 } 186 }
OLDNEW
« no previous file with comments | « services/service_manager/tests/lifecycle/app_client.cc ('k') | services/service_manager/tests/lifecycle/parent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698