| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 DCHECK(bytes_read); | 49 DCHECK(bytes_read); |
| 50 int remaining = byte_range_.last_byte_position() - data_offset_ + 1; | 50 int remaining = byte_range_.last_byte_position() - data_offset_ + 1; |
| 51 if (buf_size > remaining) | 51 if (buf_size > remaining) |
| 52 buf_size = remaining; | 52 buf_size = remaining; |
| 53 memcpy(buf->data(), data_.data() + data_offset_, buf_size); | 53 memcpy(buf->data(), data_.data() + data_offset_, buf_size); |
| 54 data_offset_ += buf_size; | 54 data_offset_ += buf_size; |
| 55 *bytes_read = buf_size; | 55 *bytes_read = buf_size; |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 int URLRequestSimpleJob::GetData(std::string* mime_type, |
| 60 std::string* charset, |
| 61 std::string* data, |
| 62 const CompletionCallback& callback) const { |
| 63 NOTREACHED(); |
| 64 return ERR_UNEXPECTED; |
| 65 } |
| 66 |
| 67 int URLRequestSimpleJob::GetStringPieceData( |
| 68 std::string* mime_type, |
| 69 std::string* charset, |
| 70 base::StringPiece* data, |
| 71 const CompletionCallback& callback) { |
| 72 int result = GetData(mime_type, charset, &data_storage_, callback); |
| 73 *data = data_storage_; |
| 74 return result; |
| 75 } |
| 76 |
| 59 void URLRequestSimpleJob::StartAsync() { | 77 void URLRequestSimpleJob::StartAsync() { |
| 60 if (!request_) | 78 if (!request_) |
| 61 return; | 79 return; |
| 62 | 80 |
| 63 if (ranges().size() > 1) { | 81 if (ranges().size() > 1) { |
| 64 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. | 82 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. |
| 65 tracked_objects::ScopedTracker tracking_profile( | 83 tracked_objects::ScopedTracker tracking_profile( |
| 66 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 84 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 67 "422489 URLRequestSimpleJob::StartAsync 1")); | 85 "422489 URLRequestSimpleJob::StartAsync 1")); |
| 68 | 86 |
| 69 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 87 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 70 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 88 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 71 return; | 89 return; |
| 72 } | 90 } |
| 73 | 91 |
| 74 if (!ranges().empty() && range_parse_result() == OK) | 92 if (!ranges().empty() && range_parse_result() == OK) |
| 75 byte_range_ = ranges().front(); | 93 byte_range_ = ranges().front(); |
| 76 | 94 |
| 77 int result; | 95 int result; |
| 78 { | 96 { |
| 79 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. | 97 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. |
| 80 // Remove the block and assign 'result' in its declaration. | 98 // Remove the block and assign 'result' in its declaration. |
| 81 tracked_objects::ScopedTracker tracking_profile( | 99 tracked_objects::ScopedTracker tracking_profile( |
| 82 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 100 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 83 "422489 URLRequestSimpleJob::StartAsync 2")); | 101 "422489 URLRequestSimpleJob::StartAsync 2")); |
| 84 | 102 |
| 85 result = GetData(&mime_type_, | 103 result = |
| 86 &charset_, | 104 GetStringPieceData(&mime_type_, &charset_, &data_, |
| 87 &data_, | 105 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted, |
| 88 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted, | 106 weak_factory_.GetWeakPtr())); |
| 89 weak_factory_.GetWeakPtr())); | |
| 90 } | 107 } |
| 91 | 108 |
| 92 if (result != ERR_IO_PENDING) { | 109 if (result != ERR_IO_PENDING) { |
| 93 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. | 110 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. |
| 94 tracked_objects::ScopedTracker tracking_profile( | 111 tracked_objects::ScopedTracker tracking_profile( |
| 95 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 112 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 96 "422489 URLRequestSimpleJob::StartAsync 3")); | 113 "422489 URLRequestSimpleJob::StartAsync 3")); |
| 97 | 114 |
| 98 OnGetDataCompleted(result); | 115 OnGetDataCompleted(result); |
| 99 } | 116 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 117 int remaining_bytes = byte_range_.last_byte_position() - | 134 int remaining_bytes = byte_range_.last_byte_position() - |
| 118 byte_range_.first_byte_position() + 1; | 135 byte_range_.first_byte_position() + 1; |
| 119 set_expected_content_size(remaining_bytes); | 136 set_expected_content_size(remaining_bytes); |
| 120 NotifyHeadersComplete(); | 137 NotifyHeadersComplete(); |
| 121 } else { | 138 } else { |
| 122 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 139 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 123 } | 140 } |
| 124 } | 141 } |
| 125 | 142 |
| 126 } // namespace net | 143 } // namespace net |
| OLD | NEW |