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/http/partial_data.h" | 5 #include "net/http/partial_data.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 } | 235 } |
236 | 236 |
237 bool PartialData::IsLastRange() const { | 237 bool PartialData::IsLastRange() const { |
238 return final_range_; | 238 return final_range_; |
239 } | 239 } |
240 | 240 |
241 bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers, | 241 bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers, |
242 disk_cache::Entry* entry, | 242 disk_cache::Entry* entry, |
243 bool truncated) { | 243 bool truncated) { |
244 resource_size_ = 0; | 244 resource_size_ = 0; |
245 if (!headers->HasStrongValidators()) | |
246 return false; | |
247 | |
248 if (truncated) { | 245 if (truncated) { |
249 DCHECK_EQ(headers->response_code(), 200); | 246 DCHECK_EQ(headers->response_code(), 200); |
250 // We don't have the real length and the user may be trying to create a | 247 // We don't have the real length and the user may be trying to create a |
251 // sparse entry so let's not write to this entry. | 248 // sparse entry so let's not write to this entry. |
252 if (byte_range_.IsValid()) | 249 if (byte_range_.IsValid()) |
253 return false; | 250 return false; |
254 | 251 |
252 if (!headers->HasStrongValidators()) | |
253 return false; | |
254 | |
255 // Now we avoid resume if there is no content length, but that was not | 255 // Now we avoid resume if there is no content length, but that was not |
256 // always the case so double check here. | 256 // always the case so double check here. |
257 int64 total_length = headers->GetContentLength(); | 257 int64 total_length = headers->GetContentLength(); |
258 if (total_length <= 0) | 258 if (total_length <= 0) |
259 return false; | 259 return false; |
260 | 260 |
261 truncated_ = true; | 261 truncated_ = true; |
262 initial_validation_ = true; | 262 initial_validation_ = true; |
263 sparse_entry_ = false; | 263 sparse_entry_ = false; |
264 int current_len = entry->GetDataSize(kDataStream); | 264 int current_len = entry->GetDataSize(kDataStream); |
265 byte_range_.set_first_byte_position(current_len); | 265 byte_range_.set_first_byte_position(current_len); |
266 resource_size_ = total_length; | 266 resource_size_ = total_length; |
267 current_range_start_ = current_len; | 267 current_range_start_ = current_len; |
268 cached_min_len_ = current_len; | 268 cached_min_len_ = current_len; |
269 cached_start_ = current_len + 1; | 269 cached_start_ = current_len + 1; |
270 return true; | 270 return true; |
271 } | 271 } |
272 | 272 |
273 if (headers->response_code() == 200) { | 273 if (headers->response_code() != 206) { |
274 DCHECK(byte_range_.IsValid()); | 274 DCHECK(byte_range_.IsValid()); |
275 sparse_entry_ = false; | 275 sparse_entry_ = false; |
276 resource_size_ = entry->GetDataSize(kDataStream); | 276 resource_size_ = entry->GetDataSize(kDataStream); |
277 DVLOG(2) << "UpdateFromStoredHeaders size: " << resource_size_; | 277 DVLOG(2) << "UpdateFromStoredHeaders size: " << resource_size_; |
gavinp
2012/07/30 18:35:07
Should this DVLOG be deleted??
rvargas (doing something else)
2012/07/30 21:38:52
Not sure. I've used this one to get an idea of whe
| |
278 return true; | 278 return true; |
279 } | 279 } |
280 | 280 |
281 if (!headers->HasStrongValidators()) | 281 if (!headers->HasStrongValidators()) |
282 return false; | 282 return false; |
283 | 283 |
284 int64 length_value = headers->GetContentLength(); | 284 int64 length_value = headers->GetContentLength(); |
285 if (length_value <= 0) | 285 if (length_value <= 0) |
286 return false; // We must have stored the resource length. | 286 return false; // We must have stored the resource length. |
287 | 287 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 cached_min_len_ = result; | 487 cached_min_len_ = result; |
488 if (result >= 0) | 488 if (result >= 0) |
489 result = 1; // Return success, go ahead and validate the entry. | 489 result = 1; // Return success, go ahead and validate the entry. |
490 | 490 |
491 CompletionCallback cb = callback_; | 491 CompletionCallback cb = callback_; |
492 callback_.Reset(); | 492 callback_.Reset(); |
493 cb.Run(result); | 493 cb.Run(result); |
494 } | 494 } |
495 | 495 |
496 } // namespace net | 496 } // namespace net |
OLD | NEW |