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

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

Issue 49027: Disk cache: First pass to make it possible to have... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/trace.cc ('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.
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 <set> 18 #include <set>
19 19
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/hash_tables.h" 21 #include "base/hash_tables.h"
22 #include "base/scoped_ptr.h" 22 #include "base/scoped_ptr.h"
23 #include "base/task.h" 23 #include "base/task.h"
24 #include "net/base/cache_type.h"
24 #include "net/http/http_transaction_factory.h" 25 #include "net/http/http_transaction_factory.h"
25 26
26 namespace disk_cache { 27 namespace disk_cache {
27 class Backend; 28 class Backend;
28 class Entry; 29 class Entry;
29 } 30 }
30 31
31 namespace net { 32 namespace net {
32 33
33 class HttpNetworkSession; 34 class HttpNetworkSession;
34 class HttpRequestInfo; 35 class HttpRequestInfo;
35 class HttpResponseInfo; 36 class HttpResponseInfo;
36 class ProxyService; 37 class ProxyService;
37 38
38 class HttpCache : public HttpTransactionFactory { 39 class HttpCache : public HttpTransactionFactory {
39 public: 40 public:
40 ~HttpCache(); 41 ~HttpCache();
41 42
42 // The cache mode of operation. 43 // The cache mode of operation.
43 enum Mode { 44 enum Mode {
44 // Normal mode just behaves like a standard web cache. 45 // Normal mode just behaves like a standard web cache.
45 NORMAL = 0, 46 NORMAL = 0,
46 // Record mode caches everything for purposes of offline playback. 47 // Record mode caches everything for purposes of offline playback.
47 RECORD, 48 RECORD,
48 // Playback mode replays from a cache without considering any 49 // Playback mode replays from a cache without considering any
49 // standard invalidations. 50 // standard invalidations.
50 PLAYBACK 51 PLAYBACK
51 }; 52 };
52 53
53 // The type of an HttpCache object, essentially describe what an HttpCache
54 // object is for.
55 enum Type {
56 // An HttpCache object for common objects, e.g. html pages, images, fonts,
57 // css files, js files and other common web resources.
58 COMMON = 0,
59 // A cache system for media file, e.g. video and audio files. These files
60 // are huge and has special requirement for access.
61 MEDIA
62 };
63
64 // Initialize the cache from the directory where its data is stored. The 54 // Initialize the cache from the directory where its data is stored. The
65 // disk cache is initialized lazily (by CreateTransaction) in this case. If 55 // disk cache is initialized lazily (by CreateTransaction) in this case. If
66 // |cache_size| is zero, a default value will be calculated automatically. 56 // |cache_size| is zero, a default value will be calculated automatically.
67 HttpCache(ProxyService* proxy_service, 57 HttpCache(ProxyService* proxy_service,
68 const std::wstring& cache_dir, 58 const std::wstring& cache_dir,
69 int cache_size); 59 int cache_size);
70 60
71 // Initialize the cache from the directory where its data is stored. The 61 // Initialize the cache from the directory where its data is stored. The
72 // disk cache is initialized lazily (by CreateTransaction) in this case. If 62 // disk cache is initialized lazily (by CreateTransaction) in this case. If
73 // |cache_size| is zero, a default value will be calculated automatically. 63 // |cache_size| is zero, a default value will be calculated automatically.
(...skipping 29 matching lines...) Expand all
103 93
104 // Helper function for writing response info into the disk cache. 94 // Helper function for writing response info into the disk cache.
105 static bool WriteResponseInfo(disk_cache::Entry* disk_entry, 95 static bool WriteResponseInfo(disk_cache::Entry* disk_entry,
106 const HttpResponseInfo* response_info, 96 const HttpResponseInfo* response_info,
107 bool skip_transient_headers); 97 bool skip_transient_headers);
108 98
109 // Get/Set the cache's mode. 99 // Get/Set the cache's mode.
110 void set_mode(Mode value) { mode_ = value; } 100 void set_mode(Mode value) { mode_ = value; }
111 Mode mode() { return mode_; } 101 Mode mode() { return mode_; }
112 102
113 void set_type(Type type) { type_ = type; } 103 void set_type(CacheType type) { type_ = type; }
114 Type type() { return type_; } 104 CacheType type() { return type_; }
115 105
116 private: 106 private:
117 107
118 // Types -------------------------------------------------------------------- 108 // Types --------------------------------------------------------------------
119 109
120 class Transaction; 110 class Transaction;
121 friend class Transaction; 111 friend class Transaction;
122 112
123 typedef std::list<Transaction*> TransactionList; 113 typedef std::list<Transaction*> TransactionList;
124 114
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 152
163 void OnProcessPendingQueue(ActiveEntry* entry); 153 void OnProcessPendingQueue(ActiveEntry* entry);
164 154
165 155
166 // Variables ---------------------------------------------------------------- 156 // Variables ----------------------------------------------------------------
167 157
168 // used when lazily constructing the disk_cache_ 158 // used when lazily constructing the disk_cache_
169 std::wstring disk_cache_dir_; 159 std::wstring disk_cache_dir_;
170 160
171 Mode mode_; 161 Mode mode_;
172 Type type_; 162 CacheType type_;
173 163
174 scoped_ptr<HttpTransactionFactory> network_layer_; 164 scoped_ptr<HttpTransactionFactory> network_layer_;
175 scoped_ptr<disk_cache::Backend> disk_cache_; 165 scoped_ptr<disk_cache::Backend> disk_cache_;
176 166
177 // The set of active entries indexed by cache key 167 // The set of active entries indexed by cache key
178 ActiveEntriesMap active_entries_; 168 ActiveEntriesMap active_entries_;
179 169
180 // The set of doomed entries 170 // The set of doomed entries
181 ActiveEntriesSet doomed_entries_; 171 ActiveEntriesSet doomed_entries_;
182 172
183 ScopedRunnableMethodFactory<HttpCache> task_factory_; 173 ScopedRunnableMethodFactory<HttpCache> task_factory_;
184 174
185 bool in_memory_cache_; 175 bool in_memory_cache_;
186 int cache_size_; 176 int cache_size_;
187 177
188 typedef base::hash_map<std::string, int> PlaybackCacheMap; 178 typedef base::hash_map<std::string, int> PlaybackCacheMap;
189 scoped_ptr<PlaybackCacheMap> playback_cache_map_; 179 scoped_ptr<PlaybackCacheMap> playback_cache_map_;
190 180
191 RevocableStore transactions_; 181 RevocableStore transactions_;
192 182
193 DISALLOW_COPY_AND_ASSIGN(HttpCache); 183 DISALLOW_COPY_AND_ASSIGN(HttpCache);
194 }; 184 };
195 185
196 } // namespace net 186 } // namespace net
197 187
198 #endif // NET_HTTP_HTTP_CACHE_H_ 188 #endif // NET_HTTP_HTTP_CACHE_H_
OLDNEW
« no previous file with comments | « net/disk_cache/trace.cc ('k') | net/http/http_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698