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/adb_client_socket.h" | 5 #include "chrome/browser/devtools/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_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 if (!CheckNetResultOrDie(result)) | 151 if (!CheckNetResultOrDie(result)) |
152 return; | 152 return; |
153 if (result == 0) { | 153 if (result == 0) { |
154 CheckNetResultOrDie(net::ERR_CONNECTION_CLOSED); | 154 CheckNetResultOrDie(net::ERR_CONNECTION_CLOSED); |
155 return; | 155 return; |
156 } | 156 } |
157 | 157 |
158 response_ += std::string(response_buffer->data(), result); | 158 response_ += std::string(response_buffer->data(), result); |
159 int expected_length = 0; | 159 int expected_length = 0; |
160 if (bytes_total < 0) { | 160 if (bytes_total < 0) { |
| 161 // TODO(kaznacheev): Use net::HttpResponseHeader to parse the header. |
161 size_t content_pos = response_.find("Content-Length:"); | 162 size_t content_pos = response_.find("Content-Length:"); |
162 if (content_pos != std::string::npos) { | 163 if (content_pos != std::string::npos) { |
163 size_t endline_pos = response_.find("\n", content_pos); | 164 size_t endline_pos = response_.find("\n", content_pos); |
164 if (endline_pos != std::string::npos) { | 165 if (endline_pos != std::string::npos) { |
165 std::string len = response_.substr(content_pos + 15, | 166 std::string len = response_.substr(content_pos + 15, |
166 endline_pos - content_pos - 15); | 167 endline_pos - content_pos - 15); |
167 TrimWhitespace(len, TRIM_ALL, &len); | 168 TrimWhitespace(len, TRIM_ALL, &len); |
168 if (!base::StringToInt(len, &expected_length)) { | 169 if (!base::StringToInt(len, &expected_length)) { |
169 CheckNetResultOrDie(net::ERR_FAILED); | 170 CheckNetResultOrDie(net::ERR_FAILED); |
170 return; | 171 return; |
171 } | 172 } |
172 } | 173 } |
173 } | 174 } |
174 | 175 |
175 body_pos_ = response_.find("\r\n\r\n"); | 176 body_pos_ = response_.find("\r\n\r\n"); |
176 if (body_pos_ != std::string::npos) { | 177 if (body_pos_ != std::string::npos) { |
177 body_pos_ += 4; | 178 body_pos_ += 4; |
178 bytes_total = body_pos_ + expected_length; | 179 bytes_total = body_pos_ + expected_length; |
179 } | 180 } |
180 } | 181 } |
181 | 182 |
182 if (bytes_total == static_cast<int>(response_.length())) { | 183 if (bytes_total == static_cast<int>(response_.length())) { |
183 if (!command_callback_.is_null()) | 184 if (!command_callback_.is_null()) |
184 command_callback_.Run(body_pos_, response_); | 185 command_callback_.Run(net::OK, response_.substr(body_pos_)); |
185 else | 186 else |
186 socket_callback_.Run(net::OK, socket_.release()); | 187 socket_callback_.Run(net::OK, socket_.release()); |
187 delete this; | 188 delete this; |
188 return; | 189 return; |
189 } | 190 } |
190 | 191 |
191 result = socket_->Read(response_buffer.get(), | 192 result = socket_->Read(response_buffer.get(), |
192 kBufferSize, | 193 kBufferSize, |
193 base::Bind(&HttpOverAdbSocket::OnResponseData, | 194 base::Bind(&HttpOverAdbSocket::OnResponseData, |
194 base::Unretained(this), | 195 base::Unretained(this), |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 base::Unretained(this), | 454 base::Unretained(this), |
454 callback, | 455 callback, |
455 new_response, | 456 new_response, |
456 response_buffer, | 457 response_buffer, |
457 bytes_left)); | 458 bytes_left)); |
458 if (result > 0) | 459 if (result > 0) |
459 OnResponseData(callback, new_response, response_buffer, bytes_left, result); | 460 OnResponseData(callback, new_response, response_buffer, bytes_left, result); |
460 else if (result != net::ERR_IO_PENDING) | 461 else if (result != net::ERR_IO_PENDING) |
461 callback.Run(net::OK, new_response); | 462 callback.Run(net::OK, new_response); |
462 } | 463 } |
OLD | NEW |