| 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/android_device.h" | 14 #include "chrome/browser/devtools/android_device.h" |
| 15 #include "chrome/browser/devtools/refcounted_adb_thread.h" | 15 #include "chrome/browser/devtools/refcounted_adb_thread.h" |
| 16 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 16 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
| 20 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
| 21 | 21 |
| 22 template<typename T> struct DefaultSingletonTraits; | 22 template<typename T> struct DefaultSingletonTraits; |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class MessageLoop; | 25 class MessageLoop; |
| 26 class DictionaryValue; | 26 class DictionaryValue; |
| 27 class ListValue; | |
| 28 class Thread; | 27 class Thread; |
| 29 } | 28 } |
| 30 | 29 |
| 31 namespace content { | 30 namespace content { |
| 32 class BrowserContext; | 31 class BrowserContext; |
| 33 } | 32 } |
| 34 | 33 |
| 35 namespace crypto { | 34 namespace crypto { |
| 36 class RSAPrivateKey; | 35 class RSAPrivateKey; |
| 37 } | 36 } |
| 38 | 37 |
| 39 class DevToolsTargetImpl; | |
| 40 class Profile; | 38 class Profile; |
| 41 | 39 |
| 42 // The format used for constructing DevTools server socket names. | 40 // The format used for constructing DevTools server socket names. |
| 43 extern const char kDevToolsChannelNameFormat[]; | 41 extern const char kDevToolsChannelNameFormat[]; |
| 44 | 42 |
| 45 class DevToolsAdbBridge | 43 class DevToolsAdbBridge |
| 46 : public base::RefCountedThreadSafe< | 44 : public base::RefCountedThreadSafe< |
| 47 DevToolsAdbBridge, | 45 DevToolsAdbBridge, |
| 48 content::BrowserThread::DeleteOnUIThread> { | 46 content::BrowserThread::DeleteOnUIThread> { |
| 49 public: | 47 public: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 75 | 73 |
| 76 Factory(); | 74 Factory(); |
| 77 virtual ~Factory(); | 75 virtual ~Factory(); |
| 78 | 76 |
| 79 // BrowserContextKeyedServiceFactory overrides: | 77 // BrowserContextKeyedServiceFactory overrides: |
| 80 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 78 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
| 81 content::BrowserContext* context) const OVERRIDE; | 79 content::BrowserContext* context) const OVERRIDE; |
| 82 DISALLOW_COPY_AND_ASSIGN(Factory); | 80 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 83 }; | 81 }; |
| 84 | 82 |
| 83 class RemotePage : public base::RefCounted<RemotePage> { |
| 84 public: |
| 85 RemotePage(scoped_refptr<RefCountedAdbThread> adb_thread, |
| 86 scoped_refptr<AndroidDevice> device, |
| 87 const std::string& socket, |
| 88 const base::DictionaryValue& value); |
| 89 |
| 90 std::string id() { return id_; } |
| 91 std::string url() { return url_; } |
| 92 std::string title() { return title_; } |
| 93 std::string description() { return description_; } |
| 94 std::string favicon_url() { return favicon_url_; } |
| 95 bool attached() { return debug_url_.empty(); } |
| 96 |
| 97 bool HasDevToolsWindow(); |
| 98 |
| 99 void Inspect(Profile* profile); |
| 100 void Activate(); |
| 101 void Close(); |
| 102 void Reload(); |
| 103 |
| 104 void SendProtocolCommand(const std::string& method, |
| 105 base::DictionaryValue* params); |
| 106 |
| 107 private: |
| 108 friend class base::RefCounted<RemotePage>; |
| 109 virtual ~RemotePage(); |
| 110 |
| 111 void RequestActivate(const AndroidDevice::CommandCallback& callback); |
| 112 |
| 113 void InspectOnHandlerThread( |
| 114 Profile* profile, int result, const std::string& response); |
| 115 |
| 116 void InspectOnUIThread(Profile* profile); |
| 117 |
| 118 scoped_refptr<RefCountedAdbThread> adb_thread_; |
| 119 scoped_refptr<AndroidDevice> device_; |
| 120 std::string socket_; |
| 121 std::string id_; |
| 122 std::string url_; |
| 123 std::string title_; |
| 124 std::string description_; |
| 125 std::string favicon_url_; |
| 126 std::string debug_url_; |
| 127 std::string frontend_url_; |
| 128 std::string agent_id_; |
| 129 DISALLOW_COPY_AND_ASSIGN(RemotePage); |
| 130 }; |
| 131 |
| 132 typedef std::vector<scoped_refptr<RemotePage> > RemotePages; |
| 133 |
| 85 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { | 134 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { |
| 86 public: | 135 public: |
| 87 RemoteBrowser( | 136 RemoteBrowser( |
| 88 scoped_refptr<RefCountedAdbThread> adb_thread, | 137 scoped_refptr<RefCountedAdbThread> adb_thread, |
| 89 scoped_refptr<AndroidDevice> device, | 138 scoped_refptr<AndroidDevice> device, |
| 90 const std::string& socket); | 139 const std::string& socket); |
| 91 | 140 |
| 92 scoped_refptr<RefCountedAdbThread> adb_thread() { return adb_thread_; } | |
| 93 | |
| 94 scoped_refptr<AndroidDevice> device() { return device_; } | 141 scoped_refptr<AndroidDevice> device() { return device_; } |
| 95 std::string socket() { return socket_; } | 142 std::string socket() { return socket_; } |
| 96 | 143 |
| 97 std::string product() { return product_; } | 144 std::string product() { return product_; } |
| 98 void set_product(const std::string& product) { product_ = product; } | 145 void set_product(const std::string& product) { product_ = product; } |
| 99 std::string version() { return version_; } | 146 std::string version() { return version_; } |
| 100 void set_version(const std::string& version) { version_ = version; } | 147 void set_version(const std::string& version) { version_ = version; } |
| 101 std::string pid() { return pid_; } | 148 std::string pid() { return pid_; } |
| 102 void set_pid(const std::string& pid) { pid_ = pid; } | 149 void set_pid(const std::string& pid) { pid_ = pid; } |
| 103 std::string package() { return package_; } | 150 std::string package() { return package_; } |
| 104 void set_package(const std::string& package) { package_ = package; } | 151 void set_package(const std::string& package) { package_ = package; } |
| 105 | 152 |
| 106 bool IsChrome() const; | 153 RemotePages& pages() { return pages_; } |
| 107 | 154 void AddPage(scoped_refptr<RemotePage> page) { pages_.push_back(page); } |
| 108 typedef std::vector<int> ParsedVersion; | |
| 109 ParsedVersion GetParsedVersion() const; | |
| 110 | |
| 111 std::vector<DevToolsTargetImpl*> CreatePageTargets(); | |
| 112 void SetPageDescriptors(const base::ListValue&); | |
| 113 | |
| 114 void SendJsonRequest(const std::string& request, base::Closure callback); | |
| 115 void SendProtocolCommand(const std::string& debug_url, | |
| 116 const std::string& method, | |
| 117 base::DictionaryValue* params); | |
| 118 | 155 |
| 119 void Open(const std::string& url); | 156 void Open(const std::string& url); |
| 120 | 157 |
| 121 private: | 158 private: |
| 122 friend class base::RefCounted<RemoteBrowser>; | 159 friend class base::RefCounted<RemoteBrowser>; |
| 123 virtual ~RemoteBrowser(); | 160 virtual ~RemoteBrowser(); |
| 124 | 161 |
| 125 void PageCreatedOnHandlerThread( | 162 void PageCreatedOnHandlerThread( |
| 126 const std::string& url, int result, const std::string& response); | 163 const std::string& url, int result, const std::string& response); |
| 127 | 164 |
| 128 void PageCreatedOnUIThread( | 165 void PageCreatedOnUIThread( |
| 129 const std::string& response, const std::string& url); | 166 const std::string& response, const std::string& url); |
| 130 | 167 |
| 131 scoped_refptr<RefCountedAdbThread> adb_thread_; | 168 scoped_refptr<RefCountedAdbThread> adb_thread_; |
| 132 scoped_refptr<AndroidDevice> device_; | 169 scoped_refptr<AndroidDevice> device_; |
| 133 const std::string socket_; | 170 const std::string socket_; |
| 134 std::string product_; | 171 std::string product_; |
| 135 std::string version_; | 172 std::string version_; |
| 136 std::string pid_; | 173 std::string pid_; |
| 137 std::string package_; | 174 std::string package_; |
| 138 scoped_ptr<base::ListValue> page_descriptors_; | 175 RemotePages pages_; |
| 139 | 176 |
| 140 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); | 177 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); |
| 141 }; | 178 }; |
| 142 | 179 |
| 143 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; | 180 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; |
| 144 | 181 |
| 145 class RemoteDevice : public base::RefCounted<RemoteDevice> { | 182 class RemoteDevice : public base::RefCounted<RemoteDevice> { |
| 146 public: | 183 public: |
| 147 explicit RemoteDevice(scoped_refptr<AndroidDevice> device); | 184 explicit RemoteDevice(scoped_refptr<AndroidDevice> device); |
| 148 | 185 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 179 virtual ~Listener() {} | 216 virtual ~Listener() {} |
| 180 }; | 217 }; |
| 181 | 218 |
| 182 DevToolsAdbBridge(); | 219 DevToolsAdbBridge(); |
| 183 void AddListener(Listener* listener); | 220 void AddListener(Listener* listener); |
| 184 void RemoveListener(Listener* listener); | 221 void RemoveListener(Listener* listener); |
| 185 | 222 |
| 186 void set_device_providers(DeviceProviders device_providers) { | 223 void set_device_providers(DeviceProviders device_providers) { |
| 187 device_providers_ = device_providers; | 224 device_providers_ = device_providers; |
| 188 } | 225 } |
| 189 static bool HasDevToolsWindow(const std::string& agent_id); | |
| 190 | 226 |
| 191 private: | 227 private: |
| 192 friend struct content::BrowserThread::DeleteOnThread< | 228 friend struct content::BrowserThread::DeleteOnThread< |
| 193 content::BrowserThread::UI>; | 229 content::BrowserThread::UI>; |
| 194 friend class base::DeleteHelper<DevToolsAdbBridge>; | 230 friend class base::DeleteHelper<DevToolsAdbBridge>; |
| 195 | 231 |
| 196 virtual ~DevToolsAdbBridge(); | 232 virtual ~DevToolsAdbBridge(); |
| 197 | 233 |
| 198 void RequestRemoteDevices(); | 234 void RequestRemoteDevices(); |
| 199 void ReceivedRemoteDevices(RemoteDevices* devices); | 235 void ReceivedRemoteDevices(RemoteDevices* devices); |
| 200 | 236 |
| 201 scoped_refptr<RefCountedAdbThread> adb_thread_; | 237 scoped_refptr<RefCountedAdbThread> adb_thread_; |
| 202 bool has_message_loop_; | 238 bool has_message_loop_; |
| 203 typedef std::vector<Listener*> Listeners; | 239 typedef std::vector<Listener*> Listeners; |
| 204 Listeners listeners_; | 240 Listeners listeners_; |
| 205 DeviceProviders device_providers_; | 241 DeviceProviders device_providers_; |
| 206 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); | 242 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); |
| 207 }; | 243 }; |
| 208 | 244 |
| 209 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ | 245 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
| OLD | NEW |