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

Unified Diff: mojo/public/shell/service.h

Issue 137623017: Cleanup Service<> and ServiceFactory<> when clients go away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review nits Created 6 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
« no previous file with comments | « mojo/public/shell/lib/service.cc ('k') | mojo/shell/service_connector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/shell/service.h
diff --git a/mojo/public/shell/service.h b/mojo/public/shell/service.h
index fc1da801c2b4f6dc7cd3013e5366de68aa74e602..b2ca7b4859c65f612ab18b92f3b621c0c214fa3f 100644
--- a/mojo/public/shell/service.h
+++ b/mojo/public/shell/service.h
@@ -58,6 +58,8 @@ class ServiceFactoryBase : public ShellClient {
protected:
ServiceFactoryBase(ScopedMessagePipeHandle shell_handle);
Shell* shell() { return shell_.get(); }
+ // Destroys connection to Shell.
+ void DisconnectFromShell();
private:
RemotePtr<Shell> shell_;
@@ -88,6 +90,8 @@ class ServiceFactory : public ServiceFactoryBase {
it != services_.end(); ++it) {
if (*it == service) {
services_.erase(it);
+ if (services_.empty())
+ DisconnectFromShell();
return;
}
}
@@ -116,12 +120,12 @@ class Service : public ServiceInterface {
protected:
friend class ServiceFactory<ServiceImpl, Context>;
- Service() {}
+ Service() : reaper_(this) {}
void Initialize(ServiceFactory<ServiceImpl, Context>* service_factory,
ScopedMessagePipeHandle client_handle) {
service_factory_ = service_factory;
- client_.reset(client_handle.Pass(), this);
+ client_.reset(client_handle.Pass(), this, &reaper_);
}
Context* context() const {
@@ -131,6 +135,19 @@ class Service : public ServiceInterface {
typename ServiceInterface::_Peer* client() { return client_.get(); }
private:
+ // The Reaper class allows us to handle errors on the client proxy without
+ // polluting the name space of the Service<> class.
+ class Reaper : public ErrorHandler {
+ public:
+ Reaper(Service<ServiceInterface, ServiceImpl, Context>* service)
+ : service_(service) {}
+ virtual void OnError() {
+ delete service_;
+ }
+ private:
+ Service<ServiceInterface, ServiceImpl, Context>* service_;
+ };
+ Reaper reaper_;
ServiceFactory<ServiceImpl, Context>* service_factory_;
RemotePtr<typename ServiceInterface::_Peer> client_;
};
« no previous file with comments | « mojo/public/shell/lib/service.cc ('k') | mojo/shell/service_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698