Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 #include "base/macros.h" | 24 #include "base/macros.h" |
| 25 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
| 26 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
| 27 #include "base/time/clock.h" | 27 #include "base/time/clock.h" |
| 28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 29 #include "net/base/cache_type.h" | 29 #include "net/base/cache_type.h" |
| 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/disk_cache/disk_cache.h" | |
| 34 #include "net/http/http_network_session.h" | 35 #include "net/http/http_network_session.h" |
| 35 #include "net/http/http_transaction_factory.h" | 36 #include "net/http/http_transaction_factory.h" |
| 36 | 37 |
| 37 class GURL; | 38 class GURL; |
| 38 | 39 |
| 39 namespace base { | 40 namespace base { |
| 40 class SingleThreadTaskRunner; | 41 class SingleThreadTaskRunner; |
| 41 namespace trace_event { | 42 namespace trace_event { |
| 42 class ProcessMemoryDump; | 43 class ProcessMemoryDump; |
| 43 } | 44 } |
| 44 } // namespace base | 45 } // namespace base |
| 45 | 46 |
| 46 namespace disk_cache { | 47 namespace disk_cache { |
| 47 class Backend; | |
| 48 class Entry; | 48 class Entry; |
| 49 } // namespace disk_cache | 49 } // namespace disk_cache |
| 50 | 50 |
| 51 namespace net { | 51 namespace net { |
| 52 | 52 |
| 53 class HttpNetworkSession; | 53 class HttpNetworkSession; |
| 54 class HttpResponseInfo; | 54 class HttpResponseInfo; |
| 55 class IOBuffer; | 55 class IOBuffer; |
| 56 class NetLog; | 56 class NetLog; |
| 57 class ViewCacheHelper; | 57 class ViewCacheHelper; |
| 58 struct HttpRequestInfo; | 58 struct HttpRequestInfo; |
| 59 | 59 |
| 60 class NET_EXPORT HttpCache : public HttpTransactionFactory { | 60 class NET_EXPORT HttpCache : public HttpTransactionFactory { |
| 61 public: | 61 public: |
| 62 // The cache mode of operation. | 62 // The cache mode of operation. |
| 63 enum Mode { | 63 enum Mode { |
| 64 // Normal mode just behaves like a standard web cache. | 64 // Normal mode just behaves like a standard web cache. |
| 65 NORMAL = 0, | 65 NORMAL = 0, |
| 66 // Disables reads and writes from the cache. | 66 // Disables reads and writes from the cache. |
| 67 // Equivalent to setting LOAD_DISABLE_CACHE on every request. | 67 // Equivalent to setting LOAD_DISABLE_CACHE on every request. |
| 68 DISABLE | 68 DISABLE |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 // ### probably don't need to blow all of 3 bits on this. | |
| 72 enum OracleByteHints { | |
| 73 OBH_ZERO_LIFETIME = 1, | |
| 74 OBH_RESPONSE_CANT_CONDITIONALIZE = 2, | |
| 75 OBH_UNUSED_SINCE_PREFETCH = 4 | |
|
pasko
2017/06/13 14:30:05
it's nice to have it here in general, but probably
Maks Orlovich
2017/06/13 14:58:47
We have to deal with it, since it affects HttpCach
| |
| 76 }; | |
| 77 | |
| 71 // A BackendFactory creates a backend object to be used by the HttpCache. | 78 // A BackendFactory creates a backend object to be used by the HttpCache. |
| 72 class NET_EXPORT BackendFactory { | 79 class NET_EXPORT BackendFactory { |
| 73 public: | 80 public: |
| 74 virtual ~BackendFactory() {} | 81 virtual ~BackendFactory() {} |
| 75 | 82 |
| 76 // The actual method to build the backend. Returns a net error code. If | 83 // The actual method to build the backend. Returns a net error code. If |
| 77 // ERR_IO_PENDING is returned, the |callback| will be notified when the | 84 // ERR_IO_PENDING is returned, the |callback| will be notified when the |
| 78 // operation completes, and |backend| must remain valid until the | 85 // operation completes, and |backend| must remain valid until the |
| 79 // notification arrives. | 86 // notification arrives. |
| 80 // The implementation must not access the factory object after invoking the | 87 // The implementation must not access the factory object after invoking the |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 // Returns the PendingOp for the desired |key|. If an entry is not under | 329 // Returns the PendingOp for the desired |key|. If an entry is not under |
| 323 // construction already, a new PendingOp structure is created. | 330 // construction already, a new PendingOp structure is created. |
| 324 PendingOp* GetPendingOp(const std::string& key); | 331 PendingOp* GetPendingOp(const std::string& key); |
| 325 | 332 |
| 326 // Deletes a PendingOp. | 333 // Deletes a PendingOp. |
| 327 void DeletePendingOp(PendingOp* pending_op); | 334 void DeletePendingOp(PendingOp* pending_op); |
| 328 | 335 |
| 329 // Opens the disk cache entry associated with |key|, returning an ActiveEntry | 336 // Opens the disk cache entry associated with |key|, returning an ActiveEntry |
| 330 // in |*entry|. |trans| will be notified via its IO callback if this method | 337 // in |*entry|. |trans| will be notified via its IO callback if this method |
| 331 // returns ERR_IO_PENDING. | 338 // returns ERR_IO_PENDING. |
| 332 int OpenEntry(const std::string& key, ActiveEntry** entry, | 339 int OpenEntry(const std::string& key, |
| 340 ActiveEntry** entry, | |
| 333 Transaction* trans); | 341 Transaction* trans); |
| 334 | 342 |
| 335 // Creates the disk cache entry associated with |key|, returning an | 343 // Creates the disk cache entry associated with |key|, returning an |
| 336 // ActiveEntry in |*entry|. |trans| will be notified via its IO callback if | 344 // ActiveEntry in |*entry|. |trans| will be notified via its IO callback if |
| 337 // this method returns ERR_IO_PENDING. | 345 // this method returns ERR_IO_PENDING. |
| 338 int CreateEntry(const std::string& key, ActiveEntry** entry, | 346 int CreateEntry(const std::string& key, ActiveEntry** entry, |
| 339 Transaction* trans); | 347 Transaction* trans); |
| 340 | 348 |
| 341 // Destroys an ActiveEntry (active or doomed). | 349 // Destroys an ActiveEntry (active or doomed). |
| 342 void DestroyEntry(ActiveEntry* entry); | 350 void DestroyEntry(ActiveEntry* entry); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 THREAD_CHECKER(thread_checker_); | 444 THREAD_CHECKER(thread_checker_); |
| 437 | 445 |
| 438 base::WeakPtrFactory<HttpCache> weak_factory_; | 446 base::WeakPtrFactory<HttpCache> weak_factory_; |
| 439 | 447 |
| 440 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 448 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
| 441 }; | 449 }; |
| 442 | 450 |
| 443 } // namespace net | 451 } // namespace net |
| 444 | 452 |
| 445 #endif // NET_HTTP_HTTP_CACHE_H_ | 453 #endif // NET_HTTP_HTTP_CACHE_H_ |
| OLD | NEW |