Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry, | 939 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry, |
| 940 Transaction* transaction) { | 940 Transaction* transaction) { |
| 941 DCHECK(!entry->writer); | 941 DCHECK(!entry->writer); |
| 942 auto it = entry->readers.find(transaction); | 942 auto it = entry->readers.find(transaction); |
| 943 DCHECK(it != entry->readers.end()); | 943 DCHECK(it != entry->readers.end()); |
| 944 entry->readers.erase(it); | 944 entry->readers.erase(it); |
| 945 | 945 |
| 946 ProcessQueuedTransactions(entry); | 946 ProcessQueuedTransactions(entry); |
| 947 } | 947 } |
| 948 | 948 |
| 949 void HttpCache::DoomEntryValidationNoMatch(ActiveEntry* entry, | |
| 950 Transaction* transaction) { | |
| 951 // Validating transaction received a non-matching response. | |
| 952 | |
| 953 // TODO(shivanisha) Can transaction be a writer in case of partial requests? | |
|
jkarlin
2017/06/09 17:04:49
s/a writer/the writer/
shivanisha
2017/06/12 18:01:22
done
| |
| 954 // Handlie the writer case if that's possible. | |
|
jkarlin
2017/06/09 17:04:49
Seems like we need to answer that question before
jkarlin
2017/06/09 17:04:49
s/Handlie/Handle/
shivanisha
2017/06/12 18:01:22
Handled this TODO in CanTransactionWriteResponseHe
| |
| 955 CHECK(transaction == entry->headers_transaction); | |
|
jkarlin
2017/06/09 17:04:49
Let's DCHECK this and save CHECK for cases where w
shivanisha
2017/06/12 18:01:22
done
| |
| 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. | |
| 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 | |
| 970 // for them to not be found in this entry. | |
| 971 for (auto* transaction : entry->add_to_entry_queue) { | |
| 972 transaction->ResetCachePendingState(); | |
|
jkarlin
2017/06/09 17:04:49
Why is this necessary? Won't they all have this re
shivanisha
2017/06/12 18:01:23
I am thinking of the race where we remove them fro
| |
| 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 | |
| 949 void HttpCache::RemoveAllQueuedTransactions(ActiveEntry* entry, | 979 void HttpCache::RemoveAllQueuedTransactions(ActiveEntry* entry, |
| 950 TransactionList* list) { | 980 TransactionList* list) { |
| 951 // 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 |
| 952 // order. | 982 // order. |
| 953 | 983 |
| 954 for (auto* transaction : entry->done_headers_queue) | 984 for (auto* transaction : entry->done_headers_queue) |
| 955 list->push_back(transaction); | 985 list->push_back(transaction); |
| 956 entry->done_headers_queue.clear(); | 986 entry->done_headers_queue.clear(); |
| 957 | 987 |
| 958 for (auto* pending_transaction : entry->add_to_entry_queue) | 988 for (auto* pending_transaction : entry->add_to_entry_queue) |
| 959 list->push_back(pending_transaction); | 989 list->push_back(pending_transaction); |
| 960 entry->add_to_entry_queue.clear(); | 990 entry->add_to_entry_queue.clear(); |
| 961 } | 991 } |
| 962 | 992 |
| 963 void HttpCache::ProcessEntryFailure(ActiveEntry* entry, | 993 void HttpCache::ProcessEntryFailure(ActiveEntry* entry, |
| 964 Transaction* transaction) { | 994 Transaction* transaction) { |
| 965 // Failure case is either writer failing to completely write the response to | 995 // Writer failed to completely write the response to |
| 966 // the cache or validating transaction received a non-304 response. | 996 // the cache. |
| 967 | 997 |
| 968 if (entry->headers_transaction && transaction != entry->headers_transaction) | 998 if (entry->headers_transaction && transaction != entry->headers_transaction) |
| 969 RestartHeadersTransaction(entry, transaction); | 999 RestartHeadersTransaction(entry, transaction); |
| 970 | 1000 |
| 971 TransactionList list; | 1001 TransactionList list; |
| 972 RemoveAllQueuedTransactions(entry, &list); | 1002 RemoveAllQueuedTransactions(entry, &list); |
| 973 | 1003 |
| 974 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) { | 1004 if (entry->HasNoTransactions() && !entry->will_process_queued_transactions) { |
| 975 entry->disk_entry->Doom(); | 1005 entry->disk_entry->Doom(); |
| 976 DestroyEntry(entry); | 1006 DestroyEntry(entry); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1351 building_backend_ = false; | 1381 building_backend_ = false; |
| 1352 DeletePendingOp(pending_op); | 1382 DeletePendingOp(pending_op); |
| 1353 } | 1383 } |
| 1354 | 1384 |
| 1355 // The cache may be gone when we return from the callback. | 1385 // The cache may be gone when we return from the callback. |
| 1356 if (!item->DoCallback(result, disk_cache_.get())) | 1386 if (!item->DoCallback(result, disk_cache_.get())) |
| 1357 item->NotifyTransaction(result, NULL); | 1387 item->NotifyTransaction(result, NULL); |
| 1358 } | 1388 } |
| 1359 | 1389 |
| 1360 } // namespace net | 1390 } // namespace net |
| OLD | NEW |