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

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

Issue 261045: Start migrating the disk cache to using FilePath. (Closed)
Patch Set: rebase Created 11 years, 2 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 | « no previous file | 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/file_path.h"
10 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
11 #include "base/timer.h" 12 #include "base/timer.h"
12 #include "net/disk_cache/block_files.h" 13 #include "net/disk_cache/block_files.h"
13 #include "net/disk_cache/disk_cache.h" 14 #include "net/disk_cache/disk_cache.h"
14 #include "net/disk_cache/eviction.h" 15 #include "net/disk_cache/eviction.h"
15 #include "net/disk_cache/rankings.h" 16 #include "net/disk_cache/rankings.h"
16 #include "net/disk_cache/stats.h" 17 #include "net/disk_cache/stats.h"
17 #include "net/disk_cache/trace.h" 18 #include "net/disk_cache/trace.h"
18 19
19 namespace disk_cache { 20 namespace disk_cache {
20 21
21 enum BackendFlags { 22 enum BackendFlags {
22 kNone = 0, 23 kNone = 0,
23 kMask = 1, // A mask (for the index table) was specified. 24 kMask = 1, // A mask (for the index table) was specified.
24 kMaxSize = 1 << 1, // A maximum size was provided. 25 kMaxSize = 1 << 1, // A maximum size was provided.
25 kUnitTestMode = 1 << 2, // We are modifying the behavior for testing. 26 kUnitTestMode = 1 << 2, // We are modifying the behavior for testing.
26 kUpgradeMode = 1 << 3, // This is the upgrade tool (dump). 27 kUpgradeMode = 1 << 3, // This is the upgrade tool (dump).
27 kNewEviction = 1 << 4, // Use of new eviction was specified. 28 kNewEviction = 1 << 4, // Use of new eviction was specified.
28 kNoRandom = 1 << 5, // Don't add randomness to the behavior. 29 kNoRandom = 1 << 5, // Don't add randomness to the behavior.
29 kNoLoadProtection = 1 << 6 // Don't act conservatively under load. 30 kNoLoadProtection = 1 << 6 // Don't act conservatively under load.
30 }; 31 };
31 32
32 // This class implements the Backend interface. An object of this 33 // This class implements the Backend interface. An object of this
33 // class handles the operations of the cache for a particular profile. 34 // class handles the operations of the cache for a particular profile.
34 class BackendImpl : public Backend { 35 class BackendImpl : public Backend {
35 friend class Eviction; 36 friend class Eviction;
36 public: 37 public:
37 explicit BackendImpl(const std::wstring& path) 38 explicit BackendImpl(const FilePath& path)
38 : path_(path), block_files_(path), mask_(0), max_size_(0), 39 : path_(path), block_files_(path.ToWStringHack()), mask_(0), max_size_(0),
39 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(0), 40 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(0),
40 init_(false), restarted_(false), unit_test_(false), read_only_(false), 41 init_(false), restarted_(false), unit_test_(false), read_only_(false),
41 new_eviction_(false), first_timer_(true), 42 new_eviction_(false), first_timer_(true),
42 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} 43 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
43 // mask can be used to limit the usable size of the hash table, for testing. 44 // mask can be used to limit the usable size of the hash table, for testing.
44 BackendImpl(const std::wstring& path, uint32 mask) 45 BackendImpl(const FilePath& path, uint32 mask)
45 : path_(path), block_files_(path), mask_(mask), max_size_(0), 46 : path_(path), block_files_(path.ToWStringHack()), mask_(mask), max_size_( 0),
46 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(kMask), 47 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(kMask),
47 init_(false), restarted_(false), unit_test_(false), read_only_(false), 48 init_(false), restarted_(false), unit_test_(false), read_only_(false),
48 new_eviction_(false), first_timer_(true), 49 new_eviction_(false), first_timer_(true),
49 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} 50 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
50 ~BackendImpl(); 51 ~BackendImpl();
51 52
52 // Returns a new backend with the desired flags. See the declaration of 53 // Returns a new backend with the desired flags. See the declaration of
53 // CreateCacheBackend(). 54 // CreateCacheBackend().
54 static Backend* CreateBackend(const std::wstring& full_path, bool force, 55 static Backend* CreateBackend(const std::wstring& full_path, bool force,
55 int max_bytes, net::CacheType type, 56 int max_bytes, net::CacheType type,
(...skipping 15 matching lines...) Expand all
71 virtual void EndEnumeration(void** iter); 72 virtual void EndEnumeration(void** iter);
72 virtual void GetStats(StatsItems* stats); 73 virtual void GetStats(StatsItems* stats);
73 74
74 // Sets the maximum size for the total amount of data stored by this instance. 75 // Sets the maximum size for the total amount of data stored by this instance.
75 bool SetMaxSize(int max_bytes); 76 bool SetMaxSize(int max_bytes);
76 77
77 // Sets the cache type for this backend. 78 // Sets the cache type for this backend.
78 void SetType(net::CacheType type); 79 void SetType(net::CacheType type);
79 80
80 // Returns the full name for an external storage file. 81 // Returns the full name for an external storage file.
81 std::wstring GetFileName(Addr address) const; 82 FilePath GetFileName(Addr address) const;
82 83
83 // Returns the actual file used to store a given (non-external) address. 84 // Returns the actual file used to store a given (non-external) address.
84 MappedFile* File(Addr address); 85 MappedFile* File(Addr address);
85 86
86 // Creates an external storage file. 87 // Creates an external storage file.
87 bool CreateExternalFile(Addr* address); 88 bool CreateExternalFile(Addr* address);
88 89
89 // Creates a new storage block of size block_count. 90 // Creates a new storage block of size block_count.
90 bool CreateBlock(FileType block_type, int block_count, 91 bool CreateBlock(FileType block_type, int block_count,
91 Addr* block_address); 92 Addr* block_address);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Performs basic checks on the index file. Returns false on failure. 256 // Performs basic checks on the index file. Returns false on failure.
256 bool CheckIndex(); 257 bool CheckIndex();
257 258
258 // Part of the selt test. Returns the number or dirty entries, or an error. 259 // Part of the selt test. Returns the number or dirty entries, or an error.
259 int CheckAllEntries(); 260 int CheckAllEntries();
260 261
261 // Part of the self test. Returns false if the entry is corrupt. 262 // Part of the self test. Returns false if the entry is corrupt.
262 bool CheckEntry(EntryImpl* cache_entry); 263 bool CheckEntry(EntryImpl* cache_entry);
263 264
264 scoped_refptr<MappedFile> index_; // The main cache index. 265 scoped_refptr<MappedFile> index_; // The main cache index.
265 std::wstring path_; // Path to the folder used as backing storage. 266 FilePath path_; // Path to the folder used as backing storage.
266 Index* data_; // Pointer to the index data. 267 Index* data_; // Pointer to the index data.
267 BlockFiles block_files_; // Set of files used to store all data. 268 BlockFiles block_files_; // Set of files used to store all data.
268 Rankings rankings_; // Rankings to be able to trim the cache. 269 Rankings rankings_; // Rankings to be able to trim the cache.
269 uint32 mask_; // Binary mask to map a hash to the hash table. 270 uint32 mask_; // Binary mask to map a hash to the hash table.
270 int32 max_size_; // Maximum data size for this instance. 271 int32 max_size_; // Maximum data size for this instance.
271 Eviction eviction_; // Handler of the eviction algorithm. 272 Eviction eviction_; // Handler of the eviction algorithm.
272 EntriesMap open_entries_; // Map of open entries. 273 EntriesMap open_entries_; // Map of open entries.
273 int num_refs_; // Number of referenced cache entries. 274 int num_refs_; // Number of referenced cache entries.
274 int max_refs_; // Max number of referenced cache entries. 275 int max_refs_; // Max number of referenced cache entries.
275 int num_pending_io_; // Number of pending IO operations. 276 int num_pending_io_; // Number of pending IO operations.
(...skipping 15 matching lines...) Expand all
291 292
292 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); 293 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl);
293 }; 294 };
294 295
295 // Returns the prefered max cache size given the available disk space. 296 // Returns the prefered max cache size given the available disk space.
296 int PreferedCacheSize(int64 available); 297 int PreferedCacheSize(int64 available);
297 298
298 } // namespace disk_cache 299 } // namespace disk_cache
299 300
300 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ 301 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/backend_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698