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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 | 194 |
195 // Initializes the Infinite Cache, if selected by the field trial. | 195 // Initializes the Infinite Cache, if selected by the field trial. |
196 void InitializeInfiniteCache(const base::FilePath& path); | 196 void InitializeInfiniteCache(const base::FilePath& path); |
197 | 197 |
198 // Causes all transactions created after this point to effectively bypass | 198 // Causes all transactions created after this point to effectively bypass |
199 // the cache lock whenever there is lock contention. | 199 // the cache lock whenever there is lock contention. |
200 void BypassLockForTest() { | 200 void BypassLockForTest() { |
201 bypass_lock_for_test_ = true; | 201 bypass_lock_for_test_ = true; |
202 } | 202 } |
203 | 203 |
204 bool use_stale_while_revalidate() const { | |
205 return use_stale_while_revalidate_; | |
206 } | |
207 | |
208 // Enable stale_while_revalidate functionality for testing purposes. | |
209 void set_use_stale_while_revalidate_for_testing( | |
210 bool use_stale_while_revalidate) { | |
211 use_stale_while_revalidate_ = use_stale_while_revalidate; | |
212 } | |
213 | |
204 // HttpTransactionFactory implementation: | 214 // HttpTransactionFactory implementation: |
205 virtual int CreateTransaction(RequestPriority priority, | 215 virtual int CreateTransaction(RequestPriority priority, |
206 scoped_ptr<HttpTransaction>* trans) OVERRIDE; | 216 scoped_ptr<HttpTransaction>* trans) OVERRIDE; |
207 virtual HttpCache* GetCache() OVERRIDE; | 217 virtual HttpCache* GetCache() OVERRIDE; |
208 virtual HttpNetworkSession* GetSession() OVERRIDE; | 218 virtual HttpNetworkSession* GetSession() OVERRIDE; |
209 | 219 |
210 base::WeakPtr<HttpCache> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | 220 base::WeakPtr<HttpCache> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
211 | 221 |
212 // Resets the network layer to allow for tests that probe | 222 // Resets the network layer to allow for tests that probe |
213 // network changes (e.g. host unreachable). The old network layer is | 223 // network changes (e.g. host unreachable). The old network layer is |
(...skipping 16 matching lines...) Expand all Loading... | |
230 kNumCacheEntryDataIndices | 240 kNumCacheEntryDataIndices |
231 }; | 241 }; |
232 | 242 |
233 class MetadataWriter; | 243 class MetadataWriter; |
234 class QuicServerInfoFactoryAdaptor; | 244 class QuicServerInfoFactoryAdaptor; |
235 class Transaction; | 245 class Transaction; |
236 class WorkItem; | 246 class WorkItem; |
237 friend class Transaction; | 247 friend class Transaction; |
238 friend class ViewCacheHelper; | 248 friend class ViewCacheHelper; |
239 struct PendingOp; // Info for an entry under construction. | 249 struct PendingOp; // Info for an entry under construction. |
250 class AsyncValidation; // Encapsulates a single async revalidation. | |
240 | 251 |
241 typedef std::list<Transaction*> TransactionList; | 252 typedef std::list<Transaction*> TransactionList; |
242 typedef std::list<WorkItem*> WorkItemList; | 253 typedef std::list<WorkItem*> WorkItemList; |
254 typedef std::set<AsyncValidation*> AsyncValidationSet; | |
243 | 255 |
244 struct ActiveEntry { | 256 struct ActiveEntry { |
245 explicit ActiveEntry(disk_cache::Entry* entry); | 257 explicit ActiveEntry(disk_cache::Entry* entry); |
246 ~ActiveEntry(); | 258 ~ActiveEntry(); |
247 | 259 |
248 disk_cache::Entry* disk_entry; | 260 disk_cache::Entry* disk_entry; |
249 Transaction* writer; | 261 Transaction* writer; |
250 TransactionList readers; | 262 TransactionList readers; |
251 TransactionList pending_queue; | 263 TransactionList pending_queue; |
252 bool will_process_pending_queue; | 264 bool will_process_pending_queue; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 // Removes the transaction |trans|, from the pending list of |pending_op|. | 379 // Removes the transaction |trans|, from the pending list of |pending_op|. |
368 bool RemovePendingTransactionFromPendingOp(PendingOp* pending_op, | 380 bool RemovePendingTransactionFromPendingOp(PendingOp* pending_op, |
369 Transaction* trans); | 381 Transaction* trans); |
370 | 382 |
371 // Instantiates and sets QUIC server info factory. | 383 // Instantiates and sets QUIC server info factory. |
372 void SetupQuicServerInfoFactory(HttpNetworkSession* session); | 384 void SetupQuicServerInfoFactory(HttpNetworkSession* session); |
373 | 385 |
374 // Resumes processing the pending list of |entry|. | 386 // Resumes processing the pending list of |entry|. |
375 void ProcessPendingQueue(ActiveEntry* entry); | 387 void ProcessPendingQueue(ActiveEntry* entry); |
376 | 388 |
389 // Called by Transaction to perform an asynchronous revalidation. Creates a | |
390 // new independent transaction as a copy of the original. | |
391 void PerformAsyncValidation(const HttpRequestInfo& original_request, | |
392 const BoundNetLog& net_log); | |
393 | |
394 // Remove |async_validation| from the |async_validations_| set and delete it. | |
395 void DeleteAsyncValidation(AsyncValidation* async_validation); | |
396 | |
377 // Events (called via PostTask) --------------------------------------------- | 397 // Events (called via PostTask) --------------------------------------------- |
378 | 398 |
379 void OnProcessPendingQueue(ActiveEntry* entry); | 399 void OnProcessPendingQueue(ActiveEntry* entry); |
380 | 400 |
381 // Callbacks ---------------------------------------------------------------- | 401 // Callbacks ---------------------------------------------------------------- |
382 | 402 |
383 // Processes BackendCallback notifications. | 403 // Processes BackendCallback notifications. |
384 void OnIOComplete(int result, PendingOp* entry); | 404 void OnIOComplete(int result, PendingOp* entry); |
385 | 405 |
386 // Helper to conditionally delete |pending_op| if the HttpCache object it | 406 // Helper to conditionally delete |pending_op| if the HttpCache object it |
(...skipping 11 matching lines...) Expand all Loading... | |
398 | 418 |
399 // Variables ---------------------------------------------------------------- | 419 // Variables ---------------------------------------------------------------- |
400 | 420 |
401 NetLog* net_log_; | 421 NetLog* net_log_; |
402 | 422 |
403 // Used when lazily constructing the disk_cache_. | 423 // Used when lazily constructing the disk_cache_. |
404 scoped_ptr<BackendFactory> backend_factory_; | 424 scoped_ptr<BackendFactory> backend_factory_; |
405 bool building_backend_; | 425 bool building_backend_; |
406 bool bypass_lock_for_test_; | 426 bool bypass_lock_for_test_; |
407 | 427 |
428 // true if the implementation of Cache-Control: stale-while-revalidate | |
429 // directive is enabled (either via command-line flag or experiment). | |
430 bool use_stale_while_revalidate_; | |
431 | |
408 Mode mode_; | 432 Mode mode_; |
409 | 433 |
410 scoped_ptr<QuicServerInfoFactoryAdaptor> quic_server_info_factory_; | 434 scoped_ptr<QuicServerInfoFactoryAdaptor> quic_server_info_factory_; |
411 | 435 |
412 scoped_ptr<HttpTransactionFactory> network_layer_; | 436 scoped_ptr<HttpTransactionFactory> network_layer_; |
413 | 437 |
414 scoped_ptr<disk_cache::Backend> disk_cache_; | 438 scoped_ptr<disk_cache::Backend> disk_cache_; |
415 | 439 |
416 scoped_ptr<DiskBasedCertCache> cert_cache_; | 440 scoped_ptr<DiskBasedCertCache> cert_cache_; |
417 | 441 |
418 // The set of active entries indexed by cache key. | 442 // The set of active entries indexed by cache key. |
419 ActiveEntriesMap active_entries_; | 443 ActiveEntriesMap active_entries_; |
420 | 444 |
421 // The set of doomed entries. | 445 // The set of doomed entries. |
422 ActiveEntriesSet doomed_entries_; | 446 ActiveEntriesSet doomed_entries_; |
423 | 447 |
424 // The set of entries "under construction". | 448 // The set of entries "under construction". |
425 PendingOpsMap pending_ops_; | 449 PendingOpsMap pending_ops_; |
426 | 450 |
427 scoped_ptr<PlaybackCacheMap> playback_cache_map_; | 451 scoped_ptr<PlaybackCacheMap> playback_cache_map_; |
428 | 452 |
453 // The set of async validations currently in progress. Invariant: all | |
454 // live AsyncValidation objects connected to this cache are in this set. | |
rvargas (doing something else)
2014/09/05 22:52:39
Isn't the invariant the expected behavior? Why doc
Adam Rice
2014/09/09 12:36:45
I have seen people do a lot of weird things in my
| |
455 AsyncValidationSet async_validations_; | |
456 | |
429 base::WeakPtrFactory<HttpCache> weak_factory_; | 457 base::WeakPtrFactory<HttpCache> weak_factory_; |
430 | 458 |
431 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 459 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
432 }; | 460 }; |
433 | 461 |
434 } // namespace net | 462 } // namespace net |
435 | 463 |
436 #endif // NET_HTTP_HTTP_CACHE_H_ | 464 #endif // NET_HTTP_HTTP_CACHE_H_ |
OLD | NEW |