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

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

Issue 1741123002: Add removal filter support for Cookies, Storage, and Content Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 9 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 (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 10
(...skipping 27 matching lines...) Expand all
38 #include "chrome/browser/search_engines/template_url_service_factory.h" 38 #include "chrome/browser/search_engines/template_url_service_factory.h"
39 #include "chrome/browser/sessions/tab_restore_service_factory.h" 39 #include "chrome/browser/sessions/tab_restore_service_factory.h"
40 #include "chrome/browser/web_data_service_factory.h" 40 #include "chrome/browser/web_data_service_factory.h"
41 #include "chrome/common/features.h" 41 #include "chrome/common/features.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
44 #include "components/autofill/core/browser/personal_data_manager.h" 44 #include "components/autofill/core/browser/personal_data_manager.h"
45 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 45 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
46 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" 46 #include "components/browsing_data/storage_partition_http_cache_data_remover.h"
47 #include "components/content_settings/core/browser/host_content_settings_map.h" 47 #include "components/content_settings/core/browser/host_content_settings_map.h"
48 #include "components/content_settings/core/common/content_settings.h"
49 #include "components/content_settings/core/common/content_settings_pattern.h"
48 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h" 50 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h"
49 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 51 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
50 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 52 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
51 #include "components/domain_reliability/service.h" 53 #include "components/domain_reliability/service.h"
52 #include "components/history/core/browser/history_service.h" 54 #include "components/history/core/browser/history_service.h"
53 #include "components/nacl/browser/nacl_browser.h" 55 #include "components/nacl/browser/nacl_browser.h"
54 #include "components/nacl/browser/pnacl_host.h" 56 #include "components/nacl/browser/pnacl_host.h"
55 #include "components/omnibox/browser/omnibox_pref_names.h" 57 #include "components/omnibox/browser/omnibox_pref_names.h"
56 #include "components/password_manager/core/browser/password_store.h" 58 #include "components/password_manager/core/browser/password_store.h"
57 #include "components/power/origin_power_map.h" 59 #include "components/power/origin_power_map.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 151 }
150 152
151 // Another convenience method to turn a callback without arguments into one that 153 // Another convenience method to turn a callback without arguments into one that
152 // accepts (and ignores) a single argument. 154 // accepts (and ignores) a single argument.
153 template <typename T> 155 template <typename T>
154 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { 156 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) {
155 return base::Bind(&IgnoreArgumentHelper<T>, callback); 157 return base::Bind(&IgnoreArgumentHelper<T>, callback);
156 } 158 }
157 159
158 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask. 160 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask.
159 bool DoesOriginMatchMask( 161 bool DoesOriginMatchMaskAndUrls(
160 int origin_type_mask, 162 int origin_type_mask,
163 const base::Callback<bool(const GURL&)>& predicate,
161 const GURL& origin, 164 const GURL& origin,
162 storage::SpecialStoragePolicy* special_storage_policy) { 165 storage::SpecialStoragePolicy* special_storage_policy) {
163 return BrowsingDataHelper::DoesOriginMatchMask( 166 return predicate.Run(origin) &&
164 origin, origin_type_mask, special_storage_policy); 167 BrowsingDataHelper::DoesOriginMatchMask(origin, origin_type_mask,
168 special_storage_policy);
169 }
170
171 bool ForwardPrimaryPatternCallback(
172 const base::Callback<bool(const ContentSettingsPattern&)> predicate,
173 const ContentSettingsPattern& primary_pattern,
174 const ContentSettingsPattern& secondary_pattern) {
175 return predicate.Run(primary_pattern);
165 } 176 }
166 177
167 void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread) { 178 void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread) {
168 DCHECK_CURRENTLY_ON(BrowserThread::IO); 179 DCHECK_CURRENTLY_ON(BrowserThread::IO);
169 180
170 io_thread->ClearHostCache(); 181 io_thread->ClearHostCache();
171 } 182 }
172 183
173 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) { 184 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) {
174 DCHECK_CURRENTLY_ON(BrowserThread::IO); 185 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 330 }
320 331
321 void BrowsingDataRemover::SetRemoving(bool is_removing) { 332 void BrowsingDataRemover::SetRemoving(bool is_removing) {
322 DCHECK_NE(is_removing_, is_removing); 333 DCHECK_NE(is_removing_, is_removing);
323 is_removing_ = is_removing; 334 is_removing_ = is_removing;
324 } 335 }
325 336
326 void BrowsingDataRemover::Remove(const TimeRange& time_range, 337 void BrowsingDataRemover::Remove(const TimeRange& time_range,
327 int remove_mask, 338 int remove_mask,
328 int origin_type_mask) { 339 int origin_type_mask) {
329 RemoveImpl(time_range, remove_mask, GURL(), origin_type_mask); 340 OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
341 RemoveImpl(time_range, remove_mask, builder, origin_type_mask);
342 }
343
344 void BrowsingDataRemover::RemoveWithFilter(
345 const TimeRange& time_range,
346 int remove_mask,
347 int origin_type_mask,
348 const OriginFilterBuilder& origin_filter) {
349 RemoveImpl(time_range, remove_mask, origin_filter, origin_type_mask);
330 } 350 }
331 351
332 void BrowsingDataRemover::RemoveImpl(const TimeRange& time_range, 352 void BrowsingDataRemover::RemoveImpl(const TimeRange& time_range,
333 int remove_mask, 353 int remove_mask,
334 const GURL& remove_url, 354 const OriginFilterBuilder& origin_filter,
335 int origin_type_mask) { 355 int origin_type_mask) {
336 DCHECK_CURRENTLY_ON(BrowserThread::UI); 356 DCHECK_CURRENTLY_ON(BrowserThread::UI);
337 357
338 // crbug.com/140910: Many places were calling this with base::Time() as 358 // crbug.com/140910: Many places were calling this with base::Time() as
339 // delete_end, even though they should've used base::Time::Max(). 359 // delete_end, even though they should've used base::Time::Max().
340 DCHECK_NE(base::Time(), time_range.end); 360 DCHECK_NE(base::Time(), time_range.end);
341 361
342 SetRemoving(true); 362 SetRemoving(true);
343 delete_begin_ = time_range.begin; 363 delete_begin_ = time_range.begin;
344 delete_end_ = time_range.end; 364 delete_end_ = time_range.end;
345 remove_mask_ = remove_mask; 365 remove_mask_ = remove_mask;
346 origin_type_mask_ = origin_type_mask; 366 origin_type_mask_ = origin_type_mask;
347 367
348 // TODO(msramek): Replace |remove_origin| with |filter| in all backends.
349 const url::Origin remove_origin(remove_url);
350 OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
351 if (!remove_url.is_empty()) {
352 // Make sure that only URLs representing origins, with no extra components,
353 // are passed to this class.
354 DCHECK_EQ(remove_url, remove_url.GetOrigin());
355 builder.SetMode(OriginFilterBuilder::WHITELIST);
356 builder.AddOrigin(url::Origin(remove_origin));
357 }
358 base::Callback<bool(const GURL& url)> same_origin_filter = 368 base::Callback<bool(const GURL& url)> same_origin_filter =
359 builder.BuildSameOriginFilter(); 369 origin_filter.BuildSameOriginFilter();
370 base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter =
371 origin_filter.BuildSameOriginContentSettingsFilter();
360 372
361 PrefService* prefs = profile_->GetPrefs(); 373 PrefService* prefs = profile_->GetPrefs();
362 bool may_delete_history = prefs->GetBoolean( 374 bool may_delete_history = prefs->GetBoolean(
363 prefs::kAllowDeletingBrowserHistory); 375 prefs::kAllowDeletingBrowserHistory);
364 376
365 // All the UI entry points into the BrowsingDataRemover should be disabled, 377 // All the UI entry points into the BrowsingDataRemover should be disabled,
366 // but this will fire if something was missed or added. 378 // but this will fire if something was missed or added.
367 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || 379 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
368 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); 380 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
369 381
(...skipping 15 matching lines...) Expand all
385 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB | 397 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB |
386 BrowsingDataHelper::PROTECTED_WEB | 398 BrowsingDataHelper::PROTECTED_WEB |
387 BrowsingDataHelper::EXTENSION), 399 BrowsingDataHelper::EXTENSION),
388 "OriginTypeMask has been updated without updating user metrics"); 400 "OriginTypeMask has been updated without updating user metrics");
389 401
390 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { 402 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
391 history::HistoryService* history_service = 403 history::HistoryService* history_service =
392 HistoryServiceFactory::GetForProfile( 404 HistoryServiceFactory::GetForProfile(
393 profile_, ServiceAccessType::EXPLICIT_ACCESS); 405 profile_, ServiceAccessType::EXPLICIT_ACCESS);
394 if (history_service) { 406 if (history_service) {
395 // Selective history deletion is currently done through HistoryUI -> 407 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
396 // HistoryBackend -> HistoryService, and that is for individual URLs,
397 // not origins. The code below is currently unused, as the only callsite
398 // supplying |remove_url| is the unittest.
399 // TODO(msramek): Make it possible to delete history per origin, not just
400 // per URL, and use that functionality here.
401 std::set<GURL> restrict_urls;
402 if (!remove_url.is_empty())
403 restrict_urls.insert(remove_url);
404 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 408 content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
405 waiting_for_clear_history_ = true; 409 waiting_for_clear_history_ = true;
406
407 history_service->ExpireLocalAndRemoteHistoryBetween( 410 history_service->ExpireLocalAndRemoteHistoryBetween(
408 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls, 411 WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(),
409 delete_begin_, delete_end_, 412 delete_begin_, delete_end_,
410 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, 413 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
411 weak_ptr_factory_.GetWeakPtr()), 414 weak_ptr_factory_.GetWeakPtr()),
412 &history_task_tracker_); 415 &history_task_tracker_);
413 416
414 #if defined(ENABLE_EXTENSIONS) 417 #if defined(ENABLE_EXTENSIONS)
415 // The extension activity contains details of which websites extensions 418 // The extension activity contains details of which websites extensions
416 // were active on. It therefore indirectly stores details of websites a 419 // were active on. It therefore indirectly stores details of websites a
417 // user has visited so best clean from here as well. 420 // user has visited so best clean from here as well.
418 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(restrict_urls); 421 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(
422 std::set<GURL>());
419 #endif 423 #endif
420 } 424 }
421 425
422 #if defined(ENABLE_EXTENSIONS) 426 #if defined(ENABLE_EXTENSIONS)
423 // Clear launch times as they are a form of history. 427 // Clear launch times as they are a form of history.
424 extensions::ExtensionPrefs* extension_prefs = 428 extensions::ExtensionPrefs* extension_prefs =
425 extensions::ExtensionPrefs::Get(profile_); 429 extensions::ExtensionPrefs::Get(profile_);
426 extension_prefs->ClearLastLaunchTimes(); 430 extension_prefs->ClearLastLaunchTimes();
427 #endif 431 #endif
428 432
429 // The power consumption history by origin contains details of websites 433 // The power consumption history by origin contains details of websites
430 // that were visited. 434 // that were visited.
435 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
431 power::OriginPowerMap* origin_power_map = 436 power::OriginPowerMap* origin_power_map =
432 power::OriginPowerMapFactory::GetForBrowserContext(profile_); 437 power::OriginPowerMapFactory::GetForBrowserContext(profile_);
433 if (origin_power_map) 438 if (origin_power_map)
434 origin_power_map->ClearOriginMap(); 439 origin_power_map->ClearOriginMap();
435 440
436 // Need to clear the host cache and accumulated speculative data, as it also 441 // Need to clear the host cache and accumulated speculative data, as it also
437 // reveals some history: we have no mechanism to track when these items were 442 // reveals some history: we have no mechanism to track when these items were
438 // created, so we'll clear them all. Better safe than sorry. 443 // created, so we'll clear them all. Better safe than sorry.
439 if (g_browser_process->io_thread()) { 444 if (g_browser_process->io_thread()) {
445 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
440 waiting_for_clear_hostname_resolution_cache_ = true; 446 waiting_for_clear_hostname_resolution_cache_ = true;
441 BrowserThread::PostTaskAndReply( 447 BrowserThread::PostTaskAndReply(
442 BrowserThread::IO, FROM_HERE, 448 BrowserThread::IO, FROM_HERE,
443 base::Bind(&ClearHostnameResolutionCacheOnIOThread, 449 base::Bind(&ClearHostnameResolutionCacheOnIOThread,
444 g_browser_process->io_thread()), 450 g_browser_process->io_thread()),
445 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache, 451 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache,
446 weak_ptr_factory_.GetWeakPtr())); 452 weak_ptr_factory_.GetWeakPtr()));
447 } 453 }
448 if (profile_->GetNetworkPredictor()) { 454 if (profile_->GetNetworkPredictor()) {
455 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
449 waiting_for_clear_network_predictor_ = true; 456 waiting_for_clear_network_predictor_ = true;
450 BrowserThread::PostTaskAndReply( 457 BrowserThread::PostTaskAndReply(
451 BrowserThread::IO, FROM_HERE, 458 BrowserThread::IO, FROM_HERE,
452 base::Bind(&ClearNetworkPredictorOnIOThread, 459 base::Bind(&ClearNetworkPredictorOnIOThread,
453 profile_->GetNetworkPredictor()), 460 profile_->GetNetworkPredictor()),
454 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor, 461 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor,
455 weak_ptr_factory_.GetWeakPtr())); 462 weak_ptr_factory_.GetWeakPtr()));
456 } 463 }
457 464
458 // As part of history deletion we also delete the auto-generated keywords. 465 // As part of history deletion we also delete the auto-generated keywords.
459 TemplateURLService* keywords_model = 466 TemplateURLService* keywords_model =
460 TemplateURLServiceFactory::GetForProfile(profile_); 467 TemplateURLServiceFactory::GetForProfile(profile_);
468
461 if (keywords_model && !keywords_model->loaded()) { 469 if (keywords_model && !keywords_model->loaded()) {
462 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( 470 template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
463 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded, 471 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded,
464 weak_ptr_factory_.GetWeakPtr())); 472 weak_ptr_factory_.GetWeakPtr()));
465 keywords_model->Load(); 473 keywords_model->Load();
466 waiting_for_clear_keyword_data_ = true; 474 waiting_for_clear_keyword_data_ = true;
467 } else if (keywords_model) { 475 } else if (keywords_model) {
468 keywords_model->RemoveAutoGeneratedForOriginBetween( 476 keywords_model->RemoveAutoGeneratedForOriginBetween(GURL(), delete_begin_,
469 remove_url, delete_begin_, delete_end_); 477 delete_end_);
470 } 478 }
471 479
472 // The PrerenderManager keeps history of prerendered pages, so clear that. 480 // The PrerenderManager keeps history of prerendered pages, so clear that.
473 // It also may have a prerendered page. If so, the page could be 481 // It also may have a prerendered page. If so, the page could be
474 // considered to have a small amount of historical information, so delete 482 // considered to have a small amount of historical information, so delete
475 // it, too. 483 // it, too.
476 prerender::PrerenderManager* prerender_manager = 484 prerender::PrerenderManager* prerender_manager =
477 prerender::PrerenderManagerFactory::GetForProfile(profile_); 485 prerender::PrerenderManagerFactory::GetForProfile(profile_);
478 if (prerender_manager) { 486 if (prerender_manager) {
487 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
479 prerender_manager->ClearData( 488 prerender_manager->ClearData(
480 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | 489 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
481 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); 490 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
482 } 491 }
483 492
484 // If the caller is removing history for all hosts, then clear ancillary 493 // If the caller is removing history for all hosts, then clear ancillary
485 // historical information. 494 // historical information.
486 if (remove_url.is_empty()) { 495 if (origin_filter.IsEmptyBlacklist()) {
487 // We also delete the list of recently closed tabs. Since these expire, 496 // We also delete the list of recently closed tabs. Since these expire,
488 // they can't be more than a day old, so we can simply clear them all. 497 // they can't be more than a day old, so we can simply clear them all.
489 sessions::TabRestoreService* tab_service = 498 sessions::TabRestoreService* tab_service =
490 TabRestoreServiceFactory::GetForProfile(profile_); 499 TabRestoreServiceFactory::GetForProfile(profile_);
491 if (tab_service) { 500 if (tab_service) {
492 tab_service->ClearEntries(); 501 tab_service->ClearEntries();
493 tab_service->DeleteLastSession(); 502 tab_service->DeleteLastSession();
494 } 503 }
495 504
496 #if defined(ENABLE_SESSION_SERVICE) 505 #if defined(ENABLE_SESSION_SERVICE)
497 // We also delete the last session when we delete the history. 506 // We also delete the last session when we delete the history.
498 SessionService* session_service = 507 SessionService* session_service =
499 SessionServiceFactory::GetForProfile(profile_); 508 SessionServiceFactory::GetForProfile(profile_);
500 if (session_service) 509 if (session_service)
501 session_service->DeleteLastSession(); 510 session_service->DeleteLastSession();
502 #endif 511 #endif
503 } 512 }
504 513
505 // The saved Autofill profiles and credit cards can include the origin from 514 // The saved Autofill profiles and credit cards can include the origin from
506 // which these profiles and credit cards were learned. These are a form of 515 // which these profiles and credit cards were learned. These are a form of
507 // history, so clear them as well. 516 // history, so clear them as well.
517 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
508 scoped_refptr<autofill::AutofillWebDataService> web_data_service = 518 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
509 WebDataServiceFactory::GetAutofillWebDataForProfile( 519 WebDataServiceFactory::GetAutofillWebDataForProfile(
510 profile_, ServiceAccessType::EXPLICIT_ACCESS); 520 profile_, ServiceAccessType::EXPLICIT_ACCESS);
511 if (web_data_service.get()) { 521 if (web_data_service.get()) {
512 waiting_for_clear_autofill_origin_urls_ = true; 522 waiting_for_clear_autofill_origin_urls_ = true;
513 web_data_service->RemoveOriginURLsModifiedBetween( 523 web_data_service->RemoveOriginURLsModifiedBetween(
514 delete_begin_, delete_end_); 524 delete_begin_, delete_end_);
515 // The above calls are done on the UI thread but do their work on the DB 525 // The above calls are done on the UI thread but do their work on the DB
516 // thread. So wait for it. 526 // thread. So wait for it.
517 BrowserThread::PostTaskAndReply( 527 BrowserThread::PostTaskAndReply(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 606 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
597 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); 607 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
598 608
599 storage_partition_remove_mask |= 609 storage_partition_remove_mask |=
600 content::StoragePartition::REMOVE_DATA_MASK_COOKIES; 610 content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
601 611
602 // Clear the safebrowsing cookies only if time period is for "all time". It 612 // Clear the safebrowsing cookies only if time period is for "all time". It
603 // doesn't make sense to apply the time period of deleting in the last X 613 // doesn't make sense to apply the time period of deleting in the last X
604 // hours/days to the safebrowsing cookies since they aren't the result of 614 // hours/days to the safebrowsing cookies since they aren't the result of
605 // any user action. 615 // any user action.
616 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
606 if (delete_begin_ == base::Time()) { 617 if (delete_begin_ == base::Time()) {
607 safe_browsing::SafeBrowsingService* sb_service = 618 safe_browsing::SafeBrowsingService* sb_service =
608 g_browser_process->safe_browsing_service(); 619 g_browser_process->safe_browsing_service();
609 if (sb_service) { 620 if (sb_service) {
610 scoped_refptr<net::URLRequestContextGetter> sb_context = 621 scoped_refptr<net::URLRequestContextGetter> sb_context =
611 sb_service->url_request_context(); 622 sb_service->url_request_context();
612 ++waiting_for_clear_cookies_count_; 623 ++waiting_for_clear_cookies_count_;
624 // TODONOW
613 BrowserThread::PostTask( 625 BrowserThread::PostTask(
614 BrowserThread::IO, FROM_HERE, 626 BrowserThread::IO, FROM_HERE,
615 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_, 627 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_,
616 std::move(sb_context), 628 std::move(sb_context),
617 UIThreadTrampoline( 629 UIThreadTrampoline(
618 base::Bind(&BrowsingDataRemover::OnClearedCookies, 630 base::Bind(&BrowsingDataRemover::OnClearedCookies,
619 weak_ptr_factory_.GetWeakPtr())))); 631 weak_ptr_factory_.GetWeakPtr()))));
620 } 632 }
621 } 633 }
622 634
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 plugin_data_remover_->StartRemoving(delete_begin_); 702 plugin_data_remover_->StartRemoving(delete_begin_);
691 703
692 base::WaitableEventWatcher::EventCallback watcher_callback = 704 base::WaitableEventWatcher::EventCallback watcher_callback =
693 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, 705 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
694 weak_ptr_factory_.GetWeakPtr()); 706 weak_ptr_factory_.GetWeakPtr());
695 watcher_.StartWatching(event, watcher_callback); 707 watcher_.StartWatching(event, watcher_callback);
696 } 708 }
697 #endif 709 #endif
698 710
699 if (remove_mask & REMOVE_SITE_USAGE_DATA) { 711 if (remove_mask & REMOVE_SITE_USAGE_DATA) {
700 HostContentSettingsMapFactory::GetForProfile(profile_) 712 ClearSettingsForOneTypeWithPredicate(
701 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT); 713 HostContentSettingsMapFactory::GetForProfile(profile_),
714 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
715 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
702 } 716 }
703 717
704 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) { 718 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) {
705 HostContentSettingsMapFactory::GetForProfile(profile_) 719 ClearSettingsForOneTypeWithPredicate(
706 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_APP_BANNER); 720 HostContentSettingsMapFactory::GetForProfile(profile_),
721 CONTENT_SETTINGS_TYPE_APP_BANNER,
722 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
707 } 723 }
708 724
725 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
709 if (remove_mask & REMOVE_PASSWORDS) { 726 if (remove_mask & REMOVE_PASSWORDS) {
710 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); 727 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
711 password_manager::PasswordStore* password_store = 728 password_manager::PasswordStore* password_store =
712 PasswordStoreFactory::GetForProfile( 729 PasswordStoreFactory::GetForProfile(
713 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); 730 profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
714 731
715 if (password_store) { 732 if (password_store) {
716 waiting_for_clear_passwords_ = true; 733 waiting_for_clear_passwords_ = true;
717 auto on_cleared_passwords = 734 auto on_cleared_passwords =
718 base::Bind(&BrowsingDataRemover::OnClearedPasswords, 735 base::Bind(&BrowsingDataRemover::OnClearedPasswords,
719 weak_ptr_factory_.GetWeakPtr()); 736 weak_ptr_factory_.GetWeakPtr());
720 if (remove_url.is_empty()) { 737 password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_,
721 password_store->RemoveLoginsCreatedBetween(delete_begin_, delete_end_, 738 on_cleared_passwords);
722 on_cleared_passwords);
723 } else {
724 password_store->RemoveLoginsByOriginAndTime(
725 remove_origin, delete_begin_, delete_end_, on_cleared_passwords);
726 }
727 } 739 }
728 } 740 }
729 741
730 if (remove_mask & REMOVE_HISTORY) { 742 if (remove_mask & REMOVE_HISTORY) {
731 password_manager::PasswordStore* password_store = 743 password_manager::PasswordStore* password_store =
732 PasswordStoreFactory::GetForProfile( 744 PasswordStoreFactory::GetForProfile(
733 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); 745 profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
734 746
735 if (password_store) { 747 if (password_store) {
736 waiting_for_clear_passwords_stats_ = true; 748 waiting_for_clear_passwords_stats_ = true;
737 password_store->RemoveStatisticsCreatedBetween( 749 password_store->RemoveStatisticsCreatedBetween(
738 delete_begin_, delete_end_, 750 delete_begin_, delete_end_,
739 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats, 751 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats,
740 weak_ptr_factory_.GetWeakPtr())); 752 weak_ptr_factory_.GetWeakPtr()));
741 } 753 }
742 } 754 }
743 755
756 // TODO(dmurph): Support all backends with filter (crbug.com/589586).
744 if (remove_mask & REMOVE_FORM_DATA) { 757 if (remove_mask & REMOVE_FORM_DATA) {
745 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); 758 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
746 scoped_refptr<autofill::AutofillWebDataService> web_data_service = 759 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
747 WebDataServiceFactory::GetAutofillWebDataForProfile( 760 WebDataServiceFactory::GetAutofillWebDataForProfile(
748 profile_, ServiceAccessType::EXPLICIT_ACCESS); 761 profile_, ServiceAccessType::EXPLICIT_ACCESS);
749 762
750 if (web_data_service.get()) { 763 if (web_data_service.get()) {
751 waiting_for_clear_form_ = true; 764 waiting_for_clear_form_ = true;
752 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, 765 web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
753 delete_end_); 766 delete_end_);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 if (delete_begin_ == base::Time() || 851 if (delete_begin_ == base::Time() ||
839 origin_type_mask_ & 852 origin_type_mask_ &
840 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { 853 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
841 // If we're deleting since the beginning of time, or we're removing 854 // If we're deleting since the beginning of time, or we're removing
842 // protected origins, then remove persistent quota data. 855 // protected origins, then remove persistent quota data.
843 quota_storage_remove_mask |= 856 quota_storage_remove_mask |=
844 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 857 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
845 } 858 }
846 859
847 storage_partition->ClearData( 860 storage_partition->ClearData(
848 storage_partition_remove_mask, quota_storage_remove_mask, remove_url, 861 storage_partition_remove_mask, quota_storage_remove_mask, GURL(),
849 base::Bind(&DoesOriginMatchMask, origin_type_mask_), delete_begin_, 862 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_,
850 delete_end_, 863 same_origin_filter),
864 delete_begin_, delete_end_,
851 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData, 865 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
852 weak_ptr_factory_.GetWeakPtr())); 866 weak_ptr_factory_.GetWeakPtr()));
853 } 867 }
854 868
855 #if defined(ENABLE_PLUGINS) 869 #if defined(ENABLE_PLUGINS)
856 if (remove_mask & REMOVE_CONTENT_LICENSES) { 870 if (remove_mask & REMOVE_CONTENT_LICENSES) {
857 content::RecordAction( 871 content::RecordAction(
858 UserMetricsAction("ClearBrowsingData_ContentLicenses")); 872 UserMetricsAction("ClearBrowsingData_ContentLicenses"));
859 873
860 waiting_for_clear_content_licenses_ = true; 874 waiting_for_clear_content_licenses_ = true;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 waiting_for_clear_webapp_data_ = true; 934 waiting_for_clear_webapp_data_ = true;
921 WebappRegistry::UnregisterWebapps( 935 WebappRegistry::UnregisterWebapps(
922 base::Bind(&BrowsingDataRemover::OnClearedWebappData, 936 base::Bind(&BrowsingDataRemover::OnClearedWebappData,
923 weak_ptr_factory_.GetWeakPtr())); 937 weak_ptr_factory_.GetWeakPtr()));
924 } 938 }
925 939
926 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) && 940 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) &&
927 offline_pages::IsOfflinePagesEnabled()) { 941 offline_pages::IsOfflinePagesEnabled()) {
928 waiting_for_clear_offline_page_data_ = true; 942 waiting_for_clear_offline_page_data_ = true;
929 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_) 943 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_)
930 ->ClearAll(base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData, 944 ->ClearWithURLPredicate(
931 weak_ptr_factory_.GetWeakPtr())); 945 same_origin_filter,
946 base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData,
947 weak_ptr_factory_.GetWeakPtr()));
932 } 948 }
933 #endif 949 #endif
934 950
935 // Record the combined deletion of cookies and cache. 951 // Record the combined deletion of cookies and cache.
936 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; 952 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE;
937 if (remove_mask & REMOVE_COOKIES && 953 if (remove_mask & REMOVE_COOKIES &&
938 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 954 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
939 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE 955 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE
940 : ONLY_COOKIES; 956 : ONLY_COOKIES;
941 } else if (remove_mask & REMOVE_CACHE) { 957 } else if (remove_mask & REMOVE_CACHE) {
(...skipping 11 matching lines...) Expand all
953 969
954 void BrowsingDataRemover::RemoveObserver(Observer* observer) { 970 void BrowsingDataRemover::RemoveObserver(Observer* observer) {
955 observer_list_.RemoveObserver(observer); 971 observer_list_.RemoveObserver(observer);
956 } 972 }
957 973
958 void BrowsingDataRemover::OverrideStoragePartitionForTesting( 974 void BrowsingDataRemover::OverrideStoragePartitionForTesting(
959 content::StoragePartition* storage_partition) { 975 content::StoragePartition* storage_partition) {
960 storage_partition_for_testing_ = storage_partition; 976 storage_partition_for_testing_ = storage_partition;
961 } 977 }
962 978
979 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate(
980 HostContentSettingsMap* content_settings_map,
981 ContentSettingsType content_type,
982 const base::Callback<bool(const ContentSettingsPattern& primary_pattern,
983 const ContentSettingsPattern& secondary_pattern)>&
984 predicate) {
985 ContentSettingsForOneType settings;
986 content_settings_map->GetSettingsForOneType(content_type, std::string(),
987 &settings);
988 for (const ContentSettingPatternSource& setting : settings) {
989 if (predicate.Run(setting.primary_pattern, setting.secondary_pattern)) {
990 content_settings_map->SetWebsiteSettingCustomScope(
991 setting.primary_pattern, setting.secondary_pattern, content_type,
992 std::string(), nullptr);
993 }
994 }
995 }
996
963 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( 997 base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
964 TimePeriod time_period) { 998 TimePeriod time_period) {
965 base::TimeDelta diff; 999 base::TimeDelta diff;
966 base::Time delete_begin_time = base::Time::Now(); 1000 base::Time delete_begin_time = base::Time::Now();
967 switch (time_period) { 1001 switch (time_period) {
968 case LAST_HOUR: 1002 case LAST_HOUR:
969 diff = base::TimeDelta::FromHours(1); 1003 diff = base::TimeDelta::FromHours(1);
970 break; 1004 break;
971 case LAST_DAY: 1005 case LAST_DAY:
972 diff = base::TimeDelta::FromHours(24); 1006 diff = base::TimeDelta::FromHours(24);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 waiting_for_clear_domain_reliability_monitor_ = false; 1244 waiting_for_clear_domain_reliability_monitor_ = false;
1211 NotifyIfDone(); 1245 NotifyIfDone();
1212 } 1246 }
1213 1247
1214 // static 1248 // static
1215 BrowsingDataRemover::CallbackSubscription 1249 BrowsingDataRemover::CallbackSubscription
1216 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( 1250 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
1217 const BrowsingDataRemover::Callback& callback) { 1251 const BrowsingDataRemover::Callback& callback) {
1218 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); 1252 return GetOnBrowsingDataRemovedCallbacks()->Add(callback);
1219 } 1253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698