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. |
11 // | 11 // |
12 // See HttpTransactionFactory and HttpTransaction for more details. | 12 // See HttpTransactionFactory and HttpTransaction for more details. |
13 | 13 |
14 #ifndef NET_HTTP_HTTP_CACHE_H_ | 14 #ifndef NET_HTTP_HTTP_CACHE_H_ |
15 #define NET_HTTP_HTTP_CACHE_H_ | 15 #define NET_HTTP_HTTP_CACHE_H_ |
16 | 16 |
17 #include <list> | 17 #include <list> |
18 #include <map> | 18 #include <map> |
19 #include <set> | 19 #include <set> |
20 #include <string> | 20 #include <string> |
21 | 21 |
22 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
23 #include "base/containers/hash_tables.h" | 23 #include "base/containers/hash_tables.h" |
24 #include "base/files/file_path.h" | 24 #include "base/files/file_path.h" |
25 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
26 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
27 #include "base/threading/non_thread_safe.h" | 27 #include "base/threading/non_thread_safe.h" |
| 28 #include "base/time/clock.h" |
28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
29 #include "net/base/cache_type.h" | 30 #include "net/base/cache_type.h" |
30 #include "net/base/completion_callback.h" | 31 #include "net/base/completion_callback.h" |
31 #include "net/base/load_states.h" | 32 #include "net/base/load_states.h" |
32 #include "net/base/net_export.h" | 33 #include "net/base/net_export.h" |
33 #include "net/base/request_priority.h" | 34 #include "net/base/request_priority.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; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const CompletionCallback& callback) override; | 120 const CompletionCallback& callback) override; |
120 | 121 |
121 private: | 122 private: |
122 CacheType type_; | 123 CacheType type_; |
123 BackendType backend_type_; | 124 BackendType backend_type_; |
124 const base::FilePath path_; | 125 const base::FilePath path_; |
125 int max_bytes_; | 126 int max_bytes_; |
126 scoped_refptr<base::SingleThreadTaskRunner> thread_; | 127 scoped_refptr<base::SingleThreadTaskRunner> thread_; |
127 }; | 128 }; |
128 | 129 |
| 130 // The number of minutes after a resource is prefetched that it can be used |
| 131 // again without validation. |
| 132 static const int kPrefetchReuseMins = 5; |
| 133 |
129 // The disk cache is initialized lazily (by CreateTransaction) in this case. | 134 // The disk cache is initialized lazily (by CreateTransaction) in this case. |
130 // The HttpCache takes ownership of the |backend_factory|. | 135 // The HttpCache takes ownership of the |backend_factory|. |
131 HttpCache(const net::HttpNetworkSession::Params& params, | 136 HttpCache(const net::HttpNetworkSession::Params& params, |
132 BackendFactory* backend_factory); | 137 BackendFactory* backend_factory); |
133 | 138 |
134 // The disk cache is initialized lazily (by CreateTransaction) in this case. | 139 // The disk cache is initialized lazily (by CreateTransaction) in this case. |
135 // Provide an existing HttpNetworkSession, the cache can construct a | 140 // Provide an existing HttpNetworkSession, the cache can construct a |
136 // network layer with a shared HttpNetworkSession in order for multiple | 141 // network layer with a shared HttpNetworkSession in order for multiple |
137 // network layers to share information (e.g. authentication data). The | 142 // network layers to share information (e.g. authentication data). The |
138 // HttpCache takes ownership of the |backend_factory|. | 143 // HttpCache takes ownership of the |backend_factory|. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 void WriteMetadata(const GURL& url, | 179 void WriteMetadata(const GURL& url, |
175 RequestPriority priority, | 180 RequestPriority priority, |
176 base::Time expected_response_time, | 181 base::Time expected_response_time, |
177 IOBuffer* buf, | 182 IOBuffer* buf, |
178 int buf_len); | 183 int buf_len); |
179 | 184 |
180 // Get/Set the cache's mode. | 185 // Get/Set the cache's mode. |
181 void set_mode(Mode value) { mode_ = value; } | 186 void set_mode(Mode value) { mode_ = value; } |
182 Mode mode() { return mode_; } | 187 Mode mode() { return mode_; } |
183 | 188 |
| 189 // Get/Set the cache's clock. These are public only for testing. |
| 190 void SetClockForTesting(scoped_ptr<base::Clock> clock) { |
| 191 clock_.reset(clock.release()); |
| 192 } |
| 193 base::Clock* clock() const { return clock_.get(); } |
| 194 |
184 // Close currently active sockets so that fresh page loads will not use any | 195 // Close currently active sockets so that fresh page loads will not use any |
185 // recycled connections. For sockets currently in use, they may not close | 196 // recycled connections. For sockets currently in use, they may not close |
186 // immediately, but they will not be reusable. This is for debugging. | 197 // immediately, but they will not be reusable. This is for debugging. |
187 void CloseAllConnections(); | 198 void CloseAllConnections(); |
188 | 199 |
189 // Close all idle connections. Will close all sockets not in active use. | 200 // Close all idle connections. Will close all sockets not in active use. |
190 void CloseIdleConnections(); | 201 void CloseIdleConnections(); |
191 | 202 |
192 // Called whenever an external cache in the system reuses the resource | 203 // Called whenever an external cache in the system reuses the resource |
193 // referred to by |url| and |http_method|. | 204 // referred to by |url| and |http_method|. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 ActiveEntriesSet doomed_entries_; | 466 ActiveEntriesSet doomed_entries_; |
456 | 467 |
457 // The set of entries "under construction". | 468 // The set of entries "under construction". |
458 PendingOpsMap pending_ops_; | 469 PendingOpsMap pending_ops_; |
459 | 470 |
460 scoped_ptr<PlaybackCacheMap> playback_cache_map_; | 471 scoped_ptr<PlaybackCacheMap> playback_cache_map_; |
461 | 472 |
462 // The async validations currently in progress, keyed by URL. | 473 // The async validations currently in progress, keyed by URL. |
463 AsyncValidationMap async_validations_; | 474 AsyncValidationMap async_validations_; |
464 | 475 |
| 476 // A clock that can be swapped out for testing. |
| 477 scoped_ptr<base::Clock> clock_; |
| 478 |
465 base::WeakPtrFactory<HttpCache> weak_factory_; | 479 base::WeakPtrFactory<HttpCache> weak_factory_; |
466 | 480 |
467 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 481 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
468 }; | 482 }; |
469 | 483 |
470 } // namespace net | 484 } // namespace net |
471 | 485 |
472 #endif // NET_HTTP_HTTP_CACHE_H_ | 486 #endif // NET_HTTP_HTTP_CACHE_H_ |
OLD | NEW |