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