Remove stale-while-revalidate experimental implementation.
This is in preparation for adding the new implementation.
This is a partial revert of commit
64c07d7959386d30a0e4aa1371e2bdcd3d436476. Parts which will still be
needed in the new implementation have been left.
BUG=348877
TEST=net_unittests
Review URL: https://codereview.chromium.org/1041763002
Cr-Commit-Position: refs/heads/master@{#335252}
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 5a66700..240a3fcb 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -139,9 +139,6 @@
const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled";
const char kSpdyFieldTrialParametrizedPrefix[] = "Parametrized";
-// Field trial for Cache-Control: stale-while-revalidate directive.
-const char kStaleWhileRevalidateFieldTrialName[] = "StaleWhileRevalidate";
-
#if defined(OS_MACOSX) && !defined(OS_IOS)
void ObserveKeychainEvents() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -294,15 +291,6 @@
return it->second;
}
-// Return true if stale-while-revalidate support should be enabled.
-bool IsStaleWhileRevalidateEnabled(const base::CommandLine& command_line) {
- if (command_line.HasSwitch(switches::kEnableStaleWhileRevalidate))
- return true;
- const std::string group_name =
- base::FieldTrialList::FindFullName(kStaleWhileRevalidateFieldTrialName);
- return group_name == "Enabled";
-}
-
// Parse kUseSpdy command line flag options, which may contain the following:
//
// "off" : Disables SPDY support entirely.
@@ -481,7 +469,6 @@
IOThread::Globals::Globals()
: system_request_context_leak_checker(this),
ignore_certificate_errors(false),
- use_stale_while_revalidate(false),
testing_fixed_http_port(0),
testing_fixed_https_port(0),
enable_user_alternate_protocol_ports(false) {
@@ -799,8 +786,6 @@
}
if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
globals_->ignore_certificate_errors = true;
- globals_->use_stale_while_revalidate =
- IsStaleWhileRevalidateEnabled(command_line);
if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
globals_->testing_fixed_http_port =
GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
@@ -1117,7 +1102,6 @@
params->network_delegate = globals.system_network_delegate.get();
params->host_mapping_rules = globals.host_mapping_rules.get();
params->ignore_certificate_errors = globals.ignore_certificate_errors;
- params->use_stale_while_revalidate = globals.use_stale_while_revalidate;
params->testing_fixed_http_port = globals.testing_fixed_http_port;
params->testing_fixed_https_port = globals.testing_fixed_https_port;
globals.enable_tcp_fast_open_for_ssl.CopyToIfSet(
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index b165d4a6..2406fe87 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -164,7 +164,6 @@
scoped_ptr<net::HttpUserAgentSettings> http_user_agent_settings;
scoped_ptr<net::NetworkQualityEstimator> network_quality_estimator;
bool ignore_certificate_errors;
- bool use_stale_while_revalidate;
uint16 testing_fixed_http_port;
uint16 testing_fixed_https_port;
Optional<bool> enable_tcp_fast_open_for_ssl;
diff --git a/chrome/browser/resources/net_internals/source_entry.js b/chrome/browser/resources/net_internals/source_entry.js
index bf4259d70..e1e217b18 100644
--- a/chrome/browser/resources/net_internals/source_entry.js
+++ b/chrome/browser/resources/net_internals/source_entry.js
@@ -82,7 +82,6 @@
// TODO(ricea): Remove SOCKET_STREAM after M41 is released.
case EventSourceType.SOCKET_STREAM:
case EventSourceType.HTTP_STREAM_JOB:
- case EventSourceType.ASYNC_REVALIDATION:
this.description_ = e.params.url;
break;
case EventSourceType.CONNECT_JOB:
diff --git a/net/base/load_flags_list.h b/net/base/load_flags_list.h
index cdb52059..8e09a8b 100644
--- a/net/base/load_flags_list.h
+++ b/net/base/load_flags_list.h
@@ -86,6 +86,3 @@
// reduction proxy.
// TODO(rcs): Remove this flag as soon as http://crbug.com/339237 is resolved.
LOAD_FLAG(BYPASS_DATA_REDUCTION_PROXY, 1 << 18)
-
-// Indicates the the request is an asynchronous revalidation.
-LOAD_FLAG(ASYNC_REVALIDATION, 1 << 19)
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 634f8adc..796aeea5 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -30,7 +30,6 @@
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
-#include "net/base/network_delegate.h"
#include "net/base/upload_data_stream.h"
#include "net/disk_cache/disk_cache.h"
#include "net/http/disk_based_cert_cache.h"
@@ -295,159 +294,6 @@
};
//-----------------------------------------------------------------------------
-
-class HttpCache::AsyncValidation {
- public:
- AsyncValidation(const HttpRequestInfo& original_request, HttpCache* cache)
- : request_(original_request), cache_(cache) {}
- ~AsyncValidation() {}
-
- void Start(const BoundNetLog& net_log,
- scoped_ptr<Transaction> transaction,
- NetworkDelegate* network_delegate);
-
- private:
- void OnStarted(int result);
- void DoRead();
- void OnRead(int result);
-
- // Terminate this request with net error code |result|. Logs the transaction
- // result and asks HttpCache to delete this object.
- // If there was a client or server certificate error, it cannot be recovered
- // asynchronously, so we need to prevent future attempts to asynchronously
- // fetch the resource. In this case, the cache entry is doomed.
- void Terminate(int result);
-
- HttpRequestInfo request_;
- scoped_refptr<IOBuffer> buf_;
- CompletionCallback read_callback_;
- scoped_ptr<Transaction> transaction_;
- base::Time start_time_;
-
- // The HttpCache object owns this object. This object is always deleted before
- // the pointer to the cache becomes invalid.
- HttpCache* cache_;
-
- DISALLOW_COPY_AND_ASSIGN(AsyncValidation);
-};
-
-void HttpCache::AsyncValidation::Start(const BoundNetLog& net_log,
- scoped_ptr<Transaction> transaction,
- NetworkDelegate* network_delegate) {
- transaction_ = transaction.Pass();
- if (network_delegate) {
- // This code is necessary to enable async transactions to pass over the
- // data-reduction proxy. This is a violation of the "once-and-only-once"
- // principle, since it copies code from URLRequestHttpJob. We cannot use the
- // original callback passed to HttpCache::Transaction by URLRequestHttpJob
- // as it will only be valid as long as the URLRequestHttpJob object is
- // alive, and that object will be deleted as soon as the synchronous request
- // completes.
- //
- // This code is also an encapsulation violation. We are exploiting the fact
- // that the |request| parameter to NotifyBeforeSendProxyHeaders() is never
- // actually used for anything, and so can be NULL.
- //
- // TODO(ricea): Do this better.
- transaction_->SetBeforeProxyHeadersSentCallback(
- base::Bind(&NetworkDelegate::NotifyBeforeSendProxyHeaders,
- base::Unretained(network_delegate),
- static_cast<URLRequest*>(NULL)));
- // The above use of base::Unretained is safe because the NetworkDelegate has
- // to live at least as long as the HttpNetworkSession which has to live as
- // least as long as the HttpNetworkLayer which has to live at least as long
- // this HttpCache object.
- }
-
- DCHECK_EQ(0, request_.load_flags & LOAD_ASYNC_REVALIDATION);
- request_.load_flags |= LOAD_ASYNC_REVALIDATION;
- start_time_ = cache_->clock()->Now();
- // This use of base::Unretained is safe because |transaction_| is owned by
- // this object.
- read_callback_ = base::Bind(&AsyncValidation::OnRead, base::Unretained(this));
- // This use of base::Unretained is safe as above.
- int rv = transaction_->Start(
- &request_,
- base::Bind(&AsyncValidation::OnStarted, base::Unretained(this)),
- net_log);
-
- if (rv == ERR_IO_PENDING)
- return;
-
- OnStarted(rv);
-}
-
-void HttpCache::AsyncValidation::OnStarted(int result) {
- if (result != OK) {
- DVLOG(1) << "Asynchronous transaction start failed for " << request_.url;
- Terminate(result);
- return;
- }
-
- while (transaction_->IsReadyToRestartForAuth()) {
- // This code is based on URLRequestHttpJob::RestartTransactionWithAuth,
- // however when we do this here cookies on the response will not be
- // stored. Fortunately only a tiny number of sites set cookies on 401
- // responses, and none of them use stale-while-revalidate.
- result = transaction_->RestartWithAuth(
- AuthCredentials(),
- base::Bind(&AsyncValidation::OnStarted, base::Unretained(this)));
- if (result == ERR_IO_PENDING)
- return;
- if (result != OK) {
- DVLOG(1) << "Synchronous transaction restart with auth failed for "
- << request_.url;
- Terminate(result);
- return;
- }
- }
-
- DoRead();
-}
-
-void HttpCache::AsyncValidation::DoRead() {
- const size_t kBufSize = 4096;
- if (!buf_.get())
- buf_ = new IOBuffer(kBufSize);
-
- int rv = 0;
- do {
- rv = transaction_->Read(buf_.get(), kBufSize, read_callback_);
- } while (rv > 0);
-
- if (rv == ERR_IO_PENDING)
- return;
-
- OnRead(rv);
-}
-
-void HttpCache::AsyncValidation::OnRead(int result) {
- if (result > 0) {
- DoRead();
- return;
- }
- Terminate(result);
-}
-
-void HttpCache::AsyncValidation::Terminate(int result) {
- if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED || IsCertificateError(result)) {
- // We should not attempt to access this resource asynchronously again until
- // the certificate problem has been resolved.
- // TODO(ricea): For ERR_SSL_CLIENT_AUTH_CERT_NEEDED, mark the entry as
- // requiring synchronous revalidation rather than just deleting it. Other
- // certificate errors cause the resource to be considered uncacheable
- // anyway.
- cache_->DoomEntry(transaction_->key(), transaction_.get());
- }
- base::TimeDelta duration = cache_->clock()->Now() - start_time_;
- UMA_HISTOGRAM_TIMES("HttpCache.AsyncValidationDuration", duration);
- transaction_->net_log().EndEventWithNetErrorCode(
- NetLog::TYPE_ASYNC_REVALIDATION, result);
- cache_->DeleteAsyncValidation(cache_->GenerateCacheKey(&request_));
- // |this| is deleted.
-}
-
-//-----------------------------------------------------------------------------
HttpCache::HttpCache(const HttpNetworkSession::Params& params,
BackendFactory* backend_factory)
: net_log_(params.net_log),
@@ -455,7 +301,6 @@
building_backend_(false),
bypass_lock_for_test_(false),
fail_conditionalization_for_test_(false),
- use_stale_while_revalidate_(params.use_stale_while_revalidate),
mode_(NORMAL),
network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))),
clock_(new base::DefaultClock()),
@@ -473,7 +318,6 @@
building_backend_(false),
bypass_lock_for_test_(false),
fail_conditionalization_for_test_(false),
- use_stale_while_revalidate_(session->params().use_stale_while_revalidate),
mode_(NORMAL),
network_layer_(new HttpNetworkLayer(session)),
clock_(new base::DefaultClock()),
@@ -488,15 +332,11 @@
building_backend_(false),
bypass_lock_for_test_(false),
fail_conditionalization_for_test_(false),
- use_stale_while_revalidate_(false),
mode_(NORMAL),
network_layer_(network_layer),
clock_(new base::DefaultClock()),
weak_factory_(this) {
SetupQuicServerInfoFactory(network_layer_->GetSession());
- HttpNetworkSession* session = network_layer_->GetSession();
- if (session)
- use_stale_while_revalidate_ = session->params().use_stale_while_revalidate;
}
HttpCache::~HttpCache() {
@@ -518,7 +358,6 @@
}
STLDeleteElements(&doomed_entries_);
- STLDeleteValues(&async_validations_);
// Before deleting pending_ops_, we have to make sure that the disk cache is
// done with said operations, or it will attempt to use deleted data.
@@ -1180,43 +1019,6 @@
base::Bind(&HttpCache::OnProcessPendingQueue, GetWeakPtr(), entry));
}
-void HttpCache::PerformAsyncValidation(const HttpRequestInfo& original_request,
- const BoundNetLog& net_log) {
- DCHECK(use_stale_while_revalidate_);
- std::string key = GenerateCacheKey(&original_request);
- AsyncValidation* async_validation =
- new AsyncValidation(original_request, this);
- typedef AsyncValidationMap::value_type AsyncValidationKeyValue;
- bool insert_ok =
- async_validations_.insert(AsyncValidationKeyValue(key, async_validation))
- .second;
- if (!insert_ok) {
- DVLOG(1) << "Harmless race condition detected on URL "
- << original_request.url << "; discarding redundant revalidation.";
- delete async_validation;
- return;
- }
- HttpNetworkSession* network_session = GetSession();
- NetworkDelegate* network_delegate = NULL;
- if (network_session)
- network_delegate = network_session->network_delegate();
- scoped_ptr<HttpTransaction> transaction;
- CreateTransaction(IDLE, &transaction);
- scoped_ptr<Transaction> downcast_transaction(
- static_cast<Transaction*>(transaction.release()));
- async_validation->Start(
- net_log, downcast_transaction.Pass(), network_delegate);
- // |async_validation| may have been deleted here.
-}
-
-void HttpCache::DeleteAsyncValidation(const std::string& url) {
- AsyncValidationMap::iterator it = async_validations_.find(url);
- CHECK(it != async_validations_.end()); // security-critical invariant
- AsyncValidation* async_validation = it->second;
- async_validations_.erase(it);
- delete async_validation;
-}
-
void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) {
entry->will_process_pending_queue = false;
DCHECK(!entry->writer);
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index c730049..8300c29 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -15,7 +15,6 @@
#define NET_HTTP_HTTP_CACHE_H_
#include <list>
-#include <map>
#include <set>
#include <string>
@@ -211,16 +210,6 @@
fail_conditionalization_for_test_ = true;
}
- bool use_stale_while_revalidate() const {
- return use_stale_while_revalidate_;
- }
-
- // Enable stale_while_revalidate functionality for testing purposes.
- void set_use_stale_while_revalidate_for_testing(
- bool use_stale_while_revalidate) {
- use_stale_while_revalidate_ = use_stale_while_revalidate;
- }
-
// HttpTransactionFactory implementation:
int CreateTransaction(RequestPriority priority,
scoped_ptr<HttpTransaction>* trans) override;
@@ -257,11 +246,9 @@
friend class Transaction;
friend class ViewCacheHelper;
struct PendingOp; // Info for an entry under construction.
- class AsyncValidation; // Encapsulates a single async revalidation.
typedef std::list<Transaction*> TransactionList;
typedef std::list<WorkItem*> WorkItemList;
- typedef std::map<std::string, AsyncValidation*> AsyncValidationMap;
struct ActiveEntry {
explicit ActiveEntry(disk_cache::Entry* entry);
@@ -396,15 +383,6 @@
// Resumes processing the pending list of |entry|.
void ProcessPendingQueue(ActiveEntry* entry);
- // Called by Transaction to perform an asynchronous revalidation. Creates a
- // new independent transaction as a copy of the original.
- void PerformAsyncValidation(const HttpRequestInfo& original_request,
- const BoundNetLog& net_log);
-
- // Remove the AsyncValidation with url |url| from the |async_validations_| set
- // and delete it.
- void DeleteAsyncValidation(const std::string& url);
-
// Events (called via PostTask) ---------------------------------------------
void OnProcessPendingQueue(ActiveEntry* entry);
@@ -437,10 +415,6 @@
bool bypass_lock_for_test_;
bool fail_conditionalization_for_test_;
- // true if the implementation of Cache-Control: stale-while-revalidate
- // directive is enabled (either via command-line flag or experiment).
- bool use_stale_while_revalidate_;
-
Mode mode_;
scoped_ptr<QuicServerInfoFactoryAdaptor> quic_server_info_factory_;
@@ -462,9 +436,6 @@
scoped_ptr<PlaybackCacheMap> playback_cache_map_;
- // The async validations currently in progress, keyed by URL.
- AsyncValidationMap async_validations_;
-
// A clock that can be swapped out for testing.
scoped_ptr<base::Clock> clock_;
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index 6b62be67..9f797af8 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -176,18 +176,6 @@
}
}
-scoped_ptr<base::Value> NetLogAsyncRevalidationInfoCallback(
- const NetLog::Source& source,
- const HttpRequestInfo* request,
- NetLogCaptureMode capture_mode) {
- scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
- source.AddToEventParameters(dict.get());
-
- dict->SetString("url", request->url.possibly_invalid_spec());
- dict->SetString("method", request->method);
- return dict.Pass();
-}
-
enum ExternallyConditionalizedType {
EXTERNALLY_CONDITIONALIZED_CACHE_REQUIRES_VALIDATION,
EXTERNALLY_CONDITIONALIZED_CACHE_USABLE,
@@ -2130,13 +2118,6 @@
bool skip_validation = (required_validation == VALIDATION_NONE);
- if (required_validation == VALIDATION_ASYNCHRONOUS &&
- !(request_->method == "GET" && (truncated_ || partial_)) && cache_ &&
- cache_->use_stale_while_revalidate()) {
- TriggerAsyncValidation();
- skip_validation = true;
- }
-
if (request_->method == "HEAD" &&
(truncated_ || response_.headers->response_code() == 206)) {
DCHECK(!partial_);
@@ -2165,7 +2146,6 @@
}
if (skip_validation) {
- // TODO(ricea): Is this pattern okay for asynchronous revalidations?
UpdateTransactionPattern(PATTERN_ENTRY_USED);
return SetupEntryForRead();
} else {
@@ -2345,7 +2325,7 @@
return VALIDATION_NONE;
}
- if (effective_load_flags_ & (LOAD_VALIDATE_CACHE | LOAD_ASYNC_REVALIDATION))
+ if (effective_load_flags_ & LOAD_VALIDATE_CACHE)
return VALIDATION_SYNCHRONOUS;
if (request_->method == "PUT" || request_->method == "DELETE")
@@ -2599,23 +2579,6 @@
}
}
-void HttpCache::Transaction::TriggerAsyncValidation() {
- DCHECK(!request_->upload_data_stream);
- BoundNetLog async_revalidation_net_log(
- BoundNetLog::Make(net_log_.net_log(), NetLog::SOURCE_ASYNC_REVALIDATION));
- net_log_.AddEvent(
- NetLog::TYPE_HTTP_CACHE_VALIDATE_RESOURCE_ASYNC,
- async_revalidation_net_log.source().ToEventParametersCallback());
- async_revalidation_net_log.BeginEvent(
- NetLog::TYPE_ASYNC_REVALIDATION,
- base::Bind(
- &NetLogAsyncRevalidationInfoCallback, net_log_.source(), request_));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(&HttpCache::PerformAsyncValidation,
- cache_, // cache_ is a weak pointer.
- *request_, async_revalidation_net_log));
-}
-
void HttpCache::Transaction::FailRangeRequest() {
response_ = *new_response_;
partial_->FixResponseHeaders(response_.headers.get(), false);
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index cde78dc..473a610 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -351,9 +351,6 @@
// Fixes the response headers to match expectations for a HEAD request.
void FixHeadersForHead();
- // Launches an asynchronous revalidation based on this transaction.
- void TriggerAsyncValidation();
-
// Changes the response code of a range request to be 416 (Requested range not
// satisfiable).
void FailRangeRequest();
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index ea1b9ddf..f490444 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -7283,52 +7283,6 @@
EXPECT_FALSE(TransactionRequiredNetwork(LOAD_NORMAL));
}
-// Framework for tests of stale-while-revalidate related functionality. With
-// the default settings (age=3601,stale-while-revalidate=7200,max-age=3600) it
-// will trigger the stale-while-revalidate asynchronous revalidation. Setting
-// |age_| to < 3600 will prevent any revalidation, and |age_| > 10800 will cause
-// synchronous revalidation.
-class HttpCacheStaleWhileRevalidateTest : public ::testing::Test {
- protected:
- HttpCacheStaleWhileRevalidateTest()
- : transaction_(kSimpleGET_Transaction),
- age_(3601),
- stale_while_revalidate_(7200),
- validator_("Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT") {
- cache_.http_cache()->set_use_stale_while_revalidate_for_testing(true);
- }
-
- // RunTransactionTest() with the arguments from this fixture.
- void RunFixtureTransactionTest() {
- std::string response_headers = base::StringPrintf(
- "%s\n"
- "Age: %d\n"
- "Cache-Control: max-age=3600,stale-while-revalidate=%d\n",
- validator_.c_str(),
- age_,
- stale_while_revalidate_);
- transaction_.response_headers = response_headers.c_str();
- RunTransactionTest(cache_.http_cache(), transaction_);
- transaction_.response_headers = "";
- }
-
- // How many times this test has sent requests to the (fake) origin
- // server. Every test case needs to make at least one request to initialise
- // the cache.
- int transaction_count() {
- return cache_.network_layer()->transaction_count();
- }
-
- // How many times an existing cache entry was opened during the test case.
- int open_count() { return cache_.disk_cache()->open_count(); }
-
- MockHttpCache cache_;
- ScopedMockTransaction transaction_;
- int age_;
- int stale_while_revalidate_;
- std::string validator_;
-};
-
static void CheckResourceFreshnessHeader(const HttpRequestInfo* request,
std::string* response_status,
std::string* response_headers,
@@ -7340,20 +7294,27 @@
// Verify that the Resource-Freshness header is sent on a revalidation if the
// stale-while-revalidate directive was on the response.
-TEST_F(HttpCacheStaleWhileRevalidateTest, ResourceFreshnessHeaderSent) {
- age_ = 10801; // Outside the stale-while-revalidate window.
+TEST(HttpCache, ResourceFreshnessHeaderSent) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=3600,stale-while-revalidate=7200\n";
// Write to the cache.
- RunFixtureTransactionTest();
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
- EXPECT_EQ(1, transaction_count());
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
// Send the request again and check that Resource-Freshness header is added.
- transaction_.handler = CheckResourceFreshnessHeader;
+ stale_while_revalidate_transaction.handler = CheckResourceFreshnessHeader;
- RunFixtureTransactionTest();
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
- EXPECT_EQ(2, transaction_count());
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
}
static void CheckResourceFreshnessAbsent(const HttpRequestInfo* request,
@@ -7365,421 +7326,27 @@
// Verify that the Resource-Freshness header is not sent when
// stale-while-revalidate is 0.
-TEST_F(HttpCacheStaleWhileRevalidateTest, ResourceFreshnessHeaderNotSent) {
- age_ = 10801;
- stale_while_revalidate_ = 0;
+TEST(HttpCache, ResourceFreshnessHeaderNotSent) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=3600,stale-while-revalidate=0\n";
// Write to the cache.
- RunFixtureTransactionTest();
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
- EXPECT_EQ(1, transaction_count());
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
// Send the request again and check that Resource-Freshness header is absent.
- transaction_.handler = CheckResourceFreshnessAbsent;
+ stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent;
- RunFixtureTransactionTest();
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
- EXPECT_EQ(2, transaction_count());
-}
-
-// Verify that when stale-while-revalidate applies the response is read from
-// cache.
-TEST_F(HttpCacheStaleWhileRevalidateTest, ReadFromCache) {
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(0, open_count());
- EXPECT_EQ(1, transaction_count());
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, open_count());
- EXPECT_EQ(1, transaction_count());
-}
-
-// Verify that when stale-while-revalidate applies an asynchronous request is
-// sent.
-TEST_F(HttpCacheStaleWhileRevalidateTest, AsyncRequestSent) {
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Let the async request execute.
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(2, transaction_count());
-}
-
-// Verify that tearing down the HttpCache with an async revalidation in progress
-// does not break anything (this test is most likely to find problems when run
-// with a memory checker such as AddressSanitizer).
-TEST_F(HttpCacheStaleWhileRevalidateTest, AsyncTearDown) {
- // Write to the cache.
- RunFixtureTransactionTest();
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-}
-
-static void CheckIfModifiedSinceHeader(const HttpRequestInfo* request,
- std::string* response_status,
- std::string* response_headers,
- std::string* response_data) {
- std::string value;
- EXPECT_TRUE(request->extra_headers.GetHeader("If-Modified-Since", &value));
- EXPECT_EQ("Sat, 18 Apr 2007 01:10:43 GMT", value);
-}
-
-// Verify that the async revalidation contains an If-Modified-Since header.
-TEST_F(HttpCacheStaleWhileRevalidateTest, AsyncRequestIfModifiedSince) {
- // Write to the cache.
- RunFixtureTransactionTest();
-
- transaction_.handler = CheckIfModifiedSinceHeader;
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-}
-
-static void CheckIfNoneMatchHeader(const HttpRequestInfo* request,
- std::string* response_status,
- std::string* response_headers,
- std::string* response_data) {
- std::string value;
- EXPECT_TRUE(request->extra_headers.GetHeader("If-None-Match", &value));
- EXPECT_EQ("\"40a1-1320-4f6adefa22a40\"", value);
-}
-
-// If the response had ETag rather than Last-Modified, then that is used to
-// conditionalise the response.
-TEST_F(HttpCacheStaleWhileRevalidateTest, AsyncRequestIfNoneMatch) {
- validator_ = "Etag: \"40a1-1320-4f6adefa22a40\"";
-
- // Write to the cache.
- RunFixtureTransactionTest();
-
- transaction_.handler = CheckIfNoneMatchHeader;
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-}
-
-static void CheckResourceFreshnessHeaderPresent(const HttpRequestInfo* request,
- std::string* response_status,
- std::string* response_headers,
- std::string* response_data) {
- EXPECT_TRUE(request->extra_headers.HasHeader("Resource-Freshness"));
-}
-
-TEST_F(HttpCacheStaleWhileRevalidateTest, AsyncRequestHasResourceFreshness) {
- // Write to the cache.
- RunFixtureTransactionTest();
-
- transaction_.handler = CheckResourceFreshnessHeaderPresent;
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-}
-
-// Verify that when age > max-age + stale-while-revalidate stale results are
-// not returned.
-TEST_F(HttpCacheStaleWhileRevalidateTest, NotAppliedIfTooStale) {
- age_ = 10801;
-
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(0, open_count());
- EXPECT_EQ(1, transaction_count());
-
- // Reading back reads from the network.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, open_count());
- EXPECT_EQ(2, transaction_count());
-}
-
-// HEAD requests should be able to take advantage of stale-while-revalidate.
-TEST_F(HttpCacheStaleWhileRevalidateTest, WorksForHeadMethod) {
- // Write to the cache. This has to be a GET request; HEAD requests don't
- // create new cache entries.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(0, open_count());
- EXPECT_EQ(1, transaction_count());
-
- // Read back from the cache, and trigger an asynchronous HEAD request.
- transaction_.method = "HEAD";
- transaction_.data = "";
-
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, open_count());
- EXPECT_EQ(1, transaction_count());
-
- // Let the network request proceed.
- base::RunLoop().RunUntilIdle();
-
- EXPECT_EQ(2, transaction_count());
-}
-
-// POST requests should not use stale-while-revalidate.
-TEST_F(HttpCacheStaleWhileRevalidateTest, NotAppliedToPost) {
- transaction_ = ScopedMockTransaction(kSimplePOST_Transaction);
-
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(0, open_count());
- EXPECT_EQ(1, transaction_count());
-
- // Reading back reads from the network.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(0, open_count());
- EXPECT_EQ(2, transaction_count());
-}
-
-static void CheckUrlMatches(const HttpRequestInfo* request,
- std::string* response_status,
- std::string* response_headers,
- std::string* response_data) {
- EXPECT_EQ("http://www.google.com/", request->url.spec());
-}
-
-// Async revalidation is issued to the original URL.
-TEST_F(HttpCacheStaleWhileRevalidateTest, AsyncRequestUrlMatches) {
- transaction_.url = "http://www.google.com/";
- // Write to the cache.
- RunFixtureTransactionTest();
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- transaction_.handler = CheckUrlMatches;
-
- // Let the async request execute and perform the check.
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(2, transaction_count());
-}
-
-class SyncLoadFlagTest : public HttpCacheStaleWhileRevalidateTest,
- public ::testing::WithParamInterface<int> {};
-
-// Flags which should always cause the request to be synchronous.
-TEST_P(SyncLoadFlagTest, MustBeSynchronous) {
- transaction_.load_flags |= GetParam();
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Reading back reads from the network.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(2, transaction_count());
-}
-
-INSTANTIATE_TEST_CASE_P(HttpCacheStaleWhileRevalidate,
- SyncLoadFlagTest,
- ::testing::Values(LOAD_VALIDATE_CACHE,
- LOAD_BYPASS_CACHE,
- LOAD_DISABLE_CACHE));
-
-TEST_F(HttpCacheStaleWhileRevalidateTest,
- PreferringCacheDoesNotTriggerAsyncRequest) {
- transaction_.load_flags |= LOAD_PREFERRING_CACHE;
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Reading back reads from the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // If there was an async transaction created, it would run now.
- base::RunLoop().RunUntilIdle();
-
- // There was no async transaction.
- EXPECT_EQ(1, transaction_count());
-}
-
-TEST_F(HttpCacheStaleWhileRevalidateTest, NotUsedWhenDisabled) {
- cache_.http_cache()->set_use_stale_while_revalidate_for_testing(false);
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // A synchronous revalidation is performed.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(2, transaction_count());
-}
-
-TEST_F(HttpCacheStaleWhileRevalidateTest,
- OnlyFromCacheDoesNotTriggerAsyncRequest) {
- transaction_.load_flags |= LOAD_ONLY_FROM_CACHE;
- transaction_.return_code = ERR_CACHE_MISS;
-
- // Writing to the cache should fail, because we are avoiding the network.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(0, transaction_count());
-
- base::RunLoop().RunUntilIdle();
-
- // Still nothing.
- EXPECT_EQ(0, transaction_count());
-}
-
-// A certificate error during an asynchronous fetch should cause the next fetch
-// to proceed synchronously.
-// TODO(ricea): In future, only certificate errors which require user
-// interaction should fail the asynchronous revalidation, and they should cause
-// the next revalidation to be synchronous rather than requiring a total
-// refetch. This test will need to be updated appropriately.
-TEST_F(HttpCacheStaleWhileRevalidateTest, CertificateErrorCausesRefetch) {
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Now read back. RunTransactionTestBase() expects to receive the network
- // error back from the HttpCache::Transaction, but since the cache request
- // will return OK we need to duplicate some of its implementation here.
- transaction_.return_code = ERR_SSL_CLIENT_AUTH_CERT_NEEDED;
- TestCompletionCallback callback;
- scoped_ptr<HttpTransaction> trans;
- int rv = cache_.http_cache()->CreateTransaction(DEFAULT_PRIORITY, &trans);
- EXPECT_EQ(OK, rv);
- ASSERT_TRUE(trans.get());
-
- MockHttpRequest request(transaction_);
- rv = trans->Start(&request, callback.callback(), BoundNetLog());
- ASSERT_EQ(ERR_IO_PENDING, rv);
- ASSERT_EQ(OK, callback.WaitForResult());
- ReadAndVerifyTransaction(trans.get(), transaction_);
-
- EXPECT_EQ(1, transaction_count());
-
- // Allow the asynchronous fetch to run.
- base::RunLoop().RunUntilIdle();
-
- EXPECT_EQ(2, transaction_count());
-
- // Now run the transaction again. It should run synchronously.
- transaction_.return_code = OK;
- RunFixtureTransactionTest();
-
- EXPECT_EQ(3, transaction_count());
-}
-
-// Ensure that the response cached by the asynchronous request is not truncated,
-// even if the server is slow.
-TEST_F(HttpCacheStaleWhileRevalidateTest, EntireResponseCached) {
- transaction_.test_mode = TEST_MODE_SLOW_READ;
- // Write to the cache.
- RunFixtureTransactionTest();
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-
- // Let the async request execute.
- base::RunLoop().RunUntilIdle();
-
- // The cache entry should still be complete.
- transaction_.load_flags = LOAD_ONLY_FROM_CACHE;
- RunFixtureTransactionTest();
-}
-
-// Verify that there are no race conditions in the completely synchronous case.
-TEST_F(HttpCacheStaleWhileRevalidateTest, SynchronousCaseWorks) {
- transaction_.test_mode = TEST_MODE_SYNC_ALL;
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Let the async request execute.
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(2, transaction_count());
-}
-
-static void CheckLoadFlagsAsyncRevalidation(const HttpRequestInfo* request,
- std::string* response_status,
- std::string* response_headers,
- std::string* response_data) {
- EXPECT_EQ(LOAD_ASYNC_REVALIDATION, request->load_flags);
-}
-
-// Check that the load flags on the async request are the same as the load flags
-// on the original request, plus LOAD_ASYNC_REVALIDATION.
-TEST_F(HttpCacheStaleWhileRevalidateTest, LoadFlagsAsyncRevalidation) {
- transaction_.load_flags = LOAD_NORMAL;
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- transaction_.handler = CheckLoadFlagsAsyncRevalidation;
- // Let the async request execute.
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(2, transaction_count());
-}
-
-static void SimpleMockAuthHandler(const HttpRequestInfo* request,
- std::string* response_status,
- std::string* response_headers,
- std::string* response_data) {
- if (request->extra_headers.HasHeader("X-Require-Mock-Auth") &&
- !request->extra_headers.HasHeader("Authorization")) {
- response_status->assign("HTTP/1.1 401 Unauthorized");
- response_headers->assign("WWW-Authenticate: Basic realm=\"mars\"\n");
- return;
- }
- response_status->assign("HTTP/1.1 200 OK");
-}
-
-TEST_F(HttpCacheStaleWhileRevalidateTest, RestartForAuth) {
- // Write to the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Now make the transaction require auth.
- transaction_.request_headers = "X-Require-Mock-Auth: dummy\r\n\r\n";
- transaction_.handler = SimpleMockAuthHandler;
-
- // Read back from the cache.
- RunFixtureTransactionTest();
-
- EXPECT_EQ(1, transaction_count());
-
- // Let the async request execute.
- base::RunLoop().RunUntilIdle();
-
- EXPECT_EQ(2, transaction_count());
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
}
// Tests that we allow multiple simultaneous, non-overlapping transactions to
diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc
index 4b7edeb..c413b87 100644
--- a/net/http/http_network_session.cc
+++ b/net/http/http_network_session.cc
@@ -75,7 +75,6 @@
net_log(NULL),
host_mapping_rules(NULL),
ignore_certificate_errors(false),
- use_stale_while_revalidate(false),
testing_fixed_http_port(0),
testing_fixed_https_port(0),
enable_tcp_fast_open_for_ssl(false),
diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h
index 3327195..abd5e3bb 100644
--- a/net/http/http_network_session.h
+++ b/net/http/http_network_session.h
@@ -79,7 +79,6 @@
NetLog* net_log;
HostMappingRules* host_mapping_rules;
bool ignore_certificate_errors;
- bool use_stale_while_revalidate;
uint16 testing_fixed_http_port;
uint16 testing_fixed_https_port;
bool enable_tcp_fast_open_for_ssl;
diff --git a/net/log/net_log_event_type_list.h b/net/log/net_log_event_type_list.h
index d46cbff..23088d4 100644
--- a/net/log/net_log_event_type_list.h
+++ b/net/log/net_log_event_type_list.h
@@ -874,29 +874,6 @@
EVENT_TYPE(HTTP_CACHE_RESTART_PARTIAL_REQUEST)
EVENT_TYPE(HTTP_CACHE_RE_SEND_PARTIAL_REQUEST)
-// Identifies the NetLog::Source() for the asynchronous HttpCache::Transaction
-// that will revalidate this entry.
-// The event parameters are:
-// {
-// "source_dependency": <Source identifier for the async Transaction>
-// }
-EVENT_TYPE(HTTP_CACHE_VALIDATE_RESOURCE_ASYNC)
-
-// The start/end of performing an async revalidation.
-// For the BEGIN phase, the event parameters are:
-// {
-// "source_dependency": <Source identifier for the Request>
-// "url": <String of URL being loaded>,
-// "method": <Method of request>
-// }
-//
-// For the END phase, if there was an error, the following parameters are
-// attached:
-// {
-// "net_error": <Net error code of the failure>,
-// }
-EVENT_TYPE(ASYNC_REVALIDATION)
-
// ------------------------------------------------------------------------
// Disk Cache / Memory Cache
// ------------------------------------------------------------------------
diff --git a/net/log/net_log_source_type_list.h b/net/log/net_log_source_type_list.h
index f72c8de3..d538615 100644
--- a/net/log/net_log_source_type_list.h
+++ b/net/log/net_log_source_type_list.h
@@ -25,5 +25,4 @@
SOURCE_TYPE(FILESTREAM)
SOURCE_TYPE(DNS_PROBER)
SOURCE_TYPE(PROXY_CLIENT_SOCKET)
-SOURCE_TYPE(ASYNC_REVALIDATION)
SOURCE_TYPE(DATA_REDUCTION_PROXY)
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 618b0d9b..e3d28247 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -13194,6 +13194,9 @@
</histogram>
<histogram name="HttpCache.AsyncValidationDuration" units="milliseconds">
+ <obsolete>
+ Deprecated as of 3/2015.
+ </obsolete>
<owner>ricea@chromium.org</owner>
<summary>
The time spent performing an asynchronous revalidation that was triggered by