| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_DEVICE_DISCOVERY_H_ |
| 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_DEVICE_DISCOVERY_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/devtools/device/android_device_manager.h" |
| 17 #include "content/public/browser/devtools_agent_host.h" |
| 18 |
| 19 class DevToolsDeviceDiscovery { |
| 20 public: |
| 21 class RemotePage : public base::RefCounted<RemotePage> { |
| 22 public: |
| 23 scoped_refptr<AndroidDeviceManager::Device> device() { return device_; } |
| 24 const std::string& socket() { return browser_id_; } |
| 25 const std::string& frontend_url() { return frontend_url_; } |
| 26 scoped_refptr<content::DevToolsAgentHost> CreateTarget(); |
| 27 |
| 28 private: |
| 29 friend class base::RefCounted<RemotePage>; |
| 30 friend class DevToolsDeviceDiscovery; |
| 31 |
| 32 RemotePage(scoped_refptr<AndroidDeviceManager::Device> device, |
| 33 const std::string& browser_id, |
| 34 const base::DictionaryValue& dict); |
| 35 |
| 36 virtual ~RemotePage(); |
| 37 |
| 38 scoped_refptr<AndroidDeviceManager::Device> device_; |
| 39 std::string browser_id_; |
| 40 std::string frontend_url_; |
| 41 std::unique_ptr<base::DictionaryValue> dict_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(RemotePage); |
| 44 }; |
| 45 |
| 46 using RemotePages = std::vector<scoped_refptr<RemotePage>>; |
| 47 |
| 48 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { |
| 49 public: |
| 50 const std::string& serial() { return serial_; } |
| 51 const std::string& socket() { return browser_id_; } |
| 52 const std::string& display_name() { return display_name_; } |
| 53 const std::string& user() { return user_; } |
| 54 const std::string& version() { return version_; } |
| 55 const RemotePages& pages() { return pages_; } |
| 56 |
| 57 bool IsChrome(); |
| 58 std::string GetId(); |
| 59 |
| 60 using ParsedVersion = std::vector<int>; |
| 61 ParsedVersion GetParsedVersion(); |
| 62 |
| 63 private: |
| 64 friend class base::RefCounted<RemoteBrowser>; |
| 65 friend class DevToolsDeviceDiscovery; |
| 66 |
| 67 RemoteBrowser(const std::string& serial, |
| 68 const AndroidDeviceManager::BrowserInfo& browser_info); |
| 69 |
| 70 virtual ~RemoteBrowser(); |
| 71 |
| 72 std::string serial_; |
| 73 std::string browser_id_; |
| 74 std::string display_name_; |
| 75 std::string user_; |
| 76 AndroidDeviceManager::BrowserInfo::Type type_; |
| 77 std::string version_; |
| 78 RemotePages pages_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); |
| 81 }; |
| 82 |
| 83 using RemoteBrowsers = std::vector<scoped_refptr<RemoteBrowser>>; |
| 84 |
| 85 class RemoteDevice : public base::RefCounted<RemoteDevice> { |
| 86 public: |
| 87 std::string serial() { return serial_; } |
| 88 std::string model() { return model_; } |
| 89 bool is_connected() { return connected_; } |
| 90 RemoteBrowsers& browsers() { return browsers_; } |
| 91 gfx::Size screen_size() { return screen_size_; } |
| 92 |
| 93 private: |
| 94 friend class base::RefCounted<RemoteDevice>; |
| 95 friend class DevToolsDeviceDiscovery; |
| 96 |
| 97 RemoteDevice(const std::string& serial, |
| 98 const AndroidDeviceManager::DeviceInfo& device_info); |
| 99 |
| 100 virtual ~RemoteDevice(); |
| 101 |
| 102 std::string serial_; |
| 103 std::string model_; |
| 104 bool connected_; |
| 105 RemoteBrowsers browsers_; |
| 106 gfx::Size screen_size_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); |
| 109 }; |
| 110 |
| 111 using RemoteDevices = std::vector<scoped_refptr<RemoteDevice>>; |
| 112 |
| 113 using CompleteDevice = |
| 114 std::pair<scoped_refptr<AndroidDeviceManager::Device>, |
| 115 scoped_refptr<RemoteDevice>>; |
| 116 using CompleteDevices = std::vector<CompleteDevice>; |
| 117 using DeviceListCallback = base::Callback<void(const CompleteDevices&)>; |
| 118 |
| 119 DevToolsDeviceDiscovery( |
| 120 AndroidDeviceManager* device_manager, |
| 121 const DeviceListCallback& callback); |
| 122 ~DevToolsDeviceDiscovery(); |
| 123 |
| 124 void SetScheduler(base::Callback<void(const base::Closure&)> scheduler); |
| 125 |
| 126 static void DiscoverOnce( |
| 127 AndroidDeviceManager* device_manager, |
| 128 const DeviceListCallback& callback); |
| 129 static scoped_refptr<content::DevToolsAgentHost> CreateBrowserAgentHost( |
| 130 scoped_refptr<AndroidDeviceManager::Device> device, |
| 131 scoped_refptr<RemoteBrowser> browser); |
| 132 |
| 133 private: |
| 134 class DiscoveryRequest; |
| 135 |
| 136 void RequestDeviceList(); |
| 137 void ReceivedDeviceList(const CompleteDevices& complete_devices); |
| 138 |
| 139 AndroidDeviceManager* device_manager_; |
| 140 const DeviceListCallback callback_; |
| 141 base::Callback<void(const base::Closure&)> task_scheduler_; |
| 142 base::WeakPtrFactory<DevToolsDeviceDiscovery> weak_factory_; |
| 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(DevToolsDeviceDiscovery); |
| 145 }; |
| 146 |
| 147 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_DEVICE_DISCOVERY_H_ |
| OLD | NEW |