| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 headers->CopyFrom(extra_headers_); | 68 headers->CopyFrom(extra_headers_); |
| 69 if (byte_range_.IsValid()) | 69 if (byte_range_.IsValid()) |
| 70 AddRangeHeader(current_range_start_, end, headers); | 70 AddRangeHeader(current_range_start_, end, headers); |
| 71 } | 71 } |
| 72 | 72 |
| 73 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry, | 73 int PartialData::PrepareCacheValidation(disk_cache::Entry* entry, |
| 74 HttpRequestHeaders* headers) { | 74 HttpRequestHeaders* headers) { |
| 75 DCHECK(current_range_start_ >= 0); | 75 DCHECK(current_range_start_ >= 0); |
| 76 | 76 |
| 77 // Scan the disk cache for the first cached portion within this range. | 77 // Scan the disk cache for the first cached portion within this range. |
| 78 int64 range_len = byte_range_.HasLastBytePosition() ? | 78 int64 range_len = |
| 79 byte_range_.last_byte_position() - current_range_start_ + 1 : kint32max; | 79 byte_range_.HasLastBytePosition() ? |
| 80 byte_range_.last_byte_position() - current_range_start_ + 1 : |
| 81 kint32max; |
| 80 if (range_len > kint32max) | 82 if (range_len > kint32max) |
| 81 range_len = kint32max; | 83 range_len = kint32max; |
| 82 int len = static_cast<int32>(range_len); | 84 int len = static_cast<int32>(range_len); |
| 83 if (!len) | 85 if (!len) |
| 84 return 0; | 86 return 0; |
| 85 range_present_ = false; | 87 range_present_ = false; |
| 86 | 88 |
| 87 if (sparse_entry_) { | 89 if (sparse_entry_) { |
| 88 cached_min_len_ = entry->GetAvailableRange(current_range_start_, len, | 90 cached_min_len_ = entry->GetAvailableRange(current_range_start_, len, |
| 89 &cached_start_); | 91 &cached_start_); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return rv; | 206 return rv; |
| 205 } | 207 } |
| 206 | 208 |
| 207 bool PartialData::ResponseHeadersOK(const HttpResponseHeaders* headers) { | 209 bool PartialData::ResponseHeadersOK(const HttpResponseHeaders* headers) { |
| 208 if (headers->response_code() == 304) { | 210 if (headers->response_code() == 304) { |
| 209 if (!byte_range_.IsValid() || truncated_) | 211 if (!byte_range_.IsValid() || truncated_) |
| 210 return true; | 212 return true; |
| 211 | 213 |
| 212 // We must have a complete range here. | 214 // We must have a complete range here. |
| 213 return byte_range_.HasFirstBytePosition() && | 215 return byte_range_.HasFirstBytePosition() && |
| 214 byte_range_.HasLastBytePosition(); | 216 byte_range_.HasLastBytePosition(); |
| 215 } | 217 } |
| 216 | 218 |
| 217 int64 start, end, total_length; | 219 int64 start, end, total_length; |
| 218 if (!headers->GetContentRange(&start, &end, &total_length)) | 220 if (!headers->GetContentRange(&start, &end, &total_length)) |
| 219 return false; | 221 return false; |
| 220 if (total_length <= 0) | 222 if (total_length <= 0) |
| 221 return false; | 223 return false; |
| 222 | 224 |
| 223 int64 content_length = headers->GetContentLength(); | 225 int64 content_length = headers->GetContentLength(); |
| 224 if (content_length < 0 || content_length != end - start + 1) | 226 if (content_length < 0 || content_length != end - start + 1) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (current_range_start_ > kint32max) | 308 if (current_range_start_ > kint32max) |
| 307 return ERR_INVALID_ARGUMENT; | 309 return ERR_INVALID_ARGUMENT; |
| 308 | 310 |
| 309 rv = entry->ReadData(kDataStream, static_cast<int>(current_range_start_), | 311 rv = entry->ReadData(kDataStream, static_cast<int>(current_range_start_), |
| 310 data, read_len, callback); | 312 data, read_len, callback); |
| 311 } | 313 } |
| 312 return rv; | 314 return rv; |
| 313 } | 315 } |
| 314 | 316 |
| 315 int PartialData::CacheWrite(disk_cache::Entry* entry, IOBuffer* data, | 317 int PartialData::CacheWrite(disk_cache::Entry* entry, IOBuffer* data, |
| 316 int data_len, CompletionCallback* callback) { | 318 int data_len, CompletionCallback* callback) { |
| 317 if (sparse_entry_) { | 319 if (sparse_entry_) { |
| 318 return entry->WriteSparseData(current_range_start_, data, data_len, | 320 return entry->WriteSparseData(current_range_start_, data, data_len, |
| 319 callback); | 321 callback); |
| 320 } else { | 322 } else { |
| 321 if (current_range_start_ > kint32max) | 323 if (current_range_start_ > kint32max) |
| 322 return ERR_INVALID_ARGUMENT; | 324 return ERR_INVALID_ARGUMENT; |
| 323 | 325 |
| 324 return entry->WriteData(kDataStream, static_cast<int>(current_range_start_), | 326 return entry->WriteData(kDataStream, static_cast<int>(current_range_start_), |
| 325 data, data_len, callback, true); | 327 data, data_len, callback, true); |
| 326 } | 328 } |
| 327 } | 329 } |
| 328 | 330 |
| 329 void PartialData::OnCacheReadCompleted(int result) { | 331 void PartialData::OnCacheReadCompleted(int result) { |
| 330 if (result > 0) { | 332 if (result > 0) { |
| 331 current_range_start_ += result; | 333 current_range_start_ += result; |
| 332 cached_min_len_ -= result; | 334 cached_min_len_ -= result; |
| 333 DCHECK(cached_min_len_ >= 0); | 335 DCHECK(cached_min_len_ >= 0); |
| 334 } | 336 } |
| 335 } | 337 } |
| 336 | 338 |
| 337 void PartialData::OnNetworkReadCompleted(int result) { | 339 void PartialData::OnNetworkReadCompleted(int result) { |
| 338 if (result > 0) | 340 if (result > 0) |
| 339 current_range_start_ += result; | 341 current_range_start_ += result; |
| 340 } | 342 } |
| 341 | 343 |
| 342 } // namespace net | 344 } // namespace net |
| OLD | NEW |