| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ | 5 #ifndef COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ |
| 6 #define COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ | 6 #define COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/disk_cache/disk_cache.h" | 12 #include "net/disk_cache/disk_cache.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 class StoragePartition; | 15 class StoragePartition; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class URLRequestContextGetter; | 19 class URLRequestContextGetter; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace browsing_data { | 22 namespace browsing_data { |
| 23 | 23 |
| 24 // Helper to count the size of the http cache data from a StoragePartition. | 24 // Helper to count the size of the http cache data from a StoragePartition. |
| 25 class ConditionalCacheCountingHelper { | 25 class ConditionalCacheCountingHelper { |
| 26 public: | 26 public: |
| 27 // Returns the number bytes in the selected range. | 27 // Returns the number bytes in the selected range and if this value is an |
| 28 typedef base::Callback<void(int64_t)> CacheCountCallback; | 28 // upper estimate. |
| 29 typedef base::Callback<void(int64_t, bool)> CacheCountCallback; |
| 29 | 30 |
| 30 static ConditionalCacheCountingHelper* CreateForRange( | 31 static ConditionalCacheCountingHelper* CreateForRange( |
| 31 content::StoragePartition* storage_partition, | 32 content::StoragePartition* storage_partition, |
| 32 base::Time begin_time, | 33 base::Time begin_time, |
| 33 base::Time end_time); | 34 base::Time end_time); |
| 34 | 35 |
| 35 // Count the cache entries according to the specified time range. Destroys | 36 // Count the cache entries according to the specified time range. Destroys |
| 36 // this instance of ConditionalCacheCountingHelper when finished. | 37 // this instance of ConditionalCacheCountingHelper when finished. |
| 37 // Must be called on the UI thread! | 38 // Must be called on the UI thread! |
| 38 // | 39 // |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 | 64 |
| 64 void Finished(); | 65 void Finished(); |
| 65 | 66 |
| 66 void CountHttpCacheOnIOThread(); | 67 void CountHttpCacheOnIOThread(); |
| 67 void DoCountCache(int rv); | 68 void DoCountCache(int rv); |
| 68 | 69 |
| 69 // Stores the cache size computation result before it can be returned | 70 // 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 // 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 // backends, or an error code if the calculation failed. |
| 72 int64_t calculation_result_; | 73 int64_t calculation_result_; |
| 74 bool is_upper_limit_; |
| 73 | 75 |
| 74 CacheCountCallback result_callback_; | 76 CacheCountCallback result_callback_; |
| 75 const base::Time begin_time_; | 77 const base::Time begin_time_; |
| 76 const base::Time end_time_; | 78 const base::Time end_time_; |
| 77 | 79 |
| 78 bool is_finished_; | 80 bool is_finished_; |
| 79 | 81 |
| 80 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_; | 82 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_; |
| 81 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_; | 83 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_; |
| 82 | 84 |
| 83 CacheState next_cache_state_; | 85 CacheState next_cache_state_; |
| 84 disk_cache::Backend* cache_; | 86 disk_cache::Backend* cache_; |
| 85 | 87 |
| 86 std::unique_ptr<disk_cache::Backend::Iterator> iterator_; | 88 std::unique_ptr<disk_cache::Backend::Iterator> iterator_; |
| 87 | 89 |
| 88 base::WeakPtrFactory<ConditionalCacheCountingHelper> weak_ptr_factory_; | 90 base::WeakPtrFactory<ConditionalCacheCountingHelper> weak_ptr_factory_; |
| 89 | 91 |
| 90 DISALLOW_COPY_AND_ASSIGN(ConditionalCacheCountingHelper); | 92 DISALLOW_COPY_AND_ASSIGN(ConditionalCacheCountingHelper); |
| 91 }; | 93 }; |
| 92 | 94 |
| 93 } // namespace browsing_data | 95 } // namespace browsing_data |
| 94 | 96 |
| 95 #endif // COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ | 97 #endif // COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ |
| OLD | NEW |