| 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 14 matching lines...) Expand all Loading... |
| 25 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
| 26 #include "base/message_loop_proxy.h" | 26 #include "base/message_loop_proxy.h" |
| 27 #include "base/time.h" | 27 #include "base/time.h" |
| 28 #include "base/threading/non_thread_safe.h" | 28 #include "base/threading/non_thread_safe.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/http/http_network_session.h" | 33 #include "net/http/http_network_session.h" |
| 34 #include "net/http/http_transaction_factory.h" | 34 #include "net/http/http_transaction_factory.h" |
| 35 #include "net/http/infinite_cache.h" | |
| 36 | 35 |
| 37 class GURL; | 36 class GURL; |
| 38 | 37 |
| 39 namespace disk_cache { | 38 namespace disk_cache { |
| 40 class Backend; | 39 class Backend; |
| 41 class Entry; | 40 class Entry; |
| 42 } | 41 } |
| 43 | 42 |
| 44 namespace net { | 43 namespace net { |
| 45 | 44 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // Close all idle connections. Will close all sockets not in active use. | 176 // Close all idle connections. Will close all sockets not in active use. |
| 178 void CloseIdleConnections(); | 177 void CloseIdleConnections(); |
| 179 | 178 |
| 180 // Called whenever an external cache in the system reuses the resource | 179 // Called whenever an external cache in the system reuses the resource |
| 181 // referred to by |url| and |http_method|. | 180 // referred to by |url| and |http_method|. |
| 182 void OnExternalCacheHit(const GURL& url, const std::string& http_method); | 181 void OnExternalCacheHit(const GURL& url, const std::string& http_method); |
| 183 | 182 |
| 184 // Initializes the Infinite Cache, if selected by the field trial. | 183 // Initializes the Infinite Cache, if selected by the field trial. |
| 185 void InitializeInfiniteCache(const FilePath& path); | 184 void InitializeInfiniteCache(const FilePath& path); |
| 186 | 185 |
| 187 // Returns a pointer to the Infinite Cache. | |
| 188 InfiniteCache* infinite_cache() { return &infinite_cache_; } | |
| 189 | |
| 190 // HttpTransactionFactory implementation: | 186 // HttpTransactionFactory implementation: |
| 191 virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans, | 187 virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans, |
| 192 HttpTransactionDelegate* delegate) OVERRIDE; | 188 HttpTransactionDelegate* delegate) OVERRIDE; |
| 193 virtual HttpCache* GetCache() OVERRIDE; | 189 virtual HttpCache* GetCache() OVERRIDE; |
| 194 virtual HttpNetworkSession* GetSession() OVERRIDE; | 190 virtual HttpNetworkSession* GetSession() OVERRIDE; |
| 195 | 191 |
| 196 protected: | 192 protected: |
| 197 // Disk cache entry data indices. | 193 // Disk cache entry data indices. |
| 198 enum { | 194 enum { |
| 199 kResponseInfoIndex = 0, | 195 kResponseInfoIndex = 0, |
| 200 kResponseContentIndex, | 196 kResponseContentIndex, |
| 201 kMetadataIndex, | 197 kMetadataIndex, |
| 202 | 198 |
| 203 // Must remain at the end of the enum. | 199 // Must remain at the end of the enum. |
| 204 kNumCacheEntryDataIndices | 200 kNumCacheEntryDataIndices |
| 205 }; | 201 }; |
| 206 friend class ViewCacheHelper; | 202 friend class ViewCacheHelper; |
| 207 | 203 |
| 208 private: | 204 private: |
| 209 // Types -------------------------------------------------------------------- | 205 // Types -------------------------------------------------------------------- |
| 210 | 206 |
| 211 class MetadataWriter; | 207 class MetadataWriter; |
| 212 class Transaction; | 208 class Transaction; |
| 213 class WorkItem; | 209 class WorkItem; |
| 214 friend class Transaction; | 210 friend class Transaction; |
| 215 friend class InfiniteCache; | |
| 216 struct PendingOp; // Info for an entry under construction. | 211 struct PendingOp; // Info for an entry under construction. |
| 217 | 212 |
| 218 typedef std::list<Transaction*> TransactionList; | 213 typedef std::list<Transaction*> TransactionList; |
| 219 typedef std::list<WorkItem*> WorkItemList; | 214 typedef std::list<WorkItem*> WorkItemList; |
| 220 | 215 |
| 221 struct ActiveEntry { | 216 struct ActiveEntry { |
| 222 explicit ActiveEntry(disk_cache::Entry* entry); | 217 explicit ActiveEntry(disk_cache::Entry* entry); |
| 223 ~ActiveEntry(); | 218 ~ActiveEntry(); |
| 224 | 219 |
| 225 disk_cache::Entry* disk_entry; | 220 disk_cache::Entry* disk_entry; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 ActiveEntriesMap active_entries_; | 379 ActiveEntriesMap active_entries_; |
| 385 | 380 |
| 386 // The set of doomed entries. | 381 // The set of doomed entries. |
| 387 ActiveEntriesSet doomed_entries_; | 382 ActiveEntriesSet doomed_entries_; |
| 388 | 383 |
| 389 // The set of entries "under construction". | 384 // The set of entries "under construction". |
| 390 PendingOpsMap pending_ops_; | 385 PendingOpsMap pending_ops_; |
| 391 | 386 |
| 392 scoped_ptr<PlaybackCacheMap> playback_cache_map_; | 387 scoped_ptr<PlaybackCacheMap> playback_cache_map_; |
| 393 | 388 |
| 394 InfiniteCache infinite_cache_; | |
| 395 | |
| 396 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 389 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
| 397 }; | 390 }; |
| 398 | 391 |
| 399 } // namespace net | 392 } // namespace net |
| 400 | 393 |
| 401 #endif // NET_HTTP_HTTP_CACHE_H_ | 394 #endif // NET_HTTP_HTTP_CACHE_H_ |
| OLD | NEW |