| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/url_request_simple_job.h" | 5 #include "net/url_request/url_request_simple_job.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 URLRequestSimpleJob::~URLRequestSimpleJob() {} | 46 URLRequestSimpleJob::~URLRequestSimpleJob() {} |
| 47 | 47 |
| 48 bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size, | 48 bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size, |
| 49 int* bytes_read) { | 49 int* bytes_read) { |
| 50 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. | 50 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. |
| 51 tracked_objects::ScopedTracker tracking_profile( | 51 tracked_objects::ScopedTracker tracking_profile( |
| 52 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 52 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 53 "422489 URLRequestSimpleJob::ReadRawData")); | 53 "422489 URLRequestSimpleJob::ReadRawData")); |
| 54 | 54 |
| 55 DCHECK(bytes_read); | 55 DCHECK(bytes_read); |
| 56 int remaining = byte_range_.last_byte_position() - data_offset_ + 1; | 56 buf_size = static_cast<int>(std::min( |
| 57 if (buf_size > remaining) | 57 static_cast<int64>(buf_size), |
| 58 buf_size = remaining; | 58 byte_range_.last_byte_position() - data_offset_ + 1)); |
| 59 memcpy(buf->data(), data_->front() + data_offset_, buf_size); | 59 memcpy(buf->data(), data_->front() + data_offset_, buf_size); |
| 60 data_offset_ += buf_size; | 60 data_offset_ += buf_size; |
| 61 *bytes_read = buf_size; | 61 *bytes_read = buf_size; |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 int URLRequestSimpleJob::GetData(std::string* mime_type, | 65 int URLRequestSimpleJob::GetData(std::string* mime_type, |
| 66 std::string* charset, | 66 std::string* charset, |
| 67 std::string* data, | 67 std::string* data, |
| 68 const CompletionCallback& callback) const { | 68 const CompletionCallback& callback) const { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 131 |
| 132 if (result == OK) { | 132 if (result == OK) { |
| 133 // Notify that the headers are complete | 133 // Notify that the headers are complete |
| 134 if (!byte_range_.ComputeBounds(data_->size())) { | 134 if (!byte_range_.ComputeBounds(data_->size())) { |
| 135 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 135 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 136 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 136 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 137 return; | 137 return; |
| 138 } | 138 } |
| 139 | 139 |
| 140 data_offset_ = byte_range_.first_byte_position(); | 140 data_offset_ = byte_range_.first_byte_position(); |
| 141 int remaining_bytes = byte_range_.last_byte_position() - | 141 set_expected_content_size( |
| 142 byte_range_.first_byte_position() + 1; | 142 byte_range_.last_byte_position() - data_offset_ + 1); |
| 143 set_expected_content_size(remaining_bytes); | |
| 144 NotifyHeadersComplete(); | 143 NotifyHeadersComplete(); |
| 145 } else { | 144 } else { |
| 146 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 145 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 150 } // namespace net | 149 } // namespace net |
| OLD | NEW |