Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: net/http/http_cache.h

Issue 19747: URLRequestContext and disk cache for media files (Closed)
Patch Set: signed and unsigned... Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/disk_cache/mem_entry_impl.h ('k') | net/http/http_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 11 matching lines...) Expand all
22 #include "base/task.h" 22 #include "base/task.h"
23 #include "net/http/http_transaction_factory.h" 23 #include "net/http/http_transaction_factory.h"
24 24
25 namespace disk_cache { 25 namespace disk_cache {
26 class Backend; 26 class Backend;
27 class Entry; 27 class Entry;
28 } 28 }
29 29
30 namespace net { 30 namespace net {
31 31
32 class HttpNetworkSession;
32 class HttpRequestInfo; 33 class HttpRequestInfo;
33 class HttpResponseInfo; 34 class HttpResponseInfo;
34 class ProxyService; 35 class ProxyService;
35 36
36 class HttpCache : public HttpTransactionFactory { 37 class HttpCache : public HttpTransactionFactory {
37 public: 38 public:
38 ~HttpCache(); 39 ~HttpCache();
39 40
40 // The cache mode of operation. 41 // The cache mode of operation.
41 enum Mode { 42 enum Mode {
42 // Normal mode just behaves like a standard web cache. 43 // Normal mode just behaves like a standard web cache.
43 NORMAL = 0, 44 NORMAL = 0,
44 // Record mode caches everything for purposes of offline playback. 45 // Record mode caches everything for purposes of offline playback.
45 RECORD, 46 RECORD,
46 // Playback mode replays from a cache without considering any 47 // Playback mode replays from a cache without considering any
47 // standard invalidations. 48 // standard invalidations.
48 PLAYBACK 49 PLAYBACK
49 }; 50 };
50 51
51 // Initialize the cache from the directory where its data is stored. The 52 // The type of an HttpCache object, essentially describe what an HttpCache
53 // object is for.
54 enum Type {
55 // An HttpCache object for common objects, e.g. html pages, images, fonts,
56 // css files, js files and other common web resources.
57 COMMON = 0,
58 // A cache system for media file, e.g. video and audio files. These files
59 // are huge and has special requirement for access.
60 MEDIA
61 };
62
63 // Initialize the cache from the directory where its data is stored. The
52 // disk cache is initialized lazily (by CreateTransaction) in this case. If 64 // disk cache is initialized lazily (by CreateTransaction) in this case. If
53 // |cache_size| is zero, a default value will be calculated automatically. 65 // |cache_size| is zero, a default value will be calculated automatically.
54 HttpCache(ProxyService* proxy_service, 66 HttpCache(ProxyService* proxy_service,
55 const std::wstring& cache_dir, 67 const std::wstring& cache_dir,
56 int cache_size); 68 int cache_size);
57 69
70 // Initialize the cache from the directory where its data is stored. The
71 // disk cache is initialized lazily (by CreateTransaction) in this case. If
72 // |cache_size| is zero, a default value will be calculated automatically.
73 // Provide an existing HttpNetworkSession, the cache can construct a
74 // network layer with a shared HttpNetworkSession in order for multiple
75 // network layers to share information (e.g. authenication data).
76 HttpCache(HttpNetworkSession* session, const std::wstring& cache_dir,
77 int cache_size);
78
58 // Initialize using an in-memory cache. The cache is initialized lazily 79 // Initialize using an in-memory cache. The cache is initialized lazily
59 // (by CreateTransaction) in this case. If |cache_size| is zero, a default 80 // (by CreateTransaction) in this case. If |cache_size| is zero, a default
60 // value will be calculated automatically. 81 // value will be calculated automatically.
61 HttpCache(ProxyService* proxy_service, int cache_size); 82 HttpCache(ProxyService* proxy_service, int cache_size);
62 83
63 // Initialize the cache from its component parts, which is useful for 84 // Initialize the cache from its component parts, which is useful for
64 // testing. The lifetime of the network_layer and disk_cache are managed by 85 // testing. The lifetime of the network_layer and disk_cache are managed by
65 // the HttpCache and will be destroyed using |delete| when the HttpCache is 86 // the HttpCache and will be destroyed using |delete| when the HttpCache is
66 // destroyed. 87 // destroyed.
67 HttpCache(HttpTransactionFactory* network_layer, 88 HttpCache(HttpTransactionFactory* network_layer,
(...skipping 16 matching lines...) Expand all
84 const HttpResponseInfo* response_info, 105 const HttpResponseInfo* response_info,
85 bool skip_transient_headers); 106 bool skip_transient_headers);
86 107
87 // Generate a key that can be used inside the cache. 108 // Generate a key that can be used inside the cache.
88 std::string GenerateCacheKey(const HttpRequestInfo* request); 109 std::string GenerateCacheKey(const HttpRequestInfo* request);
89 110
90 // Get/Set the cache's mode. 111 // Get/Set the cache's mode.
91 void set_mode(Mode value) { mode_ = value; } 112 void set_mode(Mode value) { mode_ = value; }
92 Mode mode() { return mode_; } 113 Mode mode() { return mode_; }
93 114
115 void set_type(Type type) { type_ = type; }
116 Type type() { return type_; }
117
94 private: 118 private:
95 119
96 // Types -------------------------------------------------------------------- 120 // Types --------------------------------------------------------------------
97 121
98 class Transaction; 122 class Transaction;
99 friend class Transaction; 123 friend class Transaction;
100 124
101 typedef std::list<Transaction*> TransactionList; 125 typedef std::list<Transaction*> TransactionList;
102 126
103 struct ActiveEntry { 127 struct ActiveEntry {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 163
140 void OnProcessPendingQueue(ActiveEntry* entry); 164 void OnProcessPendingQueue(ActiveEntry* entry);
141 165
142 166
143 // Variables ---------------------------------------------------------------- 167 // Variables ----------------------------------------------------------------
144 168
145 // used when lazily constructing the disk_cache_ 169 // used when lazily constructing the disk_cache_
146 std::wstring disk_cache_dir_; 170 std::wstring disk_cache_dir_;
147 171
148 Mode mode_; 172 Mode mode_;
173 Type type_;
149 174
150 scoped_ptr<HttpTransactionFactory> network_layer_; 175 scoped_ptr<HttpTransactionFactory> network_layer_;
151 scoped_ptr<disk_cache::Backend> disk_cache_; 176 scoped_ptr<disk_cache::Backend> disk_cache_;
152 177
153 // The set of active entries indexed by cache key 178 // The set of active entries indexed by cache key
154 ActiveEntriesMap active_entries_; 179 ActiveEntriesMap active_entries_;
155 180
156 // The set of doomed entries 181 // The set of doomed entries
157 ActiveEntriesSet doomed_entries_; 182 ActiveEntriesSet doomed_entries_;
158 183
159 ScopedRunnableMethodFactory<HttpCache> task_factory_; 184 ScopedRunnableMethodFactory<HttpCache> task_factory_;
160 185
161 bool in_memory_cache_; 186 bool in_memory_cache_;
162 int cache_size_; 187 int cache_size_;
163 188
164 typedef base::hash_map<std::string, int> PlaybackCacheMap; 189 typedef base::hash_map<std::string, int> PlaybackCacheMap;
165 scoped_ptr<PlaybackCacheMap> playback_cache_map_; 190 scoped_ptr<PlaybackCacheMap> playback_cache_map_;
166 191
167 RevocableStore transactions_; 192 RevocableStore transactions_;
168 193
169 DISALLOW_COPY_AND_ASSIGN(HttpCache); 194 DISALLOW_COPY_AND_ASSIGN(HttpCache);
170 }; 195 };
171 196
172 } // namespace net 197 } // namespace net
173 198
174 #endif // NET_HTTP_HTTP_CACHE_H_ 199 #endif // NET_HTTP_HTTP_CACHE_H_
175 200
OLDNEW
« no previous file with comments | « net/disk_cache/mem_entry_impl.h ('k') | net/http/http_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698