Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / mojo / application / public / cpp / lib / service_registry.cc
blob8b3be11aca74a44befda9dcb77c344d1350eef86
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 "base/logging.h"
8 #include "mojo/application/public/cpp/application_connection.h"
9 #include "mojo/application/public/cpp/service_connector.h"
11 namespace mojo {
12 namespace internal {
14 ServiceRegistry::ServiceRegistry(
15 const std::string& connection_url,
16 const std::string& remote_url,
17 ServiceProviderPtr remote_services,
18 InterfaceRequest<ServiceProvider> local_services,
19 const std::set<std::string>& allowed_interfaces)
20 : connection_url_(connection_url),
21 remote_url_(remote_url),
22 local_binding_(this),
23 remote_service_provider_(remote_services.Pass()),
24 allowed_interfaces_(allowed_interfaces),
25 allow_all_interfaces_(allowed_interfaces_.size() == 1 &&
26 allowed_interfaces_.count("*") == 1),
27 weak_factory_(this) {
28 if (local_services.is_pending())
29 local_binding_.Bind(local_services.Pass());
32 ServiceRegistry::ServiceRegistry()
33 : local_binding_(this),
34 allow_all_interfaces_(true),
35 weak_factory_(this) {
38 ServiceRegistry::~ServiceRegistry() {
41 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) {
42 service_connector_registry_.set_service_connector(connector);
45 bool ServiceRegistry::SetServiceConnectorForName(
46 ServiceConnector* service_connector,
47 const std::string& interface_name) {
48 if (allow_all_interfaces_ ||
49 allowed_interfaces_.count(interface_name)) {
50 service_connector_registry_.SetServiceConnectorForName(service_connector,
51 interface_name);
52 return true;
54 LOG(WARNING) << "CapabilityFilter prevented connection to interface: " <<
55 interface_name;
56 return false;
59 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() {
60 return this;
63 void ServiceRegistry::SetRemoteServiceProviderConnectionErrorHandler(
64 const Closure& handler) {
65 remote_service_provider_.set_connection_error_handler(handler);
68 base::WeakPtr<ApplicationConnection> ServiceRegistry::GetWeakPtr() {
69 return weak_factory_.GetWeakPtr();
72 void ServiceRegistry::RemoveServiceConnectorForName(
73 const std::string& interface_name) {
74 service_connector_registry_.RemoveServiceConnectorForName(interface_name);
75 if (service_connector_registry_.empty())
76 remote_service_provider_.reset();
79 const std::string& ServiceRegistry::GetConnectionURL() {
80 return connection_url_;
83 const std::string& ServiceRegistry::GetRemoteApplicationURL() {
84 return remote_url_;
87 ServiceProvider* ServiceRegistry::GetServiceProvider() {
88 return remote_service_provider_.get();
91 void ServiceRegistry::ConnectToService(const mojo::String& service_name,
92 ScopedMessagePipeHandle client_handle) {
93 service_connector_registry_.ConnectToService(this, service_name,
94 client_handle.Pass());
97 } // namespace internal
98 } // namespace mojo