Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / browsing_data / storage_partition_http_cache_data_remover.h
blobeb9f575fae82478e918e5dd139d979ad09137f6b
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_
6 #define COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_
8 #include "base/callback.h"
9 #include "base/sequenced_task_runner_helpers.h"
10 #include "base/time/time.h"
12 namespace content {
13 class StoragePartition;
16 namespace disk_cache {
17 class Backend;
20 namespace net {
21 class URLRequestContextGetter;
24 namespace browsing_data {
26 // Helper to remove http cache data from a StoragePartition.
27 class StoragePartitionHttpCacheDataRemover {
28 public:
29 static StoragePartitionHttpCacheDataRemover* CreateForRange(
30 content::StoragePartition* storage_partition,
31 base::Time delete_begin,
32 base::Time delete_end);
34 // Calls |done_callback| upon completion and also destroys itself.
35 void Remove(const base::Closure& done_callback);
37 private:
38 enum CacheState {
39 STATE_NONE,
40 STATE_CREATE_MAIN,
41 STATE_CREATE_MEDIA,
42 STATE_DELETE_MAIN,
43 STATE_DELETE_MEDIA,
44 STATE_DONE
47 StoragePartitionHttpCacheDataRemover(
48 base::Time delete_begin,
49 base::Time delete_end,
50 net::URLRequestContextGetter* main_context_getter,
51 net::URLRequestContextGetter* media_context_getter);
53 // StoragePartitionHttpCacheDataRemover deletes itself (using DeleteHelper)
54 // and is not supposed to be deleted by other objects so make destructor
55 // private and DeleteHelper a friend.
56 friend class base::DeleteHelper<StoragePartitionHttpCacheDataRemover>;
58 ~StoragePartitionHttpCacheDataRemover();
60 void ClearHttpCacheOnIOThread();
61 void ClearedHttpCache();
62 // Performs the actual work to delete the cache.
63 void DoClearCache(int rv);
65 const base::Time delete_begin_;
66 const base::Time delete_end_;
68 const scoped_refptr<net::URLRequestContextGetter> main_context_getter_;
69 const scoped_refptr<net::URLRequestContextGetter> media_context_getter_;
71 base::Closure done_callback_;
73 // IO.
74 int next_cache_state_;
75 disk_cache::Backend* cache_;
77 DISALLOW_COPY_AND_ASSIGN(StoragePartitionHttpCacheDataRemover);
80 } // namespace browsing_data
82 #endif // COMPONENTS_BROWSING_DATA_STORAGE_PARTITION_HTTP_CACHE_DATA_REMOVER_H_