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 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // class handles the operations of the cache for a particular profile. | 35 // class handles the operations of the cache for a particular profile. |
36 class BackendImpl : public Backend { | 36 class BackendImpl : public Backend { |
37 friend class Eviction; | 37 friend class Eviction; |
38 public: | 38 public: |
39 BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread) | 39 BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread) |
40 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), | 40 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), |
41 path_(path), block_files_(path), mask_(0), max_size_(0), | 41 path_(path), block_files_(path), mask_(0), max_size_(0), |
42 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(0), | 42 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(0), |
43 init_(false), restarted_(false), unit_test_(false), read_only_(false), | 43 init_(false), restarted_(false), unit_test_(false), read_only_(false), |
44 new_eviction_(false), first_timer_(true), done_(true, false), | 44 new_eviction_(false), first_timer_(true), done_(true, false), |
45 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} | 45 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), |
| 46 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {} |
46 // 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. |
47 BackendImpl(const FilePath& path, uint32 mask, | 48 BackendImpl(const FilePath& path, uint32 mask, |
48 base::MessageLoopProxy* cache_thread) | 49 base::MessageLoopProxy* cache_thread) |
49 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), | 50 : ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)), |
50 path_(path), block_files_(path), mask_(mask), max_size_(0), | 51 path_(path), block_files_(path), mask_(mask), max_size_(0), |
51 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(kMask), | 52 cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(kMask), |
52 init_(false), restarted_(false), unit_test_(false), read_only_(false), | 53 init_(false), restarted_(false), unit_test_(false), read_only_(false), |
53 new_eviction_(false), first_timer_(true), done_(true, false), | 54 new_eviction_(false), first_timer_(true), done_(true, false), |
54 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} | 55 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), |
| 56 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {} |
55 ~BackendImpl(); | 57 ~BackendImpl(); |
56 | 58 |
57 // Returns a new backend with the desired flags. See the declaration of | 59 // Returns a new backend with the desired flags. See the declaration of |
58 // CreateCacheBackend(). | 60 // CreateCacheBackend(). |
59 static int CreateBackend(const FilePath& full_path, bool force, | 61 static int CreateBackend(const FilePath& full_path, bool force, |
60 int max_bytes, net::CacheType type, | 62 int max_bytes, net::CacheType type, |
61 uint32 flags, base::MessageLoopProxy* thread, | 63 uint32 flags, base::MessageLoopProxy* thread, |
62 Backend** backend, CompletionCallback* callback); | 64 Backend** backend, CompletionCallback* callback); |
63 | 65 |
64 // Performs general initialization for this current instance of the cache. | 66 // Performs general initialization for this current instance of the cache. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 179 |
178 // Returns the full histogram name, for the given base |name| and experiment, | 180 // Returns the full histogram name, for the given base |name| and experiment, |
179 // and the current cache type. The name will be "DiskCache.t.name_e" where n | 181 // and the current cache type. The name will be "DiskCache.t.name_e" where n |
180 // is the cache type and e the provided |experiment|. | 182 // is the cache type and e the provided |experiment|. |
181 std::string HistogramName(const char* name, int experiment) const; | 183 std::string HistogramName(const char* name, int experiment) const; |
182 | 184 |
183 net::CacheType cache_type() const { | 185 net::CacheType cache_type() const { |
184 return cache_type_; | 186 return cache_type_; |
185 } | 187 } |
186 | 188 |
| 189 // Returns a weak pointer to this object. |
| 190 base::WeakPtr<BackendImpl> GetWeakPtr() { |
| 191 return ptr_factory_.GetWeakPtr(); |
| 192 } |
| 193 |
187 // Returns the group for this client, based on the current cache size. | 194 // Returns the group for this client, based on the current cache size. |
188 int GetSizeGroup() const; | 195 int GetSizeGroup() const; |
189 | 196 |
190 // Returns true if we should send histograms for this user again. The caller | 197 // Returns true if we should send histograms for this user again. The caller |
191 // must call this function only once per run (because it returns always the | 198 // must call this function only once per run (because it returns always the |
192 // same thing on a given run). | 199 // same thing on a given run). |
193 bool ShouldReportAgain(); | 200 bool ShouldReportAgain(); |
194 | 201 |
195 // Reports some data when we filled up the cache. | 202 // Reports some data when we filled up the cache. |
196 void FirstEviction(); | 203 void FirstEviction(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 bool read_only_; // Prevents updates of the rankings data (used by tools). | 337 bool read_only_; // Prevents updates of the rankings data (used by tools). |
331 bool disabled_; | 338 bool disabled_; |
332 bool new_eviction_; // What eviction algorithm should be used. | 339 bool new_eviction_; // What eviction algorithm should be used. |
333 bool first_timer_; // True if the timer has not been called. | 340 bool first_timer_; // True if the timer has not been called. |
334 | 341 |
335 Stats stats_; // Usage statistcs. | 342 Stats stats_; // Usage statistcs. |
336 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. | 343 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. |
337 base::WaitableEvent done_; // Signals the end of background work. | 344 base::WaitableEvent done_; // Signals the end of background work. |
338 scoped_refptr<TraceObject> trace_object_; // Inits internal tracing. | 345 scoped_refptr<TraceObject> trace_object_; // Inits internal tracing. |
339 ScopedRunnableMethodFactory<BackendImpl> factory_; | 346 ScopedRunnableMethodFactory<BackendImpl> factory_; |
| 347 base::WeakPtrFactory<BackendImpl> ptr_factory_; |
340 | 348 |
341 DISALLOW_COPY_AND_ASSIGN(BackendImpl); | 349 DISALLOW_COPY_AND_ASSIGN(BackendImpl); |
342 }; | 350 }; |
343 | 351 |
344 // Returns the prefered max cache size given the available disk space. | 352 // Returns the prefered max cache size given the available disk space. |
345 int PreferedCacheSize(int64 available); | 353 int PreferedCacheSize(int64 available); |
346 | 354 |
347 } // namespace disk_cache | 355 } // namespace disk_cache |
348 | 356 |
349 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ | 357 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ |
OLD | NEW |