OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #ifndef CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_IMPL_H_ | |
6 #define CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_IMPL_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "content/common/content_export.h" | |
12 #include "mojo/public/cpp/system/message_pipe.h" | |
13 #include "services/service_manager/public/cpp/connector.h" | |
14 #include "third_party/WebKit/public/platform/Connector.h" | |
15 | |
16 namespace base { | |
17 class SingleThreadTaskRunner; | |
18 } | |
19 | |
20 namespace content { | |
21 | |
22 // An implementation of blink::Connector that forwards to a | |
23 // service_manager::Connector. | |
24 class CONTENT_EXPORT BlinkConnectorImpl : public blink::Connector { | |
25 public: | |
26 explicit BlinkConnectorImpl( | |
27 std::unique_ptr<service_manager::Connector> connector); | |
28 ~BlinkConnectorImpl(); | |
29 | |
30 // blink::Connector override. | |
31 void getInterface(const char* service_name, | |
32 const char* interface_name, | |
33 mojo::ScopedMessagePipeHandle handle) override; | |
34 | |
35 void AddOverrideForTesting( | |
36 const std::string& service_name, | |
37 const std::string& interface_name, | |
38 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& binder); | |
39 | |
40 void ClearOverridesForTesting(); | |
41 | |
42 void SetConnector(std::unique_ptr<service_manager::Connector> connector) { | |
43 connector_ = std::move(connector); | |
44 } | |
45 | |
46 base::WeakPtr<BlinkConnectorImpl> GetWeakPtr(); | |
47 | |
48 private: | |
49 using Binder = base::Callback<void(mojo::ScopedMessagePipeHandle)>; | |
50 using InterfaceBinderMap = std::map<std::string, Binder>; | |
51 using ServiceBinderMap = | |
52 std::map<std::string, std::unique_ptr<InterfaceBinderMap>>; | |
53 | |
54 // Returns a pointer to the InterfaceBinderMap in action for |service_name|, | |
55 // or nullptr if |service_name| has no overrides in action. | |
56 InterfaceBinderMap* GetOverridesForService(const char* service_name); | |
57 | |
58 // Maps service names to the per-interface overrides that have been set for | |
59 // that service. | |
60 ServiceBinderMap service_binders_; | |
61 | |
62 std::unique_ptr<service_manager::Connector> connector_; | |
63 | |
64 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
esprehn
2017/02/01 06:02:23
Hmm, what scheduler queue is this?
| |
65 | |
66 base::WeakPtrFactory<BlinkConnectorImpl> weak_ptr_factory_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(BlinkConnectorImpl); | |
69 }; | |
70 | |
71 } // namespace content | |
72 | |
73 #endif // CONTENT_RENDERER_MOJO_BLINK_CONNECTOR_IMPL_H_ | |
OLD | NEW |