| 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 AddRangeHeader(current_range_start_, end, headers); | 50 headers->assign(extra_headers_); |
| 51 if (byte_range_.IsValid()) |
| 52 AddRangeHeader(current_range_start_, end, headers); |
| 51 } | 53 } |
| 52 | 54 |
| 53 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry, | 55 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry, |
| 54 std::string* headers) { | 56 std::string* headers) { |
| 55 DCHECK(current_range_start_ >= 0); | 57 DCHECK(current_range_start_ >= 0); |
| 56 | 58 |
| 57 // Scan the disk cache for the first cached portion within this range. | 59 // Scan the disk cache for the first cached portion within this range. |
| 58 int64 range_len = byte_range_.HasLastBytePosition() ? | 60 int64 range_len = byte_range_.HasLastBytePosition() ? |
| 59 byte_range_.last_byte_position() - current_range_start_ + 1 : kint32max; | 61 byte_range_.last_byte_position() - current_range_start_ + 1 : kint32max; |
| 60 if (range_len > kint32max) | 62 if (range_len > kint32max) |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 if (start >= 0) | 314 if (start >= 0) |
| 313 my_start = Int64ToString(start); | 315 my_start = Int64ToString(start); |
| 314 if (end >= 0) | 316 if (end >= 0) |
| 315 my_end = Int64ToString(end); | 317 my_end = Int64ToString(end); |
| 316 | 318 |
| 317 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), | 319 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), |
| 318 my_end.c_str())); | 320 my_end.c_str())); |
| 319 } | 321 } |
| 320 | 322 |
| 321 } // namespace net | 323 } // namespace net |
| OLD | NEW |