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

Unified Diff: mojo/shell/service_connector.cc

Issue 137623017: Cleanup Service<> and ServiceFactory<> when clients go away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
Index: mojo/shell/service_connector.cc
diff --git a/mojo/shell/service_connector.cc b/mojo/shell/service_connector.cc
index afbb8041384ef240b923abe89e0558fda06bebf3..3b924233fccf0b583eccf29f009b5ae113799964 100644
--- a/mojo/shell/service_connector.cc
+++ b/mojo/shell/service_connector.cc
@@ -5,19 +5,20 @@
#include "mojo/shell/service_connector.h"
#include "base/logging.h"
+#include "mojo/public/bindings/error_handler.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojom/shell.h"
namespace mojo {
namespace shell {
-class ServiceConnector::ServiceFactory : public Shell {
+class ServiceConnector::ServiceFactory : public Shell, public ErrorHandler {
public:
ServiceFactory(ServiceConnector* connector, const GURL& url)
: connector_(connector),
url_(url) {
MessagePipe pipe;
- shell_client_.reset(pipe.handle0.Pass(), this);
+ shell_client_.reset(pipe.handle0.Pass(), this, this);
connector_->GetLoaderForURL(url)->Load(url, pipe.handle1.Pass());
}
virtual ~ServiceFactory() {}
@@ -32,6 +33,12 @@ class ServiceConnector::ServiceFactory : public Shell {
connector_->Connect(GURL(url.To<std::string>()), client_pipe.Pass());
}
+ virtual void OnError() MOJO_OVERRIDE {
+ connector_->RemoveServiceFactory(this);
+ }
+
+ GURL url() const { return url_; }
+
private:
ServiceConnector* connector_;
GURL url_;
@@ -80,5 +87,17 @@ void ServiceConnector::Connect(const GURL& url,
service_factory->ConnectToClient(client_handle.Pass());
}
+bool ServiceConnector::HasFactoryForURL(const GURL& url) const {
+ return url_to_service_factory_.find(url) != url_to_service_factory_.end();
+}
+
+void ServiceConnector::RemoveServiceFactory(ServiceFactory* service_factory) {
+ ServiceFactoryMap::iterator it =
+ url_to_service_factory_.find(service_factory->url());
+ DCHECK(it != url_to_service_factory_.end());
+ delete it->second;
+ url_to_service_factory_.erase(it);
+}
+
} // namespace shell
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698