Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: headless/lib/browser/headless_devtools_client_impl.h

Issue 2783983002: Cleanup headless templates and message_dispatcher.h. (Closed)
Patch Set: build fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_
6 #define HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ 6 #define HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_
7 7
8 #include <unordered_map> 8 #include <unordered_map>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const std::string& json_message) override; 99 const std::string& json_message) override;
100 void AgentHostClosed(content::DevToolsAgentHost* agent_host, 100 void AgentHostClosed(content::DevToolsAgentHost* agent_host,
101 bool replaced_with_another_client) override; 101 bool replaced_with_another_client) override;
102 102
103 // internal::MessageDispatcher implementation: 103 // internal::MessageDispatcher implementation:
104 void SendMessage(const char* method, 104 void SendMessage(const char* method,
105 std::unique_ptr<base::Value> params, 105 std::unique_ptr<base::Value> params,
106 base::Callback<void(const base::Value&)> callback) override; 106 base::Callback<void(const base::Value&)> callback) override;
107 void SendMessage(const char* method, 107 void SendMessage(const char* method,
108 std::unique_ptr<base::Value> params, 108 std::unique_ptr<base::Value> params,
109 base::Callback<void()> callback) override; 109 base::Closure callback) override;
110 void SendMessage(const char* method,
111 base::Callback<void(const base::Value&)> callback) override;
112 void SendMessage(const char* method,
113 base::Callback<void()> callback) override;
114 void RegisterEventHandler( 110 void RegisterEventHandler(
115 const char* method, 111 const char* method,
116 base::Callback<void(const base::Value&)> callback) override; 112 base::Callback<void(const base::Value&)> callback) override;
117 113
118 bool AttachToHost(content::DevToolsAgentHost* agent_host); 114 bool AttachToHost(content::DevToolsAgentHost* agent_host);
119 void ForceAttachToHost(content::DevToolsAgentHost* agent_host); 115 void ForceAttachToHost(content::DevToolsAgentHost* agent_host);
120 void DetachFromHost(content::DevToolsAgentHost* agent_host); 116 void DetachFromHost(content::DevToolsAgentHost* agent_host);
121 117
122 private: 118 private:
123 // Contains a callback with or without a result parameter depending on the 119 // Contains a callback with or without a result parameter depending on the
124 // message type. 120 // message type.
125 struct Callback { 121 struct Callback {
126 Callback(); 122 Callback();
127 Callback(Callback&& other); 123 Callback(Callback&& other);
128 explicit Callback(base::Callback<void()> callback); 124 explicit Callback(base::Closure callback);
129 explicit Callback(base::Callback<void(const base::Value&)> callback); 125 explicit Callback(base::Callback<void(const base::Value&)> callback);
130 ~Callback(); 126 ~Callback();
131 127
132 Callback& operator=(Callback&& other); 128 Callback& operator=(Callback&& other);
133 129
134 base::Callback<void()> callback; 130 base::Closure callback;
135 base::Callback<void(const base::Value&)> callback_with_result; 131 base::Callback<void(const base::Value&)> callback_with_result;
136 }; 132 };
137 133
138 template <typename CallbackType> 134 template <typename CallbackType>
139 void FinalizeAndSendMessage(base::DictionaryValue* message, 135 void FinalizeAndSendMessage(base::DictionaryValue* message,
140 CallbackType callback); 136 CallbackType callback);
141 137
142 template <typename CallbackType> 138 template <typename CallbackType>
143 void SendMessageWithParams(const char* method, 139 void SendMessageWithParams(const char* method,
144 std::unique_ptr<base::Value> params, 140 std::unique_ptr<base::Value> params,
145 CallbackType callback); 141 CallbackType callback);
146 142
147 template <typename CallbackType>
148 void SendMessageWithoutParams(const char* method, CallbackType callback);
149
150 bool DispatchMessageReply(const base::DictionaryValue& message_dict); 143 bool DispatchMessageReply(const base::DictionaryValue& message_dict);
151 144
152 using EventHandler = base::Callback<void(const base::Value&)>; 145 using EventHandler = base::Callback<void(const base::Value&)>;
153 using EventHandlerMap = std::unordered_map<std::string, EventHandler>; 146 using EventHandlerMap = std::unordered_map<std::string, EventHandler>;
154 147
155 bool DispatchEvent(std::unique_ptr<base::Value> owning_message, 148 bool DispatchEvent(std::unique_ptr<base::Value> owning_message,
156 const base::DictionaryValue& message_dict); 149 const base::DictionaryValue& message_dict);
157 void DispatchEventTask(std::unique_ptr<base::Value> owning_message, 150 void DispatchEventTask(std::unique_ptr<base::Value> owning_message,
158 const EventHandler* event_handler, 151 const EventHandler* event_handler,
159 const base::DictionaryValue* result_dict); 152 const base::DictionaryValue* result_dict);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 tracing::ExperimentalDomain tracing_domain_; 191 tracing::ExperimentalDomain tracing_domain_;
199 scoped_refptr<base::SingleThreadTaskRunner> browser_main_thread_; 192 scoped_refptr<base::SingleThreadTaskRunner> browser_main_thread_;
200 base::WeakPtrFactory<HeadlessDevToolsClientImpl> weak_ptr_factory_; 193 base::WeakPtrFactory<HeadlessDevToolsClientImpl> weak_ptr_factory_;
201 194
202 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsClientImpl); 195 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsClientImpl);
203 }; 196 };
204 197
205 } // namespace headless 198 } // namespace headless
206 199
207 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ 200 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_
OLDNEW
« no previous file with comments | « headless/lib/browser/devtools_api/domain_types_h.template ('k') | headless/lib/browser/headless_devtools_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698