summaryrefslogtreecommitdiffstats
path: root/net/http/partial_data.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-02 18:08:25 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-02 18:08:25 +0000
commit634739bf391585057f2f1a9f8f173d418958ae0f (patch)
treec68d3b382be4edaebf5aec10de6dba870563df7b /net/http/partial_data.cc
parent18699b72815f6f435c4e00f4f1eb900440898468 (diff)
downloadchromium_src-634739bf391585057f2f1a9f8f173d418958ae0f.zip
chromium_src-634739bf391585057f2f1a9f8f173d418958ae0f.tar.gz
chromium_src-634739bf391585057f2f1a9f8f173d418958ae0f.tar.bz2
Http cache: Fix handling of truncated entries.
- Always validate a truncated entry. Furthermore, given that a server can say not-modified (304), followed by 200 when actually asked for the final range, now we validate truncated entries by asking for the next byte that we need. - If a server refuses to serve a byte range and instead sends the whole resource, we just cache the response as if nothing was stored before. - If we receive a network error while reading from the net, we don't discard the cached entry right away. Now we wait until the transaction is closed, and attempt to mark the entry as truncated. BUG=48468 TEST=net_unittests Review URL: http://codereview.chromium.org/6588105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/partial_data.cc')
-rw-r--r--net/http/partial_data.cc31
1 files changed, 19 insertions, 12 deletions
diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc
index 68d8048..c1f448e 100644
--- a/net/http/partial_data.cc
+++ b/net/http/partial_data.cc
@@ -111,6 +111,7 @@ PartialData::PartialData()
final_range_(false),
sparse_entry_(true),
truncated_(false),
+ initial_validation_(false),
core_(NULL),
callback_(NULL) {
}
@@ -153,7 +154,7 @@ void PartialData::RestoreHeaders(HttpRequestHeaders* headers) const {
byte_range_.suffix_length() : byte_range_.last_byte_position();
headers->CopyFrom(extra_headers_);
- if (byte_range_.IsValid())
+ if (!truncated_ && byte_range_.IsValid())
AddRangeHeader(current_range_start_, end, headers);
}
@@ -178,13 +179,7 @@ int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
callback_ = callback;
return ERR_IO_PENDING;
}
- } else if (truncated_) {
- if (!current_range_start_) {
- // Update the cached range only the first time.
- cached_min_len_ = static_cast<int32>(byte_range_.first_byte_position());
- cached_start_ = 0;
- }
- } else {
+ } else if (!truncated_) {
if (byte_range_.HasFirstBytePosition() &&
byte_range_.first_byte_position() >= resource_size_) {
// The caller should take care of this condition because we should have
@@ -259,10 +254,14 @@ bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers,
return false;
truncated_ = true;
+ initial_validation_ = true;
sparse_entry_ = false;
- byte_range_.set_first_byte_position(entry->GetDataSize(kDataStream));
+ int current_len = entry->GetDataSize(kDataStream);
+ byte_range_.set_first_byte_position(current_len);
resource_size_ = total_length;
- current_range_start_ = 0;
+ current_range_start_ = current_len;
+ cached_min_len_ = current_len;
+ cached_start_ = current_len + 1;
return true;
}
@@ -284,12 +283,20 @@ bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers,
return entry->CouldBeSparse();
}
+void PartialData::SetRangeToStartDownload() {
+ DCHECK(truncated_);
+ DCHECK(!sparse_entry_);
+ current_range_start_ = 0;
+ cached_start_ = 0;
+ initial_validation_ = false;
+}
+
bool PartialData::IsRequestedRangeOK() {
if (byte_range_.IsValid()) {
- if (truncated_)
- return true;
if (!byte_range_.ComputeBounds(resource_size_))
return false;
+ if (truncated_)
+ return true;
if (current_range_start_ < 0)
current_range_start_ = byte_range_.first_byte_position();