Fixes bug in html_viewer that could lead to dropping interface requests
[chromium-blink-merge.git] / mojo / application / public / cpp / lib / service_registry.cc
blob911bbebae7a08d8a0db7e15061bd5a41758a9853
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/application/public/cpp/lib/service_registry.h"
7 #include "mojo/application/public/cpp/application_connection.h"
8 #include "mojo/application/public/cpp/application_impl.h"
9 #include "mojo/application/public/cpp/service_connector.h"
11 namespace mojo {
12 namespace internal {
14 ServiceRegistry::ServiceRegistry(
15 ApplicationImpl* application_impl,
16 const std::string& connection_url,
17 const std::string& remote_url,
18 ServiceProviderPtr remote_services,
19 InterfaceRequest<ServiceProvider> local_services)
20 : application_impl_(application_impl),
21 connection_url_(connection_url),
22 remote_url_(remote_url),
23 local_binding_(this),
24 remote_service_provider_(remote_services.Pass()) {
25 if (local_services.is_pending())
26 local_binding_.Bind(local_services.Pass());
29 ServiceRegistry::ServiceRegistry()
30 : application_impl_(nullptr), local_binding_(this) {
33 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) {
34 service_connector_registry_.set_service_connector(connector);
37 void ServiceRegistry::SetServiceConnectorForName(
38 ServiceConnector* service_connector,
39 const std::string& interface_name) {
40 service_connector_registry_.SetServiceConnectorForName(service_connector,
41 interface_name);
44 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() {
45 return this;
48 void ServiceRegistry::RemoveServiceConnectorForName(
49 const std::string& interface_name) {
50 service_connector_registry_.RemoveServiceConnectorForName(interface_name);
51 if (service_connector_registry_.empty())
52 remote_service_provider_.reset();
55 const std::string& ServiceRegistry::GetConnectionURL() {
56 return connection_url_;
59 const std::string& ServiceRegistry::GetRemoteApplicationURL() {
60 return remote_url_;
63 ServiceProvider* ServiceRegistry::GetServiceProvider() {
64 return remote_service_provider_.get();
67 ServiceRegistry::~ServiceRegistry() {
70 void ServiceRegistry::OnCloseConnection() {
71 if (application_impl_)
72 application_impl_->CloseConnection(this);
75 void ServiceRegistry::ConnectToService(const mojo::String& service_name,
76 ScopedMessagePipeHandle client_handle) {
77 service_connector_registry_.ConnectToService(this, service_name,
78 client_handle.Pass());
81 } // namespace internal
82 } // namespace mojo