| 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/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 disk_cache::Entry* entry, | 123 disk_cache::Entry* entry, |
| 124 bool truncated) { | 124 bool truncated) { |
| 125 resource_size_ = 0; | 125 resource_size_ = 0; |
| 126 if (truncated) { | 126 if (truncated) { |
| 127 DCHECK_EQ(headers->response_code(), 200); | 127 DCHECK_EQ(headers->response_code(), 200); |
| 128 // We don't have the real length and the user may be trying to create a | 128 // We don't have the real length and the user may be trying to create a |
| 129 // sparse entry so let's not write to this entry. | 129 // sparse entry so let's not write to this entry. |
| 130 if (byte_range_.IsValid()) | 130 if (byte_range_.IsValid()) |
| 131 return false; | 131 return false; |
| 132 | 132 |
| 133 // Now we avoid resume if there is no content length, but that was not |
| 134 // always the case so double check here. |
| 135 int64 total_length = headers->GetContentLength(); |
| 136 if (total_length <= 0 || !headers->HasStrongValidators()) |
| 137 return false; |
| 138 |
| 133 truncated_ = true; | 139 truncated_ = true; |
| 134 sparse_entry_ = false; | 140 sparse_entry_ = false; |
| 135 byte_range_.set_first_byte_position(entry->GetDataSize(kDataStream)); | 141 byte_range_.set_first_byte_position(entry->GetDataSize(kDataStream)); |
| 142 resource_size_ = total_length; |
| 136 current_range_start_ = 0; | 143 current_range_start_ = 0; |
| 137 return true; | 144 return true; |
| 138 } | 145 } |
| 139 | 146 |
| 140 if (headers->response_code() == 200) { | 147 if (headers->response_code() == 200) { |
| 141 DCHECK(byte_range_.IsValid()); | 148 DCHECK(byte_range_.IsValid()); |
| 142 sparse_entry_ = false; | 149 sparse_entry_ = false; |
| 143 resource_size_ = entry->GetDataSize(kDataStream); | 150 resource_size_ = entry->GetDataSize(kDataStream); |
| 144 return true; | 151 return true; |
| 145 } | 152 } |
| 146 | 153 |
| 147 std::string length_value; | 154 int64 length_value = headers->GetContentLength(); |
| 148 if (!headers->GetNormalizedHeader(kLengthHeader, &length_value)) | 155 if (length_value <= 0) |
| 149 return false; // We must have stored the resource length. | 156 return false; // We must have stored the resource length. |
| 150 | 157 |
| 151 if (!StringToInt64(length_value, &resource_size_) || !resource_size_) | 158 resource_size_ = length_value; |
| 152 return false; | |
| 153 | 159 |
| 154 // Make sure that this is really a sparse entry. | 160 // Make sure that this is really a sparse entry. |
| 155 int64 n; | 161 int64 n; |
| 156 if (ERR_CACHE_OPERATION_NOT_SUPPORTED == entry->GetAvailableRange(0, 5, &n)) | 162 if (ERR_CACHE_OPERATION_NOT_SUPPORTED == entry->GetAvailableRange(0, 5, &n)) |
| 157 return false; | 163 return false; |
| 158 | 164 |
| 159 return true; | 165 return true; |
| 160 } | 166 } |
| 161 | 167 |
| 162 bool PartialData::IsRequestedRangeOK() { | 168 bool PartialData::IsRequestedRangeOK() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (!byte_range_.HasFirstBytePosition()) { | 213 if (!byte_range_.HasFirstBytePosition()) { |
| 208 byte_range_.set_first_byte_position(start); | 214 byte_range_.set_first_byte_position(start); |
| 209 current_range_start_ = start; | 215 current_range_start_ = start; |
| 210 } | 216 } |
| 211 if (!byte_range_.HasLastBytePosition()) | 217 if (!byte_range_.HasLastBytePosition()) |
| 212 byte_range_.set_last_byte_position(end); | 218 byte_range_.set_last_byte_position(end); |
| 213 } else if (resource_size_ != total_length) { | 219 } else if (resource_size_ != total_length) { |
| 214 return false; | 220 return false; |
| 215 } | 221 } |
| 216 | 222 |
| 223 if (truncated_) { |
| 224 if (!byte_range_.HasLastBytePosition()) |
| 225 byte_range_.set_last_byte_position(end); |
| 226 } |
| 227 |
| 217 if (start != current_range_start_) | 228 if (start != current_range_start_) |
| 218 return false; | 229 return false; |
| 219 | 230 |
| 220 if (byte_range_.IsValid() && end > byte_range_.last_byte_position()) | 231 if (byte_range_.IsValid() && end > byte_range_.last_byte_position()) |
| 221 return false; | 232 return false; |
| 222 | 233 |
| 223 return true; | 234 return true; |
| 224 } | 235 } |
| 225 | 236 |
| 226 // We are making multiple requests to complete the range requested by the user. | 237 // We are making multiple requests to complete the range requested by the user. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 if (start >= 0) | 329 if (start >= 0) |
| 319 my_start = Int64ToString(start); | 330 my_start = Int64ToString(start); |
| 320 if (end >= 0) | 331 if (end >= 0) |
| 321 my_end = Int64ToString(end); | 332 my_end = Int64ToString(end); |
| 322 | 333 |
| 323 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), | 334 headers->append(StringPrintf("Range: bytes=%s-%s\r\n", my_start.c_str(), |
| 324 my_end.c_str())); | 335 my_end.c_str())); |
| 325 } | 336 } |
| 326 | 337 |
| 327 } // namespace net | 338 } // namespace net |
| OLD | NEW |