OLD | NEW |
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_client_socket.h" | 5 #include "chrome/browser/devtools/device/adb/adb_client_socket.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
13 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
14 #include "net/socket/tcp_client_socket.h" | 15 #include "net/socket/tcp_client_socket.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 const int kBufferSize = 16 * 1024; | 19 const int kBufferSize = 16 * 1024; |
19 const char kOkayResponse[] = "OKAY"; | 20 const char kOkayResponse[] = "OKAY"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 }; | 89 }; |
89 | 90 |
90 class AdbQuerySocket : AdbClientSocket { | 91 class AdbQuerySocket : AdbClientSocket { |
91 public: | 92 public: |
92 AdbQuerySocket(int port, | 93 AdbQuerySocket(int port, |
93 const std::string& query, | 94 const std::string& query, |
94 const CommandCallback& callback) | 95 const CommandCallback& callback) |
95 : AdbClientSocket(port), | 96 : AdbClientSocket(port), |
96 current_query_(0), | 97 current_query_(0), |
97 callback_(callback) { | 98 callback_(callback) { |
98 if (Tokenize(query, "|", &queries_) == 0) { | 99 queries_ = base::SplitString(query, "|", base::KEEP_WHITESPACE, |
| 100 base::SPLIT_WANT_NONEMPTY); |
| 101 if (queries_.empty()) { |
99 CheckNetResultOrDie(net::ERR_INVALID_ARGUMENT); | 102 CheckNetResultOrDie(net::ERR_INVALID_ARGUMENT); |
100 return; | 103 return; |
101 } | 104 } |
102 Connect(base::Bind(&AdbQuerySocket::SendNextQuery, | 105 Connect(base::Bind(&AdbQuerySocket::SendNextQuery, |
103 base::Unretained(this))); | 106 base::Unretained(this))); |
104 } | 107 } |
105 | 108 |
106 private: | 109 private: |
107 ~AdbQuerySocket() { | 110 ~AdbQuerySocket() { |
108 } | 111 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 base::Unretained(this), | 287 base::Unretained(this), |
285 callback, | 288 callback, |
286 new_response, | 289 new_response, |
287 response_buffer, | 290 response_buffer, |
288 bytes_left)); | 291 bytes_left)); |
289 if (result > 0) | 292 if (result > 0) |
290 OnResponseData(callback, new_response, response_buffer, bytes_left, result); | 293 OnResponseData(callback, new_response, response_buffer, bytes_left, result); |
291 else if (result != net::ERR_IO_PENDING) | 294 else if (result != net::ERR_IO_PENDING) |
292 callback.Run(net::OK, new_response); | 295 callback.Run(net::OK, new_response); |
293 } | 296 } |
OLD | NEW |