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

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: Feedback addressed. Created 3 years, 6 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
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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry, 941 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry,
942 Transaction* transaction) { 942 Transaction* transaction) {
943 DCHECK(!entry->writer); 943 DCHECK(!entry->writer);
944 auto it = entry->readers.find(transaction); 944 auto it = entry->readers.find(transaction);
945 DCHECK(it != entry->readers.end()); 945 DCHECK(it != entry->readers.end());
946 entry->readers.erase(it); 946 entry->readers.erase(it);
947 947
948 ProcessQueuedTransactions(entry); 948 ProcessQueuedTransactions(entry);
949 } 949 }
950 950
951 void HttpCache::DoomEntryValidationNoMatch(ActiveEntry* entry,
952 Transaction* transaction) {
jkarlin 2017/06/16 18:28:01 transaction is unused except for a dcheck, let's r
shivanisha 2017/06/27 15:31:14 done
953 // Validating transaction received a non-matching response.
954
955 DCHECK(transaction == entry->headers_transaction);
956
957 entry->headers_transaction = nullptr;
958 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) {
959 entry->disk_entry->Doom();
960 DestroyEntry(entry);
961 return;
962 }
963
964 // Restart only add_to_entry_queue transactions.
jkarlin 2017/06/16 18:28:01 Seems like this comment should be the first line o
shivanisha 2017/06/27 15:31:14 done
965
966 DoomActiveEntry(entry->disk_entry->GetKey());
967 // Post task here to avoid a race in creating the entry between |transaction|
968 // and the add_to_entry_queue transactions. Reset the queued transactions'
969 // cache pending state so that in case their destructor is invoked, it's ok
jkarlin 2017/06/16 18:28:01 s/their/its/
shivanisha 2017/06/27 15:31:14 done
970 // for them to not be found in this entry.
971 for (auto* transaction : entry->add_to_entry_queue) {
972 transaction->ResetCachePendingState();
973 base::ThreadTaskRunnerHandle::Get()->PostTask(
974 FROM_HERE, base::Bind(transaction->io_callback(), net::ERR_CACHE_RACE));
975 }
976 entry->add_to_entry_queue.clear();
977 }
978
951 void HttpCache::RemoveAllQueuedTransactions(ActiveEntry* entry, 979 void HttpCache::RemoveAllQueuedTransactions(ActiveEntry* entry,
952 TransactionList* list) { 980 TransactionList* list) {
953 // Process done_headers_queue before add_to_entry_queue to maintain FIFO 981 // Process done_headers_queue before add_to_entry_queue to maintain FIFO
954 // order. 982 // order.
955 983
956 for (auto* transaction : entry->done_headers_queue) 984 for (auto* transaction : entry->done_headers_queue)
957 list->push_back(transaction); 985 list->push_back(transaction);
958 entry->done_headers_queue.clear(); 986 entry->done_headers_queue.clear();
959 987
960 for (auto* pending_transaction : entry->add_to_entry_queue) 988 for (auto* pending_transaction : entry->add_to_entry_queue)
961 list->push_back(pending_transaction); 989 list->push_back(pending_transaction);
962 entry->add_to_entry_queue.clear(); 990 entry->add_to_entry_queue.clear();
963 } 991 }
964 992
965 void HttpCache::ProcessEntryFailure(ActiveEntry* entry, 993 void HttpCache::ProcessEntryFailure(ActiveEntry* entry,
966 Transaction* transaction) { 994 Transaction* transaction) {
967 // Failure case is either writer failing to completely write the response to 995 // Writer failed to completely write the response to
jkarlin 2017/06/16 18:28:01 The writer failed ...
shivanisha 2017/06/27 15:31:14 done
968 // the cache or validating transaction received a non-304 response. 996 // the cache.
969 997
970 if (entry->headers_transaction && transaction != entry->headers_transaction) 998 if (entry->headers_transaction && transaction != entry->headers_transaction)
971 RestartHeadersTransaction(entry, transaction); 999 RestartHeadersTransaction(entry, transaction);
972 1000
973 TransactionList list; 1001 TransactionList list;
974 RemoveAllQueuedTransactions(entry, &list); 1002 RemoveAllQueuedTransactions(entry, &list);
975 1003
976 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) { 1004 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) {
977 entry->disk_entry->Doom(); 1005 entry->disk_entry->Doom();
978 DestroyEntry(entry); 1006 DestroyEntry(entry);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 building_backend_ = false; 1392 building_backend_ = false;
1365 DeletePendingOp(pending_op); 1393 DeletePendingOp(pending_op);
1366 } 1394 }
1367 1395
1368 // The cache may be gone when we return from the callback. 1396 // The cache may be gone when we return from the callback.
1369 if (!item->DoCallback(result, disk_cache_.get())) 1397 if (!item->DoCallback(result, disk_cache_.get()))
1370 item->NotifyTransaction(result, NULL); 1398 item->NotifyTransaction(result, NULL);
1371 } 1399 }
1372 1400
1373 } // namespace net 1401 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698