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() : weak_factory_(this) {} | 9 InterfaceProvider::InterfaceProvider() : weak_factory_(this) { |
| 10 pending_request_ = GetProxy(&interface_provider_); |
| 11 } |
10 InterfaceProvider::~InterfaceProvider() {} | 12 InterfaceProvider::~InterfaceProvider() {} |
11 | 13 |
12 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) { | 14 void InterfaceProvider::Bind(mojom::InterfaceProviderPtr interface_provider) { |
13 DCHECK(!interface_provider_.is_bound()); | 15 DCHECK(pending_request_.is_pending()); |
14 interface_provider_ = std::move(interface_provider); | 16 mojo::FuseInterface(std::move(pending_request_), |
| 17 interface_provider.PassInterface()); |
15 } | 18 } |
16 | 19 |
17 void InterfaceProvider::SetConnectionLostClosure( | 20 void InterfaceProvider::SetConnectionLostClosure( |
18 const base::Closure& connection_lost_closure) { | 21 const base::Closure& connection_lost_closure) { |
19 interface_provider_.set_connection_error_handler(connection_lost_closure); | 22 interface_provider_.set_connection_error_handler(connection_lost_closure); |
20 } | 23 } |
21 | 24 |
22 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() { | 25 base::WeakPtr<InterfaceProvider> InterfaceProvider::GetWeakPtr() { |
23 return weak_factory_.GetWeakPtr(); | 26 return weak_factory_.GetWeakPtr(); |
24 } | 27 } |
25 | 28 |
26 void InterfaceProvider::GetInterface( | 29 void InterfaceProvider::GetInterface( |
27 const std::string& name, | 30 const std::string& name, |
28 mojo::ScopedMessagePipeHandle request_handle) { | 31 mojo::ScopedMessagePipeHandle request_handle) { |
29 // Local binders can be registered via TestApi. | 32 // Local binders can be registered via TestApi. |
30 auto it = binders_.find(name); | 33 auto it = binders_.find(name); |
31 if (it != binders_.end()) { | 34 if (it != binders_.end()) { |
32 it->second.Run(std::move(request_handle)); | 35 it->second.Run(std::move(request_handle)); |
33 return; | 36 return; |
34 } | 37 } |
35 interface_provider_->GetInterface(name, std::move(request_handle)); | 38 interface_provider_->GetInterface(name, std::move(request_handle)); |
36 } | 39 } |
37 | 40 |
38 void InterfaceProvider::ClearBinders() { | 41 void InterfaceProvider::ClearBinders() { |
39 binders_.clear(); | 42 binders_.clear(); |
40 } | 43 } |
41 | 44 |
42 } // namespace shell | 45 } // namespace shell |
OLD | NEW |