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/public/common/associated_interface_provider.h" | 5 #include "content/public/common/associated_interface_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <memory> | |
8 | 9 |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "content/common/associated_interfaces.mojom.h" | 11 #include "content/common/associated_interfaces.mojom.h" |
12 #include "mojo/public/cpp/bindings/associated_binding.h" | |
11 #include "mojo/public/cpp/bindings/associated_group.h" | 13 #include "mojo/public/cpp/bindings/associated_group.h" |
14 #include "mojo/public/cpp/bindings/binding.h" | |
12 | 15 |
13 namespace content { | 16 namespace content { |
14 | 17 |
15 class AssociatedInterfaceProviderImpl : public AssociatedInterfaceProvider { | 18 class AssociatedInterfaceProviderImpl : public AssociatedInterfaceProvider { |
16 public: | 19 public: |
17 // Binds this to a remote mojom::AssociatedInterfaceProvider. | 20 // Binds this to a remote mojom::AssociatedInterfaceProvider. |
18 explicit AssociatedInterfaceProviderImpl( | 21 explicit AssociatedInterfaceProviderImpl( |
19 mojom::AssociatedInterfaceProviderAssociatedPtr proxy); | 22 mojom::AssociatedInterfaceProviderAssociatedPtr proxy); |
23 // This constructor is only used for some tests when there has no injected | |
24 // mojom::AssociatedInterfaceProviderAssociatedPtr. Here will emulate it | |
25 // by providing self-contained local implementations of both | |
26 // mojom::RouteProvider and mojom::AssociatedInterfaceProvider. | |
Ken Rockot(use gerrit already)
2016/09/28 14:42:48
nit: We can reduce this documentation a bit since
leonhsl(Using Gerrit)
2016/10/07 09:42:52
Done and Thanks!
| |
27 AssociatedInterfaceProviderImpl(); | |
20 ~AssociatedInterfaceProviderImpl() override; | 28 ~AssociatedInterfaceProviderImpl() override; |
21 | 29 |
22 // AssociatedInterfaceProvider: | 30 // AssociatedInterfaceProvider: |
23 void GetInterface(const std::string& name, | 31 void GetInterface(const std::string& name, |
24 mojo::ScopedInterfaceEndpointHandle handle) override; | 32 mojo::ScopedInterfaceEndpointHandle handle) override; |
25 mojo::AssociatedGroup* GetAssociatedGroup() override; | 33 mojo::AssociatedGroup* GetAssociatedGroup() override; |
34 void OverrideBinderForTesting( | |
35 const std::string& name, | |
36 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) | |
37 override; | |
26 | 38 |
27 private: | 39 private: |
40 class LocalProvider : public mojom::RouteProvider, | |
Ken Rockot(use gerrit already)
2016/09/28 14:42:48
Please move the class definition into the cc file.
leonhsl(Using Gerrit)
2016/10/07 09:42:52
Done.
| |
41 mojom::AssociatedInterfaceProvider { | |
42 public: | |
43 explicit LocalProvider( | |
44 mojom::AssociatedInterfaceProviderAssociatedPtr* proxy); | |
45 ~LocalProvider() override; | |
46 | |
47 void SetBinderForName(const std::string& name, | |
48 const base::Callback<void( | |
49 mojo::ScopedInterfaceEndpointHandle)>& binder); | |
50 | |
51 private: | |
52 // mojom::RouteProvider: | |
53 void GetRoute( | |
54 int32_t routing_id, | |
55 mojom::AssociatedInterfaceProviderAssociatedRequest request) override; | |
56 | |
57 // mojom::AssociatedInterfaceProvider: | |
58 void GetAssociatedInterface( | |
59 const std::string& name, | |
60 mojom::AssociatedInterfaceAssociatedRequest request) override; | |
61 | |
62 using BinderMap = | |
63 std::map<std::string, | |
64 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>>; | |
65 BinderMap binders_; | |
66 | |
67 mojom::RouteProviderPtr route_provider_ptr_; | |
68 mojo::Binding<mojom::RouteProvider> route_provider_binding_; | |
69 | |
70 mojo::AssociatedBinding<mojom::AssociatedInterfaceProvider> | |
71 associated_interface_provider_binding_; | |
72 }; | |
73 | |
28 mojom::AssociatedInterfaceProviderAssociatedPtr proxy_; | 74 mojom::AssociatedInterfaceProviderAssociatedPtr proxy_; |
29 | 75 |
76 std::unique_ptr<LocalProvider> local_provider_; | |
77 | |
30 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfaceProviderImpl); | 78 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfaceProviderImpl); |
31 }; | 79 }; |
32 | 80 |
33 } // namespace content | 81 } // namespace content |
OLD | NEW |