Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: net/http/http_cache.h

Issue 455623003: stale-while-revalidate experimental implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(bool use_stale_while_revalidate) {
yhirano 2014/08/26 07:52:01 How about adding "for_testing" suffix to this func
Adam Rice 2014/08/26 13:38:42 Done.
210 use_stale_while_revalidate_ = use_stale_while_revalidate;
211 }
212
204 // HttpTransactionFactory implementation: 213 // HttpTransactionFactory implementation:
205 virtual int CreateTransaction(RequestPriority priority, 214 virtual int CreateTransaction(RequestPriority priority,
206 scoped_ptr<HttpTransaction>* trans) OVERRIDE; 215 scoped_ptr<HttpTransaction>* trans) OVERRIDE;
207 virtual HttpCache* GetCache() OVERRIDE; 216 virtual HttpCache* GetCache() OVERRIDE;
208 virtual HttpNetworkSession* GetSession() OVERRIDE; 217 virtual HttpNetworkSession* GetSession() OVERRIDE;
209 218
210 base::WeakPtr<HttpCache> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } 219 base::WeakPtr<HttpCache> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
211 220
212 // Resets the network layer to allow for tests that probe 221 // Resets the network layer to allow for tests that probe
213 // network changes (e.g. host unreachable). The old network layer is 222 // network changes (e.g. host unreachable). The old network layer is
(...skipping 16 matching lines...) Expand all
230 kNumCacheEntryDataIndices 239 kNumCacheEntryDataIndices
231 }; 240 };
232 241
233 class MetadataWriter; 242 class MetadataWriter;
234 class QuicServerInfoFactoryAdaptor; 243 class QuicServerInfoFactoryAdaptor;
235 class Transaction; 244 class Transaction;
236 class WorkItem; 245 class WorkItem;
237 friend class Transaction; 246 friend class Transaction;
238 friend class ViewCacheHelper; 247 friend class ViewCacheHelper;
239 struct PendingOp; // Info for an entry under construction. 248 struct PendingOp; // Info for an entry under construction.
249 class AsyncValidation; // Encapsulates a single async revalidation.
240 250
241 typedef std::list<Transaction*> TransactionList; 251 typedef std::list<Transaction*> TransactionList;
242 typedef std::list<WorkItem*> WorkItemList; 252 typedef std::list<WorkItem*> WorkItemList;
253 typedef std::set<AsyncValidation*> AsyncValidationSet;
243 254
244 struct ActiveEntry { 255 struct ActiveEntry {
245 explicit ActiveEntry(disk_cache::Entry* entry); 256 explicit ActiveEntry(disk_cache::Entry* entry);
246 ~ActiveEntry(); 257 ~ActiveEntry();
247 258
248 disk_cache::Entry* disk_entry; 259 disk_cache::Entry* disk_entry;
249 Transaction* writer; 260 Transaction* writer;
250 TransactionList readers; 261 TransactionList readers;
251 TransactionList pending_queue; 262 TransactionList pending_queue;
252 bool will_process_pending_queue; 263 bool will_process_pending_queue;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // Removes the transaction |trans|, from the pending list of |pending_op|. 378 // Removes the transaction |trans|, from the pending list of |pending_op|.
368 bool RemovePendingTransactionFromPendingOp(PendingOp* pending_op, 379 bool RemovePendingTransactionFromPendingOp(PendingOp* pending_op,
369 Transaction* trans); 380 Transaction* trans);
370 381
371 // Instantiates and sets QUIC server info factory. 382 // Instantiates and sets QUIC server info factory.
372 void SetupQuicServerInfoFactory(HttpNetworkSession* session); 383 void SetupQuicServerInfoFactory(HttpNetworkSession* session);
373 384
374 // Resumes processing the pending list of |entry|. 385 // Resumes processing the pending list of |entry|.
375 void ProcessPendingQueue(ActiveEntry* entry); 386 void ProcessPendingQueue(ActiveEntry* entry);
376 387
388 // Called by Transaction to perform an asynchronous revalidation. Creates a
389 // new independent transaction as a copy of the original.
390 void PerformAsyncValidation(const HttpRequestInfo& original_request,
391 const BoundNetLog& net_log);
392
393 // Remove |async_validation| from the |async_validations_| set and delete it.
394 void DeleteAsyncValidation(AsyncValidation* async_validation);
395
377 // Events (called via PostTask) --------------------------------------------- 396 // Events (called via PostTask) ---------------------------------------------
378 397
379 void OnProcessPendingQueue(ActiveEntry* entry); 398 void OnProcessPendingQueue(ActiveEntry* entry);
380 399
381 // Callbacks ---------------------------------------------------------------- 400 // Callbacks ----------------------------------------------------------------
382 401
383 // Processes BackendCallback notifications. 402 // Processes BackendCallback notifications.
384 void OnIOComplete(int result, PendingOp* entry); 403 void OnIOComplete(int result, PendingOp* entry);
385 404
386 // Helper to conditionally delete |pending_op| if the HttpCache object it 405 // Helper to conditionally delete |pending_op| if the HttpCache object it
(...skipping 11 matching lines...) Expand all
398 417
399 // Variables ---------------------------------------------------------------- 418 // Variables ----------------------------------------------------------------
400 419
401 NetLog* net_log_; 420 NetLog* net_log_;
402 421
403 // Used when lazily constructing the disk_cache_. 422 // Used when lazily constructing the disk_cache_.
404 scoped_ptr<BackendFactory> backend_factory_; 423 scoped_ptr<BackendFactory> backend_factory_;
405 bool building_backend_; 424 bool building_backend_;
406 bool bypass_lock_for_test_; 425 bool bypass_lock_for_test_;
407 426
427 // true if the implementation of Cache-Control: stale-while-revalidate
428 // directive is enabled (either via command-line flag or experiment).
429 bool use_stale_while_revalidate_;
430
408 Mode mode_; 431 Mode mode_;
409 432
410 scoped_ptr<QuicServerInfoFactoryAdaptor> quic_server_info_factory_; 433 scoped_ptr<QuicServerInfoFactoryAdaptor> quic_server_info_factory_;
411 434
412 scoped_ptr<HttpTransactionFactory> network_layer_; 435 scoped_ptr<HttpTransactionFactory> network_layer_;
413 436
414 scoped_ptr<disk_cache::Backend> disk_cache_; 437 scoped_ptr<disk_cache::Backend> disk_cache_;
415 438
416 scoped_ptr<DiskBasedCertCache> cert_cache_; 439 scoped_ptr<DiskBasedCertCache> cert_cache_;
417 440
418 // The set of active entries indexed by cache key. 441 // The set of active entries indexed by cache key.
419 ActiveEntriesMap active_entries_; 442 ActiveEntriesMap active_entries_;
420 443
421 // The set of doomed entries. 444 // The set of doomed entries.
422 ActiveEntriesSet doomed_entries_; 445 ActiveEntriesSet doomed_entries_;
423 446
424 // The set of entries "under construction". 447 // The set of entries "under construction".
425 PendingOpsMap pending_ops_; 448 PendingOpsMap pending_ops_;
426 449
427 scoped_ptr<PlaybackCacheMap> playback_cache_map_; 450 scoped_ptr<PlaybackCacheMap> playback_cache_map_;
428 451
452 // The set of async validations currently in progress
453 AsyncValidationSet async_validations_;
454
429 base::WeakPtrFactory<HttpCache> weak_factory_; 455 base::WeakPtrFactory<HttpCache> weak_factory_;
430 456
431 DISALLOW_COPY_AND_ASSIGN(HttpCache); 457 DISALLOW_COPY_AND_ASSIGN(HttpCache);
432 }; 458 };
433 459
434 } // namespace net 460 } // namespace net
435 461
436 #endif // NET_HTTP_HTTP_CACHE_H_ 462 #endif // NET_HTTP_HTTP_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698