Commit 5fe20f35 authored by Titouan Rigoudy's avatar Titouan Rigoudy Committed by Commit Bot

Small no-op refactor in HttpCache::Transaction.

Extract the checks that need not be run on each iteration of the loop.
Given the constant size of kValidationHeaders, this does not
meaningfully improve complexity, only readability (hopefully).

Change-Id: Ic14796c1a76426f0bbb3f40247744ba5b98318f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386739
Commit-Queue: Titouan Rigoudy <titouan@chromium.org>
Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803862}
parent af8f4f5d
...@@ -2632,28 +2632,39 @@ int HttpCache::Transaction::ValidateEntryHeadersAndContinue() { ...@@ -2632,28 +2632,39 @@ int HttpCache::Transaction::ValidateEntryHeadersAndContinue() {
return OK; return OK;
} }
int HttpCache::Transaction::BeginExternallyConditionalizedRequest() { bool HttpCache::Transaction::
DCHECK_EQ(UPDATE, mode_); ExternallyConditionalizedValidationHeadersMatchEntry() const {
DCHECK(external_validation_.initialized); DCHECK(external_validation_.initialized);
for (size_t i = 0; i < base::size(kValidationHeaders); i++) { for (size_t i = 0; i < base::size(kValidationHeaders); i++) {
if (external_validation_.values[i].empty()) if (external_validation_.values[i].empty())
continue; continue;
// Retrieve either the cached response's "etag" or "last-modified" header. // Retrieve either the cached response's "etag" or "last-modified" header.
std::string validator; std::string validator;
response_.headers->EnumerateHeader( response_.headers->EnumerateHeader(
nullptr, kValidationHeaders[i].related_response_header_name, nullptr, kValidationHeaders[i].related_response_header_name,
&validator); &validator);
if (response_.headers->response_code() != 200 || truncated_ || if (validator != external_validation_.values[i]) {
validator.empty() || validator != external_validation_.values[i]) { return false;
// The externally conditionalized request is not a validation request
// for our existing cache entry. Proceed with caching disabled.
UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER);
DoneWithEntry(true);
} }
} }
return true;
}
int HttpCache::Transaction::BeginExternallyConditionalizedRequest() {
DCHECK_EQ(UPDATE, mode_);
if (response_.headers->response_code() != 200 || truncated_ ||
!ExternallyConditionalizedValidationHeadersMatchEntry()) {
// The externally conditionalized request is not a validation request
// for our existing cache entry. Proceed with caching disabled.
UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER);
DoneWithEntry(true);
}
TransitionToState(STATE_SEND_REQUEST); TransitionToState(STATE_SEND_REQUEST);
return OK; return OK;
} }
......
...@@ -381,6 +381,10 @@ class NET_EXPORT_PRIVATE HttpCache::Transaction : public HttpTransaction { ...@@ -381,6 +381,10 @@ class NET_EXPORT_PRIVATE HttpCache::Transaction : public HttpTransaction {
// the validation of the rest of the entry. Returns a network error code. // the validation of the rest of the entry. Returns a network error code.
int ValidateEntryHeadersAndContinue(); int ValidateEntryHeadersAndContinue();
// Returns whether the current externally conditionalized request's validation
// headers match the current cache entry's headers.
bool ExternallyConditionalizedValidationHeadersMatchEntry() const;
// Called to start requests which were given an "if-modified-since" or // Called to start requests which were given an "if-modified-since" or
// "if-none-match" validation header by the caller (NOT when the request was // "if-none-match" validation header by the caller (NOT when the request was
// conditionalized internally in response to LOAD_VALIDATE_CACHE). // conditionalized internally in response to LOAD_VALIDATE_CACHE).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment