OLD | NEW |
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_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_ | 5 #ifndef COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_ |
6 #define COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_ | 6 #define COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/sequenced_task_runner_helpers.h" | 9 #include "base/sequenced_task_runner_helpers.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "net/base/completion_callback.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 class StoragePartition; | 14 class StoragePartition; |
14 } | 15 } |
15 | 16 |
16 namespace disk_cache { | 17 namespace disk_cache { |
17 class Backend; | 18 class Backend; |
18 } | 19 } |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
22 } | 23 } |
23 | 24 |
24 namespace browsing_data { | 25 namespace browsing_data { |
25 | 26 |
26 // Helper to remove http cache data from a StoragePartition. | 27 // Helper to remove http cache data from a StoragePartition. |
27 class StoragePartitionHttpCacheDataRemover { | 28 class StoragePartitionHttpCacheDataRemover { |
28 public: | 29 public: |
29 static StoragePartitionHttpCacheDataRemover* CreateForRange( | 30 static StoragePartitionHttpCacheDataRemover* CreateForRange( |
30 content::StoragePartition* storage_partition, | 31 content::StoragePartition* storage_partition, |
31 base::Time delete_begin, | 32 base::Time delete_begin, |
32 base::Time delete_end); | 33 base::Time delete_end); |
33 | 34 |
34 // Calls |done_callback| upon completion and also destroys itself. | 35 // Calls |done_callback| upon completion and also destroys itself. |
35 void Remove(const base::Closure& done_callback); | 36 void Remove(const base::Closure& done_callback); |
36 | 37 |
| 38 // Counts the total size of entries that would be removed by calling |Remove|. |
| 39 // Reports it via |result_callback| and then destroys itself. |
| 40 void Count(const net::Int64CompletionCallback& result_callback); |
| 41 |
37 private: | 42 private: |
38 enum CacheState { | 43 enum CacheState { |
39 STATE_NONE, | 44 STATE_NONE, |
40 STATE_CREATE_MAIN, | 45 STATE_CREATE_MAIN, |
41 STATE_CREATE_MEDIA, | 46 STATE_CREATE_MEDIA, |
42 STATE_DELETE_MAIN, | 47 STATE_PROCESS_MAIN, |
43 STATE_DELETE_MEDIA, | 48 STATE_PROCESS_MEDIA, |
44 STATE_DONE | 49 STATE_DONE |
45 }; | 50 }; |
46 | 51 |
47 StoragePartitionHttpCacheDataRemover( | 52 StoragePartitionHttpCacheDataRemover( |
48 base::Time delete_begin, | 53 base::Time delete_begin, |
49 base::Time delete_end, | 54 base::Time delete_end, |
50 net::URLRequestContextGetter* main_context_getter, | 55 net::URLRequestContextGetter* main_context_getter, |
51 net::URLRequestContextGetter* media_context_getter); | 56 net::URLRequestContextGetter* media_context_getter); |
52 | 57 |
53 // StoragePartitionHttpCacheDataRemover deletes itself (using DeleteHelper) | 58 // StoragePartitionHttpCacheDataRemover deletes itself (using DeleteHelper) |
54 // and is not supposed to be deleted by other objects so make destructor | 59 // and is not supposed to be deleted by other objects so make destructor |
55 // private and DeleteHelper a friend. | 60 // private and DeleteHelper a friend. |
56 friend class base::DeleteHelper<StoragePartitionHttpCacheDataRemover>; | 61 friend class base::DeleteHelper<StoragePartitionHttpCacheDataRemover>; |
57 | 62 |
58 ~StoragePartitionHttpCacheDataRemover(); | 63 ~StoragePartitionHttpCacheDataRemover(); |
59 | 64 |
60 void ClearHttpCacheOnIOThread(); | 65 void ClearHttpCacheOnIOThread(); |
| 66 void CountHttpCacheOnIOThread(); |
| 67 |
61 void ClearedHttpCache(); | 68 void ClearedHttpCache(); |
62 // Performs the actual work to delete the cache. | 69 void CountedHttpCache(); |
| 70 |
| 71 // Performs the actual work to delete or count the cache. |
63 void DoClearCache(int rv); | 72 void DoClearCache(int rv); |
| 73 void DoCountCache(int rv); |
64 | 74 |
65 const base::Time delete_begin_; | 75 const base::Time delete_begin_; |
66 const base::Time delete_end_; | 76 const base::Time delete_end_; |
67 | 77 |
68 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_; | 78 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_; |
69 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_; | 79 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_; |
70 | 80 |
71 base::Closure done_callback_; | 81 base::Closure done_callback_; |
| 82 net::Int64CompletionCallback result_callback_; |
72 | 83 |
73 // IO. | 84 // IO. |
74 int next_cache_state_; | 85 int next_cache_state_; |
75 disk_cache::Backend* cache_; | 86 disk_cache::Backend* cache_; |
76 | 87 |
| 88 // Stores the cache size computation result before it can be returned |
| 89 // via a callback. This is either the sum of size of the the two cache |
| 90 // backends, or an error code if the calculation failed. |
| 91 int64 calculation_result_; |
| 92 |
77 DISALLOW_COPY_AND_ASSIGN(StoragePartitionHttpCacheDataRemover); | 93 DISALLOW_COPY_AND_ASSIGN(StoragePartitionHttpCacheDataRemover); |
78 }; | 94 }; |
79 | 95 |
80 } // namespace browsing_data | 96 } // namespace browsing_data |
81 | 97 |
82 #endif // COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_ | 98 #endif // COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_ |
OLD | NEW |