diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-11 21:06:24 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-11 21:06:24 +0000 |
commit | 7e6a4f39d228f64a9f666ea8ccbe88bcff3850d2 (patch) | |
tree | cdec59f4684bf672a94b37179a5352ab18bb0e58 /net/http | |
parent | c32f04146677ab69289f661de3236fda5791c953 (diff) | |
download | chromium_src-7e6a4f39d228f64a9f666ea8ccbe88bcff3850d2.zip chromium_src-7e6a4f39d228f64a9f666ea8ccbe88bcff3850d2.tar.gz chromium_src-7e6a4f39d228f64a9f666ea8ccbe88bcff3850d2.tar.bz2 |
Http Cache: Eliminate EntryAvailable() and make the cache use
callbacks to notify the transaction about the completion
of AddTransactionToEntry.
BUG=26729
TEST=current tests.
Review URL: http://codereview.chromium.org/593058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 10 | ||||
-rw-r--r-- | net/http/http_cache_transaction.cc | 35 | ||||
-rw-r--r-- | net/http/http_cache_transaction.h | 16 |
3 files changed, 33 insertions, 28 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index d4e3d2b..b0305af 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -555,7 +555,7 @@ int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) { if (!entry->writer && !entry->pending_queue.empty()) ProcessPendingQueue(entry); - return trans->EntryAvailable(entry); + return OK; } void HttpCache::DoneWithEntry(ActiveEntry* entry, Transaction* trans, @@ -602,7 +602,8 @@ void HttpCache::DoneWritingToEntry(ActiveEntry* entry, bool success) { // We need to do something about these pending entries, which now need to // be added to a new entry. while (!pending_queue.empty()) { - pending_queue.front()->AddToEntry(); + // ERR_CACHE_RACE causes the transaction to restart the whole process. + pending_queue.front()->io_callback()->Run(ERR_CACHE_RACE); pending_queue.pop_front(); } } @@ -718,7 +719,10 @@ void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) { entry->pending_queue.erase(entry->pending_queue.begin()); - AddTransactionToEntry(entry, next); + int rv = AddTransactionToEntry(entry, next); + if (rv != ERR_IO_PENDING) { + next->io_callback()->Run(rv); + } } void HttpCache::OnIOComplete(int result, NewEntry* new_entry) { diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index b35fd55..4870d5b 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -497,28 +497,32 @@ int HttpCache::Transaction::DoCreateEntryComplete(int result) { int HttpCache::Transaction::DoAddToEntry() { DCHECK(new_entry_); cache_pending_ = true; + next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_WAITING); - int rv = cache_->AddTransactionToEntry(new_entry_, this); - new_entry_ = NULL; - return rv; + return cache_->AddTransactionToEntry(new_entry_, this); } -int HttpCache::Transaction::EntryAvailable(ActiveEntry* entry) { +int HttpCache::Transaction::DoAddToEntryComplete(int result) { LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_WAITING); + DCHECK(new_entry_); cache_pending_ = false; - entry_ = entry; - next_state_ = STATE_ENTRY_AVAILABLE; - if (new_entry_) { - // We are inside AddTransactionToEntry() so avoid reentering DoLoop(). - DCHECK_EQ(new_entry_, entry); + if (result == ERR_CACHE_RACE) { + new_entry_ = NULL; + next_state_ = STATE_INIT_ENTRY; return OK; } - return DoLoop(OK); -} -int HttpCache::Transaction::DoEntryAvailable() { - DCHECK(!new_entry_); + if (result != OK) { + // If there is a failure, the cache should have taken care of new_entry_. + NOTREACHED(); + new_entry_ = NULL; + return result; + } + + entry_ = new_entry_; + new_entry_ = NULL; + if (mode_ == WRITE) { if (partial_.get()) partial_->RestoreHeaders(&custom_request_->extra_headers); @@ -667,9 +671,8 @@ int HttpCache::Transaction::DoLoop(int result) { DCHECK_EQ(OK, rv); rv = DoAddToEntry(); break; - case STATE_ENTRY_AVAILABLE: - DCHECK_EQ(OK, rv); - rv = DoEntryAvailable(); + case STATE_ADD_TO_ENTRY_COMPLETE: + rv = DoAddToEntryComplete(rv); break; case STATE_PARTIAL_CACHE_VALIDATION: DCHECK_EQ(OK, rv); diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h index f417378..9608093 100644 --- a/net/http/http_cache_transaction.h +++ b/net/http/http_cache_transaction.h @@ -71,18 +71,13 @@ class HttpCache::Transaction : public HttpTransaction { const std::string& key() const { return cache_key_; } - // Associates this transaction with a cache entry. - int AddToEntry(); - - // Called by the HttpCache when the given disk cache entry becomes accessible - // to the transaction. Returns network error code. - int EntryAvailable(ActiveEntry* entry); - // This transaction is being deleted and we are not done writing to the cache. // We need to indicate that the response data was truncated. Returns true on // success. bool AddTruncatedFlag(); + CompletionCallback* io_callback() { return &io_callback_; } + private: static const size_t kNumValidationHeaders = 2; // Helper struct to pair a header name with its value, for @@ -109,7 +104,7 @@ class HttpCache::Transaction : public HttpTransaction { STATE_DOOM_ENTRY, STATE_DOOM_ENTRY_COMPLETE, STATE_ADD_TO_ENTRY, - STATE_ENTRY_AVAILABLE, + STATE_ADD_TO_ENTRY_COMPLETE, STATE_PARTIAL_CACHE_VALIDATION, STATE_UPDATE_CACHED_RESPONSE, STATE_UPDATE_CACHED_RESPONSE_COMPLETE, @@ -156,7 +151,7 @@ class HttpCache::Transaction : public HttpTransaction { int DoDoomEntry(); int DoDoomEntryComplete(int result); int DoAddToEntry(); - int DoEntryAvailable(); + int DoAddToEntryComplete(int result); int DoPartialCacheValidation(); int DoUpdateCachedResponse(); int DoUpdateCachedResponseComplete(int result); @@ -183,6 +178,9 @@ class HttpCache::Transaction : public HttpTransaction { // layer (skipping the cache entirely). bool ShouldPassThrough(); + // Associates this transaction with a cache entry. + int AddToEntry(); + // Called to begin reading from the cache. Returns network error code. int BeginCacheRead(); |