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