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 "url_request_adapter.h" | 5 #include "url_request_adapter.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 // Reads all available data or starts an asynchronous read. | 204 // Reads all available data or starts an asynchronous read. |
205 void URLRequestAdapter::Read() { | 205 void URLRequestAdapter::Read() { |
206 while (true) { | 206 while (true) { |
207 if (read_buffer_->RemainingCapacity() == 0) { | 207 if (read_buffer_->RemainingCapacity() == 0) { |
208 int new_capacity = read_buffer_->capacity() + kBufferSizeIncrement; | 208 int new_capacity = read_buffer_->capacity() + kBufferSizeIncrement; |
209 read_buffer_->SetCapacity(new_capacity); | 209 read_buffer_->SetCapacity(new_capacity); |
210 } | 210 } |
211 | 211 |
212 int bytes_read; | 212 int bytes_read; |
213 if (url_request_->Read( | 213 if (url_request_->Read(read_buffer_.get(), |
214 read_buffer_, read_buffer_->RemainingCapacity(), &bytes_read)) { | 214 read_buffer_->RemainingCapacity(), |
| 215 &bytes_read)) { |
215 if (bytes_read == 0) { | 216 if (bytes_read == 0) { |
216 OnRequestSucceeded(); | 217 OnRequestSucceeded(); |
217 break; | 218 break; |
218 } | 219 } |
219 | 220 |
220 VLOG(1) << "Synchronously read: " << bytes_read << " bytes"; | 221 VLOG(1) << "Synchronously read: " << bytes_read << " bytes"; |
221 OnBytesRead(bytes_read); | 222 OnBytesRead(bytes_read); |
222 } else if (url_request_->status().status() == | 223 } else if (url_request_->status().status() == |
223 net::URLRequestStatus::IO_PENDING) { | 224 net::URLRequestStatus::IO_PENDING) { |
224 if (bytes_read_ != 0) { | 225 if (bytes_read_ != 0) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 291 |
291 delegate_->OnBytesRead(this); | 292 delegate_->OnBytesRead(this); |
292 delegate_->OnRequestFinished(this); | 293 delegate_->OnRequestFinished(this); |
293 } | 294 } |
294 | 295 |
295 unsigned char* URLRequestAdapter::Data() const { | 296 unsigned char* URLRequestAdapter::Data() const { |
296 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); | 297 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); |
297 } | 298 } |
298 | 299 |
299 } // namespace cronet | 300 } // namespace cronet |
OLD | NEW |