Index: net/http/http_cache_transaction.cc |
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc |
index 3c9953930bcac27131eb50894d2fec174f78b26f..5ed99e9a55ae56568b090573d57d33bba210e5bd 100644 |
--- a/net/http/http_cache_transaction.cc |
+++ b/net/http/http_cache_transaction.cc |
@@ -140,6 +140,7 @@ HttpCache::Transaction::Transaction( |
cache_pending_(false), |
done_reading_(false), |
vary_mismatch_(false), |
+ couldnt_conditionalize_request_(false), |
io_buf_len_(0), |
read_offset_(0), |
effective_load_flags_(0), |
@@ -810,6 +811,39 @@ int HttpCache::Transaction::DoSendRequestComplete(int result) { |
if (!cache_) |
return ERR_UNEXPECTED; |
+ // If requested, and we have a readable cache entry, and we have |
+ // an error indicating that we're offline as opposed to in contact |
+ // with a bad server, read from cache anyway. |
+ if (effective_load_flags_ & LOAD_CACHE_RETURN_IF_OFFLINE && |
rvargas (doing something else)
2013/03/05 02:58:19
nit: single space before &... and add () around th
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Whoops; done.
|
+ mode_ == READ_WRITE && entry_ && !partial_ && result != OK) { |
rvargas (doing something else)
2013/03/05 02:58:19
nit: move result != OK to the beginning of this li
rvargas (doing something else)
2013/03/05 02:58:19
it would be nice to make this work with byte range
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done.
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
I'm happy to take a swing at that, but I'm not com
rvargas (doing something else)
2013/03/06 03:11:48
I don't think we need to do that on the first vers
Randy Smith (Not in Mondays)
2013/03/06 22:55:55
Ok, sounds good.
|
+ switch (result) { |
rvargas (doing something else)
2013/03/05 02:58:19
if (IsOffline(result)) ?
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done. Note that I took the opportunity to get rid
|
+ // Errors that mean we didn't have a connection to the host. |
+ // Go ahead and read from the cache anyway. |
+ case ERR_NAME_NOT_RESOLVED: |
+ case ERR_INTERNET_DISCONNECTED: |
+ case ERR_ADDRESS_UNREACHABLE: |
+ case ERR_CONNECTION_TIMED_OUT: |
+ network_trans_.reset(); |
+ UpdateTransactionPattern(PATTERN_NOT_COVERED); |
+ |
+ cache_->ConvertWriterToReader(entry_); |
rvargas (doing something else)
2013/03/05 02:58:19
maybe extract this and 1800-1818 into a new method
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Say more? I don't follow the suggestion, probably
rvargas (doing something else)
2013/03/06 03:11:48
I just meant something like:
if (effective_flags.
Randy Smith (Not in Mondays)
2013/03/06 22:55:55
Ah, gotcha. I'm not used to thinking of things th
|
+ mode_ = READ; |
+ response_.was_cache_override = true; |
+ |
+ // If there is metadata, read it. Otherwise, we're done. |
+ if (entry_->disk_entry->GetDataSize(kMetadataIndex)) |
+ next_state_ = STATE_CACHE_READ_METADATA; |
+ return OK; |
+ default: |
+ break; |
+ } |
+ } |
+ |
+ // If we tried to conditionalize the request and failed, we know |
+ // we won't be reading from the cache after this point. |
+ if (couldnt_conditionalize_request_) |
+ mode_ = WRITE; |
+ |
if (result == OK) { |
next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; |
return OK; |
@@ -1772,6 +1806,10 @@ int HttpCache::Transaction::BeginCacheValidation() { |
} else { |
partial_.reset(); |
} |
+ } else { |
+ // Override possible flag set in RequiresValidation(); we're |
+ // validating and did not override from cache. |
+ response_.was_cache_override = false; |
rvargas (doing something else)
2013/03/05 02:58:19
remove? (see other comments)
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
As noted in other comment, I don't yet follow.
|
} |
cache_->ConvertWriterToReader(entry_); |
mode_ = READ; |
@@ -1784,12 +1822,16 @@ int HttpCache::Transaction::BeginCacheValidation() { |
// Our mode remains READ_WRITE for a conditional request. We'll switch to |
// either READ or WRITE mode once we hear back from the server. |
if (!ConditionalizeRequest()) { |
+ couldnt_conditionalize_request_ = true; |
UpdateTransactionPattern(PATTERN_ENTRY_CANT_CONDITIONALIZE); |
if (partial_.get()) |
return DoRestartPartialRequest(); |
DCHECK_NE(206, response_.headers->response_code()); |
- mode_ = WRITE; |
+ // We don't want to switch mode to WRITE here as in offline |
rvargas (doing something else)
2013/03/05 02:58:19
update the comment at 1822 instead of adding a new
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
Done. Note that I changed the comment to only ref
|
+ // mode we may still need to read from the cache. Instead |
+ // we record and test on whether we could conditionalize the |
+ // request. |
} |
next_state_ = STATE_SEND_REQUEST; |
} |
@@ -1925,8 +1967,10 @@ bool HttpCache::Transaction::RequiresValidation() { |
return true; |
} |
- if (effective_load_flags_ & LOAD_PREFERRING_CACHE) |
+ if (effective_load_flags_ & LOAD_PREFERRING_CACHE) { |
+ response_.was_cache_override = true; |
rvargas (doing something else)
2013/03/05 02:58:19
Feels wrong to do this, especially on this method.
Randy Smith (Not in Mondays)
2013/03/05 23:16:14
ETA: One of your later comments made it clear your
|
return false; |
+ } |
if (effective_load_flags_ & LOAD_VALIDATE_CACHE) |
return true; |