| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 int max_bytes, | 109 int max_bytes, |
| 110 const scoped_refptr<base::SingleThreadTaskRunner>& thread); | 110 const scoped_refptr<base::SingleThreadTaskRunner>& thread); |
| 111 virtual ~DefaultBackend(); | 111 virtual ~DefaultBackend(); |
| 112 | 112 |
| 113 // Returns a factory for an in-memory cache. | 113 // Returns a factory for an in-memory cache. |
| 114 static BackendFactory* InMemory(int max_bytes); | 114 static BackendFactory* InMemory(int max_bytes); |
| 115 | 115 |
| 116 // BackendFactory implementation. | 116 // BackendFactory implementation. |
| 117 virtual int CreateBackend(NetLog* net_log, | 117 virtual int CreateBackend(NetLog* net_log, |
| 118 scoped_ptr<disk_cache::Backend>* backend, | 118 scoped_ptr<disk_cache::Backend>* backend, |
| 119 const CompletionCallback& callback) OVERRIDE; | 119 const CompletionCallback& callback) override; |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 CacheType type_; | 122 CacheType type_; |
| 123 BackendType backend_type_; | 123 BackendType backend_type_; |
| 124 const base::FilePath path_; | 124 const base::FilePath path_; |
| 125 int max_bytes_; | 125 int max_bytes_; |
| 126 scoped_refptr<base::SingleThreadTaskRunner> thread_; | 126 scoped_refptr<base::SingleThreadTaskRunner> thread_; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 // The disk cache is initialized lazily (by CreateTransaction) in this case. | 129 // The disk cache is initialized lazily (by CreateTransaction) in this case. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Enable stale_while_revalidate functionality for testing purposes. | 209 // Enable stale_while_revalidate functionality for testing purposes. |
| 210 void set_use_stale_while_revalidate_for_testing( | 210 void set_use_stale_while_revalidate_for_testing( |
| 211 bool use_stale_while_revalidate) { | 211 bool use_stale_while_revalidate) { |
| 212 use_stale_while_revalidate_ = use_stale_while_revalidate; | 212 use_stale_while_revalidate_ = use_stale_while_revalidate; |
| 213 } | 213 } |
| 214 | 214 |
| 215 // HttpTransactionFactory implementation: | 215 // HttpTransactionFactory implementation: |
| 216 virtual int CreateTransaction(RequestPriority priority, | 216 virtual int CreateTransaction(RequestPriority priority, |
| 217 scoped_ptr<HttpTransaction>* trans) OVERRIDE; | 217 scoped_ptr<HttpTransaction>* trans) override; |
| 218 virtual HttpCache* GetCache() OVERRIDE; | 218 virtual HttpCache* GetCache() override; |
| 219 virtual HttpNetworkSession* GetSession() OVERRIDE; | 219 virtual HttpNetworkSession* GetSession() override; |
| 220 | 220 |
| 221 base::WeakPtr<HttpCache> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | 221 base::WeakPtr<HttpCache> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
| 222 | 222 |
| 223 // Resets the network layer to allow for tests that probe | 223 // Resets the network layer to allow for tests that probe |
| 224 // network changes (e.g. host unreachable). The old network layer is | 224 // network changes (e.g. host unreachable). The old network layer is |
| 225 // returned to allow for filter patterns that only intercept | 225 // returned to allow for filter patterns that only intercept |
| 226 // some creation requests. Note ownership exchange. | 226 // some creation requests. Note ownership exchange. |
| 227 scoped_ptr<HttpTransactionFactory> | 227 scoped_ptr<HttpTransactionFactory> |
| 228 SetHttpNetworkTransactionFactoryForTesting( | 228 SetHttpNetworkTransactionFactoryForTesting( |
| 229 scoped_ptr<HttpTransactionFactory> new_network_layer); | 229 scoped_ptr<HttpTransactionFactory> new_network_layer); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 AsyncValidationMap async_validations_; | 456 AsyncValidationMap async_validations_; |
| 457 | 457 |
| 458 base::WeakPtrFactory<HttpCache> weak_factory_; | 458 base::WeakPtrFactory<HttpCache> weak_factory_; |
| 459 | 459 |
| 460 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 460 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
| 461 }; | 461 }; |
| 462 | 462 |
| 463 } // namespace net | 463 } // namespace net |
| 464 | 464 |
| 465 #endif // NET_HTTP_HTTP_CACHE_H_ | 465 #endif // NET_HTTP_HTTP_CACHE_H_ |
| OLD | NEW |