OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/public/cpp/application/service_provider_impl.h" | 5 #include "mojo/public/cpp/application/service_provider_impl.h" |
6 | 6 |
7 #include "mojo/public/cpp/application/service_connector.h" | 7 #include <utility> |
8 #include "mojo/public/cpp/environment/logging.h" | |
9 | 8 |
10 namespace mojo { | 9 namespace mojo { |
11 | 10 |
12 ServiceProviderImpl::ServiceProviderImpl() | 11 ServiceProviderImpl::ServiceProviderImpl() |
13 : binding_(this), fallback_service_provider_(nullptr) { | 12 : binding_(this), fallback_service_provider_(nullptr) { |
14 } | 13 } |
15 | 14 |
16 ServiceProviderImpl::ServiceProviderImpl( | 15 ServiceProviderImpl::ServiceProviderImpl( |
17 const ConnectionContext& connection_context, | 16 const ConnectionContext& connection_context, |
18 InterfaceRequest<ServiceProvider> service_provider_request) | 17 InterfaceRequest<ServiceProvider> service_provider_request) |
(...skipping 11 matching lines...) Expand all Loading... |
30 binding_.Bind(service_provider_request.Pass()); | 29 binding_.Bind(service_provider_request.Pass()); |
31 } | 30 } |
32 | 31 |
33 void ServiceProviderImpl::Close() { | 32 void ServiceProviderImpl::Close() { |
34 if (binding_.is_bound()) { | 33 if (binding_.is_bound()) { |
35 binding_.Close(); | 34 binding_.Close(); |
36 connection_context_ = ConnectionContext(); | 35 connection_context_ = ConnectionContext(); |
37 } | 36 } |
38 } | 37 } |
39 | 38 |
| 39 void ServiceProviderImpl::AddServiceForName( |
| 40 std::unique_ptr<ServiceConnector> service_connector, |
| 41 const std::string& service_name) { |
| 42 name_to_service_connector_[service_name] = std::move(service_connector); |
| 43 } |
| 44 |
| 45 void ServiceProviderImpl::RemoveServiceForName( |
| 46 const std::string& service_name) { |
| 47 auto it = name_to_service_connector_.find(service_name); |
| 48 if (it != name_to_service_connector_.end()) |
| 49 name_to_service_connector_.erase(it); |
| 50 } |
| 51 |
40 void ServiceProviderImpl::ConnectToService( | 52 void ServiceProviderImpl::ConnectToService( |
41 const String& service_name, | 53 const String& service_name, |
42 ScopedMessagePipeHandle client_handle) { | 54 ScopedMessagePipeHandle client_handle) { |
43 bool service_found = service_connector_registry_.ConnectToService( | 55 auto it = name_to_service_connector_.find(service_name); |
44 connection_context_, service_name, &client_handle); | 56 if (it != name_to_service_connector_.end()) { |
45 if (!service_found && fallback_service_provider_) { | 57 it->second->ConnectToService(connection_context_, client_handle.Pass()); |
| 58 } else if (fallback_service_provider_) { |
46 fallback_service_provider_->ConnectToService(service_name, | 59 fallback_service_provider_->ConnectToService(service_name, |
47 client_handle.Pass()); | 60 client_handle.Pass()); |
48 } | 61 } |
49 } | 62 } |
50 | 63 |
51 } // namespace mojo | 64 } // namespace mojo |
OLD | NEW |