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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover.cc

Issue 2578723002: Reduce BrowsingDataRemover's dependencies on Chrome (Closed)
Patch Set: Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/browsing_data_remover.h" 5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" 17 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
18 #include "chrome/browser/browsing_data/browsing_data_helper.h" 18 #include "chrome/browser/browsing_data/browsing_data_helper.h"
19 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h" 19 #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
20 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" 20 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
21 #include "chrome/browser/download/download_prefs.h"
22 #include "chrome/browser/io_thread.h"
23 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
25 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h" 23 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h"
26 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
27 #include "components/web_cache/browser/web_cache_manager.h" 25 #include "components/web_cache/browser/web_cache_manager.h"
26 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/content_browser_client.h"
29 #include "content/public/browser/download_manager.h" 29 #include "content/public/browser/download_manager.h"
30 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/plugin_data_remover.h" 31 #include "content/public/browser/plugin_data_remover.h"
32 #include "content/public/browser/ssl_host_state_delegate.h" 32 #include "content/public/browser/ssl_host_state_delegate.h"
33 #include "content/public/browser/storage_partition.h" 33 #include "content/public/browser/storage_partition.h"
34 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
35 #include "extensions/features/features.h" 35 #include "extensions/features/features.h"
36 #include "media/media_features.h" 36 #include "media/media_features.h"
37 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
38 #include "net/cookies/cookie_store.h" 38 #include "net/cookies/cookie_store.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 weak_ptr_factory_.GetWeakPtr()); 149 weak_ptr_factory_.GetWeakPtr());
150 } 150 }
151 151
152 void BrowsingDataRemover::SubTask::CompletionCallback() { 152 void BrowsingDataRemover::SubTask::CompletionCallback() {
153 DCHECK_CURRENTLY_ON(BrowserThread::UI); 153 DCHECK_CURRENTLY_ON(BrowserThread::UI);
154 DCHECK(is_pending_); 154 DCHECK(is_pending_);
155 is_pending_ = false; 155 is_pending_ = false;
156 forward_callback_.Run(); 156 forward_callback_.Run();
157 } 157 }
158 158
159 bool BrowsingDataRemover::TimeRange::operator==(
160 const BrowsingDataRemover::TimeRange& other) const {
161 return begin == other.begin && end == other.end;
162 }
163
164 // static
165 BrowsingDataRemover::TimeRange BrowsingDataRemover::Unbounded() {
166 return TimeRange(base::Time(), base::Time::Max());
167 }
168
169 // static
170 BrowsingDataRemover::TimeRange BrowsingDataRemover::Period(
171 browsing_data::TimePeriod period) {
172 switch (period) {
173 case browsing_data::LAST_HOUR:
174 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastHour"));
175 break;
176 case browsing_data::LAST_DAY:
177 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastDay"));
178 break;
179 case browsing_data::LAST_WEEK:
180 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastWeek"));
181 break;
182 case browsing_data::FOUR_WEEKS:
183 content::RecordAction(UserMetricsAction("ClearBrowsingData_LastMonth"));
184 break;
185 case browsing_data::ALL_TIME:
186 content::RecordAction(UserMetricsAction("ClearBrowsingData_Everything"));
187 break;
188 }
189 return TimeRange(CalculateBeginDeleteTime(period), base::Time::Max());
190 }
191
192 BrowsingDataRemover::BrowsingDataRemover( 159 BrowsingDataRemover::BrowsingDataRemover(
193 content::BrowserContext* browser_context) 160 content::BrowserContext* browser_context)
194 : profile_(Profile::FromBrowserContext(browser_context)), 161 : browser_context_(browser_context),
195 remove_mask_(-1), 162 remove_mask_(-1),
196 origin_type_mask_(-1), 163 origin_type_mask_(-1),
197 is_removing_(false), 164 is_removing_(false),
198 #if BUILDFLAG(ENABLE_PLUGINS) 165 #if BUILDFLAG(ENABLE_PLUGINS)
199 flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(profile_)), 166 flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(browser_context_)),
200 #endif 167 #endif
201 sub_task_forward_callback_( 168 sub_task_forward_callback_(
202 base::Bind(&BrowsingDataRemover::NotifyIfDone, 169 base::Bind(&BrowsingDataRemover::NotifyIfDone,
203 base::Unretained(this))), 170 base::Unretained(this))),
204 synchronous_clear_operations_(sub_task_forward_callback_), 171 synchronous_clear_operations_(sub_task_forward_callback_),
205 clear_embedder_data_(sub_task_forward_callback_), 172 clear_embedder_data_(sub_task_forward_callback_),
206 clear_cache_(sub_task_forward_callback_), 173 clear_cache_(sub_task_forward_callback_),
207 clear_channel_ids_(sub_task_forward_callback_), 174 clear_channel_ids_(sub_task_forward_callback_),
208 clear_http_auth_cache_(sub_task_forward_callback_), 175 clear_http_auth_cache_(sub_task_forward_callback_),
209 clear_storage_partition_data_(sub_task_forward_callback_), 176 clear_storage_partition_data_(sub_task_forward_callback_),
210 weak_ptr_factory_(this) { 177 weak_ptr_factory_(this) {
211 DCHECK(browser_context); 178 DCHECK(browser_context_);
212 } 179 }
213 180
214 BrowsingDataRemover::~BrowsingDataRemover() { 181 BrowsingDataRemover::~BrowsingDataRemover() {
215 if (!task_queue_.empty()) { 182 if (!task_queue_.empty()) {
216 VLOG(1) << "BrowsingDataRemover shuts down with " << task_queue_.size() 183 VLOG(1) << "BrowsingDataRemover shuts down with " << task_queue_.size()
217 << " pending tasks"; 184 << " pending tasks";
218 } 185 }
219 186
220 // If we are still removing data, notify observers that their task has been 187 // If we are still removing data, notify observers that their task has been
221 // (albeit unsucessfuly) processed, so they can unregister themselves. 188 // (albeit unsucessfuly) processed, so they can unregister themselves.
222 // TODO(bauerb): If it becomes a problem that browsing data might not actually 189 // TODO(bauerb): If it becomes a problem that browsing data might not actually
223 // be fully cleared when an observer is notified, add a success flag. 190 // be fully cleared when an observer is notified, add a success flag.
224 while (!task_queue_.empty()) { 191 while (!task_queue_.empty()) {
225 if (observer_list_.HasObserver(task_queue_.front().observer)) 192 if (observer_list_.HasObserver(task_queue_.front().observer))
226 task_queue_.front().observer->OnBrowsingDataRemoverDone(); 193 task_queue_.front().observer->OnBrowsingDataRemoverDone();
227 task_queue_.pop(); 194 task_queue_.pop();
228 } 195 }
229 } 196 }
230 197
231 void BrowsingDataRemover::Shutdown() { 198 void BrowsingDataRemover::Shutdown() {
232 embedder_delegate_.reset(); 199 embedder_delegate_.reset();
233 } 200 }
234 201
235 void BrowsingDataRemover::SetRemoving(bool is_removing) { 202 void BrowsingDataRemover::SetRemoving(bool is_removing) {
236 DCHECK_NE(is_removing_, is_removing); 203 DCHECK_NE(is_removing_, is_removing);
237 is_removing_ = is_removing; 204 is_removing_ = is_removing;
238 } 205 }
239 206
240 void BrowsingDataRemover::Remove(const TimeRange& time_range, 207 void BrowsingDataRemover::Remove(const base::Time& delete_begin,
208 const base::Time& delete_end,
241 int remove_mask, 209 int remove_mask,
242 int origin_type_mask) { 210 int origin_type_mask) {
243 RemoveInternal(time_range, remove_mask, origin_type_mask, 211 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
244 std::unique_ptr<RegistrableDomainFilterBuilder>(), nullptr); 212 std::unique_ptr<RegistrableDomainFilterBuilder>(), nullptr);
245 } 213 }
246 214
247 void BrowsingDataRemover::RemoveAndReply( 215 void BrowsingDataRemover::RemoveAndReply(
248 const TimeRange& time_range, 216 const base::Time& delete_begin,
217 const base::Time& delete_end,
249 int remove_mask, 218 int remove_mask,
250 int origin_type_mask, 219 int origin_type_mask,
251 Observer* observer) { 220 Observer* observer) {
252 DCHECK(observer); 221 DCHECK(observer);
253 RemoveInternal(time_range, remove_mask, origin_type_mask, 222 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
254 std::unique_ptr<RegistrableDomainFilterBuilder>(), observer); 223 std::unique_ptr<RegistrableDomainFilterBuilder>(), observer);
255 } 224 }
256 225
257 void BrowsingDataRemover::RemoveWithFilter( 226 void BrowsingDataRemover::RemoveWithFilter(
258 const TimeRange& time_range, 227 const base::Time& delete_begin,
228 const base::Time& delete_end,
259 int remove_mask, 229 int remove_mask,
260 int origin_type_mask, 230 int origin_type_mask,
261 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { 231 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
262 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES); 232 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES);
263 DCHECK(filter_builder); 233 DCHECK(filter_builder);
264 RemoveInternal(time_range, remove_mask, origin_type_mask, 234 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
265 std::move(filter_builder), nullptr); 235 std::move(filter_builder), nullptr);
266 } 236 }
267 237
268 void BrowsingDataRemover::RemoveWithFilterAndReply( 238 void BrowsingDataRemover::RemoveWithFilterAndReply(
269 const TimeRange& time_range, 239 const base::Time& delete_begin,
240 const base::Time& delete_end,
270 int remove_mask, 241 int remove_mask,
271 int origin_type_mask, 242 int origin_type_mask,
272 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 243 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
273 Observer* observer) { 244 Observer* observer) {
274 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES); 245 DCHECK_EQ(0, remove_mask & ~FILTERABLE_DATATYPES);
275 DCHECK(filter_builder); 246 DCHECK(filter_builder);
276 DCHECK(observer); 247 DCHECK(observer);
277 RemoveInternal(time_range, remove_mask, origin_type_mask, 248 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask,
278 std::move(filter_builder), observer); 249 std::move(filter_builder), observer);
279 } 250 }
280 251
281 void BrowsingDataRemover::RemoveInternal( 252 void BrowsingDataRemover::RemoveInternal(
282 const TimeRange& time_range, 253 const base::Time& delete_begin,
254 const base::Time& delete_end,
283 int remove_mask, 255 int remove_mask,
284 int origin_type_mask, 256 int origin_type_mask,
285 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 257 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
286 Observer* observer) { 258 Observer* observer) {
287 DCHECK(!observer || observer_list_.HasObserver(observer)) 259 DCHECK(!observer || observer_list_.HasObserver(observer))
288 << "Every observer must register itself (by calling AddObserver()) " 260 << "Every observer must register itself (by calling AddObserver()) "
289 << "before observing a removal task."; 261 << "before observing a removal task.";
290 262
291 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter. 263 // Remove() and RemoveAndReply() pass a null pointer to indicate no filter.
292 // No filter is equivalent to one that |IsEmptyBlacklist()|. 264 // No filter is equivalent to one that |IsEmptyBlacklist()|.
293 if (!filter_builder) { 265 if (!filter_builder) {
294 filter_builder = base::MakeUnique<RegistrableDomainFilterBuilder>( 266 filter_builder = base::MakeUnique<RegistrableDomainFilterBuilder>(
295 RegistrableDomainFilterBuilder::BLACKLIST); 267 RegistrableDomainFilterBuilder::BLACKLIST);
296 DCHECK(filter_builder->IsEmptyBlacklist()); 268 DCHECK(filter_builder->IsEmptyBlacklist());
297 } 269 }
298 270
299 task_queue_.emplace( 271 task_queue_.emplace(
300 time_range, 272 delete_begin,
273 delete_end,
301 remove_mask, 274 remove_mask,
302 origin_type_mask, 275 origin_type_mask,
303 std::move(filter_builder), 276 std::move(filter_builder),
304 observer); 277 observer);
305 278
306 // If this is the only scheduled task, execute it immediately. Otherwise, 279 // If this is the only scheduled task, execute it immediately. Otherwise,
307 // it will be automatically executed when all tasks scheduled before it 280 // it will be automatically executed when all tasks scheduled before it
308 // finish. 281 // finish.
309 if (task_queue_.size() == 1) { 282 if (task_queue_.size() == 1) {
310 SetRemoving(true); 283 SetRemoving(true);
311 RunNextTask(); 284 RunNextTask();
312 } 285 }
313 } 286 }
314 287
315 void BrowsingDataRemover::RunNextTask() { 288 void BrowsingDataRemover::RunNextTask() {
316 DCHECK(!task_queue_.empty()); 289 DCHECK(!task_queue_.empty());
317 const RemovalTask& removal_task = task_queue_.front(); 290 const RemovalTask& removal_task = task_queue_.front();
318 291
319 RemoveImpl(removal_task.time_range, 292 RemoveImpl(removal_task.delete_begin,
293 removal_task.delete_end,
320 removal_task.remove_mask, 294 removal_task.remove_mask,
321 *removal_task.filter_builder, 295 *removal_task.filter_builder,
322 removal_task.origin_type_mask); 296 removal_task.origin_type_mask);
323 } 297 }
324 298
325 void BrowsingDataRemover::RemoveImpl( 299 void BrowsingDataRemover::RemoveImpl(
326 const TimeRange& time_range, 300 const base::Time& delete_begin,
301 const base::Time& delete_end,
327 int remove_mask, 302 int remove_mask,
328 const BrowsingDataFilterBuilder& filter_builder, 303 const BrowsingDataFilterBuilder& filter_builder,
329 int origin_type_mask) { 304 int origin_type_mask) {
330 // =============== README before adding more storage backends =============== 305 // =============== README before adding more storage backends ===============
331 // 306 //
332 // If you're adding a data storage backend that is included among 307 // If you're adding a data storage backend that is included among
333 // RemoveDataMask::FILTERABLE_DATATYPES, you must do one of the following: 308 // RemoveDataMask::FILTERABLE_DATATYPES, you must do one of the following:
334 // 1. Support one of the filters generated by |filter_builder|. 309 // 1. Support one of the filters generated by |filter_builder|.
335 // 2. Add a comment explaining why is it acceptable in your case to delete all 310 // 2. Add a comment explaining why is it acceptable in your case to delete all
336 // data without filtering URLs / origins / domains. 311 // data without filtering URLs / origins / domains.
337 // 3. Do not support partial deletion, i.e. only delete your data if 312 // 3. Do not support partial deletion, i.e. only delete your data if
338 // |filter_builder.IsEmptyBlacklist()|. Add a comment explaining why this 313 // |filter_builder.IsEmptyBlacklist()|. Add a comment explaining why this
339 // is acceptable. 314 // is acceptable.
340 synchronous_clear_operations_.Start(); 315 synchronous_clear_operations_.Start();
341 316
342 // crbug.com/140910: Many places were calling this with base::Time() as 317 // crbug.com/140910: Many places were calling this with base::Time() as
343 // delete_end, even though they should've used base::Time::Max(). 318 // delete_end, even though they should've used base::Time::Max().
344 DCHECK_NE(base::Time(), time_range.end); 319 DCHECK_NE(base::Time(), delete_end);
345 320
346 delete_begin_ = time_range.begin; 321 delete_begin_ = delete_begin;
347 delete_end_ = time_range.end; 322 delete_end_ = delete_end;
348 remove_mask_ = remove_mask; 323 remove_mask_ = remove_mask;
349 origin_type_mask_ = origin_type_mask; 324 origin_type_mask_ = origin_type_mask;
350 325
351 if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 326 if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
352 content::RecordAction( 327 content::RecordAction(
353 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); 328 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
354 } 329 }
355 if (origin_type_mask_ & BrowsingDataHelper::PROTECTED_WEB) { 330 if (origin_type_mask_ & BrowsingDataHelper::PROTECTED_WEB) {
356 content::RecordAction( 331 content::RecordAction(
357 UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb")); 332 UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb"));
(...skipping 19 matching lines...) Expand all
377 } else if (remove_mask & REMOVE_CACHE) { 352 } else if (remove_mask & REMOVE_CACHE) {
378 choice = ONLY_CACHE; 353 choice = ONLY_CACHE;
379 } 354 }
380 355
381 UMA_HISTOGRAM_ENUMERATION( 356 UMA_HISTOGRAM_ENUMERATION(
382 "History.ClearBrowsingData.UserDeletedCookieOrCache", 357 "History.ClearBrowsingData.UserDeletedCookieOrCache",
383 choice, MAX_CHOICE_VALUE); 358 choice, MAX_CHOICE_VALUE);
384 359
385 // Managed devices and supervised users can have restrictions on history 360 // Managed devices and supervised users can have restrictions on history
386 // deletion. 361 // deletion.
387 PrefService* prefs = profile_->GetPrefs(); 362 // TODO(crbug.com/668114): This should be provided via ContentBrowserClient
388 bool may_delete_history = prefs->GetBoolean( 363 // once BrowsingDataRemover moves to content.
389 prefs::kAllowDeletingBrowserHistory); 364 PrefService* prefs =
365 Profile::FromBrowserContext(browser_context_)->GetPrefs();
366 bool may_delete_history =
367 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
390 368
391 // All the UI entry points into the BrowsingDataRemover should be disabled, 369 // All the UI entry points into the BrowsingDataRemover should be disabled,
392 // but this will fire if something was missed or added. 370 // but this will fire if something was missed or added.
393 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || 371 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
394 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); 372 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
395 373
396 ////////////////////////////////////////////////////////////////////////////// 374 //////////////////////////////////////////////////////////////////////////////
397 // INITIALIZATION 375 // INITIALIZATION
398 base::Callback<bool(const GURL& url)> filter = 376 base::Callback<bool(const GURL& url)> filter =
399 filter_builder.BuildGeneralFilter(); 377 filter_builder.BuildGeneralFilter();
400 378
401 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { 379 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
402 // The SSL Host State that tracks SSL interstitial "proceed" decisions may 380 // The SSL Host State that tracks SSL interstitial "proceed" decisions may
403 // include origins that the user has visited, so it must be cleared. 381 // include origins that the user has visited, so it must be cleared.
404 // TODO(msramek): We can reuse the plugin filter here, since both plugins 382 // TODO(msramek): We can reuse the plugin filter here, since both plugins
405 // and SSL host state are scoped to hosts and represent them as std::string. 383 // and SSL host state are scoped to hosts and represent them as std::string.
406 // Rename the method to indicate its more general usage. 384 // Rename the method to indicate its more general usage.
407 if (profile_->GetSSLHostStateDelegate()) { 385 if (browser_context_->GetSSLHostStateDelegate()) {
408 profile_->GetSSLHostStateDelegate()->Clear( 386 browser_context_->GetSSLHostStateDelegate()->Clear(
409 filter_builder.IsEmptyBlacklist() 387 filter_builder.IsEmptyBlacklist()
410 ? base::Callback<bool(const std::string&)>() 388 ? base::Callback<bool(const std::string&)>()
411 : filter_builder.BuildPluginFilter()); 389 : filter_builder.BuildPluginFilter());
412 } 390 }
413 } 391 }
414 392
415 ////////////////////////////////////////////////////////////////////////////// 393 //////////////////////////////////////////////////////////////////////////////
416 // REMOVE_DOWNLOADS 394 // REMOVE_DOWNLOADS
417 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { 395 if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
418 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); 396 content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
419 content::DownloadManager* download_manager = 397 content::DownloadManager* download_manager =
420 BrowserContext::GetDownloadManager(profile_); 398 BrowserContext::GetDownloadManager(browser_context_);
421 download_manager->RemoveDownloadsByURLAndTime(filter, 399 download_manager->RemoveDownloadsByURLAndTime(filter,
422 delete_begin_, delete_end_); 400 delete_begin_, delete_end_);
423 DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager(
424 download_manager);
425 download_prefs->SetSaveFilePath(download_prefs->DownloadPath());
426 } 401 }
427 402
428 ////////////////////////////////////////////////////////////////////////////// 403 //////////////////////////////////////////////////////////////////////////////
429 // REMOVE_CHANNEL_IDS 404 // REMOVE_CHANNEL_IDS
430 // Channel IDs are not separated for protected and unprotected web 405 // Channel IDs are not separated for protected and unprotected web
431 // origins. We check the origin_type_mask_ to prevent unintended deletion. 406 // origins. We check the origin_type_mask_ to prevent unintended deletion.
432 if (remove_mask & REMOVE_CHANNEL_IDS && 407 if (remove_mask & REMOVE_CHANNEL_IDS &&
433 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 408 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
434 content::RecordAction( 409 content::RecordAction(
435 UserMetricsAction("ClearBrowsingData_ChannelIDs")); 410 UserMetricsAction("ClearBrowsingData_ChannelIDs"));
436 // Since we are running on the UI thread don't call GetURLRequestContext(). 411 // Since we are running on the UI thread don't call GetURLRequestContext().
437 scoped_refptr<net::URLRequestContextGetter> rq_context = 412 scoped_refptr<net::URLRequestContextGetter> rq_context =
438 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 413 content::BrowserContext::GetDefaultStoragePartition(browser_context_)->
439 GetURLRequestContext(); 414 GetURLRequestContext();
440 clear_channel_ids_.Start(); 415 clear_channel_ids_.Start();
441 BrowserThread::PostTask( 416 BrowserThread::PostTask(
442 BrowserThread::IO, FROM_HERE, 417 BrowserThread::IO, FROM_HERE,
443 base::Bind(&ClearChannelIDsOnIOThread, 418 base::Bind(&ClearChannelIDsOnIOThread,
444 filter_builder.BuildChannelIDFilter(), 419 filter_builder.BuildChannelIDFilter(),
445 delete_begin_, delete_end_, std::move(rq_context), 420 delete_begin_, delete_end_, std::move(rq_context),
446 clear_channel_ids_.GetCompletionCallback())); 421 clear_channel_ids_.GetCompletionCallback()));
447 } 422 }
448 423
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // Flash (which are deleted father down in this method). 469 // Flash (which are deleted father down in this method).
495 if (remove_mask & REMOVE_MEDIA_LICENSES) { 470 if (remove_mask & REMOVE_MEDIA_LICENSES) {
496 storage_partition_remove_mask |= 471 storage_partition_remove_mask |=
497 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA; 472 content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA;
498 } 473 }
499 474
500 if (storage_partition_remove_mask) { 475 if (storage_partition_remove_mask) {
501 clear_storage_partition_data_.Start(); 476 clear_storage_partition_data_.Start();
502 477
503 content::StoragePartition* storage_partition; 478 content::StoragePartition* storage_partition;
504 if (storage_partition_for_testing_) 479 if (storage_partition_for_testing_) {
505 storage_partition = storage_partition_for_testing_; 480 storage_partition = storage_partition_for_testing_;
506 else 481 } else {
507 storage_partition = BrowserContext::GetDefaultStoragePartition(profile_); 482 storage_partition =
483 BrowserContext::GetDefaultStoragePartition(browser_context_);
484 }
508 485
509 uint32_t quota_storage_remove_mask = 486 uint32_t quota_storage_remove_mask =
510 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 487 ~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
511 488
512 if (delete_begin_ == base::Time() || 489 if (delete_begin_ == base::Time() ||
513 origin_type_mask_ & 490 origin_type_mask_ &
514 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { 491 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
515 // If we're deleting since the beginning of time, or we're removing 492 // If we're deleting since the beginning of time, or we're removing
516 // protected origins, then remove persistent quota data. 493 // protected origins, then remove persistent quota data.
517 quota_storage_remove_mask |= 494 quota_storage_remove_mask |=
(...skipping 21 matching lines...) Expand all
539 #if BUILDFLAG(ENABLE_PLUGINS) 516 #if BUILDFLAG(ENABLE_PLUGINS)
540 // Plugin is data not separated for protected and unprotected web origins. We 517 // Plugin is data not separated for protected and unprotected web origins. We
541 // check the origin_type_mask_ to prevent unintended deletion. 518 // check the origin_type_mask_ to prevent unintended deletion.
542 if (remove_mask & REMOVE_PLUGIN_DATA && 519 if (remove_mask & REMOVE_PLUGIN_DATA &&
543 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 520 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
544 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); 521 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
545 clear_plugin_data_count_ = 1; 522 clear_plugin_data_count_ = 1;
546 523
547 if (filter_builder.IsEmptyBlacklist()) { 524 if (filter_builder.IsEmptyBlacklist()) {
548 DCHECK(!plugin_data_remover_); 525 DCHECK(!plugin_data_remover_);
549 plugin_data_remover_.reset(content::PluginDataRemover::Create(profile_)); 526 plugin_data_remover_.reset(
527 content::PluginDataRemover::Create(browser_context_));
550 base::WaitableEvent* event = 528 base::WaitableEvent* event =
551 plugin_data_remover_->StartRemoving(delete_begin_); 529 plugin_data_remover_->StartRemoving(delete_begin_);
552 530
553 base::WaitableEventWatcher::EventCallback watcher_callback = 531 base::WaitableEventWatcher::EventCallback watcher_callback =
554 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, 532 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
555 weak_ptr_factory_.GetWeakPtr()); 533 weak_ptr_factory_.GetWeakPtr());
556 watcher_.StartWatching(event, watcher_callback); 534 watcher_.StartWatching(event, watcher_callback);
557 } else { 535 } else {
558 // TODO(msramek): Store filters from the currently executed task on the 536 // TODO(msramek): Store filters from the currently executed task on the
559 // object to avoid having to copy them to callback methods. 537 // object to avoid having to copy them to callback methods.
(...skipping 10 matching lines...) Expand all
570 if (remove_mask & REMOVE_CACHE) { 548 if (remove_mask & REMOVE_CACHE) {
571 // Tell the renderers to clear their cache. 549 // Tell the renderers to clear their cache.
572 web_cache::WebCacheManager::GetInstance()->ClearCache(); 550 web_cache::WebCacheManager::GetInstance()->ClearCache();
573 551
574 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); 552 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
575 553
576 clear_cache_.Start(); 554 clear_cache_.Start();
577 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. 555 // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
578 if (filter_builder.IsEmptyBlacklist()) { 556 if (filter_builder.IsEmptyBlacklist()) {
579 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( 557 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
580 BrowserContext::GetDefaultStoragePartition(profile_), 558 BrowserContext::GetDefaultStoragePartition(browser_context_),
581 delete_begin_, delete_end_) 559 delete_begin_, delete_end_)
582 ->Remove(clear_cache_.GetCompletionCallback()); 560 ->Remove(clear_cache_.GetCompletionCallback());
583 } else { 561 } else {
584 browsing_data::StoragePartitionHttpCacheDataRemover:: 562 browsing_data::StoragePartitionHttpCacheDataRemover::
585 CreateForURLsAndRange( 563 CreateForURLsAndRange(
586 BrowserContext::GetDefaultStoragePartition(profile_), 564 BrowserContext::GetDefaultStoragePartition(browser_context_),
587 filter, delete_begin_, delete_end_) 565 filter, delete_begin_, delete_end_)
588 ->Remove(clear_cache_.GetCompletionCallback()); 566 ->Remove(clear_cache_.GetCompletionCallback());
589 } 567 }
590 568
591 // Tell the shader disk cache to clear. 569 // Tell the shader disk cache to clear.
592 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); 570 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache"));
593 storage_partition_remove_mask |= 571 storage_partition_remove_mask |=
594 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; 572 content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
595 } 573 }
596 574
597 ////////////////////////////////////////////////////////////////////////////// 575 //////////////////////////////////////////////////////////////////////////////
598 // Auth cache. 576 // Auth cache.
599 if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) { 577 if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) {
600 scoped_refptr<net::URLRequestContextGetter> request_context = 578 scoped_refptr<net::URLRequestContextGetter> request_context =
601 profile_->GetRequestContext(); 579 BrowserContext::GetDefaultStoragePartition(browser_context_)
580 ->GetURLRequestContext();
602 clear_http_auth_cache_.Start(); 581 clear_http_auth_cache_.Start();
603 BrowserThread::PostTaskAndReply( 582 BrowserThread::PostTaskAndReply(
604 BrowserThread::IO, FROM_HERE, 583 BrowserThread::IO, FROM_HERE,
605 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context), 584 base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context),
606 delete_begin_), 585 delete_begin_),
607 clear_http_auth_cache_.GetCompletionCallback()); 586 clear_http_auth_cache_.GetCompletionCallback());
608 } 587 }
609 588
610 ////////////////////////////////////////////////////////////////////////////// 589 //////////////////////////////////////////////////////////////////////////////
611 // Embedder data. 590 // Embedder data.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 633
655 int BrowsingDataRemover::GetLastUsedRemovalMask() { 634 int BrowsingDataRemover::GetLastUsedRemovalMask() {
656 return remove_mask_; 635 return remove_mask_;
657 } 636 }
658 637
659 int BrowsingDataRemover::GetLastUsedOriginTypeMask() { 638 int BrowsingDataRemover::GetLastUsedOriginTypeMask() {
660 return origin_type_mask_; 639 return origin_type_mask_;
661 } 640 }
662 641
663 BrowsingDataRemover::RemovalTask::RemovalTask( 642 BrowsingDataRemover::RemovalTask::RemovalTask(
664 const TimeRange& time_range, 643 const base::Time& delete_begin,
644 const base::Time& delete_end,
665 int remove_mask, 645 int remove_mask,
666 int origin_type_mask, 646 int origin_type_mask,
667 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder, 647 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder,
668 Observer* observer) 648 Observer* observer)
669 : time_range(time_range), 649 : delete_begin(delete_begin),
650 delete_end(delete_end),
670 remove_mask(remove_mask), 651 remove_mask(remove_mask),
671 origin_type_mask(origin_type_mask), 652 origin_type_mask(origin_type_mask),
672 filter_builder(std::move(filter_builder)), 653 filter_builder(std::move(filter_builder)),
673 observer(observer) {} 654 observer(observer) {}
674 655
675 BrowsingDataRemover::RemovalTask::~RemovalTask() {} 656 BrowsingDataRemover::RemovalTask::~RemovalTask() {}
676 657
677 bool BrowsingDataRemover::AllDone() { 658 bool BrowsingDataRemover::AllDone() {
678 return !synchronous_clear_operations_.is_pending() && 659 return !synchronous_clear_operations_.is_pending() &&
679 !clear_embedder_data_.is_pending() && 660 !clear_embedder_data_.is_pending() &&
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } 755 }
775 756
776 NotifyIfDone(); 757 NotifyIfDone();
777 } 758 }
778 759
779 void BrowsingDataRemover::OnFlashDataDeleted() { 760 void BrowsingDataRemover::OnFlashDataDeleted() {
780 clear_plugin_data_count_--; 761 clear_plugin_data_count_--;
781 NotifyIfDone(); 762 NotifyIfDone();
782 } 763 }
783 #endif 764 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698