OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 } | 972 } |
973 } | 973 } |
974 | 974 |
975 return ValidateEntryHeadersAndContinue(byte_range_requested); | 975 return ValidateEntryHeadersAndContinue(byte_range_requested); |
976 } | 976 } |
977 | 977 |
978 int HttpCache::Transaction::ValidateEntryHeadersAndContinue( | 978 int HttpCache::Transaction::ValidateEntryHeadersAndContinue( |
979 bool byte_range_requested) { | 979 bool byte_range_requested) { |
980 DCHECK(mode_ == READ_WRITE); | 980 DCHECK(mode_ == READ_WRITE); |
981 | 981 |
| 982 if (!cache_) |
| 983 return HandleResult(ERR_UNEXPECTED); |
| 984 |
982 if (!partial_->UpdateFromStoredHeaders(response_.headers, entry_->disk_entry, | 985 if (!partial_->UpdateFromStoredHeaders(response_.headers, entry_->disk_entry, |
983 truncated_)) { | 986 truncated_)) { |
984 // The stored data cannot be used. Get rid of it and restart this request. | 987 // The stored data cannot be used. Get rid of it and restart this request. |
985 // We need to also reset the |truncated_| flag as a new entry is created. | 988 // We need to also reset the |truncated_| flag as a new entry is created. |
986 DoomPartialEntry(!byte_range_requested); | 989 DoomPartialEntry(!byte_range_requested); |
987 mode_ = WRITE; | 990 mode_ = WRITE; |
988 truncated_ = false; | 991 truncated_ = false; |
989 return AddToEntry(); | 992 return AddToEntry(); |
990 } | 993 } |
991 | 994 |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 Transaction* trans = entry->writer; | 2040 Transaction* trans = entry->writer; |
2038 | 2041 |
2039 entry->writer = NULL; | 2042 entry->writer = NULL; |
2040 entry->readers.push_back(trans); | 2043 entry->readers.push_back(trans); |
2041 | 2044 |
2042 ProcessPendingQueue(entry); | 2045 ProcessPendingQueue(entry); |
2043 } | 2046 } |
2044 | 2047 |
2045 void HttpCache::RemovePendingTransaction(Transaction* trans) { | 2048 void HttpCache::RemovePendingTransaction(Transaction* trans) { |
2046 ActiveEntriesMap::const_iterator i = active_entries_.find(trans->key()); | 2049 ActiveEntriesMap::const_iterator i = active_entries_.find(trans->key()); |
2047 if (i == active_entries_.end()) | 2050 bool found = false; |
| 2051 if (i != active_entries_.end()) |
| 2052 found = RemovePendingTransactionFromEntry(i->second, trans); |
| 2053 |
| 2054 if (found) |
2048 return; | 2055 return; |
2049 | 2056 |
2050 TransactionList& pending_queue = i->second->pending_queue; | 2057 ActiveEntriesSet::iterator it = doomed_entries_.begin(); |
| 2058 for (; it != doomed_entries_.end() && !found; ++it) |
| 2059 found = RemovePendingTransactionFromEntry(*it, trans); |
| 2060 } |
| 2061 |
| 2062 bool HttpCache::RemovePendingTransactionFromEntry(ActiveEntry* entry, |
| 2063 Transaction* trans) { |
| 2064 TransactionList& pending_queue = entry->pending_queue; |
2051 | 2065 |
2052 TransactionList::iterator j = | 2066 TransactionList::iterator j = |
2053 find(pending_queue.begin(), pending_queue.end(), trans); | 2067 find(pending_queue.begin(), pending_queue.end(), trans); |
2054 if (j == pending_queue.end()) | 2068 if (j == pending_queue.end()) |
2055 return; | 2069 return false; |
2056 | 2070 |
2057 pending_queue.erase(j); | 2071 pending_queue.erase(j); |
| 2072 return true; |
2058 } | 2073 } |
2059 | 2074 |
2060 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { | 2075 void HttpCache::ProcessPendingQueue(ActiveEntry* entry) { |
2061 // Multiple readers may finish with an entry at once, so we want to batch up | 2076 // Multiple readers may finish with an entry at once, so we want to batch up |
2062 // calls to OnProcessPendingQueue. This flag also tells us that we should | 2077 // calls to OnProcessPendingQueue. This flag also tells us that we should |
2063 // not delete the entry before OnProcessPendingQueue runs. | 2078 // not delete the entry before OnProcessPendingQueue runs. |
2064 if (entry->will_process_pending_queue) | 2079 if (entry->will_process_pending_queue) |
2065 return; | 2080 return; |
2066 entry->will_process_pending_queue = true; | 2081 entry->will_process_pending_queue = true; |
2067 | 2082 |
(...skipping 28 matching lines...) Expand all Loading... |
2096 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 2111 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
2097 HttpNetworkSession* session = network->GetSession(); | 2112 HttpNetworkSession* session = network->GetSession(); |
2098 if (session) { | 2113 if (session) { |
2099 session->tcp_socket_pool()->CloseIdleSockets(); | 2114 session->tcp_socket_pool()->CloseIdleSockets(); |
2100 } | 2115 } |
2101 } | 2116 } |
2102 | 2117 |
2103 //----------------------------------------------------------------------------- | 2118 //----------------------------------------------------------------------------- |
2104 | 2119 |
2105 } // namespace net | 2120 } // namespace net |
OLD | NEW |