| 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 // This file declares a HttpTransactionFactory implementation that can be | 5 // This file declares a HttpTransactionFactory implementation that can be |
| 6 // layered on top of another HttpTransactionFactory to add HTTP caching. The | 6 // layered on top of another HttpTransactionFactory to add HTTP caching. The |
| 7 // caching logic follows RFC 7234 (any exceptions are called out in the code). | 7 // caching logic follows RFC 7234 (any exceptions are called out in the code). |
| 8 // | 8 // |
| 9 // The HttpCache takes a disk_cache::Backend as a parameter, and uses that for | 9 // The HttpCache takes a disk_cache::Backend as a parameter, and uses that for |
| 10 // the cache storage. | 10 // the cache storage. |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Disk cache entry data indices. | 233 // Disk cache entry data indices. |
| 234 enum { | 234 enum { |
| 235 kResponseInfoIndex = 0, | 235 kResponseInfoIndex = 0, |
| 236 kResponseContentIndex, | 236 kResponseContentIndex, |
| 237 kMetadataIndex, | 237 kMetadataIndex, |
| 238 | 238 |
| 239 // Must remain at the end of the enum. | 239 // Must remain at the end of the enum. |
| 240 kNumCacheEntryDataIndices | 240 kNumCacheEntryDataIndices |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 // Used with DoneWithEntry() to indicate the state of the entry. |
| 244 enum class EntryState { KEEP, DOOM }; |
| 245 |
| 243 class MetadataWriter; | 246 class MetadataWriter; |
| 244 class QuicServerInfoFactoryAdaptor; | 247 class QuicServerInfoFactoryAdaptor; |
| 245 class Transaction; | 248 class Transaction; |
| 246 class WorkItem; | 249 class WorkItem; |
| 247 friend class Transaction; | 250 friend class Transaction; |
| 248 friend class ViewCacheHelper; | 251 friend class ViewCacheHelper; |
| 249 struct PendingOp; // Info for an entry under construction. | 252 struct PendingOp; // Info for an entry under construction. |
| 250 | 253 |
| 251 typedef std::list<Transaction*> TransactionList; | 254 typedef std::list<Transaction*> TransactionList; |
| 252 typedef std::list<WorkItem*> WorkItemList; | 255 typedef std::list<WorkItem*> WorkItemList; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Destroys an ActiveEntry (active or doomed). | 343 // Destroys an ActiveEntry (active or doomed). |
| 341 void DestroyEntry(ActiveEntry* entry); | 344 void DestroyEntry(ActiveEntry* entry); |
| 342 | 345 |
| 343 // Adds a transaction to an ActiveEntry. If this method returns ERR_IO_PENDING | 346 // Adds a transaction to an ActiveEntry. If this method returns ERR_IO_PENDING |
| 344 // the transaction will be notified about completion via its IO callback. This | 347 // the transaction will be notified about completion via its IO callback. This |
| 345 // method returns ERR_CACHE_RACE to signal the transaction that it cannot be | 348 // method returns ERR_CACHE_RACE to signal the transaction that it cannot be |
| 346 // added to the provided entry, and it should retry the process with another | 349 // added to the provided entry, and it should retry the process with another |
| 347 // one (in this case, the entry is no longer valid). | 350 // one (in this case, the entry is no longer valid). |
| 348 int AddTransactionToEntry(ActiveEntry* entry, Transaction* trans); | 351 int AddTransactionToEntry(ActiveEntry* entry, Transaction* trans); |
| 349 | 352 |
| 350 // Called when the transaction has finished working with this entry. |cancel| | 353 // Removes |trans| from |entry|. |trans| is required to be a reader or writer |
| 351 // is true if the operation was cancelled by the caller instead of running | 354 // that was added to |trans| by AddTransactionToEntry(). For writers, |
| 352 // to completion. | 355 // |entry_state| indicates whether the cache entry should be kept or |
| 353 void DoneWithEntry(ActiveEntry* entry, Transaction* trans, bool cancel); | 356 // discarded. |
| 354 | 357 // |
| 355 // Called when the transaction has finished writing to this entry. |success| | 358 // If |entry_state| is DOOM, then the cache entry is destroyed and any |
| 356 // is false if the cache entry should be deleted. | 359 // pending transactions that were formerly waiting to be added to |entry| will |
| 357 void DoneWritingToEntry(ActiveEntry* entry, bool success); | 360 // receive ERR_CACHE_RACE. |
| 358 | 361 // |
| 359 // Called when the transaction has finished reading from this entry. | 362 // If |entry_state| is KEEP, then |entry| is assumed to be safe for |
| 360 void DoneReadingFromEntry(ActiveEntry* entry, Transaction* trans); | 363 // further consumption and pending transaction will be permitted to use it. |
| 364 void DoneWithEntry(ActiveEntry* entry, |
| 365 Transaction* trans, |
| 366 EntryState entry_state); |
| 361 | 367 |
| 362 // Converts the active writer transaction to a reader so that other | 368 // Converts the active writer transaction to a reader so that other |
| 363 // transactions can start reading from this entry. | 369 // transactions can start reading from this entry. |
| 364 void ConvertWriterToReader(ActiveEntry* entry); | 370 void ConvertWriterToReader(ActiveEntry* entry); |
| 365 | 371 |
| 366 // Returns the LoadState of the provided pending transaction. | 372 // Returns the LoadState of the provided pending transaction. |
| 367 LoadState GetLoadStateForPendingTransaction(const Transaction* trans); | 373 LoadState GetLoadStateForPendingTransaction(const Transaction* trans); |
| 368 | 374 |
| 369 // Removes the transaction |trans|, from the pending list of an entry | 375 // Removes the transaction |trans|, from the pending list of an entry |
| 370 // (PendingOp, active or doomed entry). | 376 // (PendingOp, active or doomed entry). |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 scoped_ptr<base::Clock> clock_; | 447 scoped_ptr<base::Clock> clock_; |
| 442 | 448 |
| 443 base::WeakPtrFactory<HttpCache> weak_factory_; | 449 base::WeakPtrFactory<HttpCache> weak_factory_; |
| 444 | 450 |
| 445 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 451 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
| 446 }; | 452 }; |
| 447 | 453 |
| 448 } // namespace net | 454 } // namespace net |
| 449 | 455 |
| 450 #endif // NET_HTTP_HTTP_CACHE_H_ | 456 #endif // NET_HTTP_HTTP_CACHE_H_ |
| OLD | NEW |