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_CONDITIONAL_CACHE_DELETION_HELPER_H_ | |
6 #define COMPONENTS_BROWSING_DATA_CONDITIONAL_CACHE_DELETION_HELPER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "base/message_loop/message_loop.h" | |
12 #include "net/base/completion_callback.h" | |
13 #include "net/base/net_errors.h" | |
14 #include "net/disk_cache/disk_cache.h" | |
15 #include "url/gurl.h" | |
16 | |
17 namespace disk_cache { | |
18 class Entry; | |
19 } | |
20 | |
21 namespace browsing_data { | |
22 | |
23 // Helper to remove http cache data from a StoragePartition. | |
24 class ConditionalCacheDeletionHelper { | |
25 public: | |
26 // Creates a helper to delete |cache| entries that match the |condition|. | |
27 // Must be created on the IO thread! | |
28 ConditionalCacheDeletionHelper( | |
29 disk_cache::Backend* cache, | |
30 const base::Callback<bool(const disk_cache::Entry*)>& condition); | |
31 | |
32 // A convenience method to create a condition matching cache entries whose | |
33 // last modified time is between |begin_time| (inclusively), |end_time| | |
34 // (exclusively) and whose URL is matched by the |url_predicate|. Note that | |
35 // |begin_time| and |end_time| can be null to indicate unbounded time interval | |
36 // in their respective direction. | |
37 static base::Callback<bool(const disk_cache::Entry*)> | |
38 CreateURLAndTimeCondition( | |
39 const base::Callback<bool(const GURL&)>& url_predicate, | |
40 const base::Time& begin_time, | |
41 const base::Time& end_time); | |
42 | |
43 // Deletes the cache entries according to the specified condition. Destroys | |
44 // this instance of ConditionalCacheDeletionHelper when finished. | |
45 // Must be called on the IO thread! | |
46 // | |
47 // The return value is a net error code. If this method returns | |
48 // ERR_IO_PENDING, the |completion_callback| will be invoked when the | |
49 // operation completes. | |
50 int DeleteAndDestroySelfWhenFinished( | |
51 const net::CompletionCallback& completion_callback); | |
52 | |
53 private: | |
54 friend class base::DeleteHelper<ConditionalCacheDeletionHelper>; | |
55 ~ConditionalCacheDeletionHelper(); | |
56 | |
57 void IterateOverEntries(int error); | |
58 | |
59 disk_cache::Backend* cache_; | |
60 const base::Callback<bool(const disk_cache::Entry*)> condition_; | |
61 | |
62 net::CompletionCallback completion_callback_; | |
63 | |
64 std::unique_ptr<disk_cache::Backend::Iterator> iterator_; | |
65 disk_cache::Entry* current_entry_; | |
66 disk_cache::Entry* previous_entry_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(ConditionalCacheDeletionHelper); | |
69 }; | |
70 | |
71 } // namespace browsing_data | |
72 | |
73 #endif // COMPONENTS_BROWSING_DATA_CONDITIONAL_CACHE_DELETION_HELPER_H_ | |
OLD | NEW |