Chromium Code Reviews| Index: net/http/http_cache_transaction.cc |
| diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc |
| index 7139abbdd79db0645bc37137d486365ad8fbbea8..c172af8a700fad3b3b7c90d02a5b67b4b107368b 100644 |
| --- a/net/http/http_cache_transaction.cc |
| +++ b/net/http/http_cache_transaction.cc |
| @@ -27,6 +27,7 @@ |
| #include "base/strings/string_piece.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| +#include "base/time/clock.h" |
| #include "base/time/time.h" |
| #include "base/values.h" |
| #include "net/base/completion_callback.h" |
| @@ -1534,6 +1535,7 @@ int HttpCache::Transaction::DoUpdateCachedResponse() { |
| response_.response_time = new_response_->response_time; |
| response_.request_time = new_response_->request_time; |
| response_.network_accessed = new_response_->network_accessed; |
| + response_.unused_since_prefetch = new_response_->unused_since_prefetch; |
| if (response_.headers->HasHeaderValue("cache-control", "no-store")) { |
| if (!entry_->doomed) { |
| @@ -1567,9 +1569,12 @@ int HttpCache::Transaction::DoUpdateCachedResponseComplete(int result) { |
| cache_->ConvertWriterToReader(entry_); |
| mode_ = READ; |
| } |
| - // We no longer need the network transaction, so destroy it. |
| - final_upload_progress_ = network_trans_->GetUploadProgress(); |
| - ResetNetworkTransaction(); |
| + |
| + if (network_trans_) { |
| + // We no longer need the network transaction, so destroy it. |
| + final_upload_progress_ = network_trans_->GetUploadProgress(); |
| + ResetNetworkTransaction(); |
| + } |
| } else if (entry_ && handling_206_ && truncated_ && |
| partial_->initial_validation()) { |
| // We just finished the validation of a truncated entry, and the server |
| @@ -2172,6 +2177,19 @@ int HttpCache::Transaction::BeginCacheValidation() { |
| // TODO(ricea): Is this pattern okay for asynchronous revalidations? |
| UpdateTransactionPattern(PATTERN_ENTRY_USED); |
| RecordOfflineStatus(effective_load_flags_, OFFLINE_STATUS_FRESH_CACHE); |
| + |
| + if (response_.unused_since_prefetch || |
| + (!response_.unused_since_prefetch && |
| + request_->load_flags & LOAD_PREFETCH)) { |
| + // Either this is the first use of an entry since it was prefetched or |
| + // this is a prefetch. Flip the bit on response.unused_since_prefetch and |
| + // write it back to the cache before reading. |
| + response_.unused_since_prefetch = !response_.unused_since_prefetch; |
|
rvargas (doing something else)
2014/12/12 02:20:49
READ and UPDATE requests don't go through this cod
jkarlin
2014/12/15 17:19:25
Done.
|
| + target_state_ = STATE_UPDATE_CACHED_RESPONSE_COMPLETE; |
|
rvargas (doing something else)
2014/12/12 02:20:49
Joining back in DoUpdateCachedResponseComplete loo
jkarlin
2014/12/15 17:19:25
Done.
|
| + next_state_ = STATE_CACHE_WRITE_RESPONSE; |
| + return OK; |
| + } |
| + |
| return SetupEntryForRead(); |
| } else { |
| // Make the network request conditional, to see if we may reuse our cached |
| @@ -2344,6 +2362,15 @@ ValidationType HttpCache::Transaction::RequiresValidation() { |
| if (effective_load_flags_ & LOAD_PREFERRING_CACHE) |
| return VALIDATION_NONE; |
| + if (response_.unused_since_prefetch && |
| + response_.headers->GetCurrentAge( |
| + response_.request_time, response_.response_time, |
| + cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) { |
| + // The first use of a resource after prefetch within a short window skips |
| + // validation. |
| + return VALIDATION_NONE; |
| + } |
| + |
| if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION)) |
| return VALIDATION_SYNCHRONOUS; |
| @@ -2351,8 +2378,9 @@ ValidationType HttpCache::Transaction::RequiresValidation() { |
| return VALIDATION_SYNCHRONOUS; |
| ValidationType validation_required_by_headers = |
| - response_.headers->RequiresValidation( |
| - response_.request_time, response_.response_time, Time::Now()); |
| + response_.headers->RequiresValidation(response_.request_time, |
| + response_.response_time, |
| + cache_->clock_->Now()); |
| if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { |
| // Asynchronous revalidation is only supported for GET and HEAD methods. |
| @@ -2413,7 +2441,8 @@ bool HttpCache::Transaction::ConditionalizeRequest() { |
| response_.headers->GetFreshnessLifetimes(response_.response_time); |
| if (lifetimes.staleness > TimeDelta()) { |
| TimeDelta current_age = response_.headers->GetCurrentAge( |
| - response_.request_time, response_.response_time, Time::Now()); |
| + response_.request_time, response_.response_time, |
| + cache_->clock_->Now()); |
| custom_request_->extra_headers.SetHeader( |
| kFreshnessHeader, |