| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 9 | |
| 10 namespace service_manager { | |
| 11 | |
| 12 InterfaceProvider::InterfaceProvider() : weak_factory_(this) { | |
| 13 pending_request_ = MakeRequest(&interface_provider_); | |
| 14 } | |
| 15 | |
| 16 InterfaceProvider::~InterfaceProvider() {} | |
| 17 | |
| 18 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) { | |
| 19 DCHECK(pending_request_.is_pending()); | |
| 20 DCHECK(forward_callback_.is_null()); | |
| 21 mojo::FuseInterface(std::move(pending_request_), | |
| 22 interface_provider.PassInterface()); | |
| 23 } | |
| 24 | |
| 25 void InterfaceProvider::Forward(const ForwardCallback& callback) { | |
| 26 DCHECK(pending_request_.is_pending()); | |
| 27 DCHECK(forward_callback_.is_null()); | |
| 28 interface_provider_.reset(); | |
| 29 pending_request_.PassMessagePipe().reset(); | |
| 30 forward_callback_ = callback; | |
| 31 } | |
| 32 | |
| 33 void InterfaceProvider::SetConnectionLostClosure( | |
| 34 const base::Closure& connection_lost_closure) { | |
| 35 interface_provider_.set_connection_error_handler(connection_lost_closure); | |
| 36 } | |
| 37 | |
| 38 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() { | |
| 39 return weak_factory_.GetWeakPtr(); | |
| 40 } | |
| 41 | |
| 42 void InterfaceProvider::GetInterface( | |
| 43 const std::string& name, | |
| 44 mojo::ScopedMessagePipeHandle request_handle) { | |
| 45 // Local binders can be registered via TestApi. | |
| 46 auto it = binders_.find(name); | |
| 47 if (it != binders_.end()) { | |
| 48 it->second.Run(std::move(request_handle)); | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 if (!forward_callback_.is_null()) { | |
| 53 DCHECK(!interface_provider_.is_bound()); | |
| 54 forward_callback_.Run(name, std::move(request_handle)); | |
| 55 } else { | |
| 56 DCHECK(interface_provider_.is_bound()); | |
| 57 interface_provider_->GetInterface(name, std::move(request_handle)); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 void InterfaceProvider::ClearBinders() { | |
| 62 binders_.clear(); | |
| 63 } | |
| 64 | |
| 65 } // namespace service_manager | |
| OLD | NEW |