Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / devtools / device / adb / adb_device_provider.cc
blob9f5b33a916da3f6f050293f4721f05f7a87d0898
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/devtools/device/adb/adb_device_provider.h"
7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/devtools/device/adb/adb_client_socket.h"
11 namespace {
13 const char kHostDevicesCommand[] = "host:devices";
14 const char kHostTransportCommand[] = "host:transport:%s|%s";
15 const char kLocalAbstractCommand[] = "localabstract:%s";
17 const int kAdbPort = 5037;
19 static void RunCommand(const std::string& serial,
20 const std::string& command,
21 const AdbDeviceProvider::CommandCallback& callback) {
22 std::string query = base::StringPrintf(
23 kHostTransportCommand, serial.c_str(), command.c_str());
24 AdbClientSocket::AdbQuery(kAdbPort, query, callback);
27 static void ReceivedAdbDevices(
28 const AdbDeviceProvider::SerialsCallback& callback,
29 int result_code,
30 const std::string& response) {
31 std::vector<std::string> result;
32 if (result_code < 0) {
33 callback.Run(result);
34 return;
36 std::vector<std::string> serials;
37 Tokenize(response, "\n", &serials);
38 for (size_t i = 0; i < serials.size(); ++i) {
39 std::vector<std::string> tokens;
40 Tokenize(serials[i], "\t ", &tokens);
41 result.push_back(tokens[0]);
43 callback.Run(result);
46 } // namespace
48 void AdbDeviceProvider::QueryDevices(const SerialsCallback& callback) {
49 AdbClientSocket::AdbQuery(
50 kAdbPort, kHostDevicesCommand, base::Bind(&ReceivedAdbDevices, callback));
53 void AdbDeviceProvider::QueryDeviceInfo(const std::string& serial,
54 const DeviceInfoCallback& callback) {
55 AndroidDeviceManager::QueryDeviceInfo(base::Bind(&RunCommand, serial),
56 callback);
59 void AdbDeviceProvider::OpenSocket(const std::string& serial,
60 const std::string& socket_name,
61 const SocketCallback& callback) {
62 std::string request =
63 base::StringPrintf(kLocalAbstractCommand, socket_name.c_str());
64 AdbClientSocket::TransportQuery(kAdbPort, serial, request, callback);
67 AdbDeviceProvider::~AdbDeviceProvider() {