OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ |
| 6 #define COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "net/base/net_errors.h" |
| 12 #include "net/disk_cache/disk_cache.h" |
| 13 |
| 14 namespace content { |
| 15 class StoragePartition; |
| 16 } |
| 17 |
| 18 namespace net { |
| 19 class URLRequestContextGetter; |
| 20 } |
| 21 |
| 22 namespace browsing_data { |
| 23 |
| 24 // Helper to count the size of the http cache data from a StoragePartition. |
| 25 class ConditionalCacheCountingHelper { |
| 26 public: |
| 27 // Returns the number bytes in the selected range. |
| 28 typedef base::Callback<void(int64_t)> CacheCountCallback; |
| 29 |
| 30 static ConditionalCacheCountingHelper* CreateForRange( |
| 31 content::StoragePartition* storage_partition, |
| 32 base::Time begin_time, |
| 33 base::Time end_time); |
| 34 |
| 35 // Count the cache entries according to the specified time range. Destroys |
| 36 // this instance of ConditionalCacheCountingHelper when finished. |
| 37 // Must be called on the UI thread! |
| 38 // |
| 39 // The |completion_callback| will be invoked when the operation completes. |
| 40 base::WeakPtr<ConditionalCacheCountingHelper> CountAndDestroySelfWhenFinished( |
| 41 const CacheCountCallback& result_callback); |
| 42 |
| 43 bool IsFinished(); |
| 44 |
| 45 private: |
| 46 enum class CacheState { |
| 47 NONE, |
| 48 CREATE_MAIN, |
| 49 CREATE_MEDIA, |
| 50 COUNT_MAIN, |
| 51 COUNT_MEDIA, |
| 52 DONE |
| 53 }; |
| 54 |
| 55 friend class base::DeleteHelper<ConditionalCacheCountingHelper>; |
| 56 |
| 57 ConditionalCacheCountingHelper( |
| 58 base::Time begin_time, |
| 59 base::Time end_time, |
| 60 net::URLRequestContextGetter* main_context_getter, |
| 61 net::URLRequestContextGetter* media_context_getter); |
| 62 ~ConditionalCacheCountingHelper(); |
| 63 |
| 64 void Finished(); |
| 65 |
| 66 void CountHttpCacheOnIOThread(); |
| 67 void DoCountCache(int rv); |
| 68 |
| 69 // Stores the cache size computation result before it can be returned |
| 70 // via a callback. This is either the sum of size of the the two cache |
| 71 // backends, or an error code if the calculation failed. |
| 72 int64_t calculation_result_; |
| 73 |
| 74 CacheCountCallback result_callback_; |
| 75 const base::Time begin_time_; |
| 76 const base::Time end_time_; |
| 77 |
| 78 bool is_finished_; |
| 79 |
| 80 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_; |
| 81 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_; |
| 82 |
| 83 CacheState next_cache_state_; |
| 84 disk_cache::Backend* cache_; |
| 85 |
| 86 std::unique_ptr<disk_cache::Backend::Iterator> iterator_; |
| 87 |
| 88 base::WeakPtrFactory<ConditionalCacheCountingHelper> weak_ptr_factory_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(ConditionalCacheCountingHelper); |
| 91 }; |
| 92 |
| 93 } // namespace browsing_data |
| 94 |
| 95 #endif // COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ |
OLD | NEW |