Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Unified Diff: net/http/http_cache.cc

Issue 1230113012: [net] Better StopCaching() handling for HttpCache::Transaction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing MockTransaction initializers Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/http/http_cache.cc
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 796aeea501414bdacb9efa9aecd625a6702a85aa..ccdcac1b1b469760c88853bc675c05c10a7586c7 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -839,69 +839,43 @@ int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) {
return OK;
}
-void HttpCache::DoneWithEntry(ActiveEntry* entry, Transaction* trans,
- bool cancel) {
+void HttpCache::DoneWithEntry(ActiveEntry* entry,
+ Transaction* trans,
+ EntryState entry_state) {
// If we already posted a task to move on to the next transaction and this was
// the writer, there is nothing to cancel.
if (entry->will_process_pending_queue && entry->readers.empty())
return;
if (entry->writer) {
- DCHECK(trans == entry->writer);
-
- // Assume there was a failure.
- bool success = false;
- if (cancel) {
- DCHECK(entry->disk_entry);
- // This is a successful operation in the sense that we want to keep the
- // entry.
- success = trans->AddTruncatedFlag();
- // The previous operation may have deleted the entry.
- if (!trans->entry())
- return;
- }
- DoneWritingToEntry(entry, success);
- } else {
- DoneReadingFromEntry(entry, trans);
- }
-}
-
-void HttpCache::DoneWritingToEntry(ActiveEntry* entry, bool success) {
- DCHECK(entry->readers.empty());
-
- entry->writer = NULL;
+ DCHECK_EQ(trans, entry->writer);
+ DCHECK(entry->readers.empty());
- if (success) {
- ProcessPendingQueue(entry);
- } else {
- DCHECK(!entry->will_process_pending_queue);
+ entry->writer = nullptr;
- // We failed to create this entry.
- TransactionList pending_queue;
- pending_queue.swap(entry->pending_queue);
+ if (entry_state == EntryState::DOOM || entry->doomed) {
+ DCHECK(!entry->will_process_pending_queue);
- entry->disk_entry->Doom();
- DestroyEntry(entry);
+ TransactionList pending_queue;
+ pending_queue.swap(entry->pending_queue);
+ if (!entry->doomed)
+ entry->disk_entry->Doom();
+ DestroyEntry(entry);
- // We need to do something about these pending entries, which now need to
- // be added to a new entry.
- while (!pending_queue.empty()) {
- // ERR_CACHE_RACE causes the transaction to restart the whole process.
- pending_queue.front()->io_callback().Run(ERR_CACHE_RACE);
- pending_queue.pop_front();
+ // We need to do something about these pending entries, which now need to
+ // be added to a new entry.
+ while (!pending_queue.empty()) {
+ // ERR_CACHE_RACE causes the transaction to restart the whole process.
+ pending_queue.front()->io_callback().Run(ERR_CACHE_RACE);
+ pending_queue.pop_front();
+ }
+ return;
}
+ } else {
+ auto it = std::find(entry->readers.begin(), entry->readers.end(), trans);
+ DCHECK(it != entry->readers.end());
+ entry->readers.erase(it);
}
-}
-
-void HttpCache::DoneReadingFromEntry(ActiveEntry* entry, Transaction* trans) {
- DCHECK(!entry->writer);
-
- TransactionList::iterator it =
- std::find(entry->readers.begin(), entry->readers.end(), trans);
- DCHECK(it != entry->readers.end());
-
- entry->readers.erase(it);
-
ProcessPendingQueue(entry);
}

Powered by Google App Engine
This is Rietveld 408576698