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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 static const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread"; | 45 static const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread"; |
46 static const char kHostDevicesCommand[] = "host:devices"; | 46 static const char kHostDevicesCommand[] = "host:devices"; |
47 static const char kHostTransportCommand[] = "host:transport:%s|%s"; | 47 static const char kHostTransportCommand[] = "host:transport:%s|%s"; |
48 static const char kLocalAbstractCommand[] = "localabstract:%s"; | 48 static const char kLocalAbstractCommand[] = "localabstract:%s"; |
49 static const char kDeviceModelCommand[] = "shell:getprop ro.product.model"; | 49 static const char kDeviceModelCommand[] = "shell:getprop ro.product.model"; |
50 static const char kLocalChrome[] = "Local Chrome"; | 50 static const char kLocalChrome[] = "Local Chrome"; |
51 static const char kChrome[] = "Chrome"; | 51 static const char kChrome[] = "Chrome"; |
52 static const char kOpenedUnixSocketsCommand[] = "shell:cat /proc/net/unix"; | 52 static const char kOpenedUnixSocketsCommand[] = "shell:cat /proc/net/unix"; |
53 static const char kListProcessesCommand[] = "shell:ps"; | 53 static const char kListProcessesCommand[] = "shell:ps"; |
| 54 static const char kDumpsysCommand[] = "shell:dumpsys window policy"; |
| 55 static const char kDumpsysScreenSizePrefix[] = "mStable="; |
54 | 56 |
55 static const char kPageListRequest[] = "GET /json HTTP/1.1\r\n\r\n"; | 57 static const char kPageListRequest[] = "GET /json HTTP/1.1\r\n\r\n"; |
56 static const char kVersionRequest[] = "GET /json/version HTTP/1.1\r\n\r\n"; | 58 static const char kVersionRequest[] = "GET /json/version HTTP/1.1\r\n\r\n"; |
57 static const char kClosePageRequest[] = "GET /json/close/%s HTTP/1.1\r\n\r\n"; | 59 static const char kClosePageRequest[] = "GET /json/close/%s HTTP/1.1\r\n\r\n"; |
58 static const char kNewPageRequest[] = "GET /json/new HTTP/1.1\r\n\r\n"; | 60 static const char kNewPageRequest[] = "GET /json/new HTTP/1.1\r\n\r\n"; |
59 static const char kActivatePageRequest[] = | 61 static const char kActivatePageRequest[] = |
60 "GET /json/activate/%s HTTP/1.1\r\n\r\n"; | 62 "GET /json/activate/%s HTTP/1.1\r\n\r\n"; |
61 const int kAdbPort = 5037; | 63 const int kAdbPort = 5037; |
62 const int kBufferSize = 16 * 1024; | 64 const int kBufferSize = 16 * 1024; |
63 const int kAdbPollingIntervalMs = 1000; | 65 const int kAdbPollingIntervalMs = 1000; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 void ReceivedSockets(int result, const std::string& response) { | 290 void ReceivedSockets(int result, const std::string& response) { |
289 DCHECK_EQ(bridge_->GetAdbMessageLoop(), base::MessageLoop::current()); | 291 DCHECK_EQ(bridge_->GetAdbMessageLoop(), base::MessageLoop::current()); |
290 if (result < 0) { | 292 if (result < 0) { |
291 devices_.pop_back(); | 293 devices_.pop_back(); |
292 ProcessSerials(); | 294 ProcessSerials(); |
293 return; | 295 return; |
294 } | 296 } |
295 | 297 |
296 ParseSocketsList(response); | 298 ParseSocketsList(response); |
297 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); | 299 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); |
| 300 device->RunCommand(kDumpsysCommand, |
| 301 base::Bind(&AdbPagesCommand::ReceivedDumpsys, this)); |
| 302 } |
| 303 |
| 304 void ReceivedDumpsys(int result, const std::string& response) { |
| 305 DCHECK_EQ(bridge_->GetAdbMessageLoop(), base::MessageLoop::current()); |
| 306 if (result >= 0) |
| 307 ParseDumpsysResponse(response); |
| 308 |
| 309 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device = devices_.back(); |
298 device->RunCommand(kListProcessesCommand, | 310 device->RunCommand(kListProcessesCommand, |
299 base::Bind(&AdbPagesCommand::ReceivedProcesses, this)); | 311 base::Bind(&AdbPagesCommand::ReceivedProcesses, this)); |
300 } | 312 } |
301 | 313 |
302 void ReceivedProcesses(int result, const std::string& response) { | 314 void ReceivedProcesses(int result, const std::string& response) { |
303 if (result >= 0) | 315 if (result >= 0) |
304 ParseProcessList(response); | 316 ParseProcessList(response); |
305 | 317 |
306 if (browsers_.size() == 0) { | 318 if (browsers_.size() == 0) { |
307 devices_.pop_back(); | 319 devices_.pop_back(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 DevToolsAdbBridge::RemoteBrowsers browsers = | 470 DevToolsAdbBridge::RemoteBrowsers browsers = |
459 remote_devices_->back()->browsers(); | 471 remote_devices_->back()->browsers(); |
460 for (DevToolsAdbBridge::RemoteBrowsers::iterator it = browsers.begin(); | 472 for (DevToolsAdbBridge::RemoteBrowsers::iterator it = browsers.begin(); |
461 it != browsers.end(); ++it) { | 473 it != browsers.end(); ++it) { |
462 StringMap::iterator pit = pid_to_package.find((*it)->pid()); | 474 StringMap::iterator pit = pid_to_package.find((*it)->pid()); |
463 if (pit != pid_to_package.end()) | 475 if (pit != pid_to_package.end()) |
464 (*it)->set_package(pit->second); | 476 (*it)->set_package(pit->second); |
465 } | 477 } |
466 } | 478 } |
467 | 479 |
| 480 void ParseDumpsysResponse(const std::string& response) { |
| 481 std::vector<std::string> lines; |
| 482 Tokenize(response, "\r", &lines); |
| 483 for (size_t i = 0; i < lines.size(); ++i) { |
| 484 std::string line = lines[i]; |
| 485 size_t pos = line.find(kDumpsysScreenSizePrefix); |
| 486 if (pos != std::string::npos) { |
| 487 ParseScreenSize( |
| 488 line.substr(pos + std::string(kDumpsysScreenSizePrefix).size())); |
| 489 break; |
| 490 } |
| 491 } |
| 492 } |
| 493 |
| 494 void ParseScreenSize(const std::string& str) { |
| 495 std::vector<std::string> pairs; |
| 496 Tokenize(str, "-", &pairs); |
| 497 if (pairs.size() != 2) |
| 498 return; |
| 499 |
| 500 int width; |
| 501 int height; |
| 502 std::vector<std::string> numbers; |
| 503 Tokenize(pairs[1].substr(1, pairs[1].size() - 2), ",", &numbers); |
| 504 if (numbers.size() != 2 || |
| 505 !base::StringToInt(numbers[0], &width) || |
| 506 !base::StringToInt(numbers[1], &height)) |
| 507 return; |
| 508 |
| 509 remote_devices_->back()->SetScreenSize(gfx::Size(width, height)); |
| 510 } |
| 511 |
468 scoped_refptr<DevToolsAdbBridge> bridge_; | 512 scoped_refptr<DevToolsAdbBridge> bridge_; |
469 Callback callback_; | 513 Callback callback_; |
470 AndroidDevices devices_; | 514 AndroidDevices devices_; |
471 DevToolsAdbBridge::RemoteBrowsers browsers_; | 515 DevToolsAdbBridge::RemoteBrowsers browsers_; |
472 scoped_ptr<DevToolsAdbBridge::RemoteDevices> remote_devices_; | 516 scoped_ptr<DevToolsAdbBridge::RemoteDevices> remote_devices_; |
473 }; | 517 }; |
474 | 518 |
475 // AdbProtocolCommand --------------------------------------------------------- | 519 // AdbProtocolCommand --------------------------------------------------------- |
476 | 520 |
477 class AdbProtocolCommand : public AdbWebSocket::Delegate { | 521 class AdbProtocolCommand : public AdbWebSocket::Delegate { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 | 992 |
949 if (listeners_.empty()) | 993 if (listeners_.empty()) |
950 return; | 994 return; |
951 | 995 |
952 BrowserThread::PostDelayedTask( | 996 BrowserThread::PostDelayedTask( |
953 BrowserThread::UI, | 997 BrowserThread::UI, |
954 FROM_HERE, | 998 FROM_HERE, |
955 base::Bind(&DevToolsAdbBridge::RequestRemoteDevices, this), | 999 base::Bind(&DevToolsAdbBridge::RequestRemoteDevices, this), |
956 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); | 1000 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); |
957 } | 1001 } |
OLD | NEW |