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 "content/common/associated_interface_provider_impl.h" | 5 #include "content/common/associated_interface_provider_impl.h" |
6 #include "mojo/public/cpp/bindings/associated_binding.h" | 6 #include "mojo/public/cpp/bindings/associated_binding.h" |
7 #include "mojo/public/cpp/bindings/binding.h" | |
8 | 7 |
9 namespace content { | 8 namespace content { |
10 | 9 |
11 class AssociatedInterfaceProviderImpl::LocalProvider | 10 class AssociatedInterfaceProviderImpl::LocalProvider |
12 : public mojom::RouteProvider, | 11 : public mojom::AssociatedInterfaceProvider { |
13 mojom::AssociatedInterfaceProvider { | |
14 public: | 12 public: |
15 explicit LocalProvider(mojom::AssociatedInterfaceProviderAssociatedPtr* proxy) | 13 explicit LocalProvider(mojom::AssociatedInterfaceProviderAssociatedPtr* proxy) |
16 : route_provider_binding_(this), | 14 : associated_interface_provider_binding_(this) { |
17 associated_interface_provider_binding_(this) { | 15 associated_interface_provider_binding_.Bind( |
18 route_provider_binding_.Bind(mojo::MakeRequest(&route_provider_ptr_)); | 16 mojo::MakeRequestForTesting(proxy)); |
kinuko
2016/12/28 02:47:24
Is this ctor mainly for testing? ...looks like so
leonhsl(Using Gerrit)
2016/12/28 03:03:40
Yeah it's true, this ctor is only used from Associ
| |
19 route_provider_ptr_->GetRoute( | |
20 0, mojo::MakeRequest(proxy, route_provider_ptr_.associated_group())); | |
21 } | 17 } |
22 | 18 |
23 ~LocalProvider() override {} | 19 ~LocalProvider() override {} |
24 | 20 |
25 void SetBinderForName( | 21 void SetBinderForName( |
26 const std::string& name, | 22 const std::string& name, |
27 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { | 23 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { |
28 binders_[name] = binder; | 24 binders_[name] = binder; |
29 } | 25 } |
30 | 26 |
31 private: | 27 private: |
32 // mojom::RouteProvider: | |
33 void GetRoute( | |
34 int32_t routing_id, | |
35 mojom::AssociatedInterfaceProviderAssociatedRequest request) override { | |
36 DCHECK(request.is_pending()); | |
37 associated_interface_provider_binding_.Bind(std::move(request)); | |
38 } | |
39 | |
40 // mojom::AssociatedInterfaceProvider: | 28 // mojom::AssociatedInterfaceProvider: |
41 void GetAssociatedInterface( | 29 void GetAssociatedInterface( |
42 const std::string& name, | 30 const std::string& name, |
43 mojom::AssociatedInterfaceAssociatedRequest request) override { | 31 mojom::AssociatedInterfaceAssociatedRequest request) override { |
44 auto it = binders_.find(name); | 32 auto it = binders_.find(name); |
45 if (it != binders_.end()) | 33 if (it != binders_.end()) |
46 it->second.Run(request.PassHandle()); | 34 it->second.Run(request.PassHandle()); |
47 } | 35 } |
48 | 36 |
49 using BinderMap = | 37 using BinderMap = |
50 std::map<std::string, | 38 std::map<std::string, |
51 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>>; | 39 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>>; |
52 BinderMap binders_; | 40 BinderMap binders_; |
53 | 41 |
54 mojom::RouteProviderPtr route_provider_ptr_; | |
55 mojo::Binding<mojom::RouteProvider> route_provider_binding_; | |
56 | |
57 mojo::AssociatedBinding<mojom::AssociatedInterfaceProvider> | 42 mojo::AssociatedBinding<mojom::AssociatedInterfaceProvider> |
58 associated_interface_provider_binding_; | 43 associated_interface_provider_binding_; |
59 }; | 44 }; |
60 | 45 |
61 AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl( | 46 AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl( |
62 mojom::AssociatedInterfaceProviderAssociatedPtr proxy) | 47 mojom::AssociatedInterfaceProviderAssociatedPtr proxy) |
63 : proxy_(std::move(proxy)) { | 48 : proxy_(std::move(proxy)) { |
64 DCHECK(proxy_.is_bound()); | 49 DCHECK(proxy_.is_bound()); |
65 } | 50 } |
66 | 51 |
(...skipping 15 matching lines...) Expand all Loading... | |
82 } | 67 } |
83 | 68 |
84 void AssociatedInterfaceProviderImpl::OverrideBinderForTesting( | 69 void AssociatedInterfaceProviderImpl::OverrideBinderForTesting( |
85 const std::string& name, | 70 const std::string& name, |
86 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { | 71 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { |
87 DCHECK(local_provider_); | 72 DCHECK(local_provider_); |
88 local_provider_->SetBinderForName(name, binder); | 73 local_provider_->SetBinderForName(name, binder); |
89 } | 74 } |
90 | 75 |
91 } // namespace content | 76 } // namespace content |
OLD | NEW |