Chromium Code Reviews| 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 RemoteBrowser(const std::string& serial, |
|
dgozman
2014/09/25 14:23:17
Can we make constructor private?
vkuzkokov
2014/09/25 16:48:47
Done.
| |
| 92 const AndroidDeviceManager::BrowserInfo& browser_info); | 86 const AndroidDeviceManager::BrowserInfo& browser_info); |
| 93 | 87 |
| 94 std::string serial() { return device_->serial(); } | 88 const std::string& serial() { return serial_; } |
| 95 std::string socket() { return socket_; } | 89 const std::string& socket() { return socket_; } |
| 96 | 90 |
| 97 std::string display_name() { return display_name_; } | 91 const std::string& display_name() { return display_name_; } |
| 98 void set_display_name(const std::string& name) { display_name_ = name; } | 92 void set_display_name(const std::string& name) { display_name_ = name; } |
| 99 | 93 |
| 100 std::string version() { return version_; } | 94 const std::string& version() { return version_; } |
| 101 void set_version(const std::string& version) { version_ = version; } | 95 void set_version(const std::string& version) { version_ = version; } |
| 102 | 96 |
| 103 bool IsChrome() const; | 97 bool IsChrome(); |
| 104 bool IsWebView() const; | 98 bool IsWebView(); |
| 105 | 99 |
| 106 typedef std::vector<int> ParsedVersion; | 100 typedef std::vector<int> ParsedVersion; |
| 107 ParsedVersion GetParsedVersion() const; | 101 ParsedVersion GetParsedVersion(); |
| 108 | 102 |
| 109 std::vector<RemotePage*> CreatePages(); | 103 const base::ListValue& page_descriptors(); |
| 110 void SetPageDescriptors(const base::ListValue&); | 104 void set_page_descriptors(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 | 105 |
| 129 private: | 106 private: |
| 130 friend class base::RefCounted<RemoteBrowser>; | 107 friend class base::RefCounted<RemoteBrowser>; |
| 131 virtual ~RemoteBrowser(); | 108 virtual ~RemoteBrowser(); |
| 132 | 109 |
| 133 void InnerOpen(const std::string& url, | 110 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_; | 111 const std::string socket_; |
| 152 std::string display_name_; | 112 std::string display_name_; |
| 153 const AndroidDeviceManager::BrowserInfo::Type type_; | 113 const AndroidDeviceManager::BrowserInfo::Type type_; |
| 154 std::string version_; | 114 std::string version_; |
| 155 scoped_ptr<base::ListValue> page_descriptors_; | 115 scoped_ptr<base::ListValue> page_descriptors_; |
| 156 | 116 |
| 157 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); | 117 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); |
| 158 }; | 118 }; |
| 159 | 119 |
| 160 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; | 120 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; |
| 161 | 121 |
| 162 class RemoteDevice : public base::RefCounted<RemoteDevice> { | 122 class RemoteDevice : public base::RefCounted<RemoteDevice> { |
| 163 public: | 123 public: |
| 164 RemoteDevice(scoped_refptr<Device> device, | 124 RemoteDevice(const std::string& serial, |
|
dgozman
2014/09/25 14:23:17
ditto
vkuzkokov
2014/09/25 16:48:47
Done.
| |
| 165 const AndroidDeviceManager::DeviceInfo& device_info); | 125 const AndroidDeviceManager::DeviceInfo& device_info); |
| 166 | 126 |
| 167 std::string serial() { return device_->serial(); } | 127 std::string serial() { return serial_; } |
| 168 std::string model() { return model_; } | 128 std::string model() { return model_; } |
| 169 bool is_connected() { return connected_; } | 129 bool is_connected() { return connected_; } |
| 170 RemoteBrowsers& browsers() { return browsers_; } | 130 RemoteBrowsers& browsers() { return browsers_; } |
| 171 gfx::Size screen_size() { return screen_size_; } | 131 gfx::Size screen_size() { return screen_size_; } |
| 172 | 132 |
| 173 void OpenSocket(const std::string& socket_name, | |
| 174 const AndroidDeviceManager::SocketCallback& callback); | |
| 175 | |
| 176 private: | 133 private: |
| 177 friend class base::RefCounted<RemoteDevice>; | 134 friend class base::RefCounted<RemoteDevice>; |
| 178 virtual ~RemoteDevice(); | 135 virtual ~RemoteDevice(); |
| 179 | 136 |
| 180 scoped_refptr<Device> device_; | 137 std::string serial_; |
| 181 std::string model_; | 138 std::string model_; |
| 182 bool connected_; | 139 bool connected_; |
| 183 RemoteBrowsers browsers_; | 140 RemoteBrowsers browsers_; |
| 184 gfx::Size screen_size_; | 141 gfx::Size screen_size_; |
| 185 | 142 |
| 186 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); | 143 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); |
| 187 }; | 144 }; |
| 188 | 145 |
| 189 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; | 146 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; |
| 190 | 147 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 device_manager_->SetDeviceProviders(device_providers); | 188 device_manager_->SetDeviceProviders(device_providers); |
| 232 } | 189 } |
| 233 | 190 |
| 234 void set_task_scheduler_for_test( | 191 void set_task_scheduler_for_test( |
| 235 base::Callback<void(const base::Closure&)> scheduler) { | 192 base::Callback<void(const base::Closure&)> scheduler) { |
| 236 task_scheduler_ = scheduler; | 193 task_scheduler_ = scheduler; |
| 237 } | 194 } |
| 238 | 195 |
| 239 static bool HasDevToolsWindow(const std::string& agent_id); | 196 static bool HasDevToolsWindow(const std::string& agent_id); |
| 240 | 197 |
| 198 std::vector<RemotePage*> CreatePages(scoped_refptr<RemoteBrowser> browser); | |
|
dgozman
2014/09/25 14:23:17
Why this is not a part of RemoteBrowser?
vkuzkokov
2014/09/25 16:48:47
RemotePage requires reference to device which is n
| |
| 199 | |
| 200 typedef base::Callback<void(RemotePage*)> RemotePageCallback; | |
| 201 void Open(scoped_refptr<RemoteBrowser> browser, | |
| 202 const std::string& url, | |
| 203 const RemotePageCallback& callback); | |
| 204 | |
| 205 scoped_refptr<content::DevToolsAgentHost> GetAgentHost( | |
|
dgozman
2014/09/25 14:23:17
GetBrowserAgentHost? Why this is not a part of Rem
vkuzkokov
2014/09/25 16:48:47
GetAgentHost requires reference to device which is
| |
| 206 scoped_refptr<RemoteBrowser> browser); | |
| 207 | |
| 241 private: | 208 private: |
| 242 friend struct content::BrowserThread::DeleteOnThread< | 209 friend struct content::BrowserThread::DeleteOnThread< |
| 243 content::BrowserThread::UI>; | 210 content::BrowserThread::UI>; |
| 244 friend class base::DeleteHelper<DevToolsAndroidBridge>; | 211 friend class base::DeleteHelper<DevToolsAndroidBridge>; |
| 245 | 212 |
| 213 friend class AgentHostDelegate; | |
|
dgozman
2014/09/25 14:23:17
Let's not make AgentHostDelegate and RemotePageTar
vkuzkokov
2014/09/25 16:48:47
Done.
| |
| 214 friend class PortForwardingController; | |
| 215 friend class RemotePageTarget; | |
| 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&, |
| 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_; | |
| 266 | 277 |
| 267 typedef std::vector<DeviceListListener*> DeviceListListeners; | 278 typedef std::vector<DeviceListListener*> DeviceListListeners; |
| 268 DeviceListListeners device_list_listeners_; | 279 DeviceListListeners device_list_listeners_; |
| 269 base::CancelableCallback<void(const RemoteDevices&)> device_list_callback_; | 280 base::CancelableCallback<void(const AndroidDeviceManager::Devices&, |
| 281 const RemoteDevices&)> device_list_callback_; | |
| 270 | 282 |
| 271 typedef std::vector<DeviceCountListener*> DeviceCountListeners; | 283 typedef std::vector<DeviceCountListener*> DeviceCountListeners; |
| 272 DeviceCountListeners device_count_listeners_; | 284 DeviceCountListeners device_count_listeners_; |
| 273 base::CancelableCallback<void(int)> device_count_callback_; | 285 base::CancelableCallback<void(int)> device_count_callback_; |
| 274 base::Callback<void(const base::Closure&)> task_scheduler_; | 286 base::Callback<void(const base::Closure&)> task_scheduler_; |
| 275 | 287 |
| 276 typedef std::vector<PortForwardingListener*> PortForwardingListeners; | 288 typedef std::vector<PortForwardingListener*> PortForwardingListeners; |
| 277 PortForwardingListeners port_forwarding_listeners_; | 289 PortForwardingListeners port_forwarding_listeners_; |
| 278 scoped_ptr<PortForwardingController> port_forwarding_controller_; | 290 scoped_ptr<PortForwardingController> port_forwarding_controller_; |
| 279 | 291 |
| 280 PrefChangeRegistrar pref_change_registrar_; | 292 PrefChangeRegistrar pref_change_registrar_; |
| 281 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); | 293 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); |
| 282 }; | 294 }; |
| 283 | 295 |
| 284 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 296 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
| OLD | NEW |