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 "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | |
| 16 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" | |
| 15 #include "net/socket/tcp_client_socket.h" | 17 #include "net/socket/tcp_client_socket.h" |
| 16 | 18 |
| 19 template<typename T> struct DefaultSingletonTraits; | |
| 20 | |
| 17 namespace base { | 21 namespace base { |
| 18 class MessageLoop; | 22 class MessageLoop; |
| 19 class DictionaryValue; | 23 class DictionaryValue; |
| 20 class Thread; | 24 class Thread; |
| 21 } | 25 } |
| 22 | 26 |
| 27 namespace content { | |
| 28 class BrowserContext; | |
| 29 } | |
| 30 | |
| 31 namespace crypto { | |
| 32 class RSAPrivateKey; | |
| 33 } | |
| 34 | |
| 23 class Profile; | 35 class Profile; |
| 24 | 36 |
| 25 // The format used for constructing DevTools server socket names. | 37 // The format used for constructing DevTools server socket names. |
| 26 extern const char kDevToolsChannelNameFormat[]; | 38 extern const char kDevToolsChannelNameFormat[]; |
| 27 | 39 |
| 28 typedef base::Callback<void(int, const std::string&)> CommandCallback; | 40 typedef base::Callback<void(int, const std::string&)> CommandCallback; |
| 29 typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback; | 41 typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback; |
| 30 | 42 |
| 31 class DevToolsAdbBridge { | 43 class DevToolsAdbBridge : public BrowserContextKeyedService { |
| 32 public: | 44 public: |
| 33 typedef base::Callback<void(int result, | 45 typedef base::Callback<void(int result, |
| 34 const std::string& response)> Callback; | 46 const std::string& response)> Callback; |
| 47 class Factory : public BrowserContextKeyedServiceFactory { | |
| 48 public: | |
| 49 // Returns singleton instance of DevToolsAdbBridge. | |
| 50 static Factory* GetInstance(); | |
| 51 | |
| 52 // Returns DevToolsAdbBridge associated with |profile|. | |
| 53 static DevToolsAdbBridge* GetForProfile(Profile* profile); | |
| 54 | |
| 55 private: | |
| 56 friend struct DefaultSingletonTraits<Factory>; | |
| 57 | |
| 58 Factory(); | |
| 59 virtual ~Factory(); | |
| 60 | |
| 61 // BrowserContextKeyedServiceFactory overrides: | |
| 62 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | |
| 63 content::BrowserContext* context) const OVERRIDE; | |
| 64 DISALLOW_COPY_AND_ASSIGN(Factory); | |
| 65 }; | |
| 35 | 66 |
| 36 class RemotePage : public base::RefCounted<RemotePage> { | 67 class RemotePage : public base::RefCounted<RemotePage> { |
| 37 public: | 68 public: |
| 38 RemotePage(const std::string& serial, | 69 RemotePage(const std::string& serial, |
| 39 const std::string& model, | 70 const std::string& model, |
| 40 const std::string& package, | 71 const std::string& package, |
| 41 const std::string& socket, | 72 const std::string& socket, |
| 42 const base::DictionaryValue& value); | 73 const base::DictionaryValue& value); |
| 43 | 74 |
| 44 std::string serial() { return serial_; } | 75 std::string serial() { return serial_; } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 const SocketCallback& callback, | 137 const SocketCallback& callback, |
| 107 int result, | 138 int result, |
| 108 net::StreamSocket* socket); | 139 net::StreamSocket* socket); |
| 109 | 140 |
| 110 std::string serial_; | 141 std::string serial_; |
| 111 std::string model_; | 142 std::string model_; |
| 112 | 143 |
| 113 DISALLOW_COPY_AND_ASSIGN(AndroidDevice); | 144 DISALLOW_COPY_AND_ASSIGN(AndroidDevice); |
| 114 }; | 145 }; |
| 115 | 146 |
| 147 typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices; | |
| 148 typedef base::Callback<void(const AndroidDevices&)> AndroidDevicesCallback; | |
| 149 | |
| 116 explicit DevToolsAdbBridge(Profile* profile); | 150 explicit DevToolsAdbBridge(Profile* profile); |
| 117 ~DevToolsAdbBridge(); | 151 virtual ~DevToolsAdbBridge(); |
| 118 | 152 |
| 153 void EnumerateDevices(const AndroidDevicesCallback& callback); | |
| 119 void Query(const std::string query, const Callback& callback); | 154 void Query(const std::string query, const Callback& callback); |
| 120 void Pages(const PagesCallback& callback); | 155 void Pages(const PagesCallback& callback); |
| 121 void Attach(const std::string& serial, | 156 void Attach(const std::string& serial, |
| 122 const std::string& socket, | 157 const std::string& socket, |
| 123 const std::string& debug_url, | 158 const std::string& debug_url, |
| 124 const std::string& frontend_url); | 159 const std::string& frontend_url); |
| 125 | 160 |
| 126 private: | 161 private: |
| 162 friend class base::RefCounted<DevToolsAdbBridge>; | |
|
vsevik
2013/07/11 15:59:54
nuke
pfeldman
2013/07/11 16:26:51
Done.
| |
| 163 | |
| 127 friend class AdbAttachCommand; | 164 friend class AdbAttachCommand; |
| 128 friend class AgentHostDelegate; | 165 friend class AgentHostDelegate; |
| 129 | 166 |
| 130 class RefCountedAdbThread : public base::RefCounted<RefCountedAdbThread> { | 167 class RefCountedAdbThread : public base::RefCounted<RefCountedAdbThread> { |
| 131 public: | 168 public: |
| 132 static scoped_refptr<RefCountedAdbThread> GetInstance(); | 169 static scoped_refptr<RefCountedAdbThread> GetInstance(); |
| 133 RefCountedAdbThread(); | 170 RefCountedAdbThread(); |
| 134 base::MessageLoop* message_loop(); | 171 base::MessageLoop* message_loop(); |
| 135 | 172 |
| 136 private: | 173 private: |
| 137 friend class base::RefCounted<RefCountedAdbThread>; | 174 friend class base::RefCounted<RefCountedAdbThread>; |
| 138 static DevToolsAdbBridge::RefCountedAdbThread* instance_; | 175 static DevToolsAdbBridge::RefCountedAdbThread* instance_; |
| 139 static void StopThread(base::Thread* thread); | 176 static void StopThread(base::Thread* thread); |
| 140 | 177 |
| 141 virtual ~RefCountedAdbThread(); | 178 virtual ~RefCountedAdbThread(); |
| 142 base::Thread* thread_; | 179 base::Thread* thread_; |
| 143 }; | 180 }; |
| 144 | 181 |
| 182 void ReceivedDevices(const AndroidDevicesCallback& callback, | |
| 183 int result, | |
| 184 const std::string& response); | |
| 185 | |
| 145 Profile* profile_; | 186 Profile* profile_; |
| 146 scoped_refptr<RefCountedAdbThread> adb_thread_; | 187 scoped_refptr<RefCountedAdbThread> adb_thread_; |
| 147 base::WeakPtrFactory<DevToolsAdbBridge> weak_factory_; | 188 base::WeakPtrFactory<DevToolsAdbBridge> weak_factory_; |
| 148 bool has_message_loop_; | 189 bool has_message_loop_; |
| 190 scoped_ptr<crypto::RSAPrivateKey> rsa_key_; | |
| 149 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); | 191 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); |
| 150 }; | 192 }; |
| 151 | 193 |
| 152 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ | 194 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
| OLD | NEW |