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

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: 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/shell/service_connector.h ('k') | mojo/shell/service_connector_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/service_connector.cc
diff --git a/mojo/shell/service_connector.cc b/mojo/shell/service_connector.cc
index afbb8041384ef240b923abe89e0558fda06bebf3..c073c6e18e0b357098599f8f6c35bad09d753f5d 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_;
@@ -42,6 +49,11 @@ class ServiceConnector::ServiceFactory : public Shell {
ServiceConnector::Loader::Loader() {}
ServiceConnector::Loader::~Loader() {}
+bool ServiceConnector::TestAPI::HasFactoryForURL(const GURL& url) const {
+ return connector_->url_to_service_factory_.find(url) !=
+ connector_->url_to_service_factory_.end();
+}
+
ServiceConnector::ServiceConnector() : default_loader_(NULL) {
}
@@ -80,5 +92,13 @@ void ServiceConnector::Connect(const GURL& url,
service_factory->ConnectToClient(client_handle.Pass());
}
+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
« no previous file with comments | « mojo/shell/service_connector.h ('k') | mojo/shell/service_connector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698