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

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

Issue 2556363003: Refactor cache counting into a separate helper class (Closed)
Patch Set: Remove code depending on GetEntrySize() 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOV ER_H_ 5 #ifndef COMPONENTS_BROWSING_DATA_CONTENT_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOV ER_H_
6 #define COMPONENTS_BROWSING_DATA_CONTENT_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOV ER_H_ 6 #define COMPONENTS_BROWSING_DATA_CONTENT_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOV ER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // to the cache interface and might be slower. 44 // to the cache interface and might be slower.
45 static StoragePartitionHttpCacheDataRemover* CreateForURLsAndRange( 45 static StoragePartitionHttpCacheDataRemover* CreateForURLsAndRange(
46 content::StoragePartition* storage_partition, 46 content::StoragePartition* storage_partition,
47 const base::Callback<bool(const GURL&)>& url_predicate, 47 const base::Callback<bool(const GURL&)>& url_predicate,
48 base::Time delete_begin, 48 base::Time delete_begin,
49 base::Time delete_end); 49 base::Time delete_end);
50 50
51 // Calls |done_callback| upon completion and also destroys itself. 51 // Calls |done_callback| upon completion and also destroys itself.
52 void Remove(const base::Closure& done_callback); 52 void Remove(const base::Closure& done_callback);
53 53
54 // Counts the total size of entries that would be removed by calling |Remove|.
55 // Reports it via |result_callback| and then destroys itself.
56 void Count(const net::Int64CompletionCallback& result_callback);
57
58 private: 54 private:
59 enum CacheState { 55 enum CacheState {
60 STATE_NONE, 56 NONE,
61 STATE_CREATE_MAIN, 57 CREATE_MAIN,
62 STATE_CREATE_MEDIA, 58 CREATE_MEDIA,
63 STATE_PROCESS_MAIN, 59 DELETE_MAIN,
64 STATE_PROCESS_MEDIA, 60 DELETE_MEDIA,
65 STATE_DONE 61 DONE
66 }; 62 };
67 63
68 StoragePartitionHttpCacheDataRemover( 64 StoragePartitionHttpCacheDataRemover(
69 base::Callback<bool(const GURL&)> url_predicate, 65 base::Callback<bool(const GURL&)> url_predicate,
70 base::Time delete_begin, 66 base::Time delete_begin,
71 base::Time delete_end, 67 base::Time delete_end,
72 net::URLRequestContextGetter* main_context_getter, 68 net::URLRequestContextGetter* main_context_getter,
73 net::URLRequestContextGetter* media_context_getter); 69 net::URLRequestContextGetter* media_context_getter);
74 70
75 // StoragePartitionHttpCacheDataRemover deletes itself (using DeleteHelper) 71 // StoragePartitionHttpCacheDataRemover deletes itself (using DeleteHelper)
76 // and is not supposed to be deleted by other objects so make destructor 72 // and is not supposed to be deleted by other objects so make destructor
77 // private and DeleteHelper a friend. 73 // private and DeleteHelper a friend.
78 friend class base::DeleteHelper<StoragePartitionHttpCacheDataRemover>; 74 friend class base::DeleteHelper<StoragePartitionHttpCacheDataRemover>;
79 75
80 ~StoragePartitionHttpCacheDataRemover(); 76 ~StoragePartitionHttpCacheDataRemover();
81 77
82 void ClearHttpCacheOnIOThread(); 78 void ClearHttpCacheOnIOThread();
83 void CountHttpCacheOnIOThread();
84
85 void ClearedHttpCache(); 79 void ClearedHttpCache();
86 void CountedHttpCache();
87
88 // Performs the actual work to delete or count the cache. 80 // Performs the actual work to delete or count the cache.
89 void DoClearCache(int rv); 81 void DoClearCache(int rv);
90 void DoCountCache(int rv);
91 82
92 base::Callback<bool(const GURL&)> url_predicate_; 83 base::Callback<bool(const GURL&)> url_predicate_;
93 const base::Time delete_begin_; 84 const base::Time delete_begin_;
94 const base::Time delete_end_; 85 const base::Time delete_end_;
95 86
96 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_; 87 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_;
97 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_; 88 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_;
98 89
99 base::Closure done_callback_; 90 base::Closure done_callback_;
100 net::Int64CompletionCallback result_callback_;
101 91
102 // IO. 92 // IO.
103 int next_cache_state_; 93 int next_cache_state_;
104 disk_cache::Backend* cache_; 94 disk_cache::Backend* cache_;
105 95
106 // Stores the cache size computation result before it can be returned
107 // via a callback. This is either the sum of size of the the two cache
108 // backends, or an error code if the calculation failed.
109 int64_t calculation_result_;
110
111 DISALLOW_COPY_AND_ASSIGN(StoragePartitionHttpCacheDataRemover); 96 DISALLOW_COPY_AND_ASSIGN(StoragePartitionHttpCacheDataRemover);
112 }; 97 };
113 98
114 } // namespace browsing_data 99 } // namespace browsing_data
115 100
116 #endif // COMPONENTS_BROWSING_DATA_CONTENT_STORAGE_PARTITION_HTTP_CACHE_DATA_RE MOVER_H_ 101 #endif // COMPONENTS_BROWSING_DATA_CONTENT_STORAGE_PARTITION_HTTP_CACHE_DATA_RE MOVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698