Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 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 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/message_loop_proxy.h" | |
| 12 #include "base/timer.h" | 14 #include "base/timer.h" |
| 13 #include "net/disk_cache/block_files.h" | 15 #include "net/disk_cache/block_files.h" |
| 14 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
| 15 #include "net/disk_cache/eviction.h" | 17 #include "net/disk_cache/eviction.h" |
| 16 #include "net/disk_cache/in_flight_backend_io.h" | 18 #include "net/disk_cache/in_flight_backend_io.h" |
| 17 #include "net/disk_cache/rankings.h" | 19 #include "net/disk_cache/rankings.h" |
| 18 #include "net/disk_cache/stats.h" | 20 #include "net/disk_cache/stats.h" |
| 19 #include "net/disk_cache/stress_support.h" | 21 #include "net/disk_cache/stress_support.h" |
| 20 #include "net/disk_cache/trace.h" | 22 #include "net/disk_cache/trace.h" |
| 21 | 23 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 // CreateCacheBackend(). | 55 // CreateCacheBackend(). |
| 54 static int CreateBackend(const FilePath& full_path, bool force, | 56 static int CreateBackend(const FilePath& full_path, bool force, |
| 55 int max_bytes, net::CacheType type, | 57 int max_bytes, net::CacheType type, |
| 56 uint32 flags, base::MessageLoopProxy* thread, | 58 uint32 flags, base::MessageLoopProxy* thread, |
| 57 net::NetLog* net_log, Backend** backend, | 59 net::NetLog* net_log, Backend** backend, |
| 58 const CompletionCallback& callback); | 60 const CompletionCallback& callback); |
| 59 | 61 |
| 60 // Performs general initialization for this current instance of the cache. | 62 // Performs general initialization for this current instance of the cache. |
| 61 int Init(const CompletionCallback& callback); | 63 int Init(const CompletionCallback& callback); |
| 62 | 64 |
| 63 // Performs the actual initialization and final cleanup on destruction. | 65 // Performs the actual initialization and final cleanup on destruction. If |
| 64 int SyncInit(); | 66 // |async_thread| is non null, then |bitmap_| may be initialized on that |
| 67 // thread, otherwise |bitmap_| is left unchanged. | |
| 68 int SyncInit(scoped_refptr<base::MessageLoopProxy> async_thread); | |
| 65 void CleanupCache(); | 69 void CleanupCache(); |
| 66 | 70 |
| 67 // Same behavior as OpenNextEntry but walks the list from back to front. | 71 // Same behavior as OpenNextEntry but walks the list from back to front. |
| 68 int OpenPrevEntry(void** iter, Entry** prev_entry, | 72 int OpenPrevEntry(void** iter, Entry** prev_entry, |
| 69 const CompletionCallback& callback); | 73 const CompletionCallback& callback); |
| 70 | 74 |
| 71 // Synchronous implementation of the asynchronous interface. | 75 // Synchronous implementation of the asynchronous interface. |
| 72 int SyncOpenEntry(const std::string& key, Entry** entry); | 76 int SyncOpenEntry(const std::string& key, Entry** entry); |
| 73 int SyncCreateEntry(const std::string& key, Entry** entry); | 77 int SyncCreateEntry(const std::string& key, Entry** entry); |
| 74 int SyncDoomEntry(const std::string& key); | 78 int SyncDoomEntry(const std::string& key); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 230 |
| 227 // Sets internal parameters to enable upgrade mode (for internal tools). | 231 // Sets internal parameters to enable upgrade mode (for internal tools). |
| 228 void SetUpgradeMode(); | 232 void SetUpgradeMode(); |
| 229 | 233 |
| 230 // Sets the eviction algorithm to version 2. | 234 // Sets the eviction algorithm to version 2. |
| 231 void SetNewEviction(); | 235 void SetNewEviction(); |
| 232 | 236 |
| 233 // Sets an explicit set of BackendFlags. | 237 // Sets an explicit set of BackendFlags. |
| 234 void SetFlags(uint32 flags); | 238 void SetFlags(uint32 flags); |
| 235 | 239 |
| 240 // Clears the index bitmap for tests. | |
| 241 void ClearIndexBitmapForTest(); | |
| 242 | |
| 236 // Clears the counter of references to test handling of corruptions. | 243 // Clears the counter of references to test handling of corruptions. |
| 237 void ClearRefCountForTest(); | 244 void ClearRefCountForTest(); |
| 238 | 245 |
| 239 // Sends a dummy operation through the operation queue, for unit tests. | 246 // Sends a dummy operation through the operation queue, for unit tests. |
| 240 int FlushQueueForTest(const CompletionCallback& callback); | 247 int FlushQueueForTest(const CompletionCallback& callback); |
| 241 | 248 |
| 242 // Runs the provided task on the cache thread. The task will be automatically | 249 // Runs the provided task on the cache thread. The task will be automatically |
| 243 // deleted after it runs. | 250 // deleted after it runs. |
| 244 int RunTaskForTest(const base::Closure& task, | 251 int RunTaskForTest(const base::Closure& task, |
| 245 const CompletionCallback& callback); | 252 const CompletionCallback& callback); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 276 const CompletionCallback& callback) OVERRIDE; | 283 const CompletionCallback& callback) OVERRIDE; |
| 277 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 284 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
| 278 const CompletionCallback& callback) OVERRIDE; | 285 const CompletionCallback& callback) OVERRIDE; |
| 279 virtual void EndEnumeration(void** iter) OVERRIDE; | 286 virtual void EndEnumeration(void** iter) OVERRIDE; |
| 280 virtual void GetStats(StatsItems* stats) OVERRIDE; | 287 virtual void GetStats(StatsItems* stats) OVERRIDE; |
| 281 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 288 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
| 282 | 289 |
| 283 private: | 290 private: |
| 284 typedef base::hash_map<CacheAddr, EntryImpl*> EntriesMap; | 291 typedef base::hash_map<CacheAddr, EntryImpl*> EntriesMap; |
| 285 | 292 |
| 293 | |
| 294 // Called on the cache thread. Construct a vector<bool> of the index table. | |
| 295 void CalculateIndexBitmap(std::vector<bool>* index_bitmap) const; | |
| 296 | |
| 297 // Called on the IO thread. Sets index_bitmap_ so that future OpenEntry | |
| 298 // operations can fast miss if there is no entry chain to traverse. | |
| 299 void SetIndexBitmap(const std::vector<bool>& index_bitmap); | |
| 300 | |
| 286 // Creates a new backing file for the cache index. | 301 // Creates a new backing file for the cache index. |
| 287 bool CreateBackingStore(disk_cache::File* file); | 302 bool CreateBackingStore(disk_cache::File* file); |
| 288 bool InitBackingStore(bool* file_created); | 303 bool InitBackingStore(bool* file_created); |
| 289 void AdjustMaxCacheSize(int table_len); | 304 void AdjustMaxCacheSize(int table_len); |
| 290 | 305 |
| 291 // Deletes the cache and starts again. | 306 // Deletes the cache and starts again. |
| 292 void RestartCache(bool failure); | 307 void RestartCache(bool failure); |
| 293 void PrepareForRestart(); | 308 void PrepareForRestart(); |
| 294 | 309 |
| 295 // Creates a new entry object. Returns zero on success, or a disk_cache error | 310 // Creates a new entry object. Returns zero on success, or a disk_cache error |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 uint32 user_flags_; // Flags set by the user. | 392 uint32 user_flags_; // Flags set by the user. |
| 378 bool init_; // controls the initialization of the system. | 393 bool init_; // controls the initialization of the system. |
| 379 bool restarted_; | 394 bool restarted_; |
| 380 bool unit_test_; | 395 bool unit_test_; |
| 381 bool read_only_; // Prevents updates of the rankings data (used by tools). | 396 bool read_only_; // Prevents updates of the rankings data (used by tools). |
| 382 bool disabled_; | 397 bool disabled_; |
| 383 bool new_eviction_; // What eviction algorithm should be used. | 398 bool new_eviction_; // What eviction algorithm should be used. |
| 384 bool first_timer_; // True if the timer has not been called. | 399 bool first_timer_; // True if the timer has not been called. |
| 385 bool user_load_; // True if we see a high load coming from the caller. | 400 bool user_load_; // True if we see a high load coming from the caller. |
| 386 | 401 |
| 402 base::WaitableEvent index_bitmap_has_been_set_; | |
| 403 std::vector<bool> index_bitmap_; | |
|
rvargas (doing something else)
2013/01/22 22:31:51
use disk_cache::Bitmap instead.
gavinp
2013/01/22 23:15:47
Will do!
gavinp
2013/02/09 16:46:51
Can you please tell me more about why this is pref
rvargas (doing something else)
2013/02/12 01:58:33
In this particular instance there's probably not t
| |
| 404 | |
| 387 net::NetLog* net_log_; | 405 net::NetLog* net_log_; |
| 388 | 406 |
| 389 Stats stats_; // Usage statistics. | 407 Stats stats_; // Usage statistics. |
| 390 scoped_ptr<base::RepeatingTimer<BackendImpl> > timer_; // Usage timer. | 408 scoped_ptr<base::RepeatingTimer<BackendImpl> > timer_; // Usage timer. |
| 391 base::WaitableEvent done_; // Signals the end of background work. | 409 base::WaitableEvent done_; // Signals the end of background work. |
| 392 scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing. | 410 scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing. |
| 393 base::WeakPtrFactory<BackendImpl> ptr_factory_; | 411 base::WeakPtrFactory<BackendImpl> ptr_factory_; |
| 394 | 412 |
| 395 DISALLOW_COPY_AND_ASSIGN(BackendImpl); | 413 DISALLOW_COPY_AND_ASSIGN(BackendImpl); |
| 396 }; | 414 }; |
| 397 | 415 |
| 398 // Returns the preferred max cache size given the available disk space. | 416 // Returns the preferred max cache size given the available disk space. |
| 399 NET_EXPORT_PRIVATE int PreferedCacheSize(int64 available); | 417 NET_EXPORT_PRIVATE int PreferedCacheSize(int64 available); |
| 400 | 418 |
| 401 } // namespace disk_cache | 419 } // namespace disk_cache |
| 402 | 420 |
| 403 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ | 421 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ |
| OLD | NEW |