Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: components/browsing_data/content/conditional_cache_counting_helper.h

Issue 2612033002: Count exact cache size for time ranges (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 16 matching lines...) Expand all
27 // Returns the number bytes in the selected range. 27 // Returns the number bytes in the selected range.
28 typedef base::Callback<void(int64_t)> CacheCountCallback; 28 typedef base::Callback<void(int64_t)> CacheCountCallback;
29 29
30 static ConditionalCacheCountingHelper* CreateForRange( 30 static ConditionalCacheCountingHelper* CreateForRange(
31 content::StoragePartition* storage_partition, 31 content::StoragePartition* storage_partition,
32 base::Time begin_time, 32 base::Time begin_time,
33 base::Time end_time); 33 base::Time end_time);
34 34
35 // Count the cache entries according to the specified time range. Destroys 35 // Count the cache entries according to the specified time range. Destroys
36 // this instance of ConditionalCacheCountingHelper when finished. 36 // this instance of ConditionalCacheCountingHelper when finished.
37 // The returned WeakPtr can be used to cancel the operation if necessary.
37 // Must be called on the UI thread! 38 // Must be called on the UI thread!
38 // 39 //
39 // The |completion_callback| will be invoked when the operation completes. 40 // The |completion_callback| will be invoked when the operation completes.
40 base::WeakPtr<ConditionalCacheCountingHelper> CountAndDestroySelfWhenFinished( 41 base::WeakPtr<ConditionalCacheCountingHelper> CountAndDestroySelfWhenFinished(
41 const CacheCountCallback& result_callback); 42 const CacheCountCallback& result_callback);
42 43
44 // Cancel the currently counting process. The task on the IO thread will stop
45 // and the callback will return net::ERR_ABORTED.
46 void CancelCounting();
47
43 bool IsFinished(); 48 bool IsFinished();
44 49
45 private: 50 private:
46 enum class CacheState { 51 enum class CacheState {
47 NONE, 52 NONE,
48 CREATE_MAIN, 53 CREATE_MAIN,
49 CREATE_MEDIA, 54 CREATE_MEDIA,
50 COUNT_MAIN, 55 COUNT_MAIN,
51 COUNT_MEDIA, 56 COUNT_MEDIA,
52 DONE 57 DONE
53 }; 58 };
54 59
55 friend class base::DeleteHelper<ConditionalCacheCountingHelper>; 60 friend class base::DeleteHelper<ConditionalCacheCountingHelper>;
56 61
57 ConditionalCacheCountingHelper( 62 ConditionalCacheCountingHelper(
58 base::Time begin_time, 63 base::Time begin_time,
59 base::Time end_time, 64 base::Time end_time,
60 net::URLRequestContextGetter* main_context_getter, 65 net::URLRequestContextGetter* main_context_getter,
61 net::URLRequestContextGetter* media_context_getter); 66 net::URLRequestContextGetter* media_context_getter);
62 ~ConditionalCacheCountingHelper(); 67 ~ConditionalCacheCountingHelper();
63 68
64 void Finished(); 69 void Finished();
65 70
66 void CountHttpCacheOnIOThread(); 71 void CountHttpCacheOnIOThread();
67 void DoCountCache(int rv); 72 void DoCountCache(int rv);
68 73
74 int CountEntries(disk_cache::Backend* backend);
75 void IterateOverEntries(int error);
76
69 // Stores the cache size computation result before it can be returned 77 // 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 78 // 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. 79 // backends, or an error code if the calculation failed.
72 int64_t calculation_result_; 80 int64_t calculation_result_;
73 81
74 CacheCountCallback result_callback_; 82 CacheCountCallback result_callback_;
75 const base::Time begin_time_; 83 const base::Time begin_time_;
76 const base::Time end_time_; 84 const base::Time end_time_;
77 85
86 // This flag is used to tell the IO thread to stop counting if the user
87 // called CancelCounting().
88 volatile bool is_cancelled_;
78 bool is_finished_; 89 bool is_finished_;
79 90
80 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_; 91 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_;
81 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_; 92 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_;
82 93
83 CacheState next_cache_state_; 94 CacheState next_cache_state_;
84 disk_cache::Backend* cache_; 95 disk_cache::Backend* cache_;
85 96
86 std::unique_ptr<disk_cache::Backend::Iterator> iterator_; 97 std::unique_ptr<disk_cache::Backend::Iterator> iterator_;
98 disk_cache::Entry* current_entry_;
87 99
88 base::WeakPtrFactory<ConditionalCacheCountingHelper> weak_ptr_factory_; 100 base::WeakPtrFactory<ConditionalCacheCountingHelper> weak_ptr_factory_;
89 101
90 DISALLOW_COPY_AND_ASSIGN(ConditionalCacheCountingHelper); 102 DISALLOW_COPY_AND_ASSIGN(ConditionalCacheCountingHelper);
91 }; 103 };
92 104
93 } // namespace browsing_data 105 } // namespace browsing_data
94 106
95 #endif // COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_ 107 #endif // COMPONENTS_BROWSING_DATA_CONTENT_CONDITIONAL_CACHE_COUNTING_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698