Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_DEVTOOLS_ADB_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
| 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/devtools/adb/android_usb_device.h" | 14 #include "chrome/browser/devtools/adb/android_usb_device.h" |
|
Vladislav Kaznacheev
2013/10/17 20:17:37
Is this header still required?
Dmitry Zvorygin
2013/10/21 07:40:29
Done.
| |
| 15 #include "chrome/browser/devtools/devtools_device_provider.h" | |
| 16 #include "chrome/browser/devtools/refcounted_adb_thread.h" | |
| 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
| 16 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" | 18 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "net/socket/tcp_client_socket.h" | 20 #include "net/socket/tcp_client_socket.h" |
| 19 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 20 | 22 |
| 21 template<typename T> struct DefaultSingletonTraits; | 23 template<typename T> struct DefaultSingletonTraits; |
| 22 | 24 |
| 23 namespace base { | 25 namespace base { |
| 24 class MessageLoop; | 26 class MessageLoop; |
| 25 class DictionaryValue; | 27 class DictionaryValue; |
| 26 class Thread; | 28 class Thread; |
| 27 } | 29 } |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| 30 class BrowserContext; | 32 class BrowserContext; |
| 31 } | 33 } |
| 32 | 34 |
| 33 namespace crypto { | 35 namespace crypto { |
| 34 class RSAPrivateKey; | 36 class RSAPrivateKey; |
| 35 } | 37 } |
| 36 | 38 |
| 37 class Profile; | 39 class Profile; |
| 38 | 40 |
| 39 // The format used for constructing DevTools server socket names. | 41 // The format used for constructing DevTools server socket names. |
| 40 extern const char kDevToolsChannelNameFormat[]; | 42 extern const char kDevToolsChannelNameFormat[]; |
| 41 | 43 |
| 42 typedef base::Callback<void(int, const std::string&)> CommandCallback; | |
| 43 typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback; | |
| 44 | |
| 45 class DevToolsAdbBridge | 44 class DevToolsAdbBridge |
| 46 : public base::RefCountedThreadSafe< | 45 : public base::RefCountedThreadSafe< |
| 47 DevToolsAdbBridge, | 46 DevToolsAdbBridge, |
| 48 content::BrowserThread::DeleteOnUIThread> { | 47 content::BrowserThread::DeleteOnUIThread> { |
| 49 public: | 48 public: |
| 49 typedef std::vector<scoped_refptr<DevToolsDeviceProvider> > DeviceProviders; | |
| 50 typedef base::Callback<void(int result, | 50 typedef base::Callback<void(int result, |
| 51 const std::string& response)> Callback; | 51 const std::string& response)> Callback; |
| 52 | 52 |
| 53 class Wrapper : public BrowserContextKeyedService { | 53 class Wrapper : public BrowserContextKeyedService { |
| 54 public: | 54 public: |
| 55 explicit Wrapper(Profile* profile); | 55 explicit Wrapper(Profile* profile); |
| 56 virtual ~Wrapper(); | 56 virtual ~Wrapper(); |
| 57 | 57 |
| 58 DevToolsAdbBridge* Get(); | 58 DevToolsAdbBridge* Get(); |
| 59 private: | 59 private: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 73 | 73 |
| 74 Factory(); | 74 Factory(); |
| 75 virtual ~Factory(); | 75 virtual ~Factory(); |
| 76 | 76 |
| 77 // BrowserContextKeyedServiceFactory overrides: | 77 // BrowserContextKeyedServiceFactory overrides: |
| 78 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 78 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
| 79 content::BrowserContext* context) const OVERRIDE; | 79 content::BrowserContext* context) const OVERRIDE; |
| 80 DISALLOW_COPY_AND_ASSIGN(Factory); | 80 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 class AndroidDevice; | 83 class RemotePage : public base::RefCounted<RemotePage> { |
| 84 class RefCountedAdbThread; | |
| 85 | |
| 86 class RemotePage : public base::RefCounted<RemotePage> { | |
| 87 public: | 84 public: |
| 88 RemotePage(scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 85 RemotePage(scoped_refptr<RefCountedAdbThread> adb_thread, |
| 89 scoped_refptr<AndroidDevice> device, | 86 scoped_refptr<AndroidDevice> device, |
| 90 const std::string& socket, | 87 const std::string& socket, |
| 91 const base::DictionaryValue& value); | 88 const base::DictionaryValue& value); |
| 92 | 89 |
| 93 std::string id() { return id_; } | 90 std::string id() { return id_; } |
| 94 std::string url() { return url_; } | 91 std::string url() { return url_; } |
| 95 std::string title() { return title_; } | 92 std::string title() { return title_; } |
| 96 std::string description() { return description_; } | 93 std::string description() { return description_; } |
| 97 std::string favicon_url() { return favicon_url_; } | 94 std::string favicon_url() { return favicon_url_; } |
| 98 bool attached() { return debug_url_.empty(); } | 95 bool attached() { return debug_url_.empty(); } |
| 99 | 96 |
| 100 bool HasDevToolsWindow(); | 97 bool HasDevToolsWindow(); |
| 101 | 98 |
| 102 void Inspect(Profile* profile); | 99 void Inspect(Profile* profile); |
| 103 void Activate(); | 100 void Activate(); |
| 104 void Close(); | 101 void Close(); |
| 105 void Reload(); | 102 void Reload(); |
| 106 | 103 |
| 107 void SendProtocolCommand(const std::string& method, | 104 void SendProtocolCommand(const std::string& method, |
| 108 base::DictionaryValue* params); | 105 base::DictionaryValue* params); |
| 109 | 106 |
| 110 private: | 107 private: |
| 111 friend class base::RefCounted<RemotePage>; | 108 friend class base::RefCounted<RemotePage>; |
| 112 virtual ~RemotePage(); | 109 virtual ~RemotePage(); |
| 113 | 110 |
| 114 void RequestActivate(const CommandCallback& callback); | 111 void RequestActivate(const AndroidDevice::CommandCallback& callback); |
| 115 | 112 |
| 116 void InspectOnHandlerThread( | 113 void InspectOnHandlerThread( |
| 117 Profile* profile, int result, const std::string& response); | 114 Profile* profile, int result, const std::string& response); |
| 118 | 115 |
| 119 void InspectOnUIThread(Profile* profile); | 116 void InspectOnUIThread(Profile* profile); |
| 120 | 117 |
| 121 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread_; | 118 scoped_refptr<RefCountedAdbThread> adb_thread_; |
| 122 scoped_refptr<AndroidDevice> device_; | 119 scoped_refptr<AndroidDevice> device_; |
| 123 std::string socket_; | 120 std::string socket_; |
| 124 std::string id_; | 121 std::string id_; |
| 125 std::string url_; | 122 std::string url_; |
| 126 std::string title_; | 123 std::string title_; |
| 127 std::string description_; | 124 std::string description_; |
| 128 std::string favicon_url_; | 125 std::string favicon_url_; |
| 129 std::string debug_url_; | 126 std::string debug_url_; |
| 130 std::string frontend_url_; | 127 std::string frontend_url_; |
| 131 std::string agent_id_; | 128 std::string agent_id_; |
| 132 DISALLOW_COPY_AND_ASSIGN(RemotePage); | 129 DISALLOW_COPY_AND_ASSIGN(RemotePage); |
| 133 }; | 130 }; |
| 134 | 131 |
| 135 typedef std::vector<scoped_refptr<RemotePage> > RemotePages; | 132 typedef std::vector<scoped_refptr<RemotePage> > RemotePages; |
| 136 | 133 |
| 137 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { | 134 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { |
| 138 public: | 135 public: |
| 139 RemoteBrowser( | 136 RemoteBrowser( |
| 140 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 137 scoped_refptr<RefCountedAdbThread> adb_thread, |
| 141 scoped_refptr<AndroidDevice> device, | 138 scoped_refptr<AndroidDevice> device, |
| 142 const std::string& socket); | 139 const std::string& socket); |
| 143 | 140 |
| 144 scoped_refptr<AndroidDevice> device() { return device_; } | 141 scoped_refptr<AndroidDevice> device() { return device_; } |
| 145 std::string socket() { return socket_; } | 142 std::string socket() { return socket_; } |
| 146 | 143 |
| 147 std::string product() { return product_; } | 144 std::string product() { return product_; } |
| 148 void set_product(const std::string& product) { product_ = product; } | 145 void set_product(const std::string& product) { product_ = product; } |
| 149 std::string version() { return version_; } | 146 std::string version() { return version_; } |
| 150 void set_version(const std::string& version) { version_ = version; } | 147 void set_version(const std::string& version) { version_ = version; } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 161 private: | 158 private: |
| 162 friend class base::RefCounted<RemoteBrowser>; | 159 friend class base::RefCounted<RemoteBrowser>; |
| 163 virtual ~RemoteBrowser(); | 160 virtual ~RemoteBrowser(); |
| 164 | 161 |
| 165 void PageCreatedOnHandlerThread( | 162 void PageCreatedOnHandlerThread( |
| 166 const std::string& url, int result, const std::string& response); | 163 const std::string& url, int result, const std::string& response); |
| 167 | 164 |
| 168 void PageCreatedOnUIThread( | 165 void PageCreatedOnUIThread( |
| 169 const std::string& response, const std::string& url); | 166 const std::string& response, const std::string& url); |
| 170 | 167 |
| 171 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread_; | 168 scoped_refptr<RefCountedAdbThread> adb_thread_; |
| 172 scoped_refptr<AndroidDevice> device_; | 169 scoped_refptr<AndroidDevice> device_; |
| 173 const std::string socket_; | 170 const std::string socket_; |
| 174 std::string product_; | 171 std::string product_; |
| 175 std::string version_; | 172 std::string version_; |
| 176 std::string pid_; | 173 std::string pid_; |
| 177 std::string package_; | 174 std::string package_; |
| 178 RemotePages pages_; | 175 RemotePages pages_; |
| 179 | 176 |
| 180 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); | 177 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); |
| 181 }; | 178 }; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 202 | 199 |
| 203 scoped_refptr<AndroidDevice> device_; | 200 scoped_refptr<AndroidDevice> device_; |
| 204 RemoteBrowsers browsers_; | 201 RemoteBrowsers browsers_; |
| 205 gfx::Size screen_size_; | 202 gfx::Size screen_size_; |
| 206 | 203 |
| 207 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); | 204 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); |
| 208 }; | 205 }; |
| 209 | 206 |
| 210 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; | 207 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; |
| 211 | 208 |
| 212 class AndroidDevice : public base::RefCounted<AndroidDevice> { | |
| 213 public: | |
| 214 explicit AndroidDevice(const std::string& serial); | |
| 215 | |
| 216 virtual void RunCommand(const std::string& command, | |
| 217 const CommandCallback& callback) = 0; | |
| 218 virtual void OpenSocket(const std::string& socket_name, | |
| 219 const SocketCallback& callback) = 0; | |
| 220 virtual bool IsConnected() = 0; | |
| 221 void HttpQuery(const std::string& la_name, | |
| 222 const std::string& request, | |
| 223 const CommandCallback& callback); | |
| 224 void HttpUpgrade(const std::string& la_name, | |
| 225 const std::string& request, | |
| 226 const SocketCallback& callback); | |
| 227 | |
| 228 std::string serial() { return serial_; } | |
| 229 | |
| 230 std::string model() { return model_; } | |
| 231 void set_model(const std::string& model) { model_ = model; } | |
| 232 | |
| 233 protected: | |
| 234 friend class base::RefCounted<AndroidDevice>; | |
| 235 virtual ~AndroidDevice(); | |
| 236 | |
| 237 private: | |
| 238 void OnHttpSocketOpened(const std::string& request, | |
| 239 const CommandCallback& callback, | |
| 240 int result, | |
| 241 net::StreamSocket* socket); | |
| 242 void OnHttpSocketOpened2(const std::string& request, | |
| 243 const SocketCallback& callback, | |
| 244 int result, | |
| 245 net::StreamSocket* socket); | |
| 246 | |
| 247 std::string serial_; | |
| 248 std::string model_; | |
| 249 | |
| 250 DISALLOW_COPY_AND_ASSIGN(AndroidDevice); | |
| 251 }; | |
| 252 | |
| 253 typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices; | 209 typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices; |
| 254 typedef base::Callback<void(const AndroidDevices&)> AndroidDevicesCallback; | 210 typedef base::Callback<void(const AndroidDevices&)> AndroidDevicesCallback; |
| 255 | 211 |
| 256 class Listener { | 212 class Listener { |
| 257 public: | 213 public: |
| 258 virtual void RemoteDevicesChanged(RemoteDevices* devices) = 0; | 214 virtual void RemoteDevicesChanged(RemoteDevices* devices) = 0; |
| 259 protected: | 215 protected: |
| 260 virtual ~Listener() {} | 216 virtual ~Listener() {} |
| 261 }; | 217 }; |
| 262 | 218 |
| 263 class RefCountedAdbThread : public base::RefCounted<RefCountedAdbThread> { | |
| 264 public: | |
| 265 static scoped_refptr<RefCountedAdbThread> GetInstance(); | |
| 266 base::MessageLoop* message_loop(); | |
| 267 | |
| 268 private: | |
| 269 friend class base::RefCounted<RefCountedAdbThread>; | |
| 270 static DevToolsAdbBridge::RefCountedAdbThread* instance_; | |
| 271 static void StopThread(base::Thread* thread); | |
| 272 | |
| 273 RefCountedAdbThread(); | |
| 274 virtual ~RefCountedAdbThread(); | |
| 275 base::Thread* thread_; | |
| 276 }; | |
| 277 | |
| 278 explicit DevToolsAdbBridge(Profile* profile); | 219 explicit DevToolsAdbBridge(Profile* profile); |
| 279 void AddListener(Listener* listener); | 220 void AddListener(Listener* listener); |
| 280 void RemoveListener(Listener* listener); | 221 void RemoveListener(Listener* listener); |
| 281 void CountDevices(const base::Callback<void(int)>& callback); | 222 void CountDevices(const base::Callback<void(int)>& callback); |
| 282 void set_discover_usb_devices(bool enabled) { | 223 void set_discover_usb_devices(bool enabled) { |
| 283 discover_usb_devices_ = enabled; | 224 discover_usb_devices_ = enabled; |
| 284 } | 225 } |
| 285 | 226 |
| 286 private: | 227 private: |
| 287 friend struct content::BrowserThread::DeleteOnThread< | 228 friend struct content::BrowserThread::DeleteOnThread< |
| 288 content::BrowserThread::UI>; | 229 content::BrowserThread::UI>; |
| 289 friend class base::DeleteHelper<DevToolsAdbBridge>; | 230 friend class base::DeleteHelper<DevToolsAdbBridge>; |
| 290 | 231 |
| 291 virtual ~DevToolsAdbBridge(); | 232 virtual ~DevToolsAdbBridge(); |
| 292 | 233 |
| 293 void RequestRemoteDevices(); | 234 void RequestRemoteDevices(); |
| 294 void ReceivedRemoteDevices(RemoteDevices* devices); | 235 void ReceivedRemoteDevices(RemoteDevices* devices); |
| 295 | 236 |
| 296 Profile* profile_; | 237 Profile* profile_; |
| 297 scoped_refptr<RefCountedAdbThread> adb_thread_; | 238 scoped_refptr<RefCountedAdbThread> adb_thread_; |
| 298 bool has_message_loop_; | 239 bool has_message_loop_; |
| 299 scoped_ptr<crypto::RSAPrivateKey> rsa_key_; | |
| 300 typedef std::vector<Listener*> Listeners; | 240 typedef std::vector<Listener*> Listeners; |
| 301 Listeners listeners_; | 241 Listeners listeners_; |
| 302 bool discover_usb_devices_; | 242 bool discover_usb_devices_; |
| 303 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); | 243 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); |
| 304 }; | 244 }; |
| 305 | 245 |
| 306 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ | 246 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
| OLD | NEW |