OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 class DevToolsTargetImpl; | 35 class DevToolsTargetImpl; |
36 class PortForwardingController; | 36 class PortForwardingController; |
37 class Profile; | 37 class Profile; |
38 | 38 |
39 class DevToolsAndroidBridge | 39 class DevToolsAndroidBridge |
40 : public base::RefCountedThreadSafe< | 40 : public base::RefCountedThreadSafe< |
41 DevToolsAndroidBridge, | 41 DevToolsAndroidBridge, |
42 content::BrowserThread::DeleteOnUIThread> { | 42 content::BrowserThread::DeleteOnUIThread> { |
43 public: | 43 public: |
44 typedef base::Callback<void(int result, | |
45 const std::string& response)> Callback; | |
46 | |
47 class Wrapper : public KeyedService { | 44 class Wrapper : public KeyedService { |
48 public: | 45 public: |
49 explicit Wrapper(content::BrowserContext* context); | 46 explicit Wrapper(content::BrowserContext* context); |
50 virtual ~Wrapper(); | 47 virtual ~Wrapper(); |
51 | 48 |
52 DevToolsAndroidBridge* Get(); | 49 DevToolsAndroidBridge* Get(); |
53 private: | 50 private: |
54 scoped_refptr<DevToolsAndroidBridge> bridge_; | 51 scoped_refptr<DevToolsAndroidBridge> bridge_; |
55 }; | 52 }; |
56 | 53 |
(...skipping 17 matching lines...) Expand all Loading... | |
74 DISALLOW_COPY_AND_ASSIGN(Factory); | 71 DISALLOW_COPY_AND_ASSIGN(Factory); |
75 }; | 72 }; |
76 | 73 |
77 class RemotePage { | 74 class RemotePage { |
78 public: | 75 public: |
79 virtual ~RemotePage() {} | 76 virtual ~RemotePage() {} |
80 virtual DevToolsTargetImpl* GetTarget() = 0; | 77 virtual DevToolsTargetImpl* GetTarget() = 0; |
81 virtual std::string GetFrontendURL() = 0; | 78 virtual std::string GetFrontendURL() = 0; |
82 }; | 79 }; |
83 | 80 |
84 typedef base::Callback<void(RemotePage*)> RemotePageCallback; | |
85 typedef base::Callback<void(int, const std::string&)> JsonRequestCallback; | 81 typedef base::Callback<void(int, const std::string&)> JsonRequestCallback; |
86 typedef AndroidDeviceManager::Device Device; | |
87 typedef AndroidDeviceManager::AndroidWebSocket AndroidWebSocket; | |
88 | 82 |
89 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { | 83 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { |
90 public: | 84 public: |
91 RemoteBrowser(scoped_refptr<Device> device, | 85 const std::string& serial() { return serial_; } |
92 const AndroidDeviceManager::BrowserInfo& browser_info); | 86 const std::string& socket() { return socket_; } |
87 const std::string& display_name() { return display_name_; } | |
88 const std::string& version() { return version_; } | |
93 | 89 |
94 std::string serial() { return device_->serial(); } | 90 bool IsChrome(); |
dgozman
2014/10/02 12:19:34
Why removed const?
vkuzkokov
2014/10/02 13:07:46
for consistency.
| |
95 std::string socket() { return socket_; } | 91 bool IsWebView(); |
dgozman
2014/10/02 12:19:34
ditto
| |
96 | |
97 std::string display_name() { return display_name_; } | |
98 void set_display_name(const std::string& name) { display_name_ = name; } | |
99 | |
100 std::string version() { return version_; } | |
101 void set_version(const std::string& version) { version_ = version; } | |
102 | |
103 bool IsChrome() const; | |
104 bool IsWebView() const; | |
105 | 92 |
106 typedef std::vector<int> ParsedVersion; | 93 typedef std::vector<int> ParsedVersion; |
107 ParsedVersion GetParsedVersion() const; | 94 ParsedVersion GetParsedVersion(); |
108 | 95 |
109 std::vector<RemotePage*> CreatePages(); | 96 const base::ListValue& page_descriptors(); |
110 void SetPageDescriptors(const base::ListValue&); | |
111 | |
112 void SendJsonRequest(const std::string& request, | |
113 const JsonRequestCallback& callback); | |
114 | |
115 void SendProtocolCommand(const std::string& debug_url, | |
116 const std::string& method, | |
117 base::DictionaryValue* params, | |
118 const base::Closure callback); | |
119 | |
120 void Open(const std::string& url, | |
121 const RemotePageCallback& callback); | |
122 | |
123 scoped_refptr<content::DevToolsAgentHost> GetAgentHost(); | |
124 | |
125 AndroidWebSocket* CreateWebSocket( | |
126 const std::string& url, | |
127 DevToolsAndroidBridge::AndroidWebSocket::Delegate* delegate); | |
128 | 97 |
129 private: | 98 private: |
130 friend class base::RefCounted<RemoteBrowser>; | 99 friend class base::RefCounted<RemoteBrowser>; |
100 friend class DevToolsAndroidBridge; | |
101 | |
102 RemoteBrowser(const std::string& serial, | |
103 const AndroidDeviceManager::BrowserInfo& browser_info); | |
104 | |
131 virtual ~RemoteBrowser(); | 105 virtual ~RemoteBrowser(); |
132 | 106 |
133 void InnerOpen(const std::string& url, | 107 std::string serial_; |
134 const JsonRequestCallback& callback); | |
135 | |
136 void PageCreatedOnUIThread( | |
137 const JsonRequestCallback& callback, | |
138 const std::string& url, int result, const std::string& response); | |
139 | |
140 void NavigatePageOnUIThread(const JsonRequestCallback& callback, | |
141 int result, | |
142 const std::string& response, | |
143 const std::string& url); | |
144 | |
145 void RespondToOpenOnUIThread( | |
146 const DevToolsAndroidBridge::RemotePageCallback& callback, | |
147 int result, | |
148 const std::string& response); | |
149 | |
150 scoped_refptr<Device> device_; | |
151 const std::string socket_; | 108 const std::string socket_; |
152 std::string display_name_; | 109 std::string display_name_; |
153 const AndroidDeviceManager::BrowserInfo::Type type_; | 110 const AndroidDeviceManager::BrowserInfo::Type type_; |
154 std::string version_; | 111 std::string version_; |
155 scoped_ptr<base::ListValue> page_descriptors_; | 112 scoped_ptr<base::ListValue> page_descriptors_; |
156 | 113 |
157 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); | 114 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); |
158 }; | 115 }; |
159 | 116 |
160 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; | 117 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; |
161 | 118 |
162 class RemoteDevice : public base::RefCounted<RemoteDevice> { | 119 class RemoteDevice : public base::RefCounted<RemoteDevice> { |
163 public: | 120 public: |
164 RemoteDevice(scoped_refptr<Device> device, | 121 std::string serial() { return serial_; } |
165 const AndroidDeviceManager::DeviceInfo& device_info); | |
166 | |
167 std::string serial() { return device_->serial(); } | |
168 std::string model() { return model_; } | 122 std::string model() { return model_; } |
169 bool is_connected() { return connected_; } | 123 bool is_connected() { return connected_; } |
170 RemoteBrowsers& browsers() { return browsers_; } | 124 RemoteBrowsers& browsers() { return browsers_; } |
171 gfx::Size screen_size() { return screen_size_; } | 125 gfx::Size screen_size() { return screen_size_; } |
172 | 126 |
173 void OpenSocket(const std::string& socket_name, | |
174 const AndroidDeviceManager::SocketCallback& callback); | |
175 | |
176 private: | 127 private: |
177 friend class base::RefCounted<RemoteDevice>; | 128 friend class base::RefCounted<RemoteDevice>; |
129 friend class DevToolsAndroidBridge; | |
130 | |
131 RemoteDevice(const std::string& serial, | |
132 const AndroidDeviceManager::DeviceInfo& device_info); | |
133 | |
178 virtual ~RemoteDevice(); | 134 virtual ~RemoteDevice(); |
179 | 135 |
180 scoped_refptr<Device> device_; | 136 std::string serial_; |
181 std::string model_; | 137 std::string model_; |
182 bool connected_; | 138 bool connected_; |
183 RemoteBrowsers browsers_; | 139 RemoteBrowsers browsers_; |
184 gfx::Size screen_size_; | 140 gfx::Size screen_size_; |
185 | 141 |
186 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); | 142 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); |
187 }; | 143 }; |
188 | 144 |
189 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; | 145 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; |
190 | 146 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 void set_device_providers_for_test( | 188 void set_device_providers_for_test( |
233 const AndroidDeviceManager::DeviceProviders& device_providers) { | 189 const AndroidDeviceManager::DeviceProviders& device_providers) { |
234 device_manager_->SetDeviceProviders(device_providers); | 190 device_manager_->SetDeviceProviders(device_providers); |
235 } | 191 } |
236 | 192 |
237 void set_task_scheduler_for_test( | 193 void set_task_scheduler_for_test( |
238 base::Callback<void(const base::Closure&)> scheduler) { | 194 base::Callback<void(const base::Closure&)> scheduler) { |
239 task_scheduler_ = scheduler; | 195 task_scheduler_ = scheduler; |
240 } | 196 } |
241 | 197 |
242 static bool HasDevToolsWindow(const std::string& agent_id); | 198 bool HasDevToolsWindow(const std::string& agent_id); |
199 | |
200 std::vector<RemotePage*> CreatePages(scoped_refptr<RemoteBrowser> browser); | |
201 | |
202 typedef base::Callback<void(RemotePage*)> RemotePageCallback; | |
203 void Open(scoped_refptr<RemoteBrowser> browser, | |
dgozman
2014/10/02 12:19:34
OpenRemotePage
vkuzkokov
2014/10/02 13:07:46
Done.
| |
204 const std::string& url, | |
205 const RemotePageCallback& callback); | |
206 | |
207 scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost( | |
208 scoped_refptr<RemoteBrowser> browser); | |
243 | 209 |
244 private: | 210 private: |
245 friend struct content::BrowserThread::DeleteOnThread< | 211 friend struct content::BrowserThread::DeleteOnThread< |
246 content::BrowserThread::UI>; | 212 content::BrowserThread::UI>; |
247 friend class base::DeleteHelper<DevToolsAndroidBridge>; | 213 friend class base::DeleteHelper<DevToolsAndroidBridge>; |
214 friend class PortForwardingController; | |
215 | |
216 class AgentHostDelegate; | |
217 class DiscoveryRequest; | |
218 class RemotePageTarget; | |
248 | 219 |
249 virtual ~DevToolsAndroidBridge(); | 220 virtual ~DevToolsAndroidBridge(); |
250 | 221 |
251 void StartDeviceListPolling(); | 222 void StartDeviceListPolling(); |
252 void StopDeviceListPolling(); | 223 void StopDeviceListPolling(); |
253 bool NeedsDeviceListPolling(); | 224 bool NeedsDeviceListPolling(); |
254 void RequestDeviceList( | 225 |
255 const base::Callback<void(const RemoteDevices&)>& callback); | 226 typedef std::pair<scoped_refptr<AndroidDeviceManager::Device>, |
256 void ReceivedDeviceList(const RemoteDevices& devices); | 227 scoped_refptr<RemoteDevice>> CompleteDevice; |
228 typedef std::vector<CompleteDevice> CompleteDevices; | |
229 typedef base::Callback<void(const CompleteDevices&)> DeviceListCallback; | |
230 void RequestDeviceList(const DeviceListCallback& callback); | |
dgozman
2014/10/02 12:19:34
We should simplify this in a follow-up and remove
| |
231 | |
232 void ReceivedDeviceList(const CompleteDevices& complete_devices); | |
233 | |
257 void StartDeviceCountPolling(); | 234 void StartDeviceCountPolling(); |
258 void StopDeviceCountPolling(); | 235 void StopDeviceCountPolling(); |
259 void RequestDeviceCount(const base::Callback<void(int)>& callback); | 236 void RequestDeviceCount(const base::Callback<void(int)>& callback); |
260 void ReceivedDeviceCount(int count); | 237 void ReceivedDeviceCount(int count); |
261 | 238 |
262 static void ScheduleTaskDefault(const base::Closure& task); | 239 static void ScheduleTaskDefault(const base::Closure& task); |
263 | 240 |
264 void CreateDeviceProviders(); | 241 void CreateDeviceProviders(); |
265 | 242 |
243 void SendJsonRequest(scoped_refptr<RemoteBrowser> browser, | |
244 const std::string& url, | |
245 const JsonRequestCallback& callback); | |
246 | |
247 void SendProtocolCommand(scoped_refptr<RemoteBrowser> browser, | |
248 const std::string& debug_url, | |
249 const std::string& method, | |
250 base::DictionaryValue* params, | |
251 const base::Closure callback); | |
252 | |
253 AndroidDeviceManager::AndroidWebSocket* CreateWebSocket( | |
254 scoped_refptr<RemoteBrowser> browser, | |
255 const std::string& url, | |
256 AndroidDeviceManager::AndroidWebSocket::Delegate* delegate); | |
257 | |
258 void PageCreatedOnUIThread(scoped_refptr<RemoteBrowser> browser, | |
259 const RemotePageCallback& callback, | |
260 const std::string& url, | |
261 int result, | |
262 const std::string& response); | |
263 | |
264 void NavigatePageOnUIThread(scoped_refptr<RemoteBrowser> browser, | |
265 const RemotePageCallback& callback, | |
266 int result, | |
267 const std::string& response, | |
268 const std::string& url); | |
269 | |
270 void RespondToOpenOnUIThread(scoped_refptr<RemoteBrowser> browser, | |
271 const RemotePageCallback& callback, | |
272 int result, | |
273 const std::string& response); | |
274 | |
266 Profile* profile_; | 275 Profile* profile_; |
267 scoped_refptr<AndroidDeviceManager> device_manager_; | 276 scoped_refptr<AndroidDeviceManager> device_manager_; |
268 RemoteDevices devices_; | 277 |
278 typedef std::map<std::string, scoped_refptr<AndroidDeviceManager::Device>> | |
279 DeviceMap; | |
280 DeviceMap device_map_; | |
281 | |
282 typedef std::map<std::string, AgentHostDelegate*> AgentHostDelegates; | |
283 AgentHostDelegates host_delegates_; | |
269 | 284 |
270 typedef std::vector<DeviceListListener*> DeviceListListeners; | 285 typedef std::vector<DeviceListListener*> DeviceListListeners; |
271 DeviceListListeners device_list_listeners_; | 286 DeviceListListeners device_list_listeners_; |
272 base::CancelableCallback<void(const RemoteDevices&)> device_list_callback_; | 287 base::CancelableCallback<void(const CompleteDevices&)> device_list_callback_; |
273 | 288 |
274 typedef std::vector<DeviceCountListener*> DeviceCountListeners; | 289 typedef std::vector<DeviceCountListener*> DeviceCountListeners; |
275 DeviceCountListeners device_count_listeners_; | 290 DeviceCountListeners device_count_listeners_; |
276 base::CancelableCallback<void(int)> device_count_callback_; | 291 base::CancelableCallback<void(int)> device_count_callback_; |
277 base::Callback<void(const base::Closure&)> task_scheduler_; | 292 base::Callback<void(const base::Closure&)> task_scheduler_; |
278 | 293 |
279 typedef std::vector<PortForwardingListener*> PortForwardingListeners; | 294 typedef std::vector<PortForwardingListener*> PortForwardingListeners; |
280 PortForwardingListeners port_forwarding_listeners_; | 295 PortForwardingListeners port_forwarding_listeners_; |
281 scoped_ptr<PortForwardingController> port_forwarding_controller_; | 296 scoped_ptr<PortForwardingController> port_forwarding_controller_; |
282 | 297 |
283 PrefChangeRegistrar pref_change_registrar_; | 298 PrefChangeRegistrar pref_change_registrar_; |
284 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); | 299 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); |
285 }; | 300 }; |
286 | 301 |
287 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 302 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
OLD | NEW |