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

Side by Side Diff: services/service_manager/public/cpp/lib/service_context.cc

Issue 2700693004: service_manager: More consistent Service lifecycle API (Closed)
Patch Set: . Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/service_manager/public/cpp/service_context.h" 5 #include "services/service_manager/public/cpp/service_context.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void ServiceContext::DestroyService() { 73 void ServiceContext::DestroyService() {
74 QuitNow(); 74 QuitNow();
75 service_.reset(); 75 service_.reset();
76 } 76 }
77 77
78 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
79 // ServiceContext, mojom::Service implementation: 79 // ServiceContext, mojom::Service implementation:
80 80
81 void ServiceContext::OnStart(const ServiceInfo& info, 81 void ServiceContext::OnStart(const ServiceInfo& info,
82 const OnStartCallback& callback) { 82 const OnStartCallback& callback) {
83 service_started_ = true;
83 local_info_ = info; 84 local_info_ = info;
84 callback.Run(std::move(pending_connector_request_), 85 callback.Run(std::move(pending_connector_request_),
85 mojo::MakeRequest(&service_control_)); 86 mojo::MakeRequest(&service_control_));
86 87
87 service_->set_context(this); 88 service_->set_context(this);
88 service_->OnStart(); 89 service_->OnStart();
89 } 90 }
90 91
91 void ServiceContext::OnConnect( 92 void ServiceContext::OnConnect(
92 const ServiceInfo& source_info, 93 const ServiceInfo& source_info,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 134
134 InterfaceRegistry* raw_registry = registry.get(); 135 InterfaceRegistry* raw_registry = registry.get();
135 registry->AddConnectionLostClosure(base::Bind( 136 registry->AddConnectionLostClosure(base::Bind(
136 &ServiceContext::OnRegistryConnectionError, base::Unretained(this), 137 &ServiceContext::OnRegistryConnectionError, base::Unretained(this),
137 raw_registry)); 138 raw_registry));
138 connection_interface_registries_.insert( 139 connection_interface_registries_.insert(
139 std::make_pair(raw_registry, std::move(registry))); 140 std::make_pair(raw_registry, std::move(registry)));
140 } 141 }
141 142
142 void ServiceContext::OnConnectionError() { 143 void ServiceContext::OnConnectionError() {
144 if (!service_started_) {
145 // The pipe was broken before we even received OnStart().
146 service_->set_context(this);
147 service_->OnStartFailed();
148 return;
149 }
150
143 // Note that the Service doesn't technically have to quit now, it may live 151 // Note that the Service doesn't technically have to quit now, it may live
144 // on to service existing connections. All existing Connectors however are 152 // on to service existing connections. All existing Connectors however are
145 // invalid. 153 // invalid.
146 service_quit_ = service_->OnStop(); 154 service_quit_ = service_->OnStop();
147 if (service_quit_) { 155 if (service_quit_) {
148 QuitNow(); 156 QuitNow();
149 // NOTE: This call may delete |this|, so don't access any ServiceContext 157 // NOTE: This call may delete |this|, so don't access any ServiceContext
150 // state beyond this point. 158 // state beyond this point.
151 return; 159 return;
152 } 160 }
(...skipping 13 matching lines...) Expand all
166 } 174 }
167 175
168 void ServiceContext::DestroyConnectionInterfaceRegistry( 176 void ServiceContext::DestroyConnectionInterfaceRegistry(
169 InterfaceRegistry* registry) { 177 InterfaceRegistry* registry) {
170 auto it = connection_interface_registries_.find(registry); 178 auto it = connection_interface_registries_.find(registry);
171 CHECK(it != connection_interface_registries_.end()); 179 CHECK(it != connection_interface_registries_.end());
172 connection_interface_registries_.erase(it); 180 connection_interface_registries_.erase(it);
173 } 181 }
174 182
175 } // namespace service_manager 183 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/lib/service.cc ('k') | services/service_manager/public/cpp/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698