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

Side by Side Diff: net/disk_cache/backend_impl.h

Issue 12851: Disk cache: Add a tool to upgrade a set of cache files from one version to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years 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/build/dump_cache.vcproj ('k') | net/disk_cache/backend_impl.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 // See net/disk_cache/disk_cache.h for the public interface of the cache. 5 // See net/disk_cache/disk_cache.h for the public interface of the cache.
6 6
7 #ifndef NET_DISK_CACHE_BACKEND_IMPL_H__ 7 #ifndef NET_DISK_CACHE_BACKEND_IMPL_H__
8 #define NET_DISK_CACHE_BACKEND_IMPL_H__ 8 #define NET_DISK_CACHE_BACKEND_IMPL_H__
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/timer.h" 11 #include "base/timer.h"
12 #include "net/disk_cache/block_files.h" 12 #include "net/disk_cache/block_files.h"
13 #include "net/disk_cache/disk_cache.h" 13 #include "net/disk_cache/disk_cache.h"
14 #include "net/disk_cache/rankings.h" 14 #include "net/disk_cache/rankings.h"
15 #include "net/disk_cache/stats.h" 15 #include "net/disk_cache/stats.h"
16 #include "net/disk_cache/trace.h" 16 #include "net/disk_cache/trace.h"
17 17
18 namespace disk_cache { 18 namespace disk_cache {
19 19
20 // This class implements the Backend interface. An object of this 20 // This class implements the Backend interface. An object of this
21 // class handles the operations of the cache for a particular profile. 21 // class handles the operations of the cache for a particular profile.
22 class BackendImpl : public Backend { 22 class BackendImpl : public Backend {
23 public: 23 public:
24 explicit BackendImpl(const std::wstring& path) 24 explicit BackendImpl(const std::wstring& path)
25 : path_(path), block_files_(path), mask_(0), max_size_(0), 25 : path_(path), block_files_(path), mask_(0), max_size_(0),
26 init_(false), restarted_(false), unit_test_(false), 26 init_(false), restarted_(false), unit_test_(false), read_only_(false),
27 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} 27 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
28 // mask can be used to limit the usable size of the hash table, for testing. 28 // mask can be used to limit the usable size of the hash table, for testing.
29 BackendImpl(const std::wstring& path, uint32 mask) 29 BackendImpl(const std::wstring& path, uint32 mask)
30 : path_(path), block_files_(path), mask_(mask), max_size_(0), 30 : path_(path), block_files_(path), mask_(mask), max_size_(0),
31 init_(false), restarted_(false), unit_test_(false), 31 init_(false), restarted_(false), unit_test_(false), read_only_(false),
32 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} 32 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
33 ~BackendImpl(); 33 ~BackendImpl();
34 34
35 // Performs general initialization for this current instance of the cache. 35 // Performs general initialization for this current instance of the cache.
36 bool Init(); 36 bool Init();
37 37
38 // Backend interface. 38 // Backend interface.
39 virtual int32 GetEntryCount() const; 39 virtual int32 GetEntryCount() const;
40 virtual bool OpenEntry(const std::string& key, Entry** entry); 40 virtual bool OpenEntry(const std::string& key, Entry** entry);
41 virtual bool CreateEntry(const std::string& key, Entry** entry); 41 virtual bool CreateEntry(const std::string& key, Entry** entry);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Timer callback to calculate usage statistics. 102 // Timer callback to calculate usage statistics.
103 void OnStatsTimer(); 103 void OnStatsTimer();
104 104
105 // Handles the pending asynchronous IO count. 105 // Handles the pending asynchronous IO count.
106 void IncrementIoCount(); 106 void IncrementIoCount();
107 void DecrementIoCount(); 107 void DecrementIoCount();
108 108
109 // Sets internal parameters to enable unit testing mode. 109 // Sets internal parameters to enable unit testing mode.
110 void SetUnitTestMode(); 110 void SetUnitTestMode();
111 111
112 // Sets internal parameters to enable upgrade mode (for internal tools).
113 void SetUpgradeMode();
114
112 // Clears the counter of references to test handling of corruptions. 115 // Clears the counter of references to test handling of corruptions.
113 void ClearRefCountForTest(); 116 void ClearRefCountForTest();
114 117
115 // Peforms a simple self-check, and returns the number of dirty items 118 // Peforms a simple self-check, and returns the number of dirty items
116 // or an error code (negative value). 119 // or an error code (negative value).
117 int SelfCheck(); 120 int SelfCheck();
118 121
122 // Same bahavior as OpenNextEntry but walks the list from back to front.
123 bool OpenPrevEntry(void** iter, Entry** prev_entry);
124
119 private: 125 private:
120 // Creates a new backing file for the cache index. 126 // Creates a new backing file for the cache index.
121 bool CreateBackingStore(disk_cache::File* file); 127 bool CreateBackingStore(disk_cache::File* file);
122 bool InitBackingStore(bool* file_created); 128 bool InitBackingStore(bool* file_created);
123 void AdjustMaxCacheSize(int table_len); 129 void AdjustMaxCacheSize(int table_len);
124 130
125 // Deletes the cache and starts again. 131 // Deletes the cache and starts again.
126 void RestartCache(); 132 void RestartCache();
127 133
128 // Creates a new entry object and checks to see if it is dirty. Returns zero 134 // Creates a new entry object and checks to see if it is dirty. Returns zero
129 // on success, or a disk_cache error on failure. 135 // on success, or a disk_cache error on failure.
130 int NewEntry(Addr address, EntryImpl** entry, bool* dirty); 136 int NewEntry(Addr address, EntryImpl** entry, bool* dirty);
131 137
132 // Returns a given entry from the cache. The entry to match is determined by 138 // Returns a given entry from the cache. The entry to match is determined by
133 // key and hash, and the returned entry may be the matched one or it's parent 139 // key and hash, and the returned entry may be the matched one or it's parent
134 // on the list of entries with the same hash (or bucket). 140 // on the list of entries with the same hash (or bucket).
135 EntryImpl* MatchEntry(const std::string& key, uint32 hash, 141 EntryImpl* MatchEntry(const std::string& key, uint32 hash,
136 bool find_parent); 142 bool find_parent);
137 143
144 // Opens the next or previous entry on a cache iteration.
145 bool OpenFollowingEntry(bool forward, void** iter, Entry** next_entry);
146
138 void DestroyInvalidEntry(Addr address, EntryImpl* entry); 147 void DestroyInvalidEntry(Addr address, EntryImpl* entry);
139 148
140 // Deletes entries from the cache until the current size is below the limit. 149 // Deletes entries from the cache until the current size is below the limit.
141 // If empty is true, the whole cache will be trimmed, regardless of being in 150 // If empty is true, the whole cache will be trimmed, regardless of being in
142 // use. 151 // use.
143 void TrimCache(bool empty); 152 void TrimCache(bool empty);
144 153
145 // Handles the used storage count. 154 // Handles the used storage count.
146 void AddStorageSize(int32 bytes); 155 void AddStorageSize(int32 bytes);
147 void SubstractStorageSize(int32 bytes); 156 void SubstractStorageSize(int32 bytes);
(...skipping 20 matching lines...) Expand all
168 BlockFiles block_files_; // Set of files used to store all data. 177 BlockFiles block_files_; // Set of files used to store all data.
169 Rankings rankings_; // Rankings to be able to trim the cache. 178 Rankings rankings_; // Rankings to be able to trim the cache.
170 uint32 mask_; // Binary mask to map a hash to the hash table. 179 uint32 mask_; // Binary mask to map a hash to the hash table.
171 int32 max_size_; // Maximum data size for this instance. 180 int32 max_size_; // Maximum data size for this instance.
172 int num_refs_; // Number of referenced cache entries. 181 int num_refs_; // Number of referenced cache entries.
173 int max_refs_; // Max number of eferenced cache entries. 182 int max_refs_; // Max number of eferenced cache entries.
174 int num_pending_io_; // Number of pending IO operations; 183 int num_pending_io_; // Number of pending IO operations;
175 bool init_; // controls the initialization of the system. 184 bool init_; // controls the initialization of the system.
176 bool restarted_; 185 bool restarted_;
177 bool unit_test_; 186 bool unit_test_;
187 bool read_only_; // Prevents updates of the rankings data (used by tools).
178 bool disabled_; 188 bool disabled_;
179 189
180 Stats stats_; // Usage statistcs. 190 Stats stats_; // Usage statistcs.
181 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. 191 base::RepeatingTimer<BackendImpl> timer_; // Usage timer.
182 TraceObject trace_object_; // Inits and destroys internal tracing. 192 TraceObject trace_object_; // Inits and destroys internal tracing.
183 ScopedRunnableMethodFactory<BackendImpl> factory_; 193 ScopedRunnableMethodFactory<BackendImpl> factory_;
184 194
185 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); 195 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl);
186 }; 196 };
187 197
188 } // namespace disk_cache 198 } // namespace disk_cache
189 199
190 #endif // NET_DISK_CACHE_BACKEND_IMPL_H__ 200 #endif // NET_DISK_CACHE_BACKEND_IMPL_H__
191 201
OLDNEW
« no previous file with comments | « net/build/dump_cache.vcproj ('k') | net/disk_cache/backend_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698