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

Unified Diff: services/service_manager/public/cpp/lib/service_context.cc

Issue 2701883002: 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 side-by-side diff with in-line comments
Download patch
Index: services/service_manager/public/cpp/lib/service_context.cc
diff --git a/services/service_manager/public/cpp/lib/service_context.cc b/services/service_manager/public/cpp/lib/service_context.cc
index f45202e56b2324dd81f75d51d817a88c810a7fff..64594597f962f66c88174bd97da967e6babbc4f4 100644
--- a/services/service_manager/public/cpp/lib/service_context.cc
+++ b/services/service_manager/public/cpp/lib/service_context.cc
@@ -42,14 +42,18 @@ ServiceContext::ServiceContext(
} else {
DCHECK(pending_connector_request_.is_pending());
}
+ service_->SetContext(this);
}
ServiceContext::~ServiceContext() {}
-void ServiceContext::SetConnectionLostClosure(const base::Closure& closure) {
- connection_lost_closure_ = closure;
- if (service_quit_)
- QuitNow();
+void ServiceContext::SetQuitClosure(const base::Closure& closure) {
+ if (service_quit_) {
+ // CAUTION: May delete |this|.
+ closure.Run();
+ } else {
+ quit_closure_ = closure;
+ }
}
void ServiceContext::RequestQuit() {
@@ -64,15 +68,13 @@ void ServiceContext::DisconnectFromServiceManager() {
}
void ServiceContext::QuitNow() {
+ service_quit_ = true;
if (binding_.is_bound())
binding_.Close();
- if (!connection_lost_closure_.is_null())
- base::ResetAndReturn(&connection_lost_closure_).Run();
-}
-
-void ServiceContext::DestroyService() {
- QuitNow();
- service_.reset();
+ if (!quit_closure_.is_null()) {
+ // CAUTION: May delete |this|.
+ base::ResetAndReturn(&quit_closure_).Run();
+ }
}
////////////////////////////////////////////////////////////////////////////////
@@ -83,8 +85,6 @@ void ServiceContext::OnStart(const ServiceInfo& info,
local_info_ = info;
callback.Run(std::move(pending_connector_request_),
mojo::MakeRequest(&service_control_));
-
- service_->set_context(this);
service_->OnStart();
}
@@ -140,19 +140,10 @@ void ServiceContext::CallOnConnect(const ServiceInfo& source_info,
}
void ServiceContext::OnConnectionError() {
- // Note that the Service doesn't technically have to quit now, it may live
- // on to service existing connections. All existing Connectors however are
- // invalid.
- service_quit_ = service_->OnStop();
- if (service_quit_) {
+ if (service_->OnServiceManagerConnectionLost()) {
+ // CAUTION: May delete |this|.
QuitNow();
- // NOTE: This call may delete |this|, so don't access any ServiceContext
- // state beyond this point.
- return;
}
-
- // We don't reset the connector as clients may have taken a raw pointer to it.
- // Connect() will return nullptr if they try to connect to anything.
}
void ServiceContext::OnRegistryConnectionError(InterfaceRegistry* registry) {
« no previous file with comments | « services/service_manager/public/cpp/lib/service.cc ('k') | services/service_manager/public/cpp/lib/service_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698