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

Side by Side Diff: net/http/http_cache.cc

Issue 2774603003: Doom and create new entry when validation is not a match (Closed)
Patch Set: Rebased with refs/heads/master@{#484325} Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/http_cache_transaction.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry, 945 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry,
946 Transaction* transaction) { 946 Transaction* transaction) {
947 DCHECK(!entry->writer); 947 DCHECK(!entry->writer);
948 auto it = entry->readers.find(transaction); 948 auto it = entry->readers.find(transaction);
949 DCHECK(it != entry->readers.end()); 949 DCHECK(it != entry->readers.end());
950 entry->readers.erase(it); 950 entry->readers.erase(it);
951 951
952 ProcessQueuedTransactions(entry); 952 ProcessQueuedTransactions(entry);
953 } 953 }
954 954
955 void HttpCache::DoomEntryValidationNoMatch(ActiveEntry* entry) {
956 // Validating transaction received a non-matching response.
957 DCHECK(entry->headers_transaction);
958
959 entry->headers_transaction = nullptr;
960 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) {
961 entry->disk_entry->Doom();
962 DestroyEntry(entry);
963 return;
964 }
965
966 DoomActiveEntry(entry->disk_entry->GetKey());
967
968 // Restart only add_to_entry_queue transactions.
969 // Post task here to avoid a race in creating the entry between |transaction|
970 // and the add_to_entry_queue transactions. Reset the queued transaction's
971 // cache pending state so that in case it's destructor is invoked, it's ok
972 // for the transaction to not be found in this entry.
973 for (auto* transaction : entry->add_to_entry_queue) {
974 transaction->ResetCachePendingState();
975 base::ThreadTaskRunnerHandle::Get()->PostTask(
976 FROM_HERE, base::Bind(transaction->io_callback(), net::ERR_CACHE_RACE));
977 }
978 entry->add_to_entry_queue.clear();
979 }
980
955 void HttpCache::RemoveAllQueuedTransactions(ActiveEntry* entry, 981 void HttpCache::RemoveAllQueuedTransactions(ActiveEntry* entry,
956 TransactionList* list) { 982 TransactionList* list) {
957 // Process done_headers_queue before add_to_entry_queue to maintain FIFO 983 // Process done_headers_queue before add_to_entry_queue to maintain FIFO
958 // order. 984 // order.
959 985
960 for (auto* transaction : entry->done_headers_queue) 986 for (auto* transaction : entry->done_headers_queue)
961 list->push_back(transaction); 987 list->push_back(transaction);
962 entry->done_headers_queue.clear(); 988 entry->done_headers_queue.clear();
963 989
964 for (auto* pending_transaction : entry->add_to_entry_queue) 990 for (auto* pending_transaction : entry->add_to_entry_queue)
965 list->push_back(pending_transaction); 991 list->push_back(pending_transaction);
966 entry->add_to_entry_queue.clear(); 992 entry->add_to_entry_queue.clear();
967 } 993 }
968 994
969 void HttpCache::ProcessEntryFailure(ActiveEntry* entry, 995 void HttpCache::ProcessEntryFailure(ActiveEntry* entry,
970 Transaction* transaction) { 996 Transaction* transaction) {
971 // Failure case is either writer failing to completely write the response to 997 // The writer failed to completely write the response to
972 // the cache or validating transaction received a non-304 response. 998 // the cache.
973 999
974 if (entry->headers_transaction && transaction != entry->headers_transaction) 1000 if (entry->headers_transaction && transaction != entry->headers_transaction)
975 RestartHeadersTransaction(entry); 1001 RestartHeadersTransaction(entry);
976 1002
977 TransactionList list; 1003 TransactionList list;
978 RemoveAllQueuedTransactions(entry, &list); 1004 RemoveAllQueuedTransactions(entry, &list);
979 1005
980 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) { 1006 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) {
981 entry->disk_entry->Doom(); 1007 entry->disk_entry->Doom();
982 DestroyEntry(entry); 1008 DestroyEntry(entry);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 building_backend_ = false; 1392 building_backend_ = false;
1367 DeletePendingOp(pending_op); 1393 DeletePendingOp(pending_op);
1368 } 1394 }
1369 1395
1370 // The cache may be gone when we return from the callback. 1396 // The cache may be gone when we return from the callback.
1371 if (!item->DoCallback(result, disk_cache_.get())) 1397 if (!item->DoCallback(result, disk_cache_.get()))
1372 item->NotifyTransaction(result, NULL); 1398 item->NotifyTransaction(result, NULL);
1373 } 1399 }
1374 1400
1375 } // namespace net 1401 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/http_cache_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698