| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/http/partial_data.h" | 5 #include "net/http/partial_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/disk_cache/disk_cache.h" | 10 #include "net/disk_cache/disk_cache.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 void PartialData::SetHeaders(const std::string& headers) { | 40 void PartialData::SetHeaders(const std::string& headers) { |
| 41 DCHECK(extra_headers_.empty()); | 41 DCHECK(extra_headers_.empty()); |
| 42 extra_headers_ = headers; | 42 extra_headers_ = headers; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void PartialData::RestoreHeaders(std::string* headers) const { | 45 void PartialData::RestoreHeaders(std::string* headers) const { |
| 46 DCHECK(current_range_start_ >= 0 || byte_range_.IsSuffixByteRange()); | 46 DCHECK(current_range_start_ >= 0 || byte_range_.IsSuffixByteRange()); |
| 47 int64 end = byte_range_.IsSuffixByteRange() ? | 47 int64 end = byte_range_.IsSuffixByteRange() ? |
| 48 byte_range_.suffix_length() : byte_range_.last_byte_position(); | 48 byte_range_.suffix_length() : byte_range_.last_byte_position(); |
| 49 | 49 |
| 50 headers->assign(extra_headers_); | 50 AddRangeHeader(current_range_start_, end, headers); |
| 51 if (byte_range_.IsValid()) | |
| 52 AddRangeHeader(current_range_start_, end, headers); | |
| 53 } | 51 } |
| 54 | 52 |
| 55 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry, | 53 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry, |
| 56 std::string* headers) { | 54 std::string* headers) { |
| 57 DCHECK(current_range_start_ >= 0); | 55 DCHECK(current_range_start_ >= 0); |
| 58 | 56 |
| 59 // Scan the disk cache for the first cached portion within this range. | 57 // Scan the disk cache for the first cached portion within this range. |
| 60 int64 range_len = byte_range_.HasLastBytePosition() ? | 58 int64 range_len = byte_range_.HasLastBytePosition() ? |
| 61 byte_range_.last_byte_position() - current_range_start_ + 1 : kint32max; | 59 byte_range_.last_byte_position() - current_range_start_ + 1 : kint32max; |
| 62 if (range_len > kint32max) | 60 if (range_len > kint32max) |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 if (start >= 0) | 312 if (start >= 0) |
| 315 my_start = Int64ToString(start); | 313 my_start = Int64ToString(start); |
| 316 if (end >= 0) | 314 if (end >= 0) |
| 317 my_end = Int64ToString(end); | 315 my_end = Int64ToString(end); |
| 318 | 316 |
| 319 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), | 317 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), |
| 320 my_end.c_str())); | 318 my_end.c_str())); |
| 321 } | 319 } |
| 322 | 320 |
| 323 } // namespace net | 321 } // namespace net |
| OLD | NEW |