summaryrefslogtreecommitdiffstats
path: root/net/http/http_cache_transaction.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 22:31:20 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 22:31:20 +0000
commit46773166fdfb7bcfecad9bb84050ba0745955708 (patch)
treef782df29fb31ccb82d1b219967d71a7def3d9e3b /net/http/http_cache_transaction.cc
parent1f4da86c4928ccdc3c6f626d52a109b2f5da21d1 (diff)
downloadchromium_src-46773166fdfb7bcfecad9bb84050ba0745955708.zip
chromium_src-46773166fdfb7bcfecad9bb84050ba0745955708.tar.gz
chromium_src-46773166fdfb7bcfecad9bb84050ba0745955708.tar.bz2
Http Cache: Handle the asynchronous instantiation of the
backend. We queue all trasnactions that reach Start before we are done creating the disk cache. BUG=26729 TEST=unittests. Review URL: http://codereview.chromium.org/2002002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46745 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_cache_transaction.cc')
-rw-r--r--net/http/http_cache_transaction.cc113
1 files changed, 63 insertions, 50 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index 8beb825..ffb5748 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -172,44 +172,9 @@ int HttpCache::Transaction::Start(const HttpRequestInfo* request,
SetRequest(net_log, request);
- int rv;
-
- if (!ShouldPassThrough()) {
- cache_key_ = cache_->GenerateCacheKey(request);
-
- // Requested cache access mode.
- if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) {
- mode_ = READ;
- } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) {
- mode_ = WRITE;
- } else {
- mode_ = READ_WRITE;
- }
-
- // Downgrade to UPDATE if the request has been externally conditionalized.
- if (external_validation_.initialized) {
- if (mode_ & WRITE) {
- // Strip off the READ_DATA bit (and maybe add back a READ_META bit
- // in case READ was off).
- mode_ = UPDATE;
- } else {
- mode_ = NONE;
- }
- }
- }
-
- // If must use cache, then we must fail. This can happen for back/forward
- // navigations to a page generated via a form post.
- if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE)
- return ERR_CACHE_MISS;
-
- if (mode_ == NONE) {
- if (partial_.get())
- partial_->RestoreHeaders(&custom_request_->extra_headers);
- rv = BeginNetworkRequest();
- } else {
- rv = AddToEntry();
- }
+ // We have to wait until the backend is initialized so we start the SM.
+ next_state_ = STATE_GET_BACKEND;
+ int rv = DoLoop(OK);
// Setting this here allows us to check for the existance of a callback_ to
// determine if we are still inside Start.
@@ -428,6 +393,13 @@ int HttpCache::Transaction::DoLoop(int result) {
State state = next_state_;
next_state_ = STATE_NONE;
switch (state) {
+ case STATE_GET_BACKEND:
+ DCHECK_EQ(OK, rv);
+ rv = DoGetBackend();
+ break;
+ case STATE_GET_BACKEND_COMPLETE:
+ rv = DoGetBackendComplete(rv);
+ break;
case STATE_SEND_REQUEST:
DCHECK_EQ(OK, rv);
rv = DoSendRequest();
@@ -562,6 +534,58 @@ int HttpCache::Transaction::DoLoop(int result) {
return rv;
}
+int HttpCache::Transaction::DoGetBackend() {
+ cache_pending_ = true;
+ next_state_ = STATE_GET_BACKEND_COMPLETE;
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL);
+ return cache_->GetBackendForTransaction(this);
+}
+
+int HttpCache::Transaction::DoGetBackendComplete(int result) {
+ DCHECK(result == OK || result == ERR_FAILED);
+ net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL);
+ cache_pending_ = false;
+
+ if (!ShouldPassThrough()) {
+ cache_key_ = cache_->GenerateCacheKey(request_);
+
+ // Requested cache access mode.
+ if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) {
+ mode_ = READ;
+ } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) {
+ mode_ = WRITE;
+ } else {
+ mode_ = READ_WRITE;
+ }
+
+ // Downgrade to UPDATE if the request has been externally conditionalized.
+ if (external_validation_.initialized) {
+ if (mode_ & WRITE) {
+ // Strip off the READ_DATA bit (and maybe add back a READ_META bit
+ // in case READ was off).
+ mode_ = UPDATE;
+ } else {
+ mode_ = NONE;
+ }
+ }
+ }
+
+ // If must use cache, then we must fail. This can happen for back/forward
+ // navigations to a page generated via a form post.
+ if (!(mode_ & READ) && effective_load_flags_ & LOAD_ONLY_FROM_CACHE)
+ return ERR_CACHE_MISS;
+
+ if (mode_ == NONE) {
+ if (partial_.get())
+ partial_->RestoreHeaders(&custom_request_->extra_headers);
+ next_state_ = STATE_SEND_REQUEST;
+ } else {
+ next_state_ = STATE_INIT_ENTRY;
+ }
+
+ return OK;
+}
+
int HttpCache::Transaction::DoSendRequest() {
DCHECK(mode_ & WRITE || mode_ == NONE);
DCHECK(!network_trans_.get());
@@ -902,7 +926,7 @@ int HttpCache::Transaction::DoOverwriteCachedResponse() {
response_ = *new_response_;
target_state_ = STATE_TRUNCATE_CACHED_DATA;
next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE :
- STATE_CACHE_WRITE_RESPONSE;
+ STATE_CACHE_WRITE_RESPONSE;
return OK;
}
@@ -1268,12 +1292,6 @@ bool HttpCache::Transaction::ShouldPassThrough() {
return true;
}
-int HttpCache::Transaction::AddToEntry() {
- next_state_ = STATE_INIT_ENTRY;
- cache_pending_ = false;
- return DoLoop(OK);
-}
-
int HttpCache::Transaction::BeginCacheRead() {
// We don't support any combination of LOAD_ONLY_FROM_CACHE and byte ranges.
if (response_.headers->response_code() == 206 || partial_.get()) {
@@ -1388,11 +1406,6 @@ int HttpCache::Transaction::BeginExternallyConditionalizedRequest() {
return OK;
}
-int HttpCache::Transaction::BeginNetworkRequest() {
- next_state_ = STATE_SEND_REQUEST;
- return DoLoop(OK);
-}
-
int HttpCache::Transaction::RestartNetworkRequest() {
DCHECK(mode_ & WRITE || mode_ == NONE);
DCHECK(network_trans_.get());