OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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" |
12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
13 #include "base/timer.h" | 13 #include "base/timer.h" |
14 #include "net/disk_cache/block_files.h" | 14 #include "net/disk_cache/block_files.h" |
15 #include "net/disk_cache/disk_cache.h" | 15 #include "net/disk_cache/disk_cache.h" |
16 #include "net/disk_cache/eviction.h" | 16 #include "net/disk_cache/eviction.h" |
17 #include "net/disk_cache/in_flight_backend_io.h" | 17 #include "net/disk_cache/in_flight_backend_io.h" |
18 #include "net/disk_cache/rankings.h" | 18 #include "net/disk_cache/rankings.h" |
19 #include "net/disk_cache/stats.h" | 19 #include "net/disk_cache/stats.h" |
20 #include "net/disk_cache/trace.h" | 20 #include "net/disk_cache/trace.h" |
21 | 21 |
| 22 namespace net { |
| 23 class NetLog; |
| 24 } // namespace net |
| 25 |
22 namespace disk_cache { | 26 namespace disk_cache { |
23 | 27 |
24 enum BackendFlags { | 28 enum BackendFlags { |
25 kNone = 0, | 29 kNone = 0, |
26 kMask = 1, // A mask (for the index table) was specified. | 30 kMask = 1, // A mask (for the index table) was specified. |
27 kMaxSize = 1 << 1, // A maximum size was provided. | 31 kMaxSize = 1 << 1, // A maximum size was provided. |
28 kUnitTestMode = 1 << 2, // We are modifying the behavior for testing. | 32 kUnitTestMode = 1 << 2, // We are modifying the behavior for testing. |
29 kUpgradeMode = 1 << 3, // This is the upgrade tool (dump). | 33 kUpgradeMode = 1 << 3, // This is the upgrade tool (dump). |
30 kNewEviction = 1 << 4, // Use of new eviction was specified. | 34 kNewEviction = 1 << 4, // Use of new eviction was specified. |
31 kNoRandom = 1 << 5, // Don't add randomness to the behavior. | 35 kNoRandom = 1 << 5, // Don't add randomness to the behavior. |
32 kNoLoadProtection = 1 << 6, // Don't act conservatively under load. | 36 kNoLoadProtection = 1 << 6, // Don't act conservatively under load. |
33 kNoBuffering = 1 << 7 // Disable extended IO buffering. | 37 kNoBuffering = 1 << 7 // Disable extended IO buffering. |
34 }; | 38 }; |
35 | 39 |
36 // This class implements the Backend interface. An object of this | 40 // This class implements the Backend interface. An object of this |
37 // class handles the operations of the cache for a particular profile. | 41 // class handles the operations of the cache for a particular profile. |
38 class BackendImpl : public Backend { | 42 class BackendImpl : public Backend { |
39 friend class Eviction; | 43 friend class Eviction; |
40 public: | 44 public: |
41 BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread); | 45 BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread, |
| 46 net::NetLog* net_log); |
42 // mask can be used to limit the usable size of the hash table, for testing. | 47 // mask can be used to limit the usable size of the hash table, for testing. |
43 BackendImpl(const FilePath& path, uint32 mask, | 48 BackendImpl(const FilePath& path, uint32 mask, |
44 base::MessageLoopProxy* cache_thread); | 49 base::MessageLoopProxy* cache_thread, net::NetLog* net_log); |
45 ~BackendImpl(); | 50 ~BackendImpl(); |
46 | 51 |
47 // Returns a new backend with the desired flags. See the declaration of | 52 // Returns a new backend with the desired flags. See the declaration of |
48 // CreateCacheBackend(). | 53 // CreateCacheBackend(). |
49 static int CreateBackend(const FilePath& full_path, bool force, | 54 static int CreateBackend(const FilePath& full_path, bool force, |
50 int max_bytes, net::CacheType type, | 55 int max_bytes, net::CacheType type, |
51 uint32 flags, base::MessageLoopProxy* thread, | 56 uint32 flags, base::MessageLoopProxy* thread, |
52 Backend** backend, CompletionCallback* callback); | 57 net::NetLog* net_log, Backend** backend, |
| 58 CompletionCallback* callback); |
53 | 59 |
54 // Performs general initialization for this current instance of the cache. | 60 // Performs general initialization for this current instance of the cache. |
55 int Init(CompletionCallback* callback); | 61 int Init(CompletionCallback* callback); |
56 | 62 |
57 // Backend interface. | 63 // Backend interface. |
58 virtual int32 GetEntryCount() const; | 64 virtual int32 GetEntryCount() const; |
59 virtual int OpenEntry(const std::string& key, Entry** entry, | 65 virtual int OpenEntry(const std::string& key, Entry** entry, |
60 CompletionCallback* callback); | 66 CompletionCallback* callback); |
61 virtual int CreateEntry(const std::string& key, Entry** entry, | 67 virtual int CreateEntry(const std::string& key, Entry** entry, |
62 CompletionCallback* callback); | 68 CompletionCallback* callback); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 uint32 user_flags_; // Flags set by the user. | 356 uint32 user_flags_; // Flags set by the user. |
351 bool init_; // controls the initialization of the system. | 357 bool init_; // controls the initialization of the system. |
352 bool restarted_; | 358 bool restarted_; |
353 bool unit_test_; | 359 bool unit_test_; |
354 bool read_only_; // Prevents updates of the rankings data (used by tools). | 360 bool read_only_; // Prevents updates of the rankings data (used by tools). |
355 bool disabled_; | 361 bool disabled_; |
356 bool new_eviction_; // What eviction algorithm should be used. | 362 bool new_eviction_; // What eviction algorithm should be used. |
357 bool first_timer_; // True if the timer has not been called. | 363 bool first_timer_; // True if the timer has not been called. |
358 bool throttle_requests_; | 364 bool throttle_requests_; |
359 | 365 |
| 366 net::NetLog* net_log_; |
| 367 |
360 Stats stats_; // Usage statistcs. | 368 Stats stats_; // Usage statistcs. |
361 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. | 369 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. |
362 base::WaitableEvent done_; // Signals the end of background work. | 370 base::WaitableEvent done_; // Signals the end of background work. |
363 scoped_refptr<TraceObject> trace_object_; // Inits internal tracing. | 371 scoped_refptr<TraceObject> trace_object_; // Inits internal tracing. |
364 ScopedRunnableMethodFactory<BackendImpl> factory_; | 372 ScopedRunnableMethodFactory<BackendImpl> factory_; |
365 base::WeakPtrFactory<BackendImpl> ptr_factory_; | 373 base::WeakPtrFactory<BackendImpl> ptr_factory_; |
366 | 374 |
367 DISALLOW_COPY_AND_ASSIGN(BackendImpl); | 375 DISALLOW_COPY_AND_ASSIGN(BackendImpl); |
368 }; | 376 }; |
369 | 377 |
370 // Returns the prefered max cache size given the available disk space. | 378 // Returns the prefered max cache size given the available disk space. |
371 int PreferedCacheSize(int64 available); | 379 int PreferedCacheSize(int64 available); |
372 | 380 |
373 } // namespace disk_cache | 381 } // namespace disk_cache |
374 | 382 |
375 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ | 383 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ |
OLD | NEW |