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

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: Added SafeBrowsing cookie support 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 152 }
151 153
152 // Another convenience method to turn a callback without arguments into one that 154 // Another convenience method to turn a callback without arguments into one that
153 // accepts (and ignores) a single argument. 155 // accepts (and ignores) a single argument.
154 template <typename T> 156 template <typename T>
155 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { 157 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) {
156 return base::Bind(&IgnoreArgumentHelper<T>, callback); 158 return base::Bind(&IgnoreArgumentHelper<T>, callback);
157 } 159 }
158 160
159 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask. 161 // Helper to create callback for BrowsingDataRemover::DoesOriginMatchMask.
160 bool DoesOriginMatchMask( 162 bool DoesOriginMatchMaskAndUrls(
161 int origin_type_mask, 163 int origin_type_mask,
164 const base::Callback<bool(const GURL&)>& predicate,
162 const GURL& origin, 165 const GURL& origin,
163 storage::SpecialStoragePolicy* special_storage_policy) { 166 storage::SpecialStoragePolicy* special_storage_policy) {
164 return BrowsingDataHelper::DoesOriginMatchMask( 167 return predicate.Run(origin) &&
165 origin, origin_type_mask, special_storage_policy); 168 BrowsingDataHelper::DoesOriginMatchMask(origin, origin_type_mask,
169 special_storage_policy);
170 }
171
172 bool ForwardPrimaryPatternCallback(
173 const base::Callback<bool(const ContentSettingsPattern&)> predicate,
174 const ContentSettingsPattern& primary_pattern,
175 const ContentSettingsPattern& secondary_pattern) {
176 return predicate.Run(primary_pattern);
166 } 177 }
167 178
168 void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread) { 179 void ClearHostnameResolutionCacheOnIOThread(IOThread* io_thread) {
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); 180 DCHECK_CURRENTLY_ON(BrowserThread::IO);
170 181
171 io_thread->ClearHostCache(); 182 io_thread->ClearHostCache();
172 } 183 }
173 184
174 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) { 185 void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) {
175 DCHECK_CURRENTLY_ON(BrowserThread::IO); 186 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 24 matching lines...) Expand all
200 base::Time delete_end, 211 base::Time delete_end,
201 net::URLRequestContextGetter* rq_context, 212 net::URLRequestContextGetter* rq_context,
202 const base::Closure& callback) { 213 const base::Closure& callback) {
203 DCHECK_CURRENTLY_ON(BrowserThread::IO); 214 DCHECK_CURRENTLY_ON(BrowserThread::IO);
204 net::CookieStore* cookie_store = 215 net::CookieStore* cookie_store =
205 rq_context->GetURLRequestContext()->cookie_store(); 216 rq_context->GetURLRequestContext()->cookie_store();
206 cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, 217 cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
207 IgnoreArgument<int>(callback)); 218 IgnoreArgument<int>(callback));
208 } 219 }
209 220
221 void ClearCookiesWithPredicateOnIOThread(base::Time delete_begin,
222 base::Time delete_end,
223 net::CookieStore::ClearCookiesPredicate predicate,
224 net::URLRequestContextGetter* rq_context,
225 const base::Closure& callback) {
226 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 net::CookieStore* cookie_store =
228 rq_context->GetURLRequestContext()->cookie_store();
229 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
230 delete_begin, delete_end, predicate, IgnoreArgument<int>(callback));
231 }
232
210 void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context, 233 void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context,
211 const base::Closure& callback) { 234 const base::Closure& callback) {
212 DCHECK_CURRENTLY_ON(BrowserThread::IO); 235 DCHECK_CURRENTLY_ON(BrowserThread::IO);
213 236
214 // Need to close open SSL connections which may be using the channel ids we 237 // Need to close open SSL connections which may be using the channel ids we
215 // are deleting. 238 // are deleting.
216 // TODO(mattm): http://crbug.com/166069 Make the server bound cert 239 // TODO(mattm): http://crbug.com/166069 Make the server bound cert
217 // service/store have observers that can notify relevant things directly. 240 // service/store have observers that can notify relevant things directly.
218 rq_context->GetURLRequestContext() 241 rq_context->GetURLRequestContext()
219 ->ssl_config_service() 242 ->ssl_config_service()
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 343 }
321 344
322 void BrowsingDataRemover::SetRemoving(bool is_removing) { 345 void BrowsingDataRemover::SetRemoving(bool is_removing) {
323 DCHECK_NE(is_removing_, is_removing); 346 DCHECK_NE(is_removing_, is_removing);
324 is_removing_ = is_removing; 347 is_removing_ = is_removing;
325 } 348 }
326 349
327 void BrowsingDataRemover::Remove(const TimeRange& time_range, 350 void BrowsingDataRemover::Remove(const TimeRange& time_range,
328 int remove_mask, 351 int remove_mask,
329 int origin_type_mask) { 352 int origin_type_mask) {
330 RemoveImpl(time_range, remove_mask, GURL(), origin_type_mask); 353 OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
354 RemoveImpl(time_range, remove_mask, builder, origin_type_mask);
355 }
356
357 void BrowsingDataRemover::RemoveWithFilter(
358 const TimeRange& time_range,
359 int remove_mask,
360 int origin_type_mask,
361 const OriginFilterBuilder& origin_filter) {
362 RemoveImpl(time_range, remove_mask, origin_filter, origin_type_mask);
331 } 363 }
332 364
333 void BrowsingDataRemover::RemoveImpl(const TimeRange& time_range, 365 void BrowsingDataRemover::RemoveImpl(const TimeRange& time_range,
334 int remove_mask, 366 int remove_mask,
335 const GURL& remove_url, 367 const OriginFilterBuilder& origin_filter,
336 int origin_type_mask) { 368 int origin_type_mask) {
337 DCHECK_CURRENTLY_ON(BrowserThread::UI); 369 DCHECK_CURRENTLY_ON(BrowserThread::UI);
338 370
339 // crbug.com/140910: Many places were calling this with base::Time() as 371 // crbug.com/140910: Many places were calling this with base::Time() as
340 // delete_end, even though they should've used base::Time::Max(). 372 // delete_end, even though they should've used base::Time::Max().
341 DCHECK_NE(base::Time(), time_range.end); 373 DCHECK_NE(base::Time(), time_range.end);
342 374
343 SetRemoving(true); 375 SetRemoving(true);
344 delete_begin_ = time_range.begin; 376 delete_begin_ = time_range.begin;
345 delete_end_ = time_range.end; 377 delete_end_ = time_range.end;
346 remove_mask_ = remove_mask; 378 remove_mask_ = remove_mask;
347 origin_type_mask_ = origin_type_mask; 379 origin_type_mask_ = origin_type_mask;
348 380
349 // TODO(msramek): Replace |remove_origin| with |filter| in all backends.
350 const url::Origin remove_origin(remove_url);
351 OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
352 if (!remove_url.is_empty()) {
353 // Make sure that only URLs representing origins, with no extra components,
354 // are passed to this class.
355 DCHECK_EQ(remove_url, remove_url.GetOrigin());
356 builder.SetMode(OriginFilterBuilder::WHITELIST);
357 builder.AddOrigin(url::Origin(remove_origin));
358 }
359 base::Callback<bool(const GURL& url)> same_origin_filter = 381 base::Callback<bool(const GURL& url)> same_origin_filter =
360 builder.BuildSameOriginFilter(); 382 origin_filter.BuildSameOriginFilter();
383 base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter =
384 origin_filter.BuildSameOriginContentSettingsFilter();
361 385
362 PrefService* prefs = profile_->GetPrefs(); 386 PrefService* prefs = profile_->GetPrefs();
363 bool may_delete_history = prefs->GetBoolean( 387 bool may_delete_history = prefs->GetBoolean(
364 prefs::kAllowDeletingBrowserHistory); 388 prefs::kAllowDeletingBrowserHistory);
365 389
366 // All the UI entry points into the BrowsingDataRemover should be disabled, 390 // All the UI entry points into the BrowsingDataRemover should be disabled,
367 // but this will fire if something was missed or added. 391 // but this will fire if something was missed or added.
368 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || 392 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
369 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); 393 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
370 394
(...skipping 15 matching lines...) Expand all
386 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB | 410 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB |
387 BrowsingDataHelper::PROTECTED_WEB | 411 BrowsingDataHelper::PROTECTED_WEB |
388 BrowsingDataHelper::EXTENSION), 412 BrowsingDataHelper::EXTENSION),
389 "OriginTypeMask has been updated without updating user metrics"); 413 "OriginTypeMask has been updated without updating user metrics");
390 414
391 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { 415 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
392 history::HistoryService* history_service = 416 history::HistoryService* history_service =
393 HistoryServiceFactory::GetForProfile( 417 HistoryServiceFactory::GetForProfile(
394 profile_, ServiceAccessType::EXPLICIT_ACCESS); 418 profile_, ServiceAccessType::EXPLICIT_ACCESS);
395 if (history_service) { 419 if (history_service) {
396 // Selective history deletion is currently done through HistoryUI -> 420 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
397 // HistoryBackend -> HistoryService, and that is for individual URLs,
398 // not origins. The code below is currently unused, as the only callsite
399 // supplying |remove_url| is the unittest.
400 // TODO(msramek): Make it possible to delete history per origin, not just
401 // per URL, and use that functionality here.
402 std::set<GURL> restrict_urls;
403 if (!remove_url.is_empty())
404 restrict_urls.insert(remove_url);
405 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 421 content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
406 waiting_for_clear_history_ = true; 422 waiting_for_clear_history_ = true;
407
408 history_service->ExpireLocalAndRemoteHistoryBetween( 423 history_service->ExpireLocalAndRemoteHistoryBetween(
409 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls, 424 WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(),
410 delete_begin_, delete_end_, 425 delete_begin_, delete_end_,
411 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, 426 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
412 weak_ptr_factory_.GetWeakPtr()), 427 weak_ptr_factory_.GetWeakPtr()),
413 &history_task_tracker_); 428 &history_task_tracker_);
414 429
415 #if defined(ENABLE_EXTENSIONS) 430 #if defined(ENABLE_EXTENSIONS)
416 // The extension activity contains details of which websites extensions 431 // The extension activity contains details of which websites extensions
417 // were active on. It therefore indirectly stores details of websites a 432 // were active on. It therefore indirectly stores details of websites a
418 // user has visited so best clean from here as well. 433 // user has visited so best clean from here as well.
419 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(restrict_urls); 434 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(
435 std::set<GURL>());
420 #endif 436 #endif
421 } 437 }
422 438
423 #if defined(ENABLE_EXTENSIONS) 439 #if defined(ENABLE_EXTENSIONS)
424 // Clear launch times as they are a form of history. 440 // Clear launch times as they are a form of history.
425 extensions::ExtensionPrefs* extension_prefs = 441 extensions::ExtensionPrefs* extension_prefs =
426 extensions::ExtensionPrefs::Get(profile_); 442 extensions::ExtensionPrefs::Get(profile_);
427 extension_prefs->ClearLastLaunchTimes(); 443 extension_prefs->ClearLastLaunchTimes();
428 #endif 444 #endif
429 445
430 // The power consumption history by origin contains details of websites 446 // The power consumption history by origin contains details of websites
431 // that were visited. 447 // that were visited.
448 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
432 power::OriginPowerMap* origin_power_map = 449 power::OriginPowerMap* origin_power_map =
433 power::OriginPowerMapFactory::GetForBrowserContext(profile_); 450 power::OriginPowerMapFactory::GetForBrowserContext(profile_);
434 if (origin_power_map) 451 if (origin_power_map)
435 origin_power_map->ClearOriginMap(); 452 origin_power_map->ClearOriginMap();
436 453
437 // Need to clear the host cache and accumulated speculative data, as it also 454 // Need to clear the host cache and accumulated speculative data, as it also
438 // reveals some history: we have no mechanism to track when these items were 455 // reveals some history: we have no mechanism to track when these items were
439 // created, so we'll clear them all. Better safe than sorry. 456 // created, so we'll clear them all. Better safe than sorry.
440 if (g_browser_process->io_thread()) { 457 if (g_browser_process->io_thread()) {
458 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
441 waiting_for_clear_hostname_resolution_cache_ = true; 459 waiting_for_clear_hostname_resolution_cache_ = true;
442 BrowserThread::PostTaskAndReply( 460 BrowserThread::PostTaskAndReply(
443 BrowserThread::IO, FROM_HERE, 461 BrowserThread::IO, FROM_HERE,
444 base::Bind(&ClearHostnameResolutionCacheOnIOThread, 462 base::Bind(&ClearHostnameResolutionCacheOnIOThread,
445 g_browser_process->io_thread()), 463 g_browser_process->io_thread()),
446 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache, 464 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache,
447 weak_ptr_factory_.GetWeakPtr())); 465 weak_ptr_factory_.GetWeakPtr()));
448 } 466 }
449 if (profile_->GetNetworkPredictor()) { 467 if (profile_->GetNetworkPredictor()) {
468 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
450 waiting_for_clear_network_predictor_ = true; 469 waiting_for_clear_network_predictor_ = true;
451 BrowserThread::PostTaskAndReply( 470 BrowserThread::PostTaskAndReply(
452 BrowserThread::IO, FROM_HERE, 471 BrowserThread::IO, FROM_HERE,
453 base::Bind(&ClearNetworkPredictorOnIOThread, 472 base::Bind(&ClearNetworkPredictorOnIOThread,
454 profile_->GetNetworkPredictor()), 473 profile_->GetNetworkPredictor()),
455 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor, 474 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor,
456 weak_ptr_factory_.GetWeakPtr())); 475 weak_ptr_factory_.GetWeakPtr()));
457 } 476 }
458 477
459 // As part of history deletion we also delete the auto-generated keywords. 478 // As part of history deletion we also delete the auto-generated keywords.
460 TemplateURLService* keywords_model = 479 TemplateURLService* keywords_model =
461 TemplateURLServiceFactory::GetForProfile(profile_); 480 TemplateURLServiceFactory::GetForProfile(profile_);
481
462 if (keywords_model && !keywords_model->loaded()) { 482 if (keywords_model && !keywords_model->loaded()) {
463 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( 483 template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
464 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded, 484 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded,
465 weak_ptr_factory_.GetWeakPtr())); 485 weak_ptr_factory_.GetWeakPtr()));
466 keywords_model->Load(); 486 keywords_model->Load();
467 waiting_for_clear_keyword_data_ = true; 487 waiting_for_clear_keyword_data_ = true;
468 } else if (keywords_model) { 488 } else if (keywords_model) {
469 keywords_model->RemoveAutoGeneratedForOriginBetween( 489 keywords_model->RemoveAutoGeneratedForOriginBetween(GURL(), delete_begin_,
470 remove_url, delete_begin_, delete_end_); 490 delete_end_);
471 } 491 }
472 492
473 // The PrerenderManager keeps history of prerendered pages, so clear that. 493 // The PrerenderManager keeps history of prerendered pages, so clear that.
474 // It also may have a prerendered page. If so, the page could be 494 // It also may have a prerendered page. If so, the page could be
475 // considered to have a small amount of historical information, so delete 495 // considered to have a small amount of historical information, so delete
476 // it, too. 496 // it, too.
477 prerender::PrerenderManager* prerender_manager = 497 prerender::PrerenderManager* prerender_manager =
478 prerender::PrerenderManagerFactory::GetForProfile(profile_); 498 prerender::PrerenderManagerFactory::GetForProfile(profile_);
479 if (prerender_manager) { 499 if (prerender_manager) {
500 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
480 prerender_manager->ClearData( 501 prerender_manager->ClearData(
481 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | 502 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
482 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); 503 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
483 } 504 }
484 505
485 // If the caller is removing history for all hosts, then clear ancillary 506 // If the caller is removing history for all hosts, then clear ancillary
486 // historical information. 507 // historical information.
487 if (remove_url.is_empty()) { 508 if (origin_filter.IsEmptyBlacklist()) {
488 // We also delete the list of recently closed tabs. Since these expire, 509 // We also delete the list of recently closed tabs. Since these expire,
489 // they can't be more than a day old, so we can simply clear them all. 510 // they can't be more than a day old, so we can simply clear them all.
490 sessions::TabRestoreService* tab_service = 511 sessions::TabRestoreService* tab_service =
491 TabRestoreServiceFactory::GetForProfile(profile_); 512 TabRestoreServiceFactory::GetForProfile(profile_);
492 if (tab_service) { 513 if (tab_service) {
493 tab_service->ClearEntries(); 514 tab_service->ClearEntries();
494 tab_service->DeleteLastSession(); 515 tab_service->DeleteLastSession();
495 } 516 }
496 517
497 #if defined(ENABLE_SESSION_SERVICE) 518 #if defined(ENABLE_SESSION_SERVICE)
498 // We also delete the last session when we delete the history. 519 // We also delete the last session when we delete the history.
499 SessionService* session_service = 520 SessionService* session_service =
500 SessionServiceFactory::GetForProfile(profile_); 521 SessionServiceFactory::GetForProfile(profile_);
501 if (session_service) 522 if (session_service)
502 session_service->DeleteLastSession(); 523 session_service->DeleteLastSession();
503 #endif 524 #endif
504 } 525 }
505 526
506 // The saved Autofill profiles and credit cards can include the origin from 527 // The saved Autofill profiles and credit cards can include the origin from
507 // which these profiles and credit cards were learned. These are a form of 528 // which these profiles and credit cards were learned. These are a form of
508 // history, so clear them as well. 529 // history, so clear them as well.
530 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
509 scoped_refptr<autofill::AutofillWebDataService> web_data_service = 531 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
510 WebDataServiceFactory::GetAutofillWebDataForProfile( 532 WebDataServiceFactory::GetAutofillWebDataForProfile(
511 profile_, ServiceAccessType::EXPLICIT_ACCESS); 533 profile_, ServiceAccessType::EXPLICIT_ACCESS);
512 if (web_data_service.get()) { 534 if (web_data_service.get()) {
513 waiting_for_clear_autofill_origin_urls_ = true; 535 waiting_for_clear_autofill_origin_urls_ = true;
514 web_data_service->RemoveOriginURLsModifiedBetween( 536 web_data_service->RemoveOriginURLsModifiedBetween(
515 delete_begin_, delete_end_); 537 delete_begin_, delete_end_);
516 // The above calls are done on the UI thread but do their work on the DB 538 // The above calls are done on the UI thread but do their work on the DB
517 // thread. So wait for it. 539 // thread. So wait for it.
518 BrowserThread::PostTaskAndReply( 540 BrowserThread::PostTaskAndReply(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 // doesn't make sense to apply the time period of deleting in the last X 626 // doesn't make sense to apply the time period of deleting in the last X
605 // hours/days to the safebrowsing cookies since they aren't the result of 627 // hours/days to the safebrowsing cookies since they aren't the result of
606 // any user action. 628 // any user action.
607 if (delete_begin_ == base::Time()) { 629 if (delete_begin_ == base::Time()) {
608 safe_browsing::SafeBrowsingService* sb_service = 630 safe_browsing::SafeBrowsingService* sb_service =
609 g_browser_process->safe_browsing_service(); 631 g_browser_process->safe_browsing_service();
610 if (sb_service) { 632 if (sb_service) {
611 scoped_refptr<net::URLRequestContextGetter> sb_context = 633 scoped_refptr<net::URLRequestContextGetter> sb_context =
612 sb_service->url_request_context(); 634 sb_service->url_request_context();
613 ++waiting_for_clear_cookies_count_; 635 ++waiting_for_clear_cookies_count_;
614 BrowserThread::PostTask( 636
615 BrowserThread::IO, FROM_HERE, 637 if (origin_filter.IsEmptyBlacklist()) {
616 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_, 638 BrowserThread::PostTask(
617 std::move(sb_context), 639 BrowserThread::IO, FROM_HERE,
618 UIThreadTrampoline( 640 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_,
619 base::Bind(&BrowsingDataRemover::OnClearedCookies, 641 std::move(sb_context),
620 weak_ptr_factory_.GetWeakPtr())))); 642 UIThreadTrampoline(
643 base::Bind(&BrowsingDataRemover::OnClearedCookies,
644 weak_ptr_factory_.GetWeakPtr()))));
645 } else {
646 BrowserThread::PostTask(
647 BrowserThread::IO, FROM_HERE,
648 base::Bind(&ClearCookiesWithPredicateOnIOThread, delete_begin_,
649 delete_end_, origin_filter.BuildDomainCookieFilter(),
650 std::move(sb_context),
651 UIThreadTrampoline(
652 base::Bind(&BrowsingDataRemover::OnClearedCookies,
653 weak_ptr_factory_.GetWeakPtr()))));
654 }
621 } 655 }
622 } 656 }
623 657
624 MediaDeviceIDSalt::Reset(profile_->GetPrefs()); 658 MediaDeviceIDSalt::Reset(profile_->GetPrefs());
625 } 659 }
626 660
627 // Channel IDs are not separated for protected and unprotected web 661 // Channel IDs are not separated for protected and unprotected web
628 // origins. We check the origin_type_mask_ to prevent unintended deletion. 662 // origins. We check the origin_type_mask_ to prevent unintended deletion.
629 if (remove_mask & REMOVE_CHANNEL_IDS && 663 if (remove_mask & REMOVE_CHANNEL_IDS &&
630 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 664 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 plugin_data_remover_->StartRemoving(delete_begin_); 722 plugin_data_remover_->StartRemoving(delete_begin_);
689 723
690 base::WaitableEventWatcher::EventCallback watcher_callback = 724 base::WaitableEventWatcher::EventCallback watcher_callback =
691 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, 725 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled,
692 weak_ptr_factory_.GetWeakPtr()); 726 weak_ptr_factory_.GetWeakPtr());
693 watcher_.StartWatching(event, watcher_callback); 727 watcher_.StartWatching(event, watcher_callback);
694 } 728 }
695 #endif 729 #endif
696 730
697 if (remove_mask & REMOVE_SITE_USAGE_DATA) { 731 if (remove_mask & REMOVE_SITE_USAGE_DATA) {
698 HostContentSettingsMapFactory::GetForProfile(profile_) 732 ClearSettingsForOneTypeWithPredicate(
699 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT); 733 HostContentSettingsMapFactory::GetForProfile(profile_),
734 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
735 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
700 } 736 }
701 737
702 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) { 738 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) {
703 HostContentSettingsMapFactory::GetForProfile(profile_) 739 ClearSettingsForOneTypeWithPredicate(
704 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_APP_BANNER); 740 HostContentSettingsMapFactory::GetForProfile(profile_),
741 CONTENT_SETTINGS_TYPE_APP_BANNER,
742 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
705 } 743 }
706 744
707 if (remove_mask & REMOVE_PASSWORDS) { 745 if (remove_mask & REMOVE_PASSWORDS) {
708 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); 746 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
709 password_manager::PasswordStore* password_store = 747 password_manager::PasswordStore* password_store =
710 PasswordStoreFactory::GetForProfile( 748 PasswordStoreFactory::GetForProfile(
711 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); 749 profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
712 750
713 if (password_store) { 751 if (password_store) {
714 waiting_for_clear_passwords_ = true; 752 waiting_for_clear_passwords_ = true;
(...skipping 27 matching lines...) Expand all
742 780
743 if (password_store) { 781 if (password_store) {
744 waiting_for_clear_passwords_stats_ = true; 782 waiting_for_clear_passwords_stats_ = true;
745 password_store->RemoveStatisticsCreatedBetween( 783 password_store->RemoveStatisticsCreatedBetween(
746 delete_begin_, delete_end_, 784 delete_begin_, delete_end_,
747 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats, 785 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats,
748 weak_ptr_factory_.GetWeakPtr())); 786 weak_ptr_factory_.GetWeakPtr()));
749 } 787 }
750 } 788 }
751 789
790 // TODO(dmurph): Support all backends with filter (crbug.com/113621).
752 if (remove_mask & REMOVE_FORM_DATA) { 791 if (remove_mask & REMOVE_FORM_DATA) {
753 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); 792 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
754 scoped_refptr<autofill::AutofillWebDataService> web_data_service = 793 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
755 WebDataServiceFactory::GetAutofillWebDataForProfile( 794 WebDataServiceFactory::GetAutofillWebDataForProfile(
756 profile_, ServiceAccessType::EXPLICIT_ACCESS); 795 profile_, ServiceAccessType::EXPLICIT_ACCESS);
757 796
758 if (web_data_service.get()) { 797 if (web_data_service.get()) {
759 waiting_for_clear_form_ = true; 798 waiting_for_clear_form_ = true;
760 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, 799 web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
761 delete_end_); 800 delete_end_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 884
846 if (delete_begin_ == base::Time() || 885 if (delete_begin_ == base::Time() ||
847 origin_type_mask_ & 886 origin_type_mask_ &
848 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { 887 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
849 // If we're deleting since the beginning of time, or we're removing 888 // If we're deleting since the beginning of time, or we're removing
850 // protected origins, then remove persistent quota data. 889 // protected origins, then remove persistent quota data.
851 quota_storage_remove_mask |= 890 quota_storage_remove_mask |=
852 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 891 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
853 } 892 }
854 893
894 content::StoragePartition::CookieMatcherFunction cookie_matcher;
895 if (!origin_filter.IsEmptyBlacklist()) {
896 cookie_matcher = origin_filter.BuildDomainCookieFilter();
897 }
855 storage_partition->ClearData( 898 storage_partition->ClearData(
856 storage_partition_remove_mask, quota_storage_remove_mask, remove_url, 899 storage_partition_remove_mask, quota_storage_remove_mask,
857 base::Bind(&DoesOriginMatchMask, origin_type_mask_), delete_begin_, 900 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_,
858 delete_end_, 901 same_origin_filter),
902 cookie_matcher, delete_begin_, delete_end_,
859 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData, 903 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
860 weak_ptr_factory_.GetWeakPtr())); 904 weak_ptr_factory_.GetWeakPtr()));
861 } 905 }
862 906
863 #if defined(ENABLE_PLUGINS) 907 #if defined(ENABLE_PLUGINS)
864 if (remove_mask & REMOVE_CONTENT_LICENSES) { 908 if (remove_mask & REMOVE_CONTENT_LICENSES) {
865 content::RecordAction( 909 content::RecordAction(
866 UserMetricsAction("ClearBrowsingData_ContentLicenses")); 910 UserMetricsAction("ClearBrowsingData_ContentLicenses"));
867 911
868 waiting_for_clear_content_licenses_ = true; 912 waiting_for_clear_content_licenses_ = true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 waiting_for_clear_webapp_data_ = true; 973 waiting_for_clear_webapp_data_ = true;
930 WebappRegistry::UnregisterWebapps( 974 WebappRegistry::UnregisterWebapps(
931 base::Bind(&BrowsingDataRemover::OnClearedWebappData, 975 base::Bind(&BrowsingDataRemover::OnClearedWebappData,
932 weak_ptr_factory_.GetWeakPtr())); 976 weak_ptr_factory_.GetWeakPtr()));
933 } 977 }
934 978
935 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) && 979 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) &&
936 offline_pages::IsOfflinePagesEnabled()) { 980 offline_pages::IsOfflinePagesEnabled()) {
937 waiting_for_clear_offline_page_data_ = true; 981 waiting_for_clear_offline_page_data_ = true;
938 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_) 982 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_)
939 ->ClearAll(base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData, 983 ->ClearWithURLPredicate(
940 weak_ptr_factory_.GetWeakPtr())); 984 same_origin_filter,
985 base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData,
986 weak_ptr_factory_.GetWeakPtr()));
941 } 987 }
942 #endif 988 #endif
943 989
944 // Record the combined deletion of cookies and cache. 990 // Record the combined deletion of cookies and cache.
945 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; 991 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE;
946 if (remove_mask & REMOVE_COOKIES && 992 if (remove_mask & REMOVE_COOKIES &&
947 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { 993 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
948 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE 994 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE
949 : ONLY_COOKIES; 995 : ONLY_COOKIES;
950 } else if (remove_mask & REMOVE_CACHE) { 996 } else if (remove_mask & REMOVE_CACHE) {
(...skipping 11 matching lines...) Expand all
962 1008
963 void BrowsingDataRemover::RemoveObserver(Observer* observer) { 1009 void BrowsingDataRemover::RemoveObserver(Observer* observer) {
964 observer_list_.RemoveObserver(observer); 1010 observer_list_.RemoveObserver(observer);
965 } 1011 }
966 1012
967 void BrowsingDataRemover::OverrideStoragePartitionForTesting( 1013 void BrowsingDataRemover::OverrideStoragePartitionForTesting(
968 content::StoragePartition* storage_partition) { 1014 content::StoragePartition* storage_partition) {
969 storage_partition_for_testing_ = storage_partition; 1015 storage_partition_for_testing_ = storage_partition;
970 } 1016 }
971 1017
1018 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate(
1019 HostContentSettingsMap* content_settings_map,
1020 ContentSettingsType content_type,
1021 const base::Callback<bool(const ContentSettingsPattern& primary_pattern,
1022 const ContentSettingsPattern& secondary_pattern)>&
1023 predicate) {
1024 ContentSettingsForOneType settings;
1025 content_settings_map->GetSettingsForOneType(content_type, std::string(),
1026 &settings);
1027 for (const ContentSettingPatternSource& setting : settings) {
1028 if (predicate.Run(setting.primary_pattern, setting.secondary_pattern)) {
1029 content_settings_map->SetWebsiteSettingCustomScope(
1030 setting.primary_pattern, setting.secondary_pattern, content_type,
1031 std::string(), nullptr);
1032 }
1033 }
1034 }
1035
972 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( 1036 base::Time BrowsingDataRemover::CalculateBeginDeleteTime(
973 TimePeriod time_period) { 1037 TimePeriod time_period) {
974 base::TimeDelta diff; 1038 base::TimeDelta diff;
975 base::Time delete_begin_time = base::Time::Now(); 1039 base::Time delete_begin_time = base::Time::Now();
976 switch (time_period) { 1040 switch (time_period) {
977 case LAST_HOUR: 1041 case LAST_HOUR:
978 diff = base::TimeDelta::FromHours(1); 1042 diff = base::TimeDelta::FromHours(1);
979 break; 1043 break;
980 case LAST_DAY: 1044 case LAST_DAY:
981 diff = base::TimeDelta::FromHours(24); 1045 diff = base::TimeDelta::FromHours(24);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 waiting_for_clear_domain_reliability_monitor_ = false; 1284 waiting_for_clear_domain_reliability_monitor_ = false;
1221 NotifyIfDone(); 1285 NotifyIfDone();
1222 } 1286 }
1223 1287
1224 // static 1288 // static
1225 BrowsingDataRemover::CallbackSubscription 1289 BrowsingDataRemover::CallbackSubscription
1226 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( 1290 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
1227 const BrowsingDataRemover::Callback& callback) { 1291 const BrowsingDataRemover::Callback& callback) {
1228 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); 1292 return GetOnBrowsingDataRemovedCallbacks()->Add(callback);
1229 } 1293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698