| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "mojo/public/cpp/application/service_provider_impl.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 namespace mojo { | |
| 10 | |
| 11 ServiceProviderImpl::ServiceProviderImpl() | |
| 12 : binding_(this), fallback_service_provider_(nullptr) { | |
| 13 } | |
| 14 | |
| 15 ServiceProviderImpl::ServiceProviderImpl( | |
| 16 const ConnectionContext& connection_context, | |
| 17 InterfaceRequest<ServiceProvider> service_provider_request) | |
| 18 : binding_(this), fallback_service_provider_(nullptr) { | |
| 19 if (service_provider_request.is_pending()) | |
| 20 Bind(connection_context, service_provider_request.Pass()); | |
| 21 } | |
| 22 | |
| 23 ServiceProviderImpl::~ServiceProviderImpl() {} | |
| 24 | |
| 25 void ServiceProviderImpl::Bind( | |
| 26 const ConnectionContext& connection_context, | |
| 27 InterfaceRequest<ServiceProvider> service_provider_request) { | |
| 28 connection_context_ = connection_context; | |
| 29 binding_.Bind(service_provider_request.Pass()); | |
| 30 } | |
| 31 | |
| 32 void ServiceProviderImpl::Close() { | |
| 33 if (binding_.is_bound()) { | |
| 34 binding_.Close(); | |
| 35 connection_context_ = ConnectionContext(); | |
| 36 } | |
| 37 } | |
| 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 | |
| 52 void ServiceProviderImpl::ConnectToService( | |
| 53 const String& service_name, | |
| 54 ScopedMessagePipeHandle client_handle) { | |
| 55 auto it = name_to_service_connector_.find(service_name); | |
| 56 if (it != name_to_service_connector_.end()) { | |
| 57 it->second->ConnectToService(connection_context_, client_handle.Pass()); | |
| 58 } else if (fallback_service_provider_) { | |
| 59 fallback_service_provider_->ConnectToService(service_name, | |
| 60 client_handle.Pass()); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 } // namespace mojo | |
| OLD | NEW |