| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "chrome/browser/devtools/device/android_device_manager.h" | 17 #include "chrome/browser/devtools/device/android_device_manager.h" |
| 18 #include "chrome/browser/devtools/device/devtools_device_discovery.h" |
| 18 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 19 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
| 19 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 20 #include "components/prefs/pref_change_registrar.h" | 21 #include "components/prefs/pref_change_registrar.h" |
| 21 #include "content/public/browser/devtools_agent_host.h" | 22 #include "content/public/browser/devtools_agent_host.h" |
| 22 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
| 23 | 24 |
| 24 namespace base { | 25 namespace base { |
| 25 template<typename T> struct DefaultSingletonTraits; | 26 template<typename T> struct DefaultSingletonTraits; |
| 26 | 27 |
| 27 class MessageLoop; | 28 class MessageLoop; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 53 | 54 |
| 54 Factory(); | 55 Factory(); |
| 55 ~Factory() override; | 56 ~Factory() override; |
| 56 | 57 |
| 57 // BrowserContextKeyedServiceFactory overrides: | 58 // BrowserContextKeyedServiceFactory overrides: |
| 58 KeyedService* BuildServiceInstanceFor( | 59 KeyedService* BuildServiceInstanceFor( |
| 59 content::BrowserContext* context) const override; | 60 content::BrowserContext* context) const override; |
| 60 DISALLOW_COPY_AND_ASSIGN(Factory); | 61 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 class RemotePage : public base::RefCounted<RemotePage> { | 64 using RemotePage = DevToolsDeviceDiscovery::RemotePage; |
| 64 public: | 65 using RemotePages = DevToolsDeviceDiscovery::RemotePages; |
| 65 scoped_refptr<AndroidDeviceManager::Device> device() { return device_; } | 66 using RemoteBrowser = DevToolsDeviceDiscovery::RemoteBrowser; |
| 66 const std::string& socket() { return browser_id_; } | 67 using RemoteBrowsers = DevToolsDeviceDiscovery::RemoteBrowsers; |
| 67 const std::string& frontend_url() { return frontend_url_; } | 68 using RemoteDevice = DevToolsDeviceDiscovery::RemoteDevice; |
| 68 scoped_refptr<content::DevToolsAgentHost> CreateTarget(); | 69 using RemoteDevices = DevToolsDeviceDiscovery::RemoteDevices; |
| 70 using CompleteDevice = DevToolsDeviceDiscovery::CompleteDevice; |
| 71 using CompleteDevices = DevToolsDeviceDiscovery::CompleteDevices; |
| 72 using DeviceListCallback = DevToolsDeviceDiscovery::DeviceListCallback; |
| 69 | 73 |
| 70 private: | |
| 71 friend class base::RefCounted<RemotePage>; | |
| 72 friend class DevToolsAndroidBridge; | |
| 73 | |
| 74 RemotePage(scoped_refptr<AndroidDeviceManager::Device> device, | |
| 75 const std::string& browser_id, | |
| 76 const base::DictionaryValue& dict); | |
| 77 | |
| 78 virtual ~RemotePage(); | |
| 79 | |
| 80 scoped_refptr<AndroidDeviceManager::Device> device_; | |
| 81 std::string browser_id_; | |
| 82 std::string frontend_url_; | |
| 83 std::unique_ptr<base::DictionaryValue> dict_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(RemotePage); | |
| 86 }; | |
| 87 | |
| 88 using RemotePages = std::vector<scoped_refptr<RemotePage> >; | |
| 89 using JsonRequestCallback = base::Callback<void(int, const std::string&)>; | 74 using JsonRequestCallback = base::Callback<void(int, const std::string&)>; |
| 90 | 75 |
| 91 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { | |
| 92 public: | |
| 93 const std::string& serial() { return serial_; } | |
| 94 const std::string& socket() { return browser_id_; } | |
| 95 const std::string& display_name() { return display_name_; } | |
| 96 const std::string& user() { return user_; } | |
| 97 const std::string& version() { return version_; } | |
| 98 const RemotePages& pages() { return pages_; } | |
| 99 | |
| 100 bool IsChrome(); | |
| 101 std::string GetId(); | |
| 102 | |
| 103 using ParsedVersion = std::vector<int>; | |
| 104 ParsedVersion GetParsedVersion(); | |
| 105 | |
| 106 private: | |
| 107 friend class base::RefCounted<RemoteBrowser>; | |
| 108 friend class DevToolsAndroidBridge; | |
| 109 | |
| 110 RemoteBrowser(const std::string& serial, | |
| 111 const AndroidDeviceManager::BrowserInfo& browser_info); | |
| 112 | |
| 113 virtual ~RemoteBrowser(); | |
| 114 | |
| 115 std::string serial_; | |
| 116 std::string browser_id_; | |
| 117 std::string display_name_; | |
| 118 std::string user_; | |
| 119 AndroidDeviceManager::BrowserInfo::Type type_; | |
| 120 std::string version_; | |
| 121 RemotePages pages_; | |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); | |
| 124 }; | |
| 125 | |
| 126 using RemoteBrowsers = std::vector<scoped_refptr<RemoteBrowser> >; | |
| 127 | |
| 128 class RemoteDevice : public base::RefCounted<RemoteDevice> { | |
| 129 public: | |
| 130 std::string serial() { return serial_; } | |
| 131 std::string model() { return model_; } | |
| 132 bool is_connected() { return connected_; } | |
| 133 RemoteBrowsers& browsers() { return browsers_; } | |
| 134 gfx::Size screen_size() { return screen_size_; } | |
| 135 | |
| 136 private: | |
| 137 friend class base::RefCounted<RemoteDevice>; | |
| 138 friend class DevToolsAndroidBridge; | |
| 139 | |
| 140 RemoteDevice(const std::string& serial, | |
| 141 const AndroidDeviceManager::DeviceInfo& device_info); | |
| 142 | |
| 143 virtual ~RemoteDevice(); | |
| 144 | |
| 145 std::string serial_; | |
| 146 std::string model_; | |
| 147 bool connected_; | |
| 148 RemoteBrowsers browsers_; | |
| 149 gfx::Size screen_size_; | |
| 150 | |
| 151 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); | |
| 152 }; | |
| 153 | |
| 154 using RemoteDevices = std::vector<scoped_refptr<RemoteDevice> >; | |
| 155 | |
| 156 class DeviceListListener { | 76 class DeviceListListener { |
| 157 public: | 77 public: |
| 158 virtual void DeviceListChanged(const RemoteDevices& devices) = 0; | 78 virtual void DeviceListChanged(const RemoteDevices& devices) = 0; |
| 159 protected: | 79 protected: |
| 160 virtual ~DeviceListListener() {} | 80 virtual ~DeviceListListener() {} |
| 161 }; | 81 }; |
| 162 | 82 |
| 163 explicit DevToolsAndroidBridge(Profile* profile); | 83 explicit DevToolsAndroidBridge(Profile* profile); |
| 164 void AddDeviceListListener(DeviceListListener* listener); | 84 void AddDeviceListListener(DeviceListListener* listener); |
| 165 void RemoveDeviceListListener(DeviceListListener* listener); | 85 void RemoveDeviceListListener(DeviceListListener* listener); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 183 public: | 103 public: |
| 184 using PortStatusMap = DevToolsAndroidBridge::PortStatusMap; | 104 using PortStatusMap = DevToolsAndroidBridge::PortStatusMap; |
| 185 using BrowserStatus = DevToolsAndroidBridge::BrowserStatus; | 105 using BrowserStatus = DevToolsAndroidBridge::BrowserStatus; |
| 186 using ForwardingStatus = DevToolsAndroidBridge::ForwardingStatus; | 106 using ForwardingStatus = DevToolsAndroidBridge::ForwardingStatus; |
| 187 | 107 |
| 188 virtual void PortStatusChanged(const ForwardingStatus&) = 0; | 108 virtual void PortStatusChanged(const ForwardingStatus&) = 0; |
| 189 protected: | 109 protected: |
| 190 virtual ~PortForwardingListener() {} | 110 virtual ~PortForwardingListener() {} |
| 191 }; | 111 }; |
| 192 | 112 |
| 193 using CompleteDevice = std::pair<scoped_refptr<AndroidDeviceManager::Device>, | |
| 194 scoped_refptr<RemoteDevice>>; | |
| 195 using CompleteDevices = std::vector<CompleteDevice>; | |
| 196 using DeviceListCallback = base::Callback<void(const CompleteDevices&)>; | |
| 197 | |
| 198 static void QueryCompleteDevices( | |
| 199 AndroidDeviceManager* device_manager, | |
| 200 const DeviceListCallback& callback); | |
| 201 | |
| 202 void AddPortForwardingListener(PortForwardingListener* listener); | 113 void AddPortForwardingListener(PortForwardingListener* listener); |
| 203 void RemovePortForwardingListener(PortForwardingListener* listener); | 114 void RemovePortForwardingListener(PortForwardingListener* listener); |
| 204 | 115 |
| 205 void set_device_providers_for_test( | 116 void set_device_providers_for_test( |
| 206 const AndroidDeviceManager::DeviceProviders& device_providers) { | 117 const AndroidDeviceManager::DeviceProviders& device_providers) { |
| 207 device_manager_->SetDeviceProviders(device_providers); | 118 device_manager_->SetDeviceProviders(device_providers); |
| 208 } | 119 } |
| 209 | 120 |
| 210 void set_task_scheduler_for_test( | 121 void set_task_scheduler_for_test( |
| 211 base::Callback<void(const base::Closure&)> scheduler) { | 122 base::Callback<void(const base::Closure&)> scheduler) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 225 | 136 |
| 226 using TCPProviderCallback = | 137 using TCPProviderCallback = |
| 227 base::Callback<void(scoped_refptr<TCPDeviceProvider>)>; | 138 base::Callback<void(scoped_refptr<TCPDeviceProvider>)>; |
| 228 void set_tcp_provider_callback_for_test(TCPProviderCallback callback); | 139 void set_tcp_provider_callback_for_test(TCPProviderCallback callback); |
| 229 | 140 |
| 230 private: | 141 private: |
| 231 friend struct content::BrowserThread::DeleteOnThread< | 142 friend struct content::BrowserThread::DeleteOnThread< |
| 232 content::BrowserThread::UI>; | 143 content::BrowserThread::UI>; |
| 233 friend class base::DeleteHelper<DevToolsAndroidBridge>; | 144 friend class base::DeleteHelper<DevToolsAndroidBridge>; |
| 234 | 145 |
| 235 class AgentHostDelegate; | |
| 236 class DiscoveryRequest; | |
| 237 class RemotePageTarget; | |
| 238 | |
| 239 ~DevToolsAndroidBridge() override; | 146 ~DevToolsAndroidBridge() override; |
| 240 | 147 |
| 241 void StartDeviceListPolling(); | 148 void StartDeviceListPolling(); |
| 242 void StopDeviceListPolling(); | 149 void StopDeviceListPolling(); |
| 243 bool NeedsDeviceListPolling(); | 150 bool NeedsDeviceListPolling(); |
| 244 | 151 |
| 245 void RequestDeviceList(const DeviceListCallback& callback); | 152 void RequestDeviceList(const DeviceListCallback& callback); |
| 246 void ReceivedDeviceList(const CompleteDevices& complete_devices); | 153 void ReceivedDeviceList(const CompleteDevices& complete_devices); |
| 247 | 154 |
| 248 void StartDeviceCountPolling(); | 155 void StartDeviceCountPolling(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 260 | 167 |
| 261 Profile* const profile_; | 168 Profile* const profile_; |
| 262 const std::unique_ptr<AndroidDeviceManager> device_manager_; | 169 const std::unique_ptr<AndroidDeviceManager> device_manager_; |
| 263 | 170 |
| 264 using DeviceMap = | 171 using DeviceMap = |
| 265 std::map<std::string, scoped_refptr<AndroidDeviceManager::Device> >; | 172 std::map<std::string, scoped_refptr<AndroidDeviceManager::Device> >; |
| 266 DeviceMap device_map_; | 173 DeviceMap device_map_; |
| 267 | 174 |
| 268 using DeviceListListeners = std::vector<DeviceListListener*>; | 175 using DeviceListListeners = std::vector<DeviceListListener*>; |
| 269 DeviceListListeners device_list_listeners_; | 176 DeviceListListeners device_list_listeners_; |
| 270 base::CancelableCallback<void(const CompleteDevices&)> device_list_callback_; | |
| 271 | 177 |
| 272 using DeviceCountListeners = std::vector<DeviceCountListener*>; | 178 using DeviceCountListeners = std::vector<DeviceCountListener*>; |
| 273 DeviceCountListeners device_count_listeners_; | 179 DeviceCountListeners device_count_listeners_; |
| 274 base::CancelableCallback<void(int)> device_count_callback_; | 180 base::CancelableCallback<void(int)> device_count_callback_; |
| 275 base::Callback<void(const base::Closure&)> task_scheduler_; | 181 base::Callback<void(const base::Closure&)> task_scheduler_; |
| 276 | 182 |
| 277 using PortForwardingListeners = std::vector<PortForwardingListener*>; | 183 using PortForwardingListeners = std::vector<PortForwardingListener*>; |
| 278 PortForwardingListeners port_forwarding_listeners_; | 184 PortForwardingListeners port_forwarding_listeners_; |
| 279 std::unique_ptr<PortForwardingController> port_forwarding_controller_; | 185 std::unique_ptr<PortForwardingController> port_forwarding_controller_; |
| 280 | 186 |
| 281 PrefChangeRegistrar pref_change_registrar_; | 187 PrefChangeRegistrar pref_change_registrar_; |
| 282 | 188 |
| 283 TCPProviderCallback tcp_provider_callback_; | 189 TCPProviderCallback tcp_provider_callback_; |
| 284 | 190 |
| 191 std::unique_ptr<DevToolsDeviceDiscovery> device_discovery_; |
| 192 |
| 285 base::WeakPtrFactory<DevToolsAndroidBridge> weak_factory_; | 193 base::WeakPtrFactory<DevToolsAndroidBridge> weak_factory_; |
| 286 | 194 |
| 287 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); | 195 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); |
| 288 }; | 196 }; |
| 289 | 197 |
| 290 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 198 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
| OLD | NEW |