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

Unified Diff: mojo/public/cpp/application/lib/application.cc

Issue 304273004: Add name to services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get chrome to build Created 6 years, 7 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/cpp/application/connect.h ('k') | mojo/public/cpp/application/lib/service_connector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/application/lib/application.cc
diff --git a/mojo/public/cpp/application/lib/application.cc b/mojo/public/cpp/application/lib/application.cc
index 9c8f2e172db937e282e57d8e74ba4cb2fd5323e4..d825d8508646e1442c51e196b76c3e82e88c0510 100644
--- a/mojo/public/cpp/application/lib/application.cc
+++ b/mojo/public/cpp/application/lib/application.cc
@@ -18,31 +18,30 @@ Application::Application(MojoHandle service_provider_handle)
MessagePipeHandle(service_provider_handle)).Pass()) {}
Application::~Application() {
- for (ServiceConnectorList::iterator it = service_connectors_.begin();
- it != service_connectors_.end(); ++it) {
- delete *it;
+ for (NameToServiceConnectorMap::iterator i =
+ name_to_service_connector_.begin();
+ i != name_to_service_connector_.end(); ++i) {
+ delete i->second;
}
+ name_to_service_connector_.clear();
}
void Application::Initialize() {}
void Application::AddServiceConnector(
internal::ServiceConnectorBase* service_connector) {
- service_connectors_.push_back(service_connector);
+ name_to_service_connector_[service_connector->name()] = service_connector;
set_service_connector_owner(service_connector, this);
}
void Application::RemoveServiceConnector(
internal::ServiceConnectorBase* service_connector) {
- for (ServiceConnectorList::iterator it = service_connectors_.begin();
- it != service_connectors_.end(); ++it) {
- if (*it == service_connector) {
- service_connectors_.erase(it);
- delete service_connector;
- break;
- }
- }
- if (service_connectors_.empty())
+ NameToServiceConnectorMap::iterator it =
+ name_to_service_connector_.find(service_connector->name());
+ assert(it != name_to_service_connector_.end());
+ delete it->second;
+ name_to_service_connector_.erase(it);
+ if (name_to_service_connector_.empty())
service_provider_.reset();
}
@@ -53,13 +52,12 @@ void Application::BindServiceProvider(
}
void Application::ConnectToService(const mojo::String& url,
+ const mojo::String& name,
ScopedMessagePipeHandle client_handle) {
- // TODO(davemoore): This method must be overridden by an Application subclass
- // to dispatch to the right ServiceConnector. We need to figure out an
- // approach to registration to make this better.
- assert(1 == service_connectors_.size());
- return service_connectors_.front()->ConnectToService(url,
- client_handle.Pass());
+ internal::ServiceConnectorBase* service_connector =
+ name_to_service_connector_[name];
+ return service_connector->ConnectToService(
+ url, name, client_handle.Pass());
}
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/application/connect.h ('k') | mojo/public/cpp/application/lib/service_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698