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

Side by Side Diff: content/browser/browsing_data/storage_partition_http_cache_data_remover.cc

Issue 2757923002: Move StoragePartitionHttpCacheDataRemover to content/ (Closed)
Patch Set: Rebase. Created 3 years, 8 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 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h" 5 #include "content/browser/browsing_data/storage_partition_http_cache_data_remove r.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/sequenced_task_runner_helpers.h"
8 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/browsing_data/content/conditional_cache_deletion_helper.h" 11 #include "content/browser/browsing_data/conditional_cache_deletion_helper.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/storage_partition.h" 13 #include "content/public/browser/storage_partition.h"
13 #include "net/base/sdch_manager.h" 14 #include "net/base/sdch_manager.h"
14 #include "net/disk_cache/blockfile/backend_impl.h" 15 #include "net/disk_cache/blockfile/backend_impl.h"
15 #include "net/disk_cache/disk_cache.h" 16 #include "net/disk_cache/disk_cache.h"
16 #include "net/disk_cache/memory/mem_backend_impl.h" 17 #include "net/disk_cache/memory/mem_backend_impl.h"
17 #include "net/disk_cache/simple/simple_backend_impl.h" 18 #include "net/disk_cache/simple/simple_backend_impl.h"
18 #include "net/http/http_cache.h" 19 #include "net/http/http_cache.h"
19 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
20 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
22 #include "url/gurl.h"
21 23
22 using content::BrowserThread; 24 namespace content {
23
24 namespace browsing_data {
25 25
26 StoragePartitionHttpCacheDataRemover::StoragePartitionHttpCacheDataRemover( 26 StoragePartitionHttpCacheDataRemover::StoragePartitionHttpCacheDataRemover(
27 base::Callback<bool(const GURL&)> url_predicate, 27 base::Callback<bool(const GURL&)> url_predicate,
28 base::Time delete_begin, 28 base::Time delete_begin,
29 base::Time delete_end, 29 base::Time delete_end,
30 net::URLRequestContextGetter* main_context_getter, 30 net::URLRequestContextGetter* main_context_getter,
31 net::URLRequestContextGetter* media_context_getter) 31 net::URLRequestContextGetter* media_context_getter)
32 : url_predicate_(url_predicate), 32 : url_predicate_(url_predicate),
33 delete_begin_(delete_begin), 33 delete_begin_(delete_begin),
34 delete_end_(delete_end), 34 delete_end_(delete_end),
35 main_context_getter_(main_context_getter), 35 main_context_getter_(main_context_getter),
36 media_context_getter_(media_context_getter), 36 media_context_getter_(media_context_getter),
37 next_cache_state_(CacheState::NONE), 37 next_cache_state_(CacheState::NONE),
38 cache_(nullptr) {} 38 cache_(nullptr) {}
39 39
40 StoragePartitionHttpCacheDataRemover::~StoragePartitionHttpCacheDataRemover() {
41 }
42
43 // static. 40 // static.
44 StoragePartitionHttpCacheDataRemover* 41 StoragePartitionHttpCacheDataRemover*
45 StoragePartitionHttpCacheDataRemover::CreateForRange( 42 StoragePartitionHttpCacheDataRemover::CreateForRange(
46 content::StoragePartition* storage_partition, 43 content::StoragePartition* storage_partition,
47 base::Time delete_begin, 44 base::Time delete_begin,
48 base::Time delete_end) { 45 base::Time delete_end) {
49 return new StoragePartitionHttpCacheDataRemover( 46 return new StoragePartitionHttpCacheDataRemover(
50 base::Callback<bool(const GURL&)>(), // Null callback. 47 base::Callback<bool(const GURL&)>(), // Null callback.
51 delete_begin, delete_end, 48 delete_begin, delete_end, storage_partition->GetURLRequestContext(),
52 storage_partition->GetURLRequestContext(),
53 storage_partition->GetMediaURLRequestContext()); 49 storage_partition->GetMediaURLRequestContext());
54 } 50 }
55 51
56 // static. 52 // static.
57 StoragePartitionHttpCacheDataRemover* 53 StoragePartitionHttpCacheDataRemover*
58 StoragePartitionHttpCacheDataRemover::CreateForURLsAndRange( 54 StoragePartitionHttpCacheDataRemover::CreateForURLsAndRange(
59 content::StoragePartition* storage_partition, 55 content::StoragePartition* storage_partition,
60 const base::Callback<bool(const GURL&)>& url_predicate, 56 const base::Callback<bool(const GURL&)>& url_predicate,
61 base::Time delete_begin, 57 base::Time delete_begin,
62 base::Time delete_end) { 58 base::Time delete_end) {
63 return new StoragePartitionHttpCacheDataRemover( 59 return new StoragePartitionHttpCacheDataRemover(
64 url_predicate, delete_begin, delete_end, 60 url_predicate, delete_begin, delete_end,
65 storage_partition->GetURLRequestContext(), 61 storage_partition->GetURLRequestContext(),
66 storage_partition->GetMediaURLRequestContext()); 62 storage_partition->GetMediaURLRequestContext());
67 } 63 }
68 64
65 StoragePartitionHttpCacheDataRemover::~StoragePartitionHttpCacheDataRemover() {}
66
69 void StoragePartitionHttpCacheDataRemover::Remove( 67 void StoragePartitionHttpCacheDataRemover::Remove(
70 const base::Closure& done_callback) { 68 const base::Closure& done_callback) {
71 DCHECK_CURRENTLY_ON(BrowserThread::UI); 69 DCHECK_CURRENTLY_ON(BrowserThread::UI);
72 DCHECK(!done_callback.is_null()); 70 DCHECK(!done_callback.is_null());
73 done_callback_ = done_callback; 71 done_callback_ = done_callback;
74 72
75 BrowserThread::PostTask( 73 BrowserThread::PostTask(
76 BrowserThread::IO, FROM_HERE, 74 BrowserThread::IO, FROM_HERE,
77 base::Bind( 75 base::Bind(
78 &StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread, 76 &StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 case CacheState::DELETE_MAIN: 147 case CacheState::DELETE_MAIN:
150 case CacheState::DELETE_MEDIA: { 148 case CacheState::DELETE_MEDIA: {
151 next_cache_state_ = (next_cache_state_ == CacheState::DELETE_MAIN) 149 next_cache_state_ = (next_cache_state_ == CacheState::DELETE_MAIN)
152 ? CacheState::CREATE_MEDIA 150 ? CacheState::CREATE_MEDIA
153 : CacheState::DONE; 151 : CacheState::DONE;
154 152
155 // |cache_| can be null if it cannot be initialized. 153 // |cache_| can be null if it cannot be initialized.
156 if (cache_) { 154 if (cache_) {
157 if (!url_predicate_.is_null()) { 155 if (!url_predicate_.is_null()) {
158 rv = (new ConditionalCacheDeletionHelper( 156 rv = (new ConditionalCacheDeletionHelper(
159 cache_, 157 cache_,
160 ConditionalCacheDeletionHelper::CreateURLAndTimeCondition( 158 ConditionalCacheDeletionHelper::CreateURLAndTimeCondition(
161 url_predicate_, 159 url_predicate_, delete_begin_, delete_end_)))
162 delete_begin_, 160 ->DeleteAndDestroySelfWhenFinished(base::Bind(
163 delete_end_)))->DeleteAndDestroySelfWhenFinished( 161 &StoragePartitionHttpCacheDataRemover::DoClearCache,
164 base::Bind( 162 base::Unretained(this)));
165 &StoragePartitionHttpCacheDataRemover::DoClearCache,
166 base::Unretained(this)));
167 } else if (delete_begin_.is_null() && delete_end_.is_max()) { 163 } else if (delete_begin_.is_null() && delete_end_.is_max()) {
168 rv = cache_->DoomAllEntries(base::Bind( 164 rv = cache_->DoomAllEntries(
169 &StoragePartitionHttpCacheDataRemover::DoClearCache, 165 base::Bind(&StoragePartitionHttpCacheDataRemover::DoClearCache,
170 base::Unretained(this))); 166 base::Unretained(this)));
171 } else { 167 } else {
172 rv = cache_->DoomEntriesBetween( 168 rv = cache_->DoomEntriesBetween(
173 delete_begin_, delete_end_, 169 delete_begin_, delete_end_,
174 base::Bind( 170 base::Bind(&StoragePartitionHttpCacheDataRemover::DoClearCache,
175 &StoragePartitionHttpCacheDataRemover::DoClearCache, 171 base::Unretained(this)));
176 base::Unretained(this)));
177 } 172 }
178 cache_ = NULL; 173 cache_ = NULL;
179 } 174 }
180 break; 175 break;
181 } 176 }
182 case CacheState::DONE: { 177 case CacheState::DONE: {
183 cache_ = NULL; 178 cache_ = NULL;
184 next_cache_state_ = CacheState::NONE; 179 next_cache_state_ = CacheState::NONE;
185 180
186 // Notify the UI thread that we are done. 181 // Notify the UI thread that we are done.
187 BrowserThread::PostTask( 182 BrowserThread::PostTask(
188 BrowserThread::UI, FROM_HERE, 183 BrowserThread::UI, FROM_HERE,
189 base::Bind(&StoragePartitionHttpCacheDataRemover::ClearedHttpCache, 184 base::Bind(&StoragePartitionHttpCacheDataRemover::ClearedHttpCache,
190 base::Unretained(this))); 185 base::Unretained(this)));
191 return; 186 return;
192 } 187 }
193 case CacheState::NONE: { 188 case CacheState::NONE: {
194 NOTREACHED() << "bad state"; 189 NOTREACHED() << "bad state";
195 return; 190 return;
196 } 191 }
197 } 192 }
198 } 193 }
199 } 194 }
200 195
201 } // namespace browsing_data 196 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browsing_data/storage_partition_http_cache_data_remover.h ('k') | content/browser/storage_partition_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698