| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 Factory(); | 66 Factory(); |
| 67 virtual ~Factory(); | 67 virtual ~Factory(); |
| 68 | 68 |
| 69 // BrowserContextKeyedServiceFactory overrides: | 69 // BrowserContextKeyedServiceFactory overrides: |
| 70 virtual KeyedService* BuildServiceInstanceFor( | 70 virtual KeyedService* BuildServiceInstanceFor( |
| 71 content::BrowserContext* context) const OVERRIDE; | 71 content::BrowserContext* context) const OVERRIDE; |
| 72 DISALLOW_COPY_AND_ASSIGN(Factory); | 72 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class AndroidWebSocket : public base::RefCountedThreadSafe<AndroidWebSocket> { | |
| 76 public: | |
| 77 class Delegate { | |
| 78 public: | |
| 79 virtual void OnSocketOpened() = 0; | |
| 80 virtual void OnFrameRead(const std::string& message) = 0; | |
| 81 virtual void OnSocketClosed(bool closed_by_device) = 0; | |
| 82 | |
| 83 protected: | |
| 84 virtual ~Delegate() {} | |
| 85 }; | |
| 86 | |
| 87 AndroidWebSocket() {} | |
| 88 | |
| 89 virtual void Connect() = 0; | |
| 90 virtual void Disconnect() = 0; | |
| 91 virtual void SendFrame(const std::string& message) = 0; | |
| 92 virtual void ClearDelegate() = 0; | |
| 93 | |
| 94 protected: | |
| 95 virtual ~AndroidWebSocket() {} | |
| 96 | |
| 97 private: | |
| 98 friend class base::RefCountedThreadSafe<AndroidWebSocket>; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(AndroidWebSocket); | |
| 101 }; | |
| 102 | |
| 103 class RemotePage { | 75 class RemotePage { |
| 104 public: | 76 public: |
| 105 virtual ~RemotePage() {} | 77 virtual ~RemotePage() {} |
| 106 virtual DevToolsTargetImpl* GetTarget() = 0; | 78 virtual DevToolsTargetImpl* GetTarget() = 0; |
| 107 virtual std::string GetFrontendURL() = 0; | 79 virtual std::string GetFrontendURL() = 0; |
| 108 }; | 80 }; |
| 109 | 81 |
| 110 typedef base::Callback<void(RemotePage*)> RemotePageCallback; | 82 typedef base::Callback<void(RemotePage*)> RemotePageCallback; |
| 83 typedef base::Callback<void(int, const std::string&)> JsonRequestCallback; |
| 84 typedef AndroidDeviceManager::Device Device; |
| 85 typedef AndroidDeviceManager::AndroidWebSocket AndroidWebSocket; |
| 111 | 86 |
| 112 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { | 87 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { |
| 113 public: | 88 public: |
| 114 RemoteBrowser( | 89 RemoteBrowser(scoped_refptr<Device> device, |
| 115 scoped_refptr<DevToolsAndroidBridge> android_bridge, | 90 const AndroidDeviceManager::BrowserInfo& browser_info); |
| 116 const std::string& serial, | |
| 117 const AndroidDeviceManager::BrowserInfo& browser_info); | |
| 118 | 91 |
| 119 std::string serial() { return serial_; } | 92 std::string serial() { return device_->serial(); } |
| 120 std::string socket() { return socket_; } | 93 std::string socket() { return socket_; } |
| 121 | 94 |
| 122 std::string display_name() { return display_name_; } | 95 std::string display_name() { return display_name_; } |
| 123 void set_display_name(const std::string& name) { display_name_ = name; } | 96 void set_display_name(const std::string& name) { display_name_ = name; } |
| 124 | 97 |
| 125 std::string version() { return version_; } | 98 std::string version() { return version_; } |
| 126 void set_version(const std::string& version) { version_ = version; } | 99 void set_version(const std::string& version) { version_ = version; } |
| 127 | 100 |
| 128 bool IsChrome() const; | 101 bool IsChrome() const; |
| 129 bool IsWebView() const; | 102 bool IsWebView() const; |
| 130 | 103 |
| 131 typedef std::vector<int> ParsedVersion; | 104 typedef std::vector<int> ParsedVersion; |
| 132 ParsedVersion GetParsedVersion() const; | 105 ParsedVersion GetParsedVersion() const; |
| 133 | 106 |
| 134 std::vector<RemotePage*> CreatePages(); | 107 std::vector<RemotePage*> CreatePages(); |
| 135 void SetPageDescriptors(const base::ListValue&); | 108 void SetPageDescriptors(const base::ListValue&); |
| 136 | 109 |
| 137 typedef base::Callback<void(int, const std::string&)> JsonRequestCallback; | |
| 138 void SendJsonRequest(const std::string& request, | 110 void SendJsonRequest(const std::string& request, |
| 139 const JsonRequestCallback& callback); | 111 const JsonRequestCallback& callback); |
| 112 |
| 140 void SendProtocolCommand(const std::string& debug_url, | 113 void SendProtocolCommand(const std::string& debug_url, |
| 141 const std::string& method, | 114 const std::string& method, |
| 142 base::DictionaryValue* params, | 115 base::DictionaryValue* params, |
| 143 const base::Closure callback); | 116 const base::Closure callback); |
| 144 | 117 |
| 145 void Open(const std::string& url, | 118 void Open(const std::string& url, |
| 146 const RemotePageCallback& callback); | 119 const RemotePageCallback& callback); |
| 147 | 120 |
| 148 scoped_refptr<content::DevToolsAgentHost> GetAgentHost(); | 121 scoped_refptr<content::DevToolsAgentHost> GetAgentHost(); |
| 149 | 122 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 165 void NavigatePageOnUIThread(const JsonRequestCallback& callback, | 138 void NavigatePageOnUIThread(const JsonRequestCallback& callback, |
| 166 int result, | 139 int result, |
| 167 const std::string& response, | 140 const std::string& response, |
| 168 const std::string& url); | 141 const std::string& url); |
| 169 | 142 |
| 170 void RespondToOpenOnUIThread( | 143 void RespondToOpenOnUIThread( |
| 171 const DevToolsAndroidBridge::RemotePageCallback& callback, | 144 const DevToolsAndroidBridge::RemotePageCallback& callback, |
| 172 int result, | 145 int result, |
| 173 const std::string& response); | 146 const std::string& response); |
| 174 | 147 |
| 175 scoped_refptr<DevToolsAndroidBridge> android_bridge_; | 148 scoped_refptr<Device> device_; |
| 176 const std::string serial_; | |
| 177 const std::string socket_; | 149 const std::string socket_; |
| 178 std::string display_name_; | 150 std::string display_name_; |
| 179 const AndroidDeviceManager::BrowserInfo::Type type_; | 151 const AndroidDeviceManager::BrowserInfo::Type type_; |
| 180 std::string version_; | 152 std::string version_; |
| 181 scoped_ptr<base::ListValue> page_descriptors_; | 153 scoped_ptr<base::ListValue> page_descriptors_; |
| 182 | 154 |
| 183 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); | 155 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); |
| 184 }; | 156 }; |
| 185 | 157 |
| 186 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; | 158 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; |
| 187 | 159 |
| 188 class RemoteDevice : public base::RefCounted<RemoteDevice> { | 160 class RemoteDevice : public base::RefCounted<RemoteDevice> { |
| 189 public: | 161 public: |
| 190 RemoteDevice(scoped_refptr<DevToolsAndroidBridge> android_bridge, | 162 RemoteDevice(scoped_refptr<Device> device, |
| 191 const std::string& serial, | 163 const AndroidDeviceManager::DeviceInfo& device_info); |
| 192 const AndroidDeviceManager::DeviceInfo& device_info, | |
| 193 bool connected); | |
| 194 | 164 |
| 195 std::string serial() { return serial_; } | 165 std::string serial() { return device_->serial(); } |
| 196 std::string model() { return model_; } | 166 std::string model() { return model_; } |
| 197 bool is_connected() { return connected_; } | 167 bool is_connected() { return connected_; } |
| 198 RemoteBrowsers& browsers() { return browsers_; } | 168 RemoteBrowsers& browsers() { return browsers_; } |
| 199 gfx::Size screen_size() { return screen_size_; } | 169 gfx::Size screen_size() { return screen_size_; } |
| 200 | 170 |
| 201 void OpenSocket(const std::string& socket_name, | 171 void OpenSocket(const std::string& socket_name, |
| 202 const AndroidDeviceManager::SocketCallback& callback); | 172 const AndroidDeviceManager::SocketCallback& callback); |
| 203 | 173 |
| 204 private: | 174 private: |
| 205 friend class base::RefCounted<RemoteDevice>; | 175 friend class base::RefCounted<RemoteDevice>; |
| 206 virtual ~RemoteDevice(); | 176 virtual ~RemoteDevice(); |
| 207 | 177 |
| 208 scoped_refptr<DevToolsAndroidBridge> android_bridge_; | 178 scoped_refptr<Device> device_; |
| 209 std::string serial_; | |
| 210 std::string model_; | 179 std::string model_; |
| 211 bool connected_; | 180 bool connected_; |
| 212 RemoteBrowsers browsers_; | 181 RemoteBrowsers browsers_; |
| 213 gfx::Size screen_size_; | 182 gfx::Size screen_size_; |
| 214 | 183 |
| 215 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); | 184 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); |
| 216 }; | 185 }; |
| 217 | 186 |
| 218 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; | 187 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; |
| 219 | 188 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 233 virtual void DeviceCountChanged(int count) = 0; | 202 virtual void DeviceCountChanged(int count) = 0; |
| 234 protected: | 203 protected: |
| 235 virtual ~DeviceCountListener() {} | 204 virtual ~DeviceCountListener() {} |
| 236 }; | 205 }; |
| 237 | 206 |
| 238 void AddDeviceCountListener(DeviceCountListener* listener); | 207 void AddDeviceCountListener(DeviceCountListener* listener); |
| 239 void RemoveDeviceCountListener(DeviceCountListener* listener); | 208 void RemoveDeviceCountListener(DeviceCountListener* listener); |
| 240 | 209 |
| 241 void set_device_providers_for_test( | 210 void set_device_providers_for_test( |
| 242 const AndroidDeviceManager::DeviceProviders& device_providers) { | 211 const AndroidDeviceManager::DeviceProviders& device_providers) { |
| 243 device_providers_ = device_providers; | 212 device_manager_->SetDeviceProviders(device_providers); |
| 244 } | 213 } |
| 245 | 214 |
| 246 static bool HasDevToolsWindow(const std::string& agent_id); | 215 static bool HasDevToolsWindow(const std::string& agent_id); |
| 247 | 216 |
| 248 private: | 217 private: |
| 249 friend struct content::BrowserThread::DeleteOnThread< | 218 friend struct content::BrowserThread::DeleteOnThread< |
| 250 content::BrowserThread::UI>; | 219 content::BrowserThread::UI>; |
| 251 friend class base::DeleteHelper<DevToolsAndroidBridge>; | 220 friend class base::DeleteHelper<DevToolsAndroidBridge>; |
| 252 | 221 |
| 253 class HandlerThread : public base::RefCountedThreadSafe<HandlerThread> { | |
| 254 public: | |
| 255 static scoped_refptr<HandlerThread> GetInstance(); | |
| 256 base::MessageLoop* message_loop(); | |
| 257 | |
| 258 private: | |
| 259 friend class base::RefCountedThreadSafe<HandlerThread>; | |
| 260 static HandlerThread* instance_; | |
| 261 static void StopThread(base::Thread* thread); | |
| 262 | |
| 263 HandlerThread(); | |
| 264 virtual ~HandlerThread(); | |
| 265 base::Thread* thread_; | |
| 266 }; | |
| 267 | |
| 268 virtual ~DevToolsAndroidBridge(); | 222 virtual ~DevToolsAndroidBridge(); |
| 269 | 223 |
| 270 base::MessageLoop* device_message_loop() { | |
| 271 return handler_thread_->message_loop(); | |
| 272 } | |
| 273 | |
| 274 AndroidDeviceManager* device_manager() { | |
| 275 return device_manager_.get(); | |
| 276 } | |
| 277 | |
| 278 void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager); | |
| 279 void RequestDeviceList(); | 224 void RequestDeviceList(); |
| 280 void ReceivedDeviceList(RemoteDevices* devices); | 225 void ReceivedDeviceList(scoped_ptr<RemoteDevices> devices); |
| 281 | |
| 282 void RequestDeviceCount(); | 226 void RequestDeviceCount(); |
| 283 void ReceivedDeviceCount(int count); | 227 void ReceivedDeviceCount(int count); |
| 284 | 228 |
| 285 void CreateDeviceProviders(); | 229 void CreateDeviceProviders(); |
| 286 | 230 |
| 287 Profile* profile_; | 231 Profile* profile_; |
| 288 scoped_refptr<HandlerThread> handler_thread_; | |
| 289 scoped_refptr<AndroidDeviceManager> device_manager_; | 232 scoped_refptr<AndroidDeviceManager> device_manager_; |
| 233 RemoteDevices devices_; |
| 290 | 234 |
| 291 typedef std::vector<DeviceListListener*> DeviceListListeners; | 235 typedef std::vector<DeviceListListener*> DeviceListListeners; |
| 292 DeviceListListeners device_list_listeners_; | 236 DeviceListListeners device_list_listeners_; |
| 293 | 237 |
| 294 typedef std::vector<DeviceCountListener*> DeviceCountListeners; | 238 typedef std::vector<DeviceCountListener*> DeviceCountListeners; |
| 295 DeviceCountListeners device_count_listeners_; | 239 DeviceCountListeners device_count_listeners_; |
| 296 | 240 |
| 297 AndroidDeviceManager::DeviceProviders device_providers_; | |
| 298 PrefChangeRegistrar pref_change_registrar_; | 241 PrefChangeRegistrar pref_change_registrar_; |
| 299 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); | 242 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); |
| 300 }; | 243 }; |
| 301 | 244 |
| 302 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ | 245 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ |
| OLD | NEW |