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 |