| OLD | NEW |
| 1 // Copyright (c) 2011 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 // 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 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 BackendImpl(const FilePath& path, uint32 mask, | 49 BackendImpl(const FilePath& path, uint32 mask, |
| 50 base::MessageLoopProxy* cache_thread, net::NetLog* net_log); | 50 base::MessageLoopProxy* cache_thread, net::NetLog* net_log); |
| 51 virtual ~BackendImpl(); | 51 virtual ~BackendImpl(); |
| 52 | 52 |
| 53 // 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 |
| 54 // CreateCacheBackend(). | 54 // CreateCacheBackend(). |
| 55 static int CreateBackend(const FilePath& full_path, bool force, | 55 static int CreateBackend(const FilePath& full_path, bool force, |
| 56 int max_bytes, net::CacheType type, | 56 int max_bytes, net::CacheType type, |
| 57 uint32 flags, base::MessageLoopProxy* thread, | 57 uint32 flags, base::MessageLoopProxy* thread, |
| 58 net::NetLog* net_log, Backend** backend, | 58 net::NetLog* net_log, Backend** backend, |
| 59 const net::CompletionCallback& callback); | 59 const CompletionCallback& callback); |
| 60 | 60 |
| 61 // Performs general initialization for this current instance of the cache. | 61 // Performs general initialization for this current instance of the cache. |
| 62 int Init(const net::CompletionCallback& callback); | 62 int Init(const CompletionCallback& callback); |
| 63 | 63 |
| 64 // Performs the actual initialization and final cleanup on destruction. | 64 // Performs the actual initialization and final cleanup on destruction. |
| 65 int SyncInit(); | 65 int SyncInit(); |
| 66 void CleanupCache(); | 66 void CleanupCache(); |
| 67 | 67 |
| 68 // Same behavior as OpenNextEntry but walks the list from back to front. | 68 // Same behavior as OpenNextEntry but walks the list from back to front. |
| 69 int OpenPrevEntry(void** iter, Entry** prev_entry, | 69 int OpenPrevEntry(void** iter, Entry** prev_entry, |
| 70 const net::CompletionCallback& callback); | 70 const CompletionCallback& callback); |
| 71 | 71 |
| 72 // Synchronous implementation of the asynchronous interface. | 72 // Synchronous implementation of the asynchronous interface. |
| 73 int SyncOpenEntry(const std::string& key, Entry** entry); | 73 int SyncOpenEntry(const std::string& key, Entry** entry); |
| 74 int SyncCreateEntry(const std::string& key, Entry** entry); | 74 int SyncCreateEntry(const std::string& key, Entry** entry); |
| 75 int SyncDoomEntry(const std::string& key); | 75 int SyncDoomEntry(const std::string& key); |
| 76 int SyncDoomAllEntries(); | 76 int SyncDoomAllEntries(); |
| 77 int SyncDoomEntriesBetween(const base::Time initial_time, | 77 int SyncDoomEntriesBetween(const base::Time initial_time, |
| 78 const base::Time end_time); | 78 const base::Time end_time); |
| 79 int SyncDoomEntriesSince(const base::Time initial_time); | 79 int SyncDoomEntriesSince(const base::Time initial_time); |
| 80 int SyncOpenNextEntry(void** iter, Entry** next_entry); | 80 int SyncOpenNextEntry(void** iter, Entry** next_entry); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 93 | 93 |
| 94 // Sets the cache type for this backend. | 94 // Sets the cache type for this backend. |
| 95 void SetType(net::CacheType type); | 95 void SetType(net::CacheType type); |
| 96 | 96 |
| 97 // Returns the full name for an external storage file. | 97 // Returns the full name for an external storage file. |
| 98 FilePath GetFileName(Addr address) const; | 98 FilePath GetFileName(Addr address) const; |
| 99 | 99 |
| 100 // Returns the actual file used to store a given (non-external) address. | 100 // Returns the actual file used to store a given (non-external) address. |
| 101 MappedFile* File(Addr address); | 101 MappedFile* File(Addr address); |
| 102 | 102 |
| 103 InFlightBackendIO* background_queue() { | 103 // Returns a weak pointer to the background queue. |
| 104 return &background_queue_; | 104 base::WeakPtr<InFlightBackendIO> GetBackgroundQueue(); |
| 105 } | |
| 106 | 105 |
| 107 // Creates an external storage file. | 106 // Creates an external storage file. |
| 108 bool CreateExternalFile(Addr* address); | 107 bool CreateExternalFile(Addr* address); |
| 109 | 108 |
| 110 // Creates a new storage block of size block_count. | 109 // Creates a new storage block of size block_count. |
| 111 bool CreateBlock(FileType block_type, int block_count, | 110 bool CreateBlock(FileType block_type, int block_count, |
| 112 Addr* block_address); | 111 Addr* block_address); |
| 113 | 112 |
| 114 // Deletes a given storage block. deep set to true can be used to zero-fill | 113 // Deletes a given storage block. deep set to true can be used to zero-fill |
| 115 // the related storage in addition of releasing the related block. | 114 // the related storage in addition of releasing the related block. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Sets the eviction algorithm to version 2. | 230 // Sets the eviction algorithm to version 2. |
| 232 void SetNewEviction(); | 231 void SetNewEviction(); |
| 233 | 232 |
| 234 // Sets an explicit set of BackendFlags. | 233 // Sets an explicit set of BackendFlags. |
| 235 void SetFlags(uint32 flags); | 234 void SetFlags(uint32 flags); |
| 236 | 235 |
| 237 // Clears the counter of references to test handling of corruptions. | 236 // Clears the counter of references to test handling of corruptions. |
| 238 void ClearRefCountForTest(); | 237 void ClearRefCountForTest(); |
| 239 | 238 |
| 240 // Sends a dummy operation through the operation queue, for unit tests. | 239 // Sends a dummy operation through the operation queue, for unit tests. |
| 241 int FlushQueueForTest(const net::CompletionCallback& callback); | 240 int FlushQueueForTest(const CompletionCallback& callback); |
| 242 | 241 |
| 243 // Runs the provided task on the cache thread. The task will be automatically | 242 // Runs the provided task on the cache thread. The task will be automatically |
| 244 // deleted after it runs. | 243 // deleted after it runs. |
| 245 int RunTaskForTest(const base::Closure& task, | 244 int RunTaskForTest(const base::Closure& task, |
| 246 const net::CompletionCallback& callback); | 245 const CompletionCallback& callback); |
| 247 | 246 |
| 248 // Trims an entry (all if |empty| is true) from the list of deleted | 247 // Trims an entry (all if |empty| is true) from the list of deleted |
| 249 // entries. This method should be called directly on the cache thread. | 248 // entries. This method should be called directly on the cache thread. |
| 250 void TrimForTest(bool empty); | 249 void TrimForTest(bool empty); |
| 251 | 250 |
| 252 // Trims an entry (all if |empty| is true) from the list of deleted | 251 // Trims an entry (all if |empty| is true) from the list of deleted |
| 253 // entries. This method should be called directly on the cache thread. | 252 // entries. This method should be called directly on the cache thread. |
| 254 void TrimDeletedListForTest(bool empty); | 253 void TrimDeletedListForTest(bool empty); |
| 255 | 254 |
| 256 // Performs a simple self-check, and returns the number of dirty items | 255 // Performs a simple self-check, and returns the number of dirty items |
| 257 // or an error code (negative value). | 256 // or an error code (negative value). |
| 258 int SelfCheck(); | 257 int SelfCheck(); |
| 259 | 258 |
| 260 // Backend implementation. | 259 // Backend implementation. |
| 261 virtual int32 GetEntryCount() const OVERRIDE; | 260 virtual int32 GetEntryCount() const OVERRIDE; |
| 262 virtual int OpenEntry(const std::string& key, Entry** entry, | 261 virtual int OpenEntry(const std::string& key, Entry** entry, |
| 263 const net::CompletionCallback& callback) OVERRIDE; | 262 const CompletionCallback& callback) OVERRIDE; |
| 264 virtual int CreateEntry(const std::string& key, Entry** entry, | 263 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 265 const net::CompletionCallback& callback) OVERRIDE; | 264 const CompletionCallback& callback) OVERRIDE; |
| 266 virtual int DoomEntry(const std::string& key, | 265 virtual int DoomEntry(const std::string& key, |
| 267 const net::CompletionCallback& callback) OVERRIDE; | 266 const CompletionCallback& callback) OVERRIDE; |
| 268 virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE; | 267 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
| 269 virtual int DoomEntriesBetween( | 268 virtual int DoomEntriesBetween(const base::Time initial_time, |
| 270 const base::Time initial_time, | 269 const base::Time end_time, |
| 271 const base::Time end_time, | 270 const CompletionCallback& callback) OVERRIDE; |
| 272 const net::CompletionCallback& callback) OVERRIDE; | 271 virtual int DoomEntriesSince(const base::Time initial_time, |
| 273 virtual int DoomEntriesSince( | 272 const CompletionCallback& callback) OVERRIDE; |
| 274 const base::Time initial_time, | |
| 275 const net::CompletionCallback& callback) OVERRIDE; | |
| 276 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 273 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
| 277 const net::CompletionCallback& callback) OVERRIDE; | 274 const CompletionCallback& callback) OVERRIDE; |
| 278 virtual void EndEnumeration(void** iter) OVERRIDE; | 275 virtual void EndEnumeration(void** iter) OVERRIDE; |
| 279 virtual void GetStats(StatsItems* stats) OVERRIDE; | 276 virtual void GetStats(StatsItems* stats) OVERRIDE; |
| 280 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 277 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
| 281 | 278 |
| 282 private: | 279 private: |
| 283 typedef base::hash_map<CacheAddr, EntryImpl*> EntriesMap; | 280 typedef base::hash_map<CacheAddr, EntryImpl*> EntriesMap; |
| 284 | 281 |
| 285 // Creates a new backing file for the cache index. | 282 // Creates a new backing file for the cache index. |
| 286 bool CreateBackingStore(disk_cache::File* file); | 283 bool CreateBackingStore(disk_cache::File* file); |
| 287 bool InitBackingStore(bool* file_created); | 284 bool InitBackingStore(bool* file_created); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 390 |
| 394 DISALLOW_COPY_AND_ASSIGN(BackendImpl); | 391 DISALLOW_COPY_AND_ASSIGN(BackendImpl); |
| 395 }; | 392 }; |
| 396 | 393 |
| 397 // Returns the preferred max cache size given the available disk space. | 394 // Returns the preferred max cache size given the available disk space. |
| 398 NET_EXPORT_PRIVATE int PreferedCacheSize(int64 available); | 395 NET_EXPORT_PRIVATE int PreferedCacheSize(int64 available); |
| 399 | 396 |
| 400 } // namespace disk_cache | 397 } // namespace disk_cache |
| 401 | 398 |
| 402 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ | 399 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ |
| OLD | NEW |