| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/shell/public/cpp/interface_provider.h" | 5 #include "services/shell/public/cpp/interface_provider.h" |
| 6 | 6 |
| 7 namespace shell { | 7 namespace shell { |
| 8 | 8 |
| 9 InterfaceProvider::InterfaceProvider( | 9 InterfaceProvider::InterfaceProvider() : weak_factory_(this) {} |
| 10 mojom::InterfaceProviderPtr interface_provider) | |
| 11 : interface_provider_(std::move(interface_provider)), | |
| 12 weak_factory_(this) {} | |
| 13 InterfaceProvider::~InterfaceProvider() {} | 10 InterfaceProvider::~InterfaceProvider() {} |
| 14 | 11 |
| 12 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) { |
| 13 DCHECK(!interface_provider_.is_bound()); |
| 14 interface_provider_ = std::move(interface_provider); |
| 15 } |
| 16 |
| 15 void InterfaceProvider::SetConnectionLostClosure( | 17 void InterfaceProvider::SetConnectionLostClosure( |
| 16 const base::Closure& connection_lost_closure) { | 18 const base::Closure& connection_lost_closure) { |
| 17 interface_provider_.set_connection_error_handler(connection_lost_closure); | 19 interface_provider_.set_connection_error_handler(connection_lost_closure); |
| 18 } | 20 } |
| 19 | 21 |
| 20 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() { | 22 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() { |
| 21 return weak_factory_.GetWeakPtr(); | 23 return weak_factory_.GetWeakPtr(); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void InterfaceProvider::GetInterface( | 26 void InterfaceProvider::GetInterface( |
| 25 const std::string& name, | 27 const std::string& name, |
| 26 mojo::ScopedMessagePipeHandle request_handle) { | 28 mojo::ScopedMessagePipeHandle request_handle) { |
| 27 // Local binders can be registered via TestApi. | 29 // Local binders can be registered via TestApi. |
| 28 auto it = binders_.find(name); | 30 auto it = binders_.find(name); |
| 29 if (it != binders_.end()) { | 31 if (it != binders_.end()) { |
| 30 it->second.Run(std::move(request_handle)); | 32 it->second.Run(std::move(request_handle)); |
| 31 return; | 33 return; |
| 32 } | 34 } |
| 33 interface_provider_->GetInterface(name, std::move(request_handle)); | 35 interface_provider_->GetInterface(name, std::move(request_handle)); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void InterfaceProvider::ClearBinders() { | 38 void InterfaceProvider::ClearBinders() { |
| 37 binders_.clear(); | 39 binders_.clear(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 } // namespace shell | 42 } // namespace shell |
| OLD | NEW |