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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/cancelable_callback.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/prefs/pref_change_registrar.h" | 15 #include "base/prefs/pref_change_registrar.h" |
15 #include "chrome/browser/devtools/device/android_device_manager.h" | 16 #include "chrome/browser/devtools/device/android_device_manager.h" |
16 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 17 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
18 #include "content/public/browser/devtools_agent_host.h" | 19 #include "content/public/browser/devtools_agent_host.h" |
19 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
20 | 21 |
21 template<typename T> struct DefaultSingletonTraits; | 22 template<typename T> struct DefaultSingletonTraits; |
(...skipping 10 matching lines...) Expand all Loading... |
32 } | 33 } |
33 | 34 |
34 class DevToolsTargetImpl; | 35 class DevToolsTargetImpl; |
35 class Profile; | 36 class Profile; |
36 | 37 |
37 class DevToolsAndroidBridge | 38 class DevToolsAndroidBridge |
38 : public base::RefCountedThreadSafe< | 39 : public base::RefCountedThreadSafe< |
39 DevToolsAndroidBridge, | 40 DevToolsAndroidBridge, |
40 content::BrowserThread::DeleteOnUIThread> { | 41 content::BrowserThread::DeleteOnUIThread> { |
41 public: | 42 public: |
| 43 static const int kAdbPollingIntervalMs; |
| 44 |
42 typedef base::Callback<void(int result, | 45 typedef base::Callback<void(int result, |
43 const std::string& response)> Callback; | 46 const std::string& response)> Callback; |
44 | 47 |
45 class Wrapper : public KeyedService { | 48 class Wrapper : public KeyedService { |
46 public: | 49 public: |
47 explicit Wrapper(content::BrowserContext* context); | 50 explicit Wrapper(content::BrowserContext* context); |
48 virtual ~Wrapper(); | 51 virtual ~Wrapper(); |
49 | 52 |
50 DevToolsAndroidBridge* Get(); | 53 DevToolsAndroidBridge* Get(); |
51 private: | 54 private: |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 }; | 238 }; |
236 | 239 |
237 void AddDeviceCountListener(DeviceCountListener* listener); | 240 void AddDeviceCountListener(DeviceCountListener* listener); |
238 void RemoveDeviceCountListener(DeviceCountListener* listener); | 241 void RemoveDeviceCountListener(DeviceCountListener* listener); |
239 | 242 |
240 void set_device_providers_for_test( | 243 void set_device_providers_for_test( |
241 const AndroidDeviceManager::DeviceProviders& device_providers) { | 244 const AndroidDeviceManager::DeviceProviders& device_providers) { |
242 device_providers_ = device_providers; | 245 device_providers_ = device_providers; |
243 } | 246 } |
244 | 247 |
| 248 void set_device_count_request_scheduler_for_test( |
| 249 base::Callback<void(base::Closure)> scheduler) { |
| 250 device_count_request_scheduler_for_test_ = scheduler; |
| 251 } |
| 252 |
245 static bool HasDevToolsWindow(const std::string& agent_id); | 253 static bool HasDevToolsWindow(const std::string& agent_id); |
246 | 254 |
247 private: | 255 private: |
248 friend struct content::BrowserThread::DeleteOnThread< | 256 friend struct content::BrowserThread::DeleteOnThread< |
249 content::BrowserThread::UI>; | 257 content::BrowserThread::UI>; |
250 friend class base::DeleteHelper<DevToolsAndroidBridge>; | 258 friend class base::DeleteHelper<DevToolsAndroidBridge>; |
251 | 259 |
252 class HandlerThread : public base::RefCountedThreadSafe<HandlerThread> { | 260 class HandlerThread : public base::RefCountedThreadSafe<HandlerThread> { |
253 public: | 261 public: |
254 static scoped_refptr<HandlerThread> GetInstance(); | 262 static scoped_refptr<HandlerThread> GetInstance(); |
(...skipping 15 matching lines...) Expand all Loading... |
270 return handler_thread_->message_loop(); | 278 return handler_thread_->message_loop(); |
271 } | 279 } |
272 | 280 |
273 AndroidDeviceManager* device_manager() { | 281 AndroidDeviceManager* device_manager() { |
274 return device_manager_.get(); | 282 return device_manager_.get(); |
275 } | 283 } |
276 | 284 |
277 void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager); | 285 void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager); |
278 void RequestDeviceList(); | 286 void RequestDeviceList(); |
279 void ReceivedDeviceList(RemoteDevices* devices); | 287 void ReceivedDeviceList(RemoteDevices* devices); |
| 288 void StartDeviceListPollingLoop(); |
| 289 void StopDeviceListPollingLoop(); |
280 | 290 |
281 void RequestDeviceCount(); | 291 void RequestDeviceCount(); |
282 void ReceivedDeviceCount(int count); | 292 void ReceivedDeviceCount(int count); |
| 293 void StartDeviceCountPollingLoop(); |
| 294 void StopDeviceCountPollingLoop(); |
| 295 void ScheduleDeviceCountRequest(base::Closure callback); |
283 | 296 |
284 void CreateDeviceProviders(); | 297 void CreateDeviceProviders(); |
285 | 298 |
286 Profile* profile_; | 299 Profile* profile_; |
287 scoped_refptr<HandlerThread> handler_thread_; | 300 scoped_refptr<HandlerThread> handler_thread_; |
288 scoped_refptr<AndroidDeviceManager> device_manager_; | 301 scoped_refptr<AndroidDeviceManager> device_manager_; |
289 | 302 |
290 typedef std::vector<DeviceListListener*> DeviceListListeners; | 303 typedef std::vector<DeviceListListener*> DeviceListListeners; |
291 DeviceListListeners device_list_listeners_; | 304 DeviceListListeners device_list_listeners_; |
| 305 base::CancelableCallback<void()> request_device_list_bound_; |
| 306 base::CancelableCallback<void(RemoteDevices* devices_ptr)> |
| 307 received_device_list_bound_; |
292 | 308 |
293 typedef std::vector<DeviceCountListener*> DeviceCountListeners; | 309 typedef std::vector<DeviceCountListener*> DeviceCountListeners; |
294 DeviceCountListeners device_count_listeners_; | 310 DeviceCountListeners device_count_listeners_; |
| 311 base::CancelableCallback<void()> request_device_count_bound_; |
| 312 base::CancelableCallback<void(int)> received_device_count_bound_; |
295 | 313 |
296 AndroidDeviceManager::DeviceProviders device_providers_; | 314 AndroidDeviceManager::DeviceProviders device_providers_; |
297 PrefChangeRegistrar pref_change_registrar_; | 315 PrefChangeRegistrar pref_change_registrar_; |
| 316 base::Callback<void(base::Closure)> device_count_request_scheduler_for_test_; |
298 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); | 317 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); |
299 }; | 318 }; |
300 | 319 |
301 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 320 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
OLD | NEW |