| 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 "mojo/public/cpp/application/service_connector.h" |
| 8 #include "mojo/public/cpp/environment/logging.h" | 8 #include "mojo/public/cpp/environment/logging.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 | 11 |
| 12 ServiceProviderImpl::ServiceProviderImpl() | 12 ServiceProviderImpl::ServiceProviderImpl() |
| 13 : binding_(this), fallback_service_provider_(nullptr) { | 13 : binding_(this), fallback_service_provider_(nullptr) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 ServiceProviderImpl::ServiceProviderImpl( | 16 ServiceProviderImpl::ServiceProviderImpl( |
| 17 const ConnectionContext& connection_context, |
| 17 InterfaceRequest<ServiceProvider> service_provider_request) | 18 InterfaceRequest<ServiceProvider> service_provider_request) |
| 18 : binding_(this, service_provider_request.Pass()), | 19 : connection_context_(connection_context), |
| 20 binding_(this, service_provider_request.Pass()), |
| 19 fallback_service_provider_(nullptr) {} | 21 fallback_service_provider_(nullptr) {} |
| 20 | 22 |
| 21 ServiceProviderImpl::~ServiceProviderImpl() {} | 23 ServiceProviderImpl::~ServiceProviderImpl() {} |
| 22 | 24 |
| 23 void ServiceProviderImpl::Bind( | 25 void ServiceProviderImpl::Bind( |
| 26 const ConnectionContext& connection_context, |
| 24 InterfaceRequest<ServiceProvider> service_provider_request) { | 27 InterfaceRequest<ServiceProvider> service_provider_request) { |
| 28 connection_context_ = connection_context; |
| 25 binding_.Bind(service_provider_request.Pass()); | 29 binding_.Bind(service_provider_request.Pass()); |
| 26 } | 30 } |
| 27 | 31 |
| 28 void ServiceProviderImpl::Close() { | 32 void ServiceProviderImpl::Close() { |
| 29 if (binding_.is_bound()) | 33 if (binding_.is_bound()) { |
| 30 binding_.Close(); | 34 binding_.Close(); |
| 35 connection_context_ = ConnectionContext(); |
| 36 } |
| 31 } | 37 } |
| 32 | 38 |
| 33 void ServiceProviderImpl::ConnectToService( | 39 void ServiceProviderImpl::ConnectToService( |
| 34 const String& service_name, | 40 const String& service_name, |
| 35 ScopedMessagePipeHandle client_handle) { | 41 ScopedMessagePipeHandle client_handle) { |
| 36 // TODO(beng): perhaps take app connection thru ctor so that we can pass | |
| 37 // ApplicationConnection through? | |
| 38 bool service_found = service_connector_registry_.ConnectToService( | 42 bool service_found = service_connector_registry_.ConnectToService( |
| 39 nullptr, service_name, &client_handle); | 43 connection_context_, service_name, &client_handle); |
| 40 if (!service_found && fallback_service_provider_) { | 44 if (!service_found && fallback_service_provider_) { |
| 41 fallback_service_provider_->ConnectToService(service_name, | 45 fallback_service_provider_->ConnectToService(service_name, |
| 42 client_handle.Pass()); | 46 client_handle.Pass()); |
| 43 } | 47 } |
| 44 } | 48 } |
| 45 | 49 |
| 46 } // namespace mojo | 50 } // namespace mojo |
| OLD | NEW |