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(); |
95 std::string socket() { return socket_; } | 91 bool IsWebView(); |
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 void set_device_providers_for_test( | 185 void set_device_providers_for_test( |
230 const AndroidDeviceManager::DeviceProviders& device_providers) { | 186 const AndroidDeviceManager::DeviceProviders& device_providers) { |
231 device_manager_->SetDeviceProviders(device_providers); | 187 device_manager_->SetDeviceProviders(device_providers); |
232 } | 188 } |
233 | 189 |
234 void set_task_scheduler_for_test( | 190 void set_task_scheduler_for_test( |
235 base::Callback<void(const base::Closure&)> scheduler) { | 191 base::Callback<void(const base::Closure&)> scheduler) { |
236 task_scheduler_ = scheduler; | 192 task_scheduler_ = scheduler; |
237 } | 193 } |
238 | 194 |
239 static bool HasDevToolsWindow(const std::string& agent_id); | 195 bool HasDevToolsWindow(const std::string& agent_id); |
196 | |
197 std::vector<RemotePage*> CreatePages(scoped_refptr<RemoteBrowser> browser); | |
198 | |
199 typedef base::Callback<void(RemotePage*)> RemotePageCallback; | |
200 void Open(scoped_refptr<RemoteBrowser> browser, | |
201 const std::string& url, | |
202 const RemotePageCallback& callback); | |
203 | |
204 scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost( | |
205 scoped_refptr<RemoteBrowser> browser); | |
240 | 206 |
241 private: | 207 private: |
242 friend struct content::BrowserThread::DeleteOnThread< | 208 friend struct content::BrowserThread::DeleteOnThread< |
243 content::BrowserThread::UI>; | 209 content::BrowserThread::UI>; |
244 friend class base::DeleteHelper<DevToolsAndroidBridge>; | 210 friend class base::DeleteHelper<DevToolsAndroidBridge>; |
211 friend class PortForwardingController; | |
dgozman
2014/10/01 14:27:28
Why we need this friend?
vkuzkokov
2014/10/02 11:35:01
It uses CreateWebSocket which we now encapsulate w
| |
212 | |
213 class AgentHostDelegate; | |
214 class DiscoveryRequest; | |
215 class RemotePageTarget; | |
245 | 216 |
246 virtual ~DevToolsAndroidBridge(); | 217 virtual ~DevToolsAndroidBridge(); |
247 | 218 |
248 void StartDeviceListPolling(); | 219 void StartDeviceListPolling(); |
249 void StopDeviceListPolling(); | 220 void StopDeviceListPolling(); |
250 bool NeedsDeviceListPolling(); | 221 bool NeedsDeviceListPolling(); |
251 void RequestDeviceList( | 222 |
252 const base::Callback<void(const RemoteDevices&)>& callback); | 223 typedef base::Callback<void(const AndroidDeviceManager::Devices&, |
dgozman
2014/10/01 14:27:28
All the places which need both ADM::Device and Rem
vkuzkokov
2014/10/02 11:35:01
Done.
| |
253 void ReceivedDeviceList(const RemoteDevices& devices); | 224 const RemoteDevices&)> DeviceListCallback; |
225 void RequestDeviceList(const DeviceListCallback& callback); | |
226 | |
227 void ReceivedDeviceList(const AndroidDeviceManager::Devices& devices, | |
228 const RemoteDevices& remote_devices); | |
229 | |
254 void StartDeviceCountPolling(); | 230 void StartDeviceCountPolling(); |
255 void StopDeviceCountPolling(); | 231 void StopDeviceCountPolling(); |
256 void RequestDeviceCount(const base::Callback<void(int)>& callback); | 232 void RequestDeviceCount(const base::Callback<void(int)>& callback); |
257 void ReceivedDeviceCount(int count); | 233 void ReceivedDeviceCount(int count); |
258 | 234 |
259 static void ScheduleTaskDefault(const base::Closure& task); | 235 static void ScheduleTaskDefault(const base::Closure& task); |
260 | 236 |
261 void CreateDeviceProviders(); | 237 void CreateDeviceProviders(); |
262 | 238 |
239 void SendJsonRequest(scoped_refptr<RemoteBrowser> browser, | |
240 const std::string& url, | |
241 const JsonRequestCallback& callback); | |
242 | |
243 void SendProtocolCommand(scoped_refptr<RemoteBrowser> browser, | |
244 const std::string& debug_url, | |
245 const std::string& method, | |
246 base::DictionaryValue* params, | |
247 const base::Closure callback); | |
248 | |
249 AndroidDeviceManager::AndroidWebSocket* CreateWebSocket( | |
250 scoped_refptr<RemoteBrowser> browser, | |
251 const std::string& url, | |
252 AndroidDeviceManager::AndroidWebSocket::Delegate* delegate); | |
253 | |
254 void PageCreatedOnUIThread(scoped_refptr<RemoteBrowser> browser, | |
255 const RemotePageCallback& callback, | |
256 const std::string& url, | |
257 int result, | |
258 const std::string& response); | |
259 | |
260 void NavigatePageOnUIThread(scoped_refptr<RemoteBrowser> browser, | |
261 const RemotePageCallback& callback, | |
262 int result, | |
263 const std::string& response, | |
264 const std::string& url); | |
265 | |
266 void RespondToOpenOnUIThread(scoped_refptr<RemoteBrowser> browser, | |
267 const RemotePageCallback& callback, | |
268 int result, | |
269 const std::string& response); | |
270 | |
263 Profile* profile_; | 271 Profile* profile_; |
264 scoped_refptr<AndroidDeviceManager> device_manager_; | 272 scoped_refptr<AndroidDeviceManager> device_manager_; |
265 RemoteDevices devices_; | 273 |
274 typedef std::map<std::string, scoped_refptr<AndroidDeviceManager::Device>> | |
275 DeviceMap; | |
276 DeviceMap device_map_; | |
277 | |
278 typedef std::map<std::string, AgentHostDelegate*> AgentHostDelegates; | |
279 AgentHostDelegates host_delegates_; | |
266 | 280 |
267 typedef std::vector<DeviceListListener*> DeviceListListeners; | 281 typedef std::vector<DeviceListListener*> DeviceListListeners; |
268 DeviceListListeners device_list_listeners_; | 282 DeviceListListeners device_list_listeners_; |
269 base::CancelableCallback<void(const RemoteDevices&)> device_list_callback_; | 283 base::CancelableCallback<void(const AndroidDeviceManager::Devices&, |
284 const RemoteDevices&)> device_list_callback_; | |
270 | 285 |
271 typedef std::vector<DeviceCountListener*> DeviceCountListeners; | 286 typedef std::vector<DeviceCountListener*> DeviceCountListeners; |
272 DeviceCountListeners device_count_listeners_; | 287 DeviceCountListeners device_count_listeners_; |
273 base::CancelableCallback<void(int)> device_count_callback_; | 288 base::CancelableCallback<void(int)> device_count_callback_; |
274 base::Callback<void(const base::Closure&)> task_scheduler_; | 289 base::Callback<void(const base::Closure&)> task_scheduler_; |
275 | 290 |
276 typedef std::vector<PortForwardingListener*> PortForwardingListeners; | 291 typedef std::vector<PortForwardingListener*> PortForwardingListeners; |
277 PortForwardingListeners port_forwarding_listeners_; | 292 PortForwardingListeners port_forwarding_listeners_; |
278 scoped_ptr<PortForwardingController> port_forwarding_controller_; | 293 scoped_ptr<PortForwardingController> port_forwarding_controller_; |
279 | 294 |
280 PrefChangeRegistrar pref_change_registrar_; | 295 PrefChangeRegistrar pref_change_registrar_; |
281 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); | 296 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); |
282 }; | 297 }; |
283 | 298 |
284 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 299 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
OLD | NEW |