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 #include "chrome/browser/devtools/devtools_adb_bridge.h" | 5 #include "chrome/browser/devtools/devtools_adb_bridge.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "content/public/browser/devtools_external_agent_proxy.h" | 33 #include "content/public/browser/devtools_external_agent_proxy.h" |
34 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" | 34 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" |
35 #include "content/public/browser/devtools_manager.h" | 35 #include "content/public/browser/devtools_manager.h" |
36 #include "crypto/rsa_private_key.h" | 36 #include "crypto/rsa_private_key.h" |
37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
38 | 38 |
39 using content::BrowserThread; | 39 using content::BrowserThread; |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread"; | |
44 const char kHostDevicesCommand[] = "host:devices"; | 43 const char kHostDevicesCommand[] = "host:devices"; |
45 const char kHostTransportCommand[] = "host:transport:%s|%s"; | 44 const char kHostTransportCommand[] = "host:transport:%s|%s"; |
46 const char kLocalAbstractCommand[] = "localabstract:%s"; | 45 const char kLocalAbstractCommand[] = "localabstract:%s"; |
47 const char kDeviceModelCommand[] = "shell:getprop ro.product.model"; | 46 const char kDeviceModelCommand[] = "shell:getprop ro.product.model"; |
48 const char kOpenedUnixSocketsCommand[] = "shell:cat /proc/net/unix"; | 47 const char kOpenedUnixSocketsCommand[] = "shell:cat /proc/net/unix"; |
49 const char kListProcessesCommand[] = "shell:ps"; | 48 const char kListProcessesCommand[] = "shell:ps"; |
50 const char kDumpsysCommand[] = "shell:dumpsys window policy"; | 49 const char kDumpsysCommand[] = "shell:dumpsys window policy"; |
51 const char kDumpsysScreenSizePrefix[] = "mStable="; | 50 const char kDumpsysScreenSizePrefix[] = "mStable="; |
52 | 51 |
53 const char kPageListRequest[] = "GET /json HTTP/1.1\r\n\r\n"; | 52 const char kPageListRequest[] = "GET /json HTTP/1.1\r\n\r\n"; |
54 const char kVersionRequest[] = "GET /json/version HTTP/1.1\r\n\r\n"; | 53 const char kVersionRequest[] = "GET /json/version HTTP/1.1\r\n\r\n"; |
55 const char kClosePageRequest[] = "GET /json/close/%s HTTP/1.1\r\n\r\n"; | 54 const char kClosePageRequest[] = "GET /json/close/%s HTTP/1.1\r\n\r\n"; |
56 const char kNewPageRequest[] = "GET /json/new HTTP/1.1\r\n\r\n"; | 55 const char kNewPageRequest[] = "GET /json/new HTTP/1.1\r\n\r\n"; |
57 const char kActivatePageRequest[] = | 56 const char kActivatePageRequest[] = |
58 "GET /json/activate/%s HTTP/1.1\r\n\r\n"; | 57 "GET /json/activate/%s HTTP/1.1\r\n\r\n"; |
59 const int kAdbPort = 5037; | 58 const int kAdbPort = 5037; |
60 const int kBufferSize = 16 * 1024; | 59 const int kBufferSize = 16 * 1024; |
61 const int kAdbPollingIntervalMs = 1000; | 60 const int kAdbPollingIntervalMs = 1000; |
62 | 61 |
63 const char kUrlParam[] = "url"; | 62 const char kUrlParam[] = "url"; |
64 const char kPageReloadCommand[] = "Page.reload"; | 63 const char kPageReloadCommand[] = "Page.reload"; |
65 const char kPageNavigateCommand[] = "Page.navigate"; | 64 const char kPageNavigateCommand[] = "Page.navigate"; |
66 | 65 |
67 #if defined(DEBUG_DEVTOOLS) | 66 #if defined(DEBUG_DEVTOOLS) |
68 const char kChrome[] = "Chrome"; | 67 const char kChrome[] = "Chrome"; |
69 const char kLocalChrome[] = "Local Chrome"; | 68 const char kLocalChrome[] = "Local Chrome"; |
70 #endif // defined(DEBUG_DEVTOOLS) | 69 #endif // defined(DEBUG_DEVTOOLS) |
71 | 70 |
72 typedef DevToolsAdbBridge::Callback Callback; | 71 typedef DevToolsAdbBridge::Callback Callback; |
73 typedef std::vector<scoped_refptr<DevToolsAdbBridge::AndroidDevice> > | 72 typedef std::vector<scoped_refptr<AndroidDevice> > |
74 AndroidDevices; | 73 AndroidDevices; |
75 typedef base::Callback<void(const AndroidDevices&)> AndroidDevicesCallback; | 74 typedef base::Callback<void(const AndroidDevices&)> AndroidDevicesCallback; |
76 | 75 |
77 | 76 |
78 // AdbDeviceImpl -------------------------------------------------------------- | |
79 | |
80 class AdbDeviceImpl : public DevToolsAdbBridge::AndroidDevice { | |
81 public: | |
82 explicit AdbDeviceImpl(const std::string& serial); | |
83 virtual void RunCommand(const std::string& command, | |
84 const CommandCallback& callback) OVERRIDE; | |
85 virtual void OpenSocket(const std::string& name, | |
86 const SocketCallback& callback) OVERRIDE; | |
87 virtual bool IsConnected() OVERRIDE; | |
88 | |
89 private: | |
90 virtual ~AdbDeviceImpl() {} | |
91 }; | |
92 | |
93 AdbDeviceImpl::AdbDeviceImpl(const std::string& serial) | |
94 : AndroidDevice(serial) { | |
95 } | |
96 | |
97 void AdbDeviceImpl::RunCommand(const std::string& command, | |
98 const CommandCallback& callback) { | |
99 std::string query = base::StringPrintf(kHostTransportCommand, | |
100 serial().c_str(), command.c_str()); | |
101 AdbClientSocket::AdbQuery(kAdbPort, query, callback); | |
102 } | |
103 | |
104 void AdbDeviceImpl::OpenSocket(const std::string& name, | |
105 const SocketCallback& callback) { | |
106 std::string socket_name = | |
107 base::StringPrintf(kLocalAbstractCommand, name.c_str()); | |
108 AdbClientSocket::TransportQuery(kAdbPort, serial(), socket_name, callback); | |
109 } | |
110 | |
111 bool AdbDeviceImpl::IsConnected() { | |
112 return true; | |
113 } | |
114 | |
115 | |
116 // UsbDeviceImpl -------------------------------------------------------------- | |
117 | |
118 class UsbDeviceImpl : public DevToolsAdbBridge::AndroidDevice { | |
119 public: | |
120 explicit UsbDeviceImpl(AndroidUsbDevice* device); | |
121 virtual void RunCommand(const std::string& command, | |
122 const CommandCallback& callback) OVERRIDE; | |
123 virtual void OpenSocket(const std::string& name, | |
124 const SocketCallback& callback) OVERRIDE; | |
125 virtual bool IsConnected() OVERRIDE; | |
126 | |
127 private: | |
128 void OnOpenSocket(const SocketCallback& callback, | |
129 net::StreamSocket* socket, | |
130 int result); | |
131 void OpenedForCommand(const CommandCallback& callback, | |
132 net::StreamSocket* socket, | |
133 int result); | |
134 void OnRead(net::StreamSocket* socket, | |
135 scoped_refptr<net::IOBuffer> buffer, | |
136 const std::string& data, | |
137 const CommandCallback& callback, | |
138 int result); | |
139 | |
140 virtual ~UsbDeviceImpl() {} | |
141 scoped_refptr<AndroidUsbDevice> device_; | |
142 }; | |
143 | |
144 | |
145 UsbDeviceImpl::UsbDeviceImpl(AndroidUsbDevice* device) | |
146 : AndroidDevice(device->serial()), | |
147 device_(device) { | |
148 device_->InitOnCallerThread(); | |
149 } | |
150 | |
151 void UsbDeviceImpl::RunCommand(const std::string& command, | |
152 const CommandCallback& callback) { | |
153 net::StreamSocket* socket = device_->CreateSocket(command); | |
154 int result = socket->Connect(base::Bind(&UsbDeviceImpl::OpenedForCommand, | |
155 this, callback, socket)); | |
156 if (result != net::ERR_IO_PENDING) | |
157 callback.Run(result, std::string()); | |
158 } | |
159 | |
160 void UsbDeviceImpl::OpenSocket(const std::string& name, | |
161 const SocketCallback& callback) { | |
162 std::string socket_name = | |
163 base::StringPrintf(kLocalAbstractCommand, name.c_str()); | |
164 net::StreamSocket* socket = device_->CreateSocket(socket_name); | |
165 int result = socket->Connect(base::Bind(&UsbDeviceImpl::OnOpenSocket, this, | |
166 callback, socket)); | |
167 if (result != net::ERR_IO_PENDING) | |
168 callback.Run(result, NULL); | |
169 } | |
170 | |
171 void UsbDeviceImpl::OnOpenSocket(const SocketCallback& callback, | |
172 net::StreamSocket* socket, | |
173 int result) { | |
174 callback.Run(result, result == net::OK ? socket : NULL); | |
175 } | |
176 | |
177 void UsbDeviceImpl::OpenedForCommand(const CommandCallback& callback, | |
178 net::StreamSocket* socket, | |
179 int result) { | |
180 if (result != net::OK) { | |
181 callback.Run(result, std::string()); | |
182 return; | |
183 } | |
184 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kBufferSize); | |
185 result = socket->Read(buffer, kBufferSize, | |
186 base::Bind(&UsbDeviceImpl::OnRead, this, | |
187 socket, buffer, std::string(), callback)); | |
188 if (result != net::ERR_IO_PENDING) | |
189 OnRead(socket, buffer, std::string(), callback, result); | |
190 } | |
191 | |
192 void UsbDeviceImpl::OnRead(net::StreamSocket* socket, | |
193 scoped_refptr<net::IOBuffer> buffer, | |
194 const std::string& data, | |
195 const CommandCallback& callback, | |
196 int result) { | |
197 if (result <= 0) { | |
198 callback.Run(result, result == 0 ? data : std::string()); | |
199 delete socket; | |
200 return; | |
201 } | |
202 | |
203 std::string new_data = data + std::string(buffer->data(), result); | |
204 result = socket->Read(buffer, kBufferSize, | |
205 base::Bind(&UsbDeviceImpl::OnRead, this, | |
206 socket, buffer, new_data, callback)); | |
207 if (result != net::ERR_IO_PENDING) | |
208 OnRead(socket, buffer, new_data, callback, result); | |
209 } | |
210 | |
211 bool UsbDeviceImpl::IsConnected() { | |
212 return device_->is_connected(); | |
213 } | |
214 | |
215 | 77 |
216 // AdbCountDevicesCommand ----------------------------------------------------- | 78 // AdbCountDevicesCommand ----------------------------------------------------- |
217 | 79 |
218 class AdbCountDevicesCommand : public base::RefCountedThreadSafe< | 80 class AdbCountDevicesCommand : public base::RefCountedThreadSafe< |
219 AdbCountDevicesCommand, | 81 AdbCountDevicesCommand, |
220 content::BrowserThread::DeleteOnUIThread> { | 82 BrowserThread::DeleteOnUIThread> { |
221 public: | 83 public: |
222 typedef base::Callback<void(int)> Callback; | 84 typedef base::Callback<void(int)> Callback; |
223 | 85 |
224 AdbCountDevicesCommand( | 86 AdbCountDevicesCommand( |
225 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 87 scoped_refptr<RefCountedAdbThread> adb_thread, |
226 const Callback& callback); | 88 const Callback& callback); |
227 | 89 |
228 private: | 90 private: |
229 friend struct content::BrowserThread::DeleteOnThread< | 91 friend struct BrowserThread::DeleteOnThread< |
230 content::BrowserThread::UI>; | 92 BrowserThread::UI>; |
231 friend class base::DeleteHelper<AdbCountDevicesCommand>; | 93 friend class base::DeleteHelper<AdbCountDevicesCommand>; |
232 | 94 |
233 virtual ~AdbCountDevicesCommand(); | 95 virtual ~AdbCountDevicesCommand(); |
234 void RequestAdbDeviceCount(); | 96 void RequestAdbDeviceCount(); |
235 void ReceivedAdbDeviceCount(int result, const std::string& response); | 97 void ReceivedAdbDeviceCount(int result, const std::string& response); |
236 void Respond(int count); | 98 void Respond(int count); |
237 | 99 |
238 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread_; | 100 scoped_refptr<RefCountedAdbThread> adb_thread_; |
239 Callback callback_; | 101 Callback callback_; |
240 }; | 102 }; |
241 | 103 |
242 AdbCountDevicesCommand::AdbCountDevicesCommand( | 104 AdbCountDevicesCommand::AdbCountDevicesCommand( |
243 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 105 scoped_refptr<RefCountedAdbThread> adb_thread, |
244 const Callback& callback) | 106 const Callback& callback) |
245 : adb_thread_(adb_thread), | 107 : adb_thread_(adb_thread), |
246 callback_(callback) { | 108 callback_(callback) { |
247 adb_thread_->message_loop()->PostTask( | 109 adb_thread_->message_loop()->PostTask( |
248 FROM_HERE, base::Bind(&AdbCountDevicesCommand::RequestAdbDeviceCount, | 110 FROM_HERE, base::Bind(&AdbCountDevicesCommand::RequestAdbDeviceCount, |
249 this)); | 111 this)); |
250 } | 112 } |
251 | 113 |
252 AdbCountDevicesCommand::~AdbCountDevicesCommand() { | 114 AdbCountDevicesCommand::~AdbCountDevicesCommand() { |
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 19 matching lines...) Expand all Loading... | |
273 | 135 |
274 void AdbCountDevicesCommand::Respond(int count) { | 136 void AdbCountDevicesCommand::Respond(int count) { |
275 callback_.Run(count); | 137 callback_.Run(count); |
276 } | 138 } |
277 | 139 |
278 | 140 |
279 // AdbPagesCommand ------------------------------------------------------------ | 141 // AdbPagesCommand ------------------------------------------------------------ |
280 | 142 |
281 class AdbPagesCommand : public base::RefCountedThreadSafe< | 143 class AdbPagesCommand : public base::RefCountedThreadSafe< |
282 AdbPagesCommand, | 144 AdbPagesCommand, |
283 content::BrowserThread::DeleteOnUIThread> { | 145 BrowserThread::DeleteOnUIThread> { |
284 public: | 146 public: |
285 typedef base::Callback<void(DevToolsAdbBridge::RemoteDevices*)> Callback; | 147 typedef base::Callback<void(DevToolsAdbBridge::RemoteDevices*)> Callback; |
286 | 148 |
287 AdbPagesCommand( | 149 AdbPagesCommand( |
288 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 150 scoped_refptr<RefCountedAdbThread> adb_thread, |
289 crypto::RSAPrivateKey* rsa_key, bool discover_usb, | 151 const DevToolsAdbBridge::DeviceProviders& device_providers, |
290 const Callback& callback); | 152 const Callback& callback); |
291 | 153 |
292 private: | 154 private: |
293 friend struct content::BrowserThread::DeleteOnThread< | 155 friend struct BrowserThread::DeleteOnThread< |
294 content::BrowserThread::UI>; | 156 BrowserThread::UI>; |
295 friend class base::DeleteHelper<AdbPagesCommand>; | 157 friend class base::DeleteHelper<AdbPagesCommand>; |
296 | 158 |
297 virtual ~AdbPagesCommand(); | 159 virtual ~AdbPagesCommand(); |
298 void ReceivedUsbDevices(const AndroidUsbDevices& usb_devices); | 160 void ProcessDeviceProviders(); |
299 void WrapUsbDevices(const AndroidUsbDevices& usb_devices); | 161 void ReceivedDevices(const AndroidDevices& devices); |
300 | 162 |
301 void ReceivedAdbDevices(int result, const std::string& response); | |
302 void ProcessSerials(); | 163 void ProcessSerials(); |
303 void ReceivedModel(int result, const std::string& response); | 164 void ReceivedModel(int result, const std::string& response); |
304 void ReceivedSockets(int result, const std::string& response); | 165 void ReceivedSockets(int result, const std::string& response); |
305 void ReceivedDumpsys(int result, const std::string& response); | 166 void ReceivedDumpsys(int result, const std::string& response); |
306 void ReceivedProcesses(int result, const std::string& response); | 167 void ReceivedProcesses(int result, const std::string& response); |
307 void ProcessSockets(); | 168 void ProcessSockets(); |
308 void ReceivedVersion(int result, const std::string& response); | 169 void ReceivedVersion(int result, const std::string& response); |
309 void ReceivedPages(int result, const std::string& response); | 170 void ReceivedPages(int result, const std::string& response); |
310 void Respond(); | 171 void Respond(); |
311 void ParseSocketsList(const std::string& response); | 172 void ParseSocketsList(const std::string& response); |
312 void ParseProcessList(const std::string& response); | 173 void ParseProcessList(const std::string& response); |
313 void ParseDumpsysResponse(const std::string& response); | 174 void ParseDumpsysResponse(const std::string& response); |
314 void ParseScreenSize(const std::string& str); | 175 void ParseScreenSize(const std::string& str); |
315 | 176 |
316 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread_; | 177 scoped_refptr<RefCountedAdbThread> adb_thread_; |
317 Callback callback_; | 178 Callback callback_; |
318 AndroidDevices devices_; | 179 AndroidDevices devices_; |
319 DevToolsAdbBridge::RemoteBrowsers browsers_; | 180 DevToolsAdbBridge::RemoteBrowsers browsers_; |
320 scoped_ptr<DevToolsAdbBridge::RemoteDevices> remote_devices_; | 181 scoped_ptr<DevToolsAdbBridge::RemoteDevices> remote_devices_; |
182 DevToolsAdbBridge::DeviceProviders device_providers_; | |
321 }; | 183 }; |
322 | 184 |
323 AdbPagesCommand::AdbPagesCommand( | 185 AdbPagesCommand::AdbPagesCommand( |
324 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 186 scoped_refptr<RefCountedAdbThread> adb_thread, |
325 crypto::RSAPrivateKey* rsa_key, bool discover_usb, | 187 const DevToolsAdbBridge::DeviceProviders& device_providers, |
326 const Callback& callback) | 188 const Callback& callback) |
327 : adb_thread_(adb_thread), | 189 : adb_thread_(adb_thread), |
328 callback_(callback) { | 190 callback_(callback), |
191 device_providers_(device_providers){ | |
329 remote_devices_.reset(new DevToolsAdbBridge::RemoteDevices()); | 192 remote_devices_.reset(new DevToolsAdbBridge::RemoteDevices()); |
330 | 193 |
331 if (discover_usb) { | 194 DCHECK(!device_providers_.empty()); |
332 AndroidUsbDevice::Enumerate(rsa_key, | 195 |
333 base::Bind(&AdbPagesCommand::ReceivedUsbDevices, this)); | 196 ProcessDeviceProviders(); |
334 } else { | |
335 ReceivedUsbDevices(AndroidUsbDevices()); | |
336 } | |
337 } | 197 } |
338 | 198 |
339 AdbPagesCommand::~AdbPagesCommand() { | 199 AdbPagesCommand::~AdbPagesCommand() { |
340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
341 } | 201 } |
342 | 202 |
343 void AdbPagesCommand::ReceivedUsbDevices(const AndroidUsbDevices& usb_devices) { | 203 void AdbPagesCommand::ProcessDeviceProviders() { |
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
345 adb_thread_->message_loop()->PostTask( | 205 if (device_providers_.empty()) { |
346 FROM_HERE, base::Bind(&AdbPagesCommand::WrapUsbDevices, this, | 206 ProcessSerials(); |
347 usb_devices)); | 207 return; |
208 } | |
209 | |
210 const scoped_refptr<DevToolsDeviceProvider>& device_provider = | |
211 device_providers_.back(); | |
212 | |
213 device_provider->QueryDevices( | |
214 base::Bind(&AdbPagesCommand::ReceivedDevices, this)); | |
348 } | 215 } |
349 | 216 |
350 void AdbPagesCommand::WrapUsbDevices(const AndroidUsbDevices& usb_devices) { | 217 void AdbPagesCommand::ReceivedDevices(const AndroidDevices& devices) { |
351 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
219 DCHECK(!device_providers_.empty()); | |
220 device_providers_.pop_back(); | |
352 | 221 |
353 #if defined(DEBUG_DEVTOOLS) | 222 devices_.insert(devices_.end(), devices.begin(), devices.end()); |
354 devices_.push_back(new AdbDeviceImpl("")); // For desktop remote debugging. | |
355 #endif // defined(DEBUG_DEVTOOLS) | |
356 | 223 |
357 for (AndroidUsbDevices::const_iterator it = usb_devices.begin(); | 224 if (!device_providers_.empty()) { |
358 it != usb_devices.end(); ++it) { | 225 ProcessDeviceProviders(); |
359 devices_.push_back(new UsbDeviceImpl(*it)); | 226 } else { |
227 adb_thread_->message_loop()->PostTask( | |
228 FROM_HERE, base::Bind(&AdbPagesCommand::ProcessSerials, | |
229 this)); | |
360 } | 230 } |
361 | |
362 AdbClientSocket::AdbQuery( | |
363 kAdbPort, kHostDevicesCommand, | |
364 base::Bind(&AdbPagesCommand::ReceivedAdbDevices, this)); | |
365 } | |
366 | |
367 void AdbPagesCommand::ReceivedAdbDevices( | |
368 int result, | |
369 const std::string& response) { | |
370 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | |
371 std::vector<std::string> serials; | |
372 Tokenize(response, "\n", &serials); | |
373 for (size_t i = 0; i < serials.size(); ++i) { | |
374 std::vector<std::string> tokens; | |
375 Tokenize(serials[i], "\t ", &tokens); | |
376 devices_.push_back(new AdbDeviceImpl(tokens[0])); | |
377 } | |
378 ProcessSerials(); | |
379 } | 231 } |
380 | 232 |
381 void AdbPagesCommand::ProcessSerials() { | 233 void AdbPagesCommand::ProcessSerials() { |
382 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 234 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); |
383 if (devices_.size() == 0) { | 235 if (devices_.size() == 0) { |
384 BrowserThread::PostTask( | 236 BrowserThread::PostTask( |
385 BrowserThread::UI, FROM_HERE, | 237 BrowserThread::UI, FROM_HERE, |
386 base::Bind(&AdbPagesCommand::Respond, this)); | 238 base::Bind(&AdbPagesCommand::Respond, this)); |
387 return; | 239 return; |
388 } | 240 } |
389 | 241 |
390 #if defined(DEBUG_DEVTOOLS) | 242 #if defined(DEBUG_DEVTOOLS) |
391 // For desktop remote debugging. | 243 // For desktop remote debugging. |
392 if (devices_.back()->serial().empty()) { | 244 if (devices_.back()->serial().empty()) { |
393 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = | 245 scoped_refptr<AndroidDevice> device = |
394 devices_.back(); | 246 devices_.back(); |
395 device->set_model(kLocalChrome); | 247 device->set_model(kLocalChrome); |
396 remote_devices_->push_back( | 248 remote_devices_->push_back( |
397 new DevToolsAdbBridge::RemoteDevice(device)); | 249 new DevToolsAdbBridge::RemoteDevice(device)); |
398 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> remote_browser = | 250 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> remote_browser = |
399 new DevToolsAdbBridge::RemoteBrowser( | 251 new DevToolsAdbBridge::RemoteBrowser( |
400 adb_thread_, device, std::string()); | 252 adb_thread_, device, std::string()); |
401 remote_browser->set_product(kChrome); | 253 remote_browser->set_product(kChrome); |
402 remote_devices_->back()->AddBrowser(remote_browser); | 254 remote_devices_->back()->AddBrowser(remote_browser); |
403 browsers_.push_back(remote_browser); | 255 browsers_.push_back(remote_browser); |
404 device->HttpQuery( | 256 device->HttpQuery( |
405 std::string(), kVersionRequest, | 257 std::string(), kVersionRequest, |
406 base::Bind(&AdbPagesCommand::ReceivedVersion, this)); | 258 base::Bind(&AdbPagesCommand::ReceivedVersion, this)); |
407 return; | 259 return; |
408 } | 260 } |
409 #endif // defined(DEBUG_DEVTOOLS) | 261 #endif // defined(DEBUG_DEVTOOLS) |
410 | 262 |
411 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); | 263 scoped_refptr<AndroidDevice> device = devices_.back(); |
412 if (device->IsConnected()) { | 264 if (device->IsConnected()) { |
413 device->RunCommand(kDeviceModelCommand, | 265 device->RunCommand(kDeviceModelCommand, |
414 base::Bind(&AdbPagesCommand::ReceivedModel, this)); | 266 base::Bind(&AdbPagesCommand::ReceivedModel, this)); |
415 } else { | 267 } else { |
416 remote_devices_->push_back(new DevToolsAdbBridge::RemoteDevice(device)); | 268 remote_devices_->push_back(new DevToolsAdbBridge::RemoteDevice(device)); |
417 devices_.pop_back(); | 269 devices_.pop_back(); |
418 ProcessSerials(); | 270 ProcessSerials(); |
419 } | 271 } |
420 } | 272 } |
421 | 273 |
422 void AdbPagesCommand::ReceivedModel(int result, const std::string& response) { | 274 void AdbPagesCommand::ReceivedModel(int result, const std::string& response) { |
423 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 275 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); |
424 if (result < 0) { | 276 if (result < 0) { |
425 devices_.pop_back(); | 277 devices_.pop_back(); |
426 ProcessSerials(); | 278 ProcessSerials(); |
427 return; | 279 return; |
428 } | 280 } |
429 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); | 281 scoped_refptr<AndroidDevice> device = devices_.back(); |
430 device->set_model(response); | 282 device->set_model(response); |
431 remote_devices_->push_back( | 283 remote_devices_->push_back( |
432 new DevToolsAdbBridge::RemoteDevice(device)); | 284 new DevToolsAdbBridge::RemoteDevice(device)); |
433 device->RunCommand(kOpenedUnixSocketsCommand, | 285 device->RunCommand(kOpenedUnixSocketsCommand, |
434 base::Bind(&AdbPagesCommand::ReceivedSockets, this)); | 286 base::Bind(&AdbPagesCommand::ReceivedSockets, this)); |
435 } | 287 } |
436 | 288 |
437 void AdbPagesCommand::ReceivedSockets(int result, | 289 void AdbPagesCommand::ReceivedSockets(int result, |
438 const std::string& response) { | 290 const std::string& response) { |
439 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 291 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); |
440 if (result < 0) { | 292 if (result < 0) { |
441 devices_.pop_back(); | 293 devices_.pop_back(); |
442 ProcessSerials(); | 294 ProcessSerials(); |
443 return; | 295 return; |
444 } | 296 } |
445 | 297 |
446 ParseSocketsList(response); | 298 ParseSocketsList(response); |
447 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); | 299 scoped_refptr<AndroidDevice> device = devices_.back(); |
448 device->RunCommand(kDumpsysCommand, | 300 device->RunCommand(kDumpsysCommand, |
449 base::Bind(&AdbPagesCommand::ReceivedDumpsys, this)); | 301 base::Bind(&AdbPagesCommand::ReceivedDumpsys, this)); |
450 } | 302 } |
451 | 303 |
452 void AdbPagesCommand::ReceivedDumpsys(int result, | 304 void AdbPagesCommand::ReceivedDumpsys(int result, |
453 const std::string& response) { | 305 const std::string& response) { |
454 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 306 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); |
455 if (result >= 0) | 307 if (result >= 0) |
456 ParseDumpsysResponse(response); | 308 ParseDumpsysResponse(response); |
457 | 309 |
458 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); | 310 scoped_refptr<AndroidDevice> device = devices_.back(); |
459 device->RunCommand(kListProcessesCommand, | 311 device->RunCommand(kListProcessesCommand, |
460 base::Bind(&AdbPagesCommand::ReceivedProcesses, this)); | 312 base::Bind(&AdbPagesCommand::ReceivedProcesses, this)); |
461 } | 313 } |
462 | 314 |
463 void AdbPagesCommand::ReceivedProcesses(int result, | 315 void AdbPagesCommand::ReceivedProcesses(int result, |
464 const std::string& response) { | 316 const std::string& response) { |
465 if (result >= 0) | 317 if (result >= 0) |
466 ParseProcessList(response); | 318 ParseProcessList(response); |
467 | 319 |
468 if (browsers_.size() == 0) { | 320 if (browsers_.size() == 0) { |
469 devices_.pop_back(); | 321 devices_.pop_back(); |
470 ProcessSerials(); | 322 ProcessSerials(); |
471 } else { | 323 } else { |
472 ProcessSockets(); | 324 ProcessSockets(); |
473 } | 325 } |
474 } | 326 } |
475 | 327 |
476 void AdbPagesCommand::ProcessSockets() { | 328 void AdbPagesCommand::ProcessSockets() { |
477 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 329 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); |
478 if (browsers_.size() == 0) { | 330 if (browsers_.size() == 0) { |
479 devices_.pop_back(); | 331 devices_.pop_back(); |
480 ProcessSerials(); | 332 ProcessSerials(); |
481 } else { | 333 } else { |
482 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); | 334 scoped_refptr<AndroidDevice> device = devices_.back(); |
483 device->HttpQuery(browsers_.back()->socket(), kVersionRequest, | 335 device->HttpQuery(browsers_.back()->socket(), kVersionRequest, |
484 base::Bind(&AdbPagesCommand::ReceivedVersion, this)); | 336 base::Bind(&AdbPagesCommand::ReceivedVersion, this)); |
485 } | 337 } |
486 } | 338 } |
487 | 339 |
488 void AdbPagesCommand::ReceivedVersion(int result, | 340 void AdbPagesCommand::ReceivedVersion(int result, |
489 const std::string& response) { | 341 const std::string& response) { |
490 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 342 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); |
491 if (result < 0) { | 343 if (result < 0) { |
492 browsers_.pop_back(); | 344 browsers_.pop_back(); |
(...skipping 12 matching lines...) Expand all Loading... | |
505 if (parts.size() == 2) { | 357 if (parts.size() == 2) { |
506 if (parts[0] != "Version") // WebView has this for legacy reasons. | 358 if (parts[0] != "Version") // WebView has this for legacy reasons. |
507 browsers_.back()->set_product(parts[0]); | 359 browsers_.back()->set_product(parts[0]); |
508 browsers_.back()->set_version(parts[1]); | 360 browsers_.back()->set_version(parts[1]); |
509 } else { | 361 } else { |
510 browsers_.back()->set_version(browser); | 362 browsers_.back()->set_version(browser); |
511 } | 363 } |
512 } | 364 } |
513 } | 365 } |
514 | 366 |
515 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); | 367 scoped_refptr<AndroidDevice> device = devices_.back(); |
516 device->HttpQuery(browsers_.back()->socket(), kPageListRequest, | 368 device->HttpQuery(browsers_.back()->socket(), kPageListRequest, |
517 base::Bind(&AdbPagesCommand::ReceivedPages, this)); | 369 base::Bind(&AdbPagesCommand::ReceivedPages, this)); |
518 } | 370 } |
519 | 371 |
520 void AdbPagesCommand::ReceivedPages(int result, | 372 void AdbPagesCommand::ReceivedPages(int result, |
521 const std::string& response) { | 373 const std::string& response) { |
522 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); | 374 DCHECK_EQ(adb_thread_->message_loop(), base::MessageLoop::current()); |
523 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> browser = browsers_.back(); | 375 scoped_refptr<DevToolsAdbBridge::RemoteBrowser> browser = browsers_.back(); |
524 browsers_.pop_back(); | 376 browsers_.pop_back(); |
525 if (result < 0) { | 377 if (result < 0) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 | 510 |
659 remote_devices_->back()->set_screen_size(gfx::Size(width, height)); | 511 remote_devices_->back()->set_screen_size(gfx::Size(width, height)); |
660 } | 512 } |
661 | 513 |
662 | 514 |
663 // AdbProtocolCommand --------------------------------------------------------- | 515 // AdbProtocolCommand --------------------------------------------------------- |
664 | 516 |
665 class AdbProtocolCommand : public AdbWebSocket::Delegate { | 517 class AdbProtocolCommand : public AdbWebSocket::Delegate { |
666 public: | 518 public: |
667 AdbProtocolCommand( | 519 AdbProtocolCommand( |
668 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 520 scoped_refptr<RefCountedAdbThread> adb_thread, |
669 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, | 521 scoped_refptr<AndroidDevice> device, |
670 const std::string& socket_name, | 522 const std::string& socket_name, |
671 const std::string& debug_url, | 523 const std::string& debug_url, |
672 const std::string& command); | 524 const std::string& command); |
673 | 525 |
674 private: | 526 private: |
675 virtual void OnSocketOpened() OVERRIDE; | 527 virtual void OnSocketOpened() OVERRIDE; |
676 virtual void OnFrameRead(const std::string& message) OVERRIDE; | 528 virtual void OnFrameRead(const std::string& message) OVERRIDE; |
677 virtual void OnSocketClosed(bool closed_by_device) OVERRIDE; | 529 virtual void OnSocketClosed(bool closed_by_device) OVERRIDE; |
678 virtual bool ProcessIncomingMessage(const std::string& message) OVERRIDE; | 530 virtual bool ProcessIncomingMessage(const std::string& message) OVERRIDE; |
679 | 531 |
680 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread_; | 532 scoped_refptr<RefCountedAdbThread> adb_thread_; |
681 const std::string command_; | 533 const std::string command_; |
682 scoped_refptr<AdbWebSocket> web_socket_; | 534 scoped_refptr<AdbWebSocket> web_socket_; |
683 | 535 |
684 DISALLOW_COPY_AND_ASSIGN(AdbProtocolCommand); | 536 DISALLOW_COPY_AND_ASSIGN(AdbProtocolCommand); |
685 }; | 537 }; |
686 | 538 |
687 AdbProtocolCommand::AdbProtocolCommand( | 539 AdbProtocolCommand::AdbProtocolCommand( |
688 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 540 scoped_refptr<RefCountedAdbThread> adb_thread, |
689 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, | 541 scoped_refptr<AndroidDevice> device, |
690 const std::string& socket_name, | 542 const std::string& socket_name, |
691 const std::string& debug_url, | 543 const std::string& debug_url, |
692 const std::string& command) | 544 const std::string& command) |
693 : adb_thread_(adb_thread), | 545 : adb_thread_(adb_thread), |
694 command_(command) { | 546 command_(command) { |
695 web_socket_ = new AdbWebSocket( | 547 web_socket_ = new AdbWebSocket( |
696 device, socket_name, debug_url, adb_thread_->message_loop(), this); | 548 device, socket_name, debug_url, adb_thread_->message_loop(), this); |
697 } | 549 } |
698 | 550 |
699 void AdbProtocolCommand::OnSocketOpened() { | 551 void AdbProtocolCommand::OnSocketOpened() { |
(...skipping 15 matching lines...) Expand all Loading... | |
715 | 567 |
716 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote"; | 568 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote"; |
717 | 569 |
718 class AgentHostDelegate; | 570 class AgentHostDelegate; |
719 | 571 |
720 typedef std::map<std::string, AgentHostDelegate*> AgentHostDelegates; | 572 typedef std::map<std::string, AgentHostDelegate*> AgentHostDelegates; |
721 | 573 |
722 base::LazyInstance<AgentHostDelegates>::Leaky g_host_delegates = | 574 base::LazyInstance<AgentHostDelegates>::Leaky g_host_delegates = |
723 LAZY_INSTANCE_INITIALIZER; | 575 LAZY_INSTANCE_INITIALIZER; |
724 | 576 |
725 DevToolsAdbBridge::Wrapper::Wrapper(Profile* profile) | 577 DevToolsAdbBridge::Wrapper::Wrapper(Profile* profile) { |
726 : bridge_(new DevToolsAdbBridge(profile)) { | 578 bridge_ = new DevToolsAdbBridge(profile); |
727 } | 579 } |
728 | 580 |
729 DevToolsAdbBridge::Wrapper::~Wrapper() { | 581 DevToolsAdbBridge::Wrapper::~Wrapper() { |
730 } | 582 } |
731 | 583 |
732 DevToolsAdbBridge* DevToolsAdbBridge::Wrapper::Get() { | 584 DevToolsAdbBridge* DevToolsAdbBridge::Wrapper::Get() { |
733 return bridge_.get(); | 585 return bridge_.get(); |
734 } | 586 } |
735 | 587 |
736 // static | 588 // static |
(...skipping 17 matching lines...) Expand all Loading... | |
754 | 606 |
755 DevToolsAdbBridge::Factory::~Factory() {} | 607 DevToolsAdbBridge::Factory::~Factory() {} |
756 | 608 |
757 BrowserContextKeyedService* | 609 BrowserContextKeyedService* |
758 DevToolsAdbBridge::Factory::BuildServiceInstanceFor( | 610 DevToolsAdbBridge::Factory::BuildServiceInstanceFor( |
759 content::BrowserContext* context) const { | 611 content::BrowserContext* context) const { |
760 return new DevToolsAdbBridge::Wrapper(Profile::FromBrowserContext(context)); | 612 return new DevToolsAdbBridge::Wrapper(Profile::FromBrowserContext(context)); |
761 } | 613 } |
762 | 614 |
763 | 615 |
764 // DevToolsAdbBridge::AndroidDevice ------------------------------------------- | |
765 | |
766 DevToolsAdbBridge::AndroidDevice::AndroidDevice(const std::string& serial) | |
767 : serial_(serial) { | |
768 } | |
769 | |
770 void DevToolsAdbBridge::AndroidDevice::HttpQuery( | |
771 const std::string& la_name, | |
772 const std::string& request, | |
773 const CommandCallback& callback) { | |
774 OpenSocket(la_name, base::Bind(&AndroidDevice::OnHttpSocketOpened, this, | |
775 request, callback)); | |
776 } | |
777 | |
778 void DevToolsAdbBridge::AndroidDevice::HttpUpgrade( | |
779 const std::string& la_name, | |
780 const std::string& request, | |
781 const SocketCallback& callback) { | |
782 OpenSocket(la_name, base::Bind(&AndroidDevice::OnHttpSocketOpened2, this, | |
783 request, callback)); | |
784 } | |
785 | |
786 DevToolsAdbBridge::AndroidDevice::~AndroidDevice() { | |
787 } | |
788 | |
789 void DevToolsAdbBridge::AndroidDevice::OnHttpSocketOpened( | |
790 const std::string& request, | |
791 const CommandCallback& callback, | |
792 int result, | |
793 net::StreamSocket* socket) { | |
794 if (result != net::OK) { | |
795 callback.Run(result, std::string()); | |
796 return; | |
797 } | |
798 AdbClientSocket::HttpQuery(socket, request, callback); | |
799 } | |
800 | |
801 void DevToolsAdbBridge::AndroidDevice::OnHttpSocketOpened2( | |
802 const std::string& request, | |
803 const SocketCallback& callback, | |
804 int result, | |
805 net::StreamSocket* socket) { | |
806 if (result != net::OK) { | |
807 callback.Run(result, NULL); | |
808 return; | |
809 } | |
810 AdbClientSocket::HttpQuery(socket, request, callback); | |
811 } | |
812 | |
813 | |
814 // AgentHostDelegate ---------------------------------------------------------- | 616 // AgentHostDelegate ---------------------------------------------------------- |
815 | 617 |
816 class AgentHostDelegate : public content::DevToolsExternalAgentProxyDelegate, | 618 class AgentHostDelegate : public content::DevToolsExternalAgentProxyDelegate, |
817 public AdbWebSocket::Delegate { | 619 public AdbWebSocket::Delegate { |
818 public: | 620 public: |
819 AgentHostDelegate( | 621 AgentHostDelegate( |
820 const std::string& id, | 622 const std::string& id, |
821 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, | 623 scoped_refptr<AndroidDevice> device, |
822 const std::string& socket_name, | 624 const std::string& socket_name, |
823 const std::string& debug_url, | 625 const std::string& debug_url, |
824 const std::string& frontend_url, | 626 const std::string& frontend_url, |
825 base::MessageLoop* adb_message_loop, | 627 base::MessageLoop* adb_message_loop, |
826 Profile* profile) | 628 Profile* profile) |
827 : id_(id), | 629 : id_(id), |
828 serial_(device->serial()), | 630 serial_(device->serial()), |
829 frontend_url_(frontend_url), | 631 frontend_url_(frontend_url), |
830 adb_message_loop_(adb_message_loop), | 632 adb_message_loop_(adb_message_loop), |
831 profile_(profile) { | 633 profile_(profile) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
883 | 685 |
884 scoped_ptr<content::DevToolsExternalAgentProxy> proxy_; | 686 scoped_ptr<content::DevToolsExternalAgentProxy> proxy_; |
885 scoped_refptr<AdbWebSocket> web_socket_; | 687 scoped_refptr<AdbWebSocket> web_socket_; |
886 DISALLOW_COPY_AND_ASSIGN(AgentHostDelegate); | 688 DISALLOW_COPY_AND_ASSIGN(AgentHostDelegate); |
887 }; | 689 }; |
888 | 690 |
889 | 691 |
890 // DevToolsAdbBridge::RemotePage ---------------------------------------------- | 692 // DevToolsAdbBridge::RemotePage ---------------------------------------------- |
891 | 693 |
892 DevToolsAdbBridge::RemotePage::RemotePage( | 694 DevToolsAdbBridge::RemotePage::RemotePage( |
893 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 695 scoped_refptr<RefCountedAdbThread> adb_thread, |
894 scoped_refptr<AndroidDevice> device, | 696 scoped_refptr<AndroidDevice> device, |
895 const std::string& socket, | 697 const std::string& socket, |
896 const base::DictionaryValue& value) | 698 const base::DictionaryValue& value) |
897 : adb_thread_(adb_thread), | 699 : adb_thread_(adb_thread), |
898 device_(device), | 700 device_(device), |
899 socket_(socket) { | 701 socket_(socket) { |
900 value.GetString("id", &id_); | 702 value.GetString("id", &id_); |
901 value.GetString("url", &url_); | 703 value.GetString("url", &url_); |
902 value.GetString("title", &title_); | 704 value.GetString("title", &title_); |
903 value.GetString("description", &description_); | 705 value.GetString("description", &description_); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 return; | 769 return; |
968 DevToolsProtocol::Command command(1, method, params); | 770 DevToolsProtocol::Command command(1, method, params); |
969 new AdbProtocolCommand( | 771 new AdbProtocolCommand( |
970 adb_thread_, device_, socket_, debug_url_, command.Serialize()); | 772 adb_thread_, device_, socket_, debug_url_, command.Serialize()); |
971 } | 773 } |
972 | 774 |
973 DevToolsAdbBridge::RemotePage::~RemotePage() { | 775 DevToolsAdbBridge::RemotePage::~RemotePage() { |
974 } | 776 } |
975 | 777 |
976 void DevToolsAdbBridge::RemotePage::RequestActivate( | 778 void DevToolsAdbBridge::RemotePage::RequestActivate( |
977 const CommandCallback& callback) { | 779 const AndroidDevice::CommandCallback& callback) { |
978 std::string request = base::StringPrintf(kActivatePageRequest, id_.c_str()); | 780 std::string request = base::StringPrintf(kActivatePageRequest, id_.c_str()); |
979 adb_thread_->message_loop()->PostTask(FROM_HERE, | 781 adb_thread_->message_loop()->PostTask(FROM_HERE, |
980 base::Bind(&AndroidDevice::HttpQuery, | 782 base::Bind(&AndroidDevice::HttpQuery, |
981 device_, socket_, request, callback)); | 783 device_, socket_, request, callback)); |
982 } | 784 } |
983 | 785 |
984 void DevToolsAdbBridge::RemotePage::InspectOnHandlerThread( | 786 void DevToolsAdbBridge::RemotePage::InspectOnHandlerThread( |
985 Profile* profile, int result, const std::string& response) { | 787 Profile* profile, int result, const std::string& response) { |
986 BrowserThread::PostTask( | 788 BrowserThread::PostTask( |
987 BrowserThread::UI, FROM_HERE, | 789 BrowserThread::UI, FROM_HERE, |
(...skipping 10 matching lines...) Expand all Loading... | |
998 new AgentHostDelegate( | 800 new AgentHostDelegate( |
999 agent_id_, device_, socket_, debug_url_, | 801 agent_id_, device_, socket_, debug_url_, |
1000 frontend_url_, adb_thread_->message_loop(), profile); | 802 frontend_url_, adb_thread_->message_loop(), profile); |
1001 } | 803 } |
1002 } | 804 } |
1003 | 805 |
1004 | 806 |
1005 // DevToolsAdbBridge::RemoteBrowser ------------------------------------------- | 807 // DevToolsAdbBridge::RemoteBrowser ------------------------------------------- |
1006 | 808 |
1007 DevToolsAdbBridge::RemoteBrowser::RemoteBrowser( | 809 DevToolsAdbBridge::RemoteBrowser::RemoteBrowser( |
1008 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> adb_thread, | 810 scoped_refptr<RefCountedAdbThread> adb_thread, |
1009 scoped_refptr<AndroidDevice> device, | 811 scoped_refptr<AndroidDevice> device, |
1010 const std::string& socket) | 812 const std::string& socket) |
1011 : adb_thread_(adb_thread), | 813 : adb_thread_(adb_thread), |
1012 device_(device), | 814 device_(device), |
1013 socket_(socket) { | 815 socket_(socket) { |
1014 } | 816 } |
1015 | 817 |
1016 void DevToolsAdbBridge::RemoteBrowser::Open(const std::string& url) { | 818 void DevToolsAdbBridge::RemoteBrowser::Open(const std::string& url) { |
1017 adb_thread_->message_loop()->PostTask(FROM_HERE, | 819 adb_thread_->message_loop()->PostTask(FROM_HERE, |
1018 base::Bind(&AndroidDevice::HttpQuery, | 820 base::Bind(&AndroidDevice::HttpQuery, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 | 869 |
1068 void DevToolsAdbBridge::RemoteDevice::AddBrowser( | 870 void DevToolsAdbBridge::RemoteDevice::AddBrowser( |
1069 scoped_refptr<RemoteBrowser> browser) { | 871 scoped_refptr<RemoteBrowser> browser) { |
1070 browsers_.push_back(browser); | 872 browsers_.push_back(browser); |
1071 } | 873 } |
1072 | 874 |
1073 DevToolsAdbBridge::RemoteDevice::~RemoteDevice() { | 875 DevToolsAdbBridge::RemoteDevice::~RemoteDevice() { |
1074 } | 876 } |
1075 | 877 |
1076 | 878 |
1077 // DevToolsAdbBridge::RefCountedAdbThread ------------------------------------- | |
1078 | |
1079 DevToolsAdbBridge::RefCountedAdbThread* | |
1080 DevToolsAdbBridge::RefCountedAdbThread::instance_ = NULL; | |
1081 | |
1082 // static | |
1083 scoped_refptr<DevToolsAdbBridge::RefCountedAdbThread> | |
1084 DevToolsAdbBridge::RefCountedAdbThread::GetInstance() { | |
1085 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1086 if (!instance_) | |
1087 new RefCountedAdbThread(); | |
1088 return instance_; | |
1089 } | |
1090 | |
1091 DevToolsAdbBridge::RefCountedAdbThread::RefCountedAdbThread() { | |
1092 instance_ = this; | |
1093 thread_ = new base::Thread(kDevToolsAdbBridgeThreadName); | |
1094 base::Thread::Options options; | |
1095 options.message_loop_type = base::MessageLoop::TYPE_IO; | |
1096 if (!thread_->StartWithOptions(options)) { | |
1097 delete thread_; | |
1098 thread_ = NULL; | |
1099 } | |
1100 } | |
1101 | |
1102 base::MessageLoop* DevToolsAdbBridge::RefCountedAdbThread::message_loop() { | |
1103 return thread_ ? thread_->message_loop() : NULL; | |
1104 } | |
1105 | |
1106 // static | |
1107 void DevToolsAdbBridge::RefCountedAdbThread::StopThread(base::Thread* thread) { | |
1108 thread->Stop(); | |
1109 } | |
1110 | |
1111 DevToolsAdbBridge::RefCountedAdbThread::~RefCountedAdbThread() { | |
1112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1113 instance_ = NULL; | |
1114 if (!thread_) | |
1115 return; | |
1116 // Shut down thread on FILE thread to join into IO. | |
1117 BrowserThread::PostTask( | |
1118 BrowserThread::FILE, FROM_HERE, | |
1119 base::Bind(&RefCountedAdbThread::StopThread, thread_)); | |
1120 } | |
1121 | |
1122 | |
1123 // DevToolsAdbBridge ---------------------------------------------------------- | 879 // DevToolsAdbBridge ---------------------------------------------------------- |
1124 | 880 |
1125 DevToolsAdbBridge::DevToolsAdbBridge(Profile* profile) | 881 DevToolsAdbBridge::DevToolsAdbBridge(Profile* profile) |
1126 : adb_thread_(RefCountedAdbThread::GetInstance()), | 882 : profile_(profile), |
883 adb_thread_(RefCountedAdbThread::GetInstance()), | |
1127 has_message_loop_(adb_thread_->message_loop() != NULL), | 884 has_message_loop_(adb_thread_->message_loop() != NULL), |
1128 discover_usb_devices_(false) { | 885 discover_usb_devices_(false) { |
1129 rsa_key_.reset(AndroidRSAPrivateKey(profile)); | |
1130 } | 886 } |
1131 | 887 |
1132 void DevToolsAdbBridge::AddListener(Listener* listener) { | 888 void DevToolsAdbBridge::AddListener(Listener* listener) { |
1133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1134 if (listeners_.empty()) | 890 if (listeners_.empty()) |
1135 RequestRemoteDevices(); | 891 RequestRemoteDevices(); |
1136 listeners_.push_back(listener); | 892 listeners_.push_back(listener); |
1137 } | 893 } |
1138 | 894 |
1139 void DevToolsAdbBridge::RemoveListener(Listener* listener) { | 895 void DevToolsAdbBridge::RemoveListener(Listener* listener) { |
(...skipping 16 matching lines...) Expand all Loading... | |
1156 | 912 |
1157 DevToolsAdbBridge::~DevToolsAdbBridge() { | 913 DevToolsAdbBridge::~DevToolsAdbBridge() { |
1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1159 DCHECK(listeners_.empty()); | 915 DCHECK(listeners_.empty()); |
1160 } | 916 } |
1161 | 917 |
1162 void DevToolsAdbBridge::RequestRemoteDevices() { | 918 void DevToolsAdbBridge::RequestRemoteDevices() { |
1163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1164 if (!has_message_loop_) | 920 if (!has_message_loop_) |
1165 return; | 921 return; |
922 | |
923 DeviceProviders device_providers; | |
Vladislav Kaznacheev
2013/10/17 20:17:37
Here is what I do not understand:
The whole point
Dmitry Zvorygin
2013/10/21 07:40:29
Done.
Overengineered a little. Earlier devices we
| |
924 | |
925 if (discover_usb_devices_) | |
926 device_providers.push_back( | |
927 new UsbDeviceProvider(profile_, RefCountedAdbThread::GetInstance())); | |
Vladislav Kaznacheev
2013/10/17 20:17:37
It's OK to call RefCountedAdbThread::GetInstance()
Dmitry Zvorygin
2013/10/21 07:40:29
Done.
| |
928 | |
929 device_providers.push_back( | |
930 new AdbDeviceProvider(RefCountedAdbThread::GetInstance())); | |
Vladislav Kaznacheev
2013/10/17 20:17:37
Same here.
Dmitry Zvorygin
2013/10/21 07:40:29
Done.
| |
931 | |
1166 new AdbPagesCommand( | 932 new AdbPagesCommand( |
1167 adb_thread_, rsa_key_.get(), discover_usb_devices_, | 933 adb_thread_, device_providers, |
1168 base::Bind(&DevToolsAdbBridge::ReceivedRemoteDevices, this)); | 934 base::Bind(&DevToolsAdbBridge::ReceivedRemoteDevices, this)); |
1169 } | 935 } |
1170 | 936 |
1171 void DevToolsAdbBridge::ReceivedRemoteDevices(RemoteDevices* devices_ptr) { | 937 void DevToolsAdbBridge::ReceivedRemoteDevices(RemoteDevices* devices_ptr) { |
1172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1173 | 939 |
1174 scoped_ptr<RemoteDevices> devices(devices_ptr); | 940 scoped_ptr<RemoteDevices> devices(devices_ptr); |
1175 | 941 |
1176 Listeners copy(listeners_); | 942 Listeners copy(listeners_); |
1177 for (Listeners::iterator it = copy.begin(); it != copy.end(); ++it) | 943 for (Listeners::iterator it = copy.begin(); it != copy.end(); ++it) |
1178 (*it)->RemoteDevicesChanged(devices.get()); | 944 (*it)->RemoteDevicesChanged(devices.get()); |
1179 | 945 |
1180 if (listeners_.empty()) | 946 if (listeners_.empty()) |
1181 return; | 947 return; |
1182 | 948 |
1183 BrowserThread::PostDelayedTask( | 949 BrowserThread::PostDelayedTask( |
1184 BrowserThread::UI, | 950 BrowserThread::UI, |
1185 FROM_HERE, | 951 FROM_HERE, |
1186 base::Bind(&DevToolsAdbBridge::RequestRemoteDevices, this), | 952 base::Bind(&DevToolsAdbBridge::RequestRemoteDevices, this), |
1187 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); | 953 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); |
1188 } | 954 } |
OLD | NEW |