Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: chrome/browser/devtools/device/adb/adb_device_provider.cc

Issue 1197243004: Replace some Tokenize calls with SplitString. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/device/adb/adb_device_provider.h" 5 #include "chrome/browser/devtools/device/adb/adb_device_provider.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_split.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/devtools/device/adb/adb_client_socket.h" 9 #include "chrome/browser/devtools/device/adb/adb_client_socket.h"
10 10
11 namespace { 11 namespace {
12 12
13 const char kHostDevicesCommand[] = "host:devices"; 13 const char kHostDevicesCommand[] = "host:devices";
14 const char kHostTransportCommand[] = "host:transport:%s|%s"; 14 const char kHostTransportCommand[] = "host:transport:%s|%s";
15 const char kLocalAbstractCommand[] = "localabstract:%s"; 15 const char kLocalAbstractCommand[] = "localabstract:%s";
16 16
17 const int kAdbPort = 5037; 17 const int kAdbPort = 5037;
18 18
19 static void RunCommand(const std::string& serial, 19 static void RunCommand(const std::string& serial,
20 const std::string& command, 20 const std::string& command,
21 const AdbDeviceProvider::CommandCallback& callback) { 21 const AdbDeviceProvider::CommandCallback& callback) {
22 std::string query = base::StringPrintf( 22 std::string query = base::StringPrintf(
23 kHostTransportCommand, serial.c_str(), command.c_str()); 23 kHostTransportCommand, serial.c_str(), command.c_str());
24 AdbClientSocket::AdbQuery(kAdbPort, query, callback); 24 AdbClientSocket::AdbQuery(kAdbPort, query, callback);
25 } 25 }
26 26
27 static void ReceivedAdbDevices( 27 static void ReceivedAdbDevices(
28 const AdbDeviceProvider::SerialsCallback& callback, 28 const AdbDeviceProvider::SerialsCallback& callback,
29 int result_code, 29 int result_code,
30 const std::string& response) { 30 const std::string& response) {
31 std::vector<std::string> result; 31 std::vector<std::string> result;
32 if (result_code < 0) { 32 if (result_code < 0) {
33 callback.Run(result); 33 callback.Run(result);
34 return; 34 return;
35 } 35 }
36 std::vector<std::string> serials; 36 for (const base::StringPiece& line :
37 Tokenize(response, "\n", &serials); 37 base::SplitStringPiece(response, "\n", base::KEEP_WHITESPACE,
38 for (size_t i = 0; i < serials.size(); ++i) { 38 base::SPLIT_WANT_NONEMPTY)) {
39 std::vector<std::string> tokens; 39 std::vector<base::StringPiece> tokens =
40 Tokenize(serials[i], "\t ", &tokens); 40 base::SplitStringPiece(line, "\t ", base::KEEP_WHITESPACE,
41 result.push_back(tokens[0]); 41 base::SPLIT_WANT_NONEMPTY);
42 result.push_back(tokens[0].as_string());
42 } 43 }
43 callback.Run(result); 44 callback.Run(result);
44 } 45 }
45 46
46 } // namespace 47 } // namespace
47 48
48 void AdbDeviceProvider::QueryDevices(const SerialsCallback& callback) { 49 void AdbDeviceProvider::QueryDevices(const SerialsCallback& callback) {
49 AdbClientSocket::AdbQuery( 50 AdbClientSocket::AdbQuery(
50 kAdbPort, kHostDevicesCommand, base::Bind(&ReceivedAdbDevices, callback)); 51 kAdbPort, kHostDevicesCommand, base::Bind(&ReceivedAdbDevices, callback));
51 } 52 }
52 53
53 void AdbDeviceProvider::QueryDeviceInfo(const std::string& serial, 54 void AdbDeviceProvider::QueryDeviceInfo(const std::string& serial,
54 const DeviceInfoCallback& callback) { 55 const DeviceInfoCallback& callback) {
55 AndroidDeviceManager::QueryDeviceInfo(base::Bind(&RunCommand, serial), 56 AndroidDeviceManager::QueryDeviceInfo(base::Bind(&RunCommand, serial),
56 callback); 57 callback);
57 } 58 }
58 59
59 void AdbDeviceProvider::OpenSocket(const std::string& serial, 60 void AdbDeviceProvider::OpenSocket(const std::string& serial,
60 const std::string& socket_name, 61 const std::string& socket_name,
61 const SocketCallback& callback) { 62 const SocketCallback& callback) {
62 std::string request = 63 std::string request =
63 base::StringPrintf(kLocalAbstractCommand, socket_name.c_str()); 64 base::StringPrintf(kLocalAbstractCommand, socket_name.c_str());
64 AdbClientSocket::TransportQuery(kAdbPort, serial, request, callback); 65 AdbClientSocket::TransportQuery(kAdbPort, serial, request, callback);
65 } 66 }
66 67
67 AdbDeviceProvider::~AdbDeviceProvider() { 68 AdbDeviceProvider::~AdbDeviceProvider() {
68 } 69 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/adb/adb_client_socket.cc ('k') | chrome/browser/devtools/device/adb/mock_adb_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698