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

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

Issue 337533002: Introduce internal::ServiceRegistry to prepare for ServiceProvider split. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review concerns Created 6 years, 6 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/public/cpp/application/lib/service_registry.cc
diff --git a/mojo/public/cpp/application/lib/service_registry.cc b/mojo/public/cpp/application/lib/service_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea22ec4e5be62684ed0366a468325bc83cc4791e
--- /dev/null
+++ b/mojo/public/cpp/application/lib/service_registry.cc
@@ -0,0 +1,76 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/application/lib/service_registry.h"
+
+#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/lib/service_connector.h"
+
+namespace mojo {
+namespace internal {
+
+ServiceRegistry::ServiceRegistry(Application* application)
+ : application_(application) {
+}
+
+ServiceRegistry::ServiceRegistry(
+ Application* application,
+ ScopedMessagePipeHandle service_provider_handle)
+ : application_(application) {
+ remote_service_provider_.Bind(service_provider_handle.Pass());
+ remote_service_provider_.set_client(this);
+}
+
+ServiceRegistry::~ServiceRegistry() {
+ 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 ServiceRegistry::AddServiceConnector(
+ ServiceConnectorBase* service_connector) {
+ name_to_service_connector_[service_connector->name()] = service_connector;
+ service_connector->set_registry(this);
+}
+
+void ServiceRegistry::RemoveServiceConnector(
+ ServiceConnectorBase* service_connector) {
+ 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())
viettrungluu 2014/06/12 18:01:01 [I realize that this was just moved from another l
+ remote_service_provider_.reset();
+}
+
+void ServiceRegistry::BindRemoteServiceProvider(
+ ScopedMessagePipeHandle service_provider_handle) {
+ remote_service_provider_.Bind(service_provider_handle.Pass());
+ remote_service_provider_.set_client(this);
+}
+
+void ServiceRegistry::ConnectToService(const mojo::String& service_url,
+ const mojo::String& service_name,
+ ScopedMessagePipeHandle client_handle,
+ const mojo::String& requestor_url) {
+ if (!application_->AllowIncomingConnection(service_name, requestor_url)) {
+ client_handle.reset();
+ return;
+ }
+
+ internal::ServiceConnectorBase* service_connector =
+ name_to_service_connector_[service_name];
+ assert(service_connector);
+ // requestor_url is ignored because the service_connector stores the url
+ // of the requestor safely.
+ return service_connector->ConnectToService(
viettrungluu 2014/06/12 18:01:01 [Ditto.] Nit: Extraneous "return".
+ service_url, service_name, client_handle.Pass());
+}
+
+} // namespace internal
+} // namespace mojo
« no previous file with comments | « mojo/public/cpp/application/lib/service_registry.h ('k') | mojo/service_manager/service_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698