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 namespace trace_event { | 41 namespace trace_event { |
41 class ProcessMemoryDump; | 42 class ProcessMemoryDump; |
42 } | 43 } |
43 } // namespace base | 44 } // namespace base |
44 | 45 |
45 namespace disk_cache { | 46 namespace disk_cache { |
46 class Backend; | |
47 class Entry; | 47 class Entry; |
48 } // namespace disk_cache | 48 } // namespace disk_cache |
49 | 49 |
50 namespace net { | 50 namespace net { |
51 | 51 |
52 class HttpNetworkSession; | 52 class HttpNetworkSession; |
53 class HttpResponseInfo; | 53 class HttpResponseInfo; |
54 class IOBuffer; | 54 class IOBuffer; |
55 class NetLog; | 55 class NetLog; |
56 class ViewCacheHelper; | 56 class ViewCacheHelper; |
57 struct HttpRequestInfo; | 57 struct HttpRequestInfo; |
58 | 58 |
59 class NET_EXPORT HttpCache : public HttpTransactionFactory { | 59 class NET_EXPORT HttpCache : public HttpTransactionFactory { |
60 public: | 60 public: |
61 // The cache mode of operation. | 61 // The cache mode of operation. |
62 enum Mode { | 62 enum Mode { |
63 // Normal mode just behaves like a standard web cache. | 63 // Normal mode just behaves like a standard web cache. |
64 NORMAL = 0, | 64 NORMAL = 0, |
65 // Disables reads and writes from the cache. | 65 // Disables reads and writes from the cache. |
66 // Equivalent to setting LOAD_DISABLE_CACHE on every request. | 66 // Equivalent to setting LOAD_DISABLE_CACHE on every request. |
67 DISABLE | 67 DISABLE |
68 }; | 68 }; |
69 | 69 |
| 70 enum MemoryEntryDataHints { |
| 71 HINT_ZERO_LIFETIME = 1, |
| 72 HINT_RESPONSE_CANT_CONDITIONALIZE = 2, |
| 73 HINT_UNUSED_SINCE_PREFETCH = 4 |
| 74 }; |
| 75 |
70 // A BackendFactory creates a backend object to be used by the HttpCache. | 76 // A BackendFactory creates a backend object to be used by the HttpCache. |
71 class NET_EXPORT BackendFactory { | 77 class NET_EXPORT BackendFactory { |
72 public: | 78 public: |
73 virtual ~BackendFactory() {} | 79 virtual ~BackendFactory() {} |
74 | 80 |
75 // The actual method to build the backend. Returns a net error code. If | 81 // The actual method to build the backend. Returns a net error code. If |
76 // ERR_IO_PENDING is returned, the |callback| will be notified when the | 82 // ERR_IO_PENDING is returned, the |callback| will be notified when the |
77 // operation completes, and |backend| must remain valid until the | 83 // operation completes, and |backend| must remain valid until the |
78 // notification arrives. | 84 // notification arrives. |
79 // The implementation must not access the factory object after invoking the | 85 // The implementation must not access the factory object after invoking the |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 377 |
372 // Returns the PendingOp for the desired |key|. If an entry is not under | 378 // Returns the PendingOp for the desired |key|. If an entry is not under |
373 // construction already, a new PendingOp structure is created. | 379 // construction already, a new PendingOp structure is created. |
374 PendingOp* GetPendingOp(const std::string& key); | 380 PendingOp* GetPendingOp(const std::string& key); |
375 | 381 |
376 // Deletes a PendingOp. | 382 // Deletes a PendingOp. |
377 void DeletePendingOp(PendingOp* pending_op); | 383 void DeletePendingOp(PendingOp* pending_op); |
378 | 384 |
379 // Opens the disk cache entry associated with |key|, returning an ActiveEntry | 385 // Opens the disk cache entry associated with |key|, returning an ActiveEntry |
380 // in |*entry|. |trans| will be notified via its IO callback if this method | 386 // in |*entry|. |trans| will be notified via its IO callback if this method |
381 // returns ERR_IO_PENDING. | 387 // returns ERR_IO_PENDING. If there is no transaction already available, |
| 388 // it will first check with |trans->MaybeRejectBasedOnEntryInMemoryData|, |
| 389 // returning ERR_CACHE_ENTRY_NOT_SUITABLE after dooming the key if that |
| 390 // rejects the entry. |
382 int OpenEntry(const std::string& key, ActiveEntry** entry, | 391 int OpenEntry(const std::string& key, ActiveEntry** entry, |
383 Transaction* trans); | 392 Transaction* trans); |
384 | 393 |
385 // Creates the disk cache entry associated with |key|, returning an | 394 // Creates the disk cache entry associated with |key|, returning an |
386 // ActiveEntry in |*entry|. |trans| will be notified via its IO callback if | 395 // ActiveEntry in |*entry|. |trans| will be notified via its IO callback if |
387 // this method returns ERR_IO_PENDING. | 396 // this method returns ERR_IO_PENDING. |
388 int CreateEntry(const std::string& key, ActiveEntry** entry, | 397 int CreateEntry(const std::string& key, ActiveEntry** entry, |
389 Transaction* trans); | 398 Transaction* trans); |
390 | 399 |
391 // Destroys an ActiveEntry (active or doomed). | 400 // Destroys an ActiveEntry (active or doomed). |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 THREAD_CHECKER(thread_checker_); | 563 THREAD_CHECKER(thread_checker_); |
555 | 564 |
556 base::WeakPtrFactory<HttpCache> weak_factory_; | 565 base::WeakPtrFactory<HttpCache> weak_factory_; |
557 | 566 |
558 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 567 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
559 }; | 568 }; |
560 | 569 |
561 } // namespace net | 570 } // namespace net |
562 | 571 |
563 #endif // NET_HTTP_HTTP_CACHE_H_ | 572 #endif // NET_HTTP_HTTP_CACHE_H_ |
OLD | NEW |