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

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

Powered by Google App Engine
This is Rietveld 408576698