| 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 2616 (any exceptions are called out in the code). | 7 // caching logic follows RFC 2616 (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 19 matching lines...) Expand all Loading... |
| 30 #include "net/base/completion_callback.h" | 30 #include "net/base/completion_callback.h" |
| 31 #include "net/base/load_states.h" | 31 #include "net/base/load_states.h" |
| 32 #include "net/base/net_export.h" | 32 #include "net/base/net_export.h" |
| 33 #include "net/base/request_priority.h" | 33 #include "net/base/request_priority.h" |
| 34 #include "net/http/http_network_session.h" | 34 #include "net/http/http_network_session.h" |
| 35 #include "net/http/http_transaction_factory.h" | 35 #include "net/http/http_transaction_factory.h" |
| 36 | 36 |
| 37 class GURL; | 37 class GURL; |
| 38 | 38 |
| 39 namespace base { | 39 namespace base { |
| 40 class Clock; |
| 40 class SingleThreadTaskRunner; | 41 class SingleThreadTaskRunner; |
| 41 } // namespace base | 42 } // namespace base |
| 42 | 43 |
| 43 namespace disk_cache { | 44 namespace disk_cache { |
| 44 class Backend; | 45 class Backend; |
| 45 class Entry; | 46 class Entry; |
| 46 } // namespace disk_cache | 47 } // namespace disk_cache |
| 47 | 48 |
| 48 namespace net { | 49 namespace net { |
| 49 | 50 |
| 50 class CertVerifier; | 51 class CertVerifier; |
| 51 class ChannelIDService; | 52 class ChannelIDService; |
| 52 class DiskBasedCertCache; | 53 class DiskBasedCertCache; |
| 53 class HostResolver; | 54 class HostResolver; |
| 54 class HttpAuthHandlerFactory; | 55 class HttpAuthHandlerFactory; |
| 56 class HttpCachePrefetchValidationTest; |
| 55 class HttpNetworkSession; | 57 class HttpNetworkSession; |
| 56 class HttpResponseInfo; | 58 class HttpResponseInfo; |
| 57 class HttpServerProperties; | 59 class HttpServerProperties; |
| 58 class IOBuffer; | 60 class IOBuffer; |
| 59 class NetLog; | 61 class NetLog; |
| 60 class NetworkDelegate; | 62 class NetworkDelegate; |
| 61 class ProxyService; | 63 class ProxyService; |
| 62 class SSLConfigService; | 64 class SSLConfigService; |
| 63 class TransportSecurityState; | 65 class TransportSecurityState; |
| 64 class ViewCacheHelper; | 66 class ViewCacheHelper; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Must remain at the end of the enum. | 242 // Must remain at the end of the enum. |
| 241 kNumCacheEntryDataIndices | 243 kNumCacheEntryDataIndices |
| 242 }; | 244 }; |
| 243 | 245 |
| 244 class MetadataWriter; | 246 class MetadataWriter; |
| 245 class QuicServerInfoFactoryAdaptor; | 247 class QuicServerInfoFactoryAdaptor; |
| 246 class Transaction; | 248 class Transaction; |
| 247 class WorkItem; | 249 class WorkItem; |
| 248 friend class Transaction; | 250 friend class Transaction; |
| 249 friend class ViewCacheHelper; | 251 friend class ViewCacheHelper; |
| 252 friend class HttpCachePrefetchValidationTest; |
| 250 struct PendingOp; // Info for an entry under construction. | 253 struct PendingOp; // Info for an entry under construction. |
| 251 class AsyncValidation; // Encapsulates a single async revalidation. | 254 class AsyncValidation; // Encapsulates a single async revalidation. |
| 252 | 255 |
| 253 typedef std::list<Transaction*> TransactionList; | 256 typedef std::list<Transaction*> TransactionList; |
| 254 typedef std::list<WorkItem*> WorkItemList; | 257 typedef std::list<WorkItem*> WorkItemList; |
| 255 typedef std::map<std::string, AsyncValidation*> AsyncValidationMap; | 258 typedef std::map<std::string, AsyncValidation*> AsyncValidationMap; |
| 256 | 259 |
| 257 struct ActiveEntry { | 260 struct ActiveEntry { |
| 258 explicit ActiveEntry(disk_cache::Entry* entry); | 261 explicit ActiveEntry(disk_cache::Entry* entry); |
| 259 ~ActiveEntry(); | 262 ~ActiveEntry(); |
| 260 | 263 |
| 261 disk_cache::Entry* disk_entry; | 264 disk_cache::Entry* disk_entry; |
| 262 Transaction* writer; | 265 Transaction* writer; |
| 263 TransactionList readers; | 266 TransactionList readers; |
| 264 TransactionList pending_queue; | 267 TransactionList pending_queue; |
| 265 bool will_process_pending_queue; | 268 bool will_process_pending_queue; |
| 266 bool doomed; | 269 bool doomed; |
| 267 }; | 270 }; |
| 268 | 271 |
| 269 typedef base::hash_map<std::string, ActiveEntry*> ActiveEntriesMap; | 272 typedef base::hash_map<std::string, ActiveEntry*> ActiveEntriesMap; |
| 270 typedef base::hash_map<std::string, PendingOp*> PendingOpsMap; | 273 typedef base::hash_map<std::string, PendingOp*> PendingOpsMap; |
| 271 typedef std::set<ActiveEntry*> ActiveEntriesSet; | 274 typedef std::set<ActiveEntry*> ActiveEntriesSet; |
| 272 typedef base::hash_map<std::string, int> PlaybackCacheMap; | 275 typedef base::hash_map<std::string, int> PlaybackCacheMap; |
| 273 | 276 |
| 277 // The number of minutes after a resource is prefetched that it can be used |
| 278 // again without validation. |
| 279 static const int kPrefetchReuseMins = 5; |
| 280 |
| 274 // Methods ------------------------------------------------------------------ | 281 // Methods ------------------------------------------------------------------ |
| 275 | 282 |
| 276 // Creates the |backend| object and notifies the |callback| when the operation | 283 // Creates the |backend| object and notifies the |callback| when the operation |
| 277 // completes. Returns an error code. | 284 // completes. Returns an error code. |
| 278 int CreateBackend(disk_cache::Backend** backend, | 285 int CreateBackend(disk_cache::Backend** backend, |
| 279 const net::CompletionCallback& callback); | 286 const net::CompletionCallback& callback); |
| 280 | 287 |
| 281 // Makes sure that the backend creation is complete before allowing the | 288 // Makes sure that the backend creation is complete before allowing the |
| 282 // provided transaction to use the object. Returns an error code. |trans| | 289 // provided transaction to use the object. Returns an error code. |trans| |
| 283 // will be notified via its IO callback if this method returns ERR_IO_PENDING. | 290 // will be notified via its IO callback if this method returns ERR_IO_PENDING. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 ActiveEntriesSet doomed_entries_; | 455 ActiveEntriesSet doomed_entries_; |
| 449 | 456 |
| 450 // The set of entries "under construction". | 457 // The set of entries "under construction". |
| 451 PendingOpsMap pending_ops_; | 458 PendingOpsMap pending_ops_; |
| 452 | 459 |
| 453 scoped_ptr<PlaybackCacheMap> playback_cache_map_; | 460 scoped_ptr<PlaybackCacheMap> playback_cache_map_; |
| 454 | 461 |
| 455 // The async validations currently in progress, keyed by URL. | 462 // The async validations currently in progress, keyed by URL. |
| 456 AsyncValidationMap async_validations_; | 463 AsyncValidationMap async_validations_; |
| 457 | 464 |
| 465 // A clock that can be swapped out for testing. |
| 466 scoped_ptr<base::Clock> clock_; |
| 467 |
| 458 base::WeakPtrFactory<HttpCache> weak_factory_; | 468 base::WeakPtrFactory<HttpCache> weak_factory_; |
| 459 | 469 |
| 460 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 470 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
| 461 }; | 471 }; |
| 462 | 472 |
| 463 } // namespace net | 473 } // namespace net |
| 464 | 474 |
| 465 #endif // NET_HTTP_HTTP_CACHE_H_ | 475 #endif // NET_HTTP_HTTP_CACHE_H_ |
| OLD | NEW |