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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 class RemotePage { | 101 class RemotePage { |
102 public: | 102 public: |
103 virtual ~RemotePage() {} | 103 virtual ~RemotePage() {} |
104 virtual DevToolsTargetImpl* GetTarget() = 0; | 104 virtual DevToolsTargetImpl* GetTarget() = 0; |
105 virtual std::string GetFrontendURL() = 0; | 105 virtual std::string GetFrontendURL() = 0; |
106 }; | 106 }; |
107 | 107 |
108 typedef base::Callback<void(RemotePage*)> RemotePageCallback; | 108 typedef base::Callback<void(RemotePage*)> RemotePageCallback; |
109 | 109 |
| 110 class DeviceHandle : public base::RefCounted<DeviceHandle> { |
| 111 public: |
| 112 DeviceHandle(scoped_refptr<DevToolsAndroidBridge> android_bridge, |
| 113 const std::string& serial); |
| 114 |
| 115 std::string serial() const { return serial_; } |
| 116 DevToolsAndroidBridge* android_bridge() const { |
| 117 return android_bridge_.get(); |
| 118 } |
| 119 private: |
| 120 friend class base::RefCounted<DeviceHandle>; |
| 121 virtual ~DeviceHandle(); |
| 122 |
| 123 scoped_refptr<DevToolsAndroidBridge> android_bridge_; |
| 124 const std::string serial_; |
| 125 }; |
| 126 |
| 127 typedef std::map<std::string, scoped_refptr<DeviceHandle> > DeviceHandleMap; |
| 128 |
110 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { | 129 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { |
111 public: | 130 public: |
112 RemoteBrowser( | 131 RemoteBrowser( |
113 scoped_refptr<DevToolsAndroidBridge> android_bridge, | 132 scoped_refptr<DeviceHandle> device_handle, |
114 const std::string& serial, | |
115 const std::string& socket); | 133 const std::string& socket); |
116 | 134 |
117 std::string serial() { return serial_; } | 135 std::string serial() { return device_handle_->serial(); } |
118 std::string socket() { return socket_; } | 136 std::string socket() { return socket_; } |
119 | 137 |
120 std::string display_name() { return display_name_; } | 138 std::string display_name() { return display_name_; } |
121 void set_display_name(const std::string& name) { display_name_ = name; } | 139 void set_display_name(const std::string& name) { display_name_ = name; } |
122 | 140 |
123 std::string version() { return version_; } | 141 std::string version() { return version_; } |
124 void set_version(const std::string& version) { version_ = version; } | 142 void set_version(const std::string& version) { version_ = version; } |
125 | 143 |
126 bool IsChrome() const; | 144 bool IsChrome() const; |
127 | 145 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 void NavigatePageOnUIThread(const JsonRequestCallback& callback, | 178 void NavigatePageOnUIThread(const JsonRequestCallback& callback, |
161 int result, | 179 int result, |
162 const std::string& response, | 180 const std::string& response, |
163 const std::string& url); | 181 const std::string& url); |
164 | 182 |
165 void RespondToOpenOnUIThread( | 183 void RespondToOpenOnUIThread( |
166 const DevToolsAndroidBridge::RemotePageCallback& callback, | 184 const DevToolsAndroidBridge::RemotePageCallback& callback, |
167 int result, | 185 int result, |
168 const std::string& response); | 186 const std::string& response); |
169 | 187 |
170 scoped_refptr<DevToolsAndroidBridge> android_bridge_; | 188 scoped_refptr<DeviceHandle> device_handle_; |
171 const std::string serial_; | |
172 const std::string socket_; | 189 const std::string socket_; |
173 std::string display_name_; | 190 std::string display_name_; |
174 std::string version_; | 191 std::string version_; |
175 scoped_ptr<base::ListValue> page_descriptors_; | 192 scoped_ptr<base::ListValue> page_descriptors_; |
176 | 193 |
177 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); | 194 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); |
178 }; | 195 }; |
179 | 196 |
180 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; | 197 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; |
181 | 198 |
182 class RemoteDevice : public base::RefCounted<RemoteDevice> { | 199 class RemoteDevice : public base::RefCounted<RemoteDevice> { |
183 public: | 200 public: |
184 RemoteDevice(scoped_refptr<DevToolsAndroidBridge> android_bridge, | 201 RemoteDevice(scoped_refptr<DeviceHandle> device_handle, |
185 const std::string& serial, | |
186 const std::string& model, | 202 const std::string& model, |
187 bool connected); | 203 bool connected); |
188 | 204 |
189 std::string serial() { return serial_; } | 205 std::string serial() { return device_handle_->serial(); } |
190 std::string model() { return model_; } | 206 std::string model() { return model_; } |
191 bool is_connected() { return connected_; } | 207 bool is_connected() { return connected_; } |
192 void AddBrowser(scoped_refptr<RemoteBrowser> browser); | 208 void AddBrowser(scoped_refptr<RemoteBrowser> browser); |
193 | 209 |
194 RemoteBrowsers& browsers() { return browsers_; } | 210 RemoteBrowsers& browsers() { return browsers_; } |
195 gfx::Size screen_size() { return screen_size_; } | 211 gfx::Size screen_size() { return screen_size_; } |
196 void set_screen_size(const gfx::Size& size) { screen_size_ = size; } | 212 void set_screen_size(const gfx::Size& size) { screen_size_ = size; } |
197 | 213 |
198 void OpenSocket(const std::string& socket_name, | 214 void OpenSocket(const std::string& socket_name, |
199 const AndroidDeviceManager::SocketCallback& callback); | 215 const AndroidDeviceManager::SocketCallback& callback); |
200 | 216 |
201 private: | 217 private: |
202 friend class base::RefCounted<RemoteDevice>; | 218 friend class base::RefCounted<RemoteDevice>; |
203 virtual ~RemoteDevice(); | 219 virtual ~RemoteDevice(); |
204 | 220 |
205 scoped_refptr<DevToolsAndroidBridge> android_bridge_; | 221 scoped_refptr<DeviceHandle> device_handle_; |
206 std::string serial_; | |
207 std::string model_; | 222 std::string model_; |
208 bool connected_; | 223 bool connected_; |
209 RemoteBrowsers browsers_; | 224 RemoteBrowsers browsers_; |
210 gfx::Size screen_size_; | 225 gfx::Size screen_size_; |
211 | 226 |
212 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); | 227 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); |
213 }; | 228 }; |
214 | 229 |
215 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; | 230 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; |
216 | 231 |
(...skipping 18 matching lines...) Expand all Loading... |
235 void AddDeviceCountListener(DeviceCountListener* listener); | 250 void AddDeviceCountListener(DeviceCountListener* listener); |
236 void RemoveDeviceCountListener(DeviceCountListener* listener); | 251 void RemoveDeviceCountListener(DeviceCountListener* listener); |
237 | 252 |
238 void set_device_providers_for_test( | 253 void set_device_providers_for_test( |
239 const AndroidDeviceManager::DeviceProviders& device_providers) { | 254 const AndroidDeviceManager::DeviceProviders& device_providers) { |
240 device_providers_ = device_providers; | 255 device_providers_ = device_providers; |
241 } | 256 } |
242 | 257 |
243 static bool HasDevToolsWindow(const std::string& agent_id); | 258 static bool HasDevToolsWindow(const std::string& agent_id); |
244 | 259 |
| 260 void IsConnectedForTest(const std::string& serial, |
| 261 const base::Callback<void(bool)>& callback); |
| 262 |
245 private: | 263 private: |
246 friend struct content::BrowserThread::DeleteOnThread< | 264 friend struct content::BrowserThread::DeleteOnThread< |
247 content::BrowserThread::UI>; | 265 content::BrowserThread::UI>; |
248 friend class base::DeleteHelper<DevToolsAndroidBridge>; | 266 friend class base::DeleteHelper<DevToolsAndroidBridge>; |
249 | 267 |
250 class HandlerThread : public base::RefCountedThreadSafe<HandlerThread> { | 268 class HandlerThread : public base::RefCountedThreadSafe<HandlerThread> { |
251 public: | 269 public: |
252 static scoped_refptr<HandlerThread> GetInstance(); | 270 static scoped_refptr<HandlerThread> GetInstance(); |
253 base::MessageLoop* message_loop(); | 271 base::MessageLoop* message_loop(); |
254 | 272 |
(...skipping 12 matching lines...) Expand all Loading... |
267 base::MessageLoop* device_message_loop() { | 285 base::MessageLoop* device_message_loop() { |
268 return handler_thread_->message_loop(); | 286 return handler_thread_->message_loop(); |
269 } | 287 } |
270 | 288 |
271 AndroidDeviceManager* device_manager() { | 289 AndroidDeviceManager* device_manager() { |
272 return device_manager_.get(); | 290 return device_manager_.get(); |
273 } | 291 } |
274 | 292 |
275 void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager); | 293 void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager); |
276 void RequestDeviceList(); | 294 void RequestDeviceList(); |
277 void ReceivedDeviceList(RemoteDevices* devices); | 295 void ReceivedDeviceList(RemoteDevices* devices, |
| 296 DeviceHandleMap* device_handles); |
278 | 297 |
279 void RequestDeviceCount(); | 298 void RequestDeviceCount(); |
280 void ReceivedDeviceCount(int count); | 299 void ReceivedDeviceCount(int count); |
281 | 300 |
282 void CreateDeviceProviders(); | 301 void CreateDeviceProviders(); |
283 | 302 |
284 Profile* profile_; | 303 Profile* profile_; |
285 scoped_refptr<HandlerThread> handler_thread_; | 304 scoped_refptr<HandlerThread> handler_thread_; |
286 scoped_refptr<AndroidDeviceManager> device_manager_; | 305 scoped_refptr<AndroidDeviceManager> device_manager_; |
287 | 306 |
288 typedef std::vector<DeviceListListener*> DeviceListListeners; | 307 typedef std::vector<DeviceListListener*> DeviceListListeners; |
289 DeviceListListeners device_list_listeners_; | 308 DeviceListListeners device_list_listeners_; |
| 309 DeviceHandleMap device_handles_; |
290 | 310 |
291 typedef std::vector<DeviceCountListener*> DeviceCountListeners; | 311 typedef std::vector<DeviceCountListener*> DeviceCountListeners; |
292 DeviceCountListeners device_count_listeners_; | 312 DeviceCountListeners device_count_listeners_; |
293 | 313 |
294 AndroidDeviceManager::DeviceProviders device_providers_; | 314 AndroidDeviceManager::DeviceProviders device_providers_; |
295 PrefChangeRegistrar pref_change_registrar_; | 315 PrefChangeRegistrar pref_change_registrar_; |
296 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); | 316 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); |
297 }; | 317 }; |
298 | 318 |
299 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 319 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
OLD | NEW |