| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 331 } |
| 321 | 332 |
| 322 void BrowsingDataRemover::SetRemoving(bool is_removing) { | 333 void BrowsingDataRemover::SetRemoving(bool is_removing) { |
| 323 DCHECK_NE(is_removing_, is_removing); | 334 DCHECK_NE(is_removing_, is_removing); |
| 324 is_removing_ = is_removing; | 335 is_removing_ = is_removing; |
| 325 } | 336 } |
| 326 | 337 |
| 327 void BrowsingDataRemover::Remove(const TimeRange& time_range, | 338 void BrowsingDataRemover::Remove(const TimeRange& time_range, |
| 328 int remove_mask, | 339 int remove_mask, |
| 329 int origin_type_mask) { | 340 int origin_type_mask) { |
| 330 RemoveImpl(time_range, remove_mask, GURL(), origin_type_mask); | 341 OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST); |
| 342 RemoveImpl(time_range, remove_mask, builder, origin_type_mask); |
| 343 } |
| 344 |
| 345 void BrowsingDataRemover::RemoveWithFilter( |
| 346 const TimeRange& time_range, |
| 347 int remove_mask, |
| 348 int origin_type_mask, |
| 349 const OriginFilterBuilder& origin_filter) { |
| 350 RemoveImpl(time_range, remove_mask, origin_filter, origin_type_mask); |
| 331 } | 351 } |
| 332 | 352 |
| 333 void BrowsingDataRemover::RemoveImpl(const TimeRange& time_range, | 353 void BrowsingDataRemover::RemoveImpl(const TimeRange& time_range, |
| 334 int remove_mask, | 354 int remove_mask, |
| 335 const GURL& remove_url, | 355 const OriginFilterBuilder& origin_filter, |
| 336 int origin_type_mask) { | 356 int origin_type_mask) { |
| 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 357 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 338 | 358 |
| 339 // crbug.com/140910: Many places were calling this with base::Time() as | 359 // crbug.com/140910: Many places were calling this with base::Time() as |
| 340 // delete_end, even though they should've used base::Time::Max(). | 360 // delete_end, even though they should've used base::Time::Max(). |
| 341 DCHECK_NE(base::Time(), time_range.end); | 361 DCHECK_NE(base::Time(), time_range.end); |
| 342 | 362 |
| 343 SetRemoving(true); | 363 SetRemoving(true); |
| 344 delete_begin_ = time_range.begin; | 364 delete_begin_ = time_range.begin; |
| 345 delete_end_ = time_range.end; | 365 delete_end_ = time_range.end; |
| 346 remove_mask_ = remove_mask; | 366 remove_mask_ = remove_mask; |
| 347 origin_type_mask_ = origin_type_mask; | 367 origin_type_mask_ = origin_type_mask; |
| 348 | 368 |
| 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 = | 369 base::Callback<bool(const GURL& url)> same_origin_filter = |
| 360 builder.BuildSameOriginFilter(); | 370 origin_filter.BuildSameOriginFilter(); |
| 371 base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter = |
| 372 origin_filter.BuildSameOriginContentSettingsFilter(); |
| 361 | 373 |
| 362 PrefService* prefs = profile_->GetPrefs(); | 374 PrefService* prefs = profile_->GetPrefs(); |
| 363 bool may_delete_history = prefs->GetBoolean( | 375 bool may_delete_history = prefs->GetBoolean( |
| 364 prefs::kAllowDeletingBrowserHistory); | 376 prefs::kAllowDeletingBrowserHistory); |
| 365 | 377 |
| 366 // All the UI entry points into the BrowsingDataRemover should be disabled, | 378 // All the UI entry points into the BrowsingDataRemover should be disabled, |
| 367 // but this will fire if something was missed or added. | 379 // but this will fire if something was missed or added. |
| 368 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || | 380 DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) || |
| 369 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); | 381 (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS))); |
| 370 | 382 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 386 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB | | 398 BrowsingDataHelper::ALL == (BrowsingDataHelper::UNPROTECTED_WEB | |
| 387 BrowsingDataHelper::PROTECTED_WEB | | 399 BrowsingDataHelper::PROTECTED_WEB | |
| 388 BrowsingDataHelper::EXTENSION), | 400 BrowsingDataHelper::EXTENSION), |
| 389 "OriginTypeMask has been updated without updating user metrics"); | 401 "OriginTypeMask has been updated without updating user metrics"); |
| 390 | 402 |
| 391 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { | 403 if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { |
| 392 history::HistoryService* history_service = | 404 history::HistoryService* history_service = |
| 393 HistoryServiceFactory::GetForProfile( | 405 HistoryServiceFactory::GetForProfile( |
| 394 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 406 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 395 if (history_service) { | 407 if (history_service) { |
| 396 // Selective history deletion is currently done through HistoryUI -> | 408 // 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")); | 409 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 406 waiting_for_clear_history_ = true; | 410 waiting_for_clear_history_ = true; |
| 407 | |
| 408 history_service->ExpireLocalAndRemoteHistoryBetween( | 411 history_service->ExpireLocalAndRemoteHistoryBetween( |
| 409 WebHistoryServiceFactory::GetForProfile(profile_), restrict_urls, | 412 WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(), |
| 410 delete_begin_, delete_end_, | 413 delete_begin_, delete_end_, |
| 411 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, | 414 base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone, |
| 412 weak_ptr_factory_.GetWeakPtr()), | 415 weak_ptr_factory_.GetWeakPtr()), |
| 413 &history_task_tracker_); | 416 &history_task_tracker_); |
| 414 | 417 |
| 415 #if defined(ENABLE_EXTENSIONS) | 418 #if defined(ENABLE_EXTENSIONS) |
| 416 // The extension activity contains details of which websites extensions | 419 // The extension activity contains details of which websites extensions |
| 417 // were active on. It therefore indirectly stores details of websites a | 420 // were active on. It therefore indirectly stores details of websites a |
| 418 // user has visited so best clean from here as well. | 421 // user has visited so best clean from here as well. |
| 419 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(restrict_urls); | 422 extensions::ActivityLog::GetInstance(profile_)->RemoveURLs( |
| 423 std::set<GURL>()); |
| 420 #endif | 424 #endif |
| 421 } | 425 } |
| 422 | 426 |
| 423 #if defined(ENABLE_EXTENSIONS) | 427 #if defined(ENABLE_EXTENSIONS) |
| 424 // Clear launch times as they are a form of history. | 428 // Clear launch times as they are a form of history. |
| 425 extensions::ExtensionPrefs* extension_prefs = | 429 extensions::ExtensionPrefs* extension_prefs = |
| 426 extensions::ExtensionPrefs::Get(profile_); | 430 extensions::ExtensionPrefs::Get(profile_); |
| 427 extension_prefs->ClearLastLaunchTimes(); | 431 extension_prefs->ClearLastLaunchTimes(); |
| 428 #endif | 432 #endif |
| 429 | 433 |
| 430 // The power consumption history by origin contains details of websites | 434 // The power consumption history by origin contains details of websites |
| 431 // that were visited. | 435 // that were visited. |
| 436 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 432 power::OriginPowerMap* origin_power_map = | 437 power::OriginPowerMap* origin_power_map = |
| 433 power::OriginPowerMapFactory::GetForBrowserContext(profile_); | 438 power::OriginPowerMapFactory::GetForBrowserContext(profile_); |
| 434 if (origin_power_map) | 439 if (origin_power_map) |
| 435 origin_power_map->ClearOriginMap(); | 440 origin_power_map->ClearOriginMap(); |
| 436 | 441 |
| 437 // Need to clear the host cache and accumulated speculative data, as it also | 442 // 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 | 443 // 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. | 444 // created, so we'll clear them all. Better safe than sorry. |
| 440 if (g_browser_process->io_thread()) { | 445 if (g_browser_process->io_thread()) { |
| 446 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 441 waiting_for_clear_hostname_resolution_cache_ = true; | 447 waiting_for_clear_hostname_resolution_cache_ = true; |
| 442 BrowserThread::PostTaskAndReply( | 448 BrowserThread::PostTaskAndReply( |
| 443 BrowserThread::IO, FROM_HERE, | 449 BrowserThread::IO, FROM_HERE, |
| 444 base::Bind(&ClearHostnameResolutionCacheOnIOThread, | 450 base::Bind(&ClearHostnameResolutionCacheOnIOThread, |
| 445 g_browser_process->io_thread()), | 451 g_browser_process->io_thread()), |
| 446 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache, | 452 base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache, |
| 447 weak_ptr_factory_.GetWeakPtr())); | 453 weak_ptr_factory_.GetWeakPtr())); |
| 448 } | 454 } |
| 449 if (profile_->GetNetworkPredictor()) { | 455 if (profile_->GetNetworkPredictor()) { |
| 456 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 450 waiting_for_clear_network_predictor_ = true; | 457 waiting_for_clear_network_predictor_ = true; |
| 451 BrowserThread::PostTaskAndReply( | 458 BrowserThread::PostTaskAndReply( |
| 452 BrowserThread::IO, FROM_HERE, | 459 BrowserThread::IO, FROM_HERE, |
| 453 base::Bind(&ClearNetworkPredictorOnIOThread, | 460 base::Bind(&ClearNetworkPredictorOnIOThread, |
| 454 profile_->GetNetworkPredictor()), | 461 profile_->GetNetworkPredictor()), |
| 455 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor, | 462 base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor, |
| 456 weak_ptr_factory_.GetWeakPtr())); | 463 weak_ptr_factory_.GetWeakPtr())); |
| 457 } | 464 } |
| 458 | 465 |
| 459 // As part of history deletion we also delete the auto-generated keywords. | 466 // As part of history deletion we also delete the auto-generated keywords. |
| 460 TemplateURLService* keywords_model = | 467 TemplateURLService* keywords_model = |
| 461 TemplateURLServiceFactory::GetForProfile(profile_); | 468 TemplateURLServiceFactory::GetForProfile(profile_); |
| 469 |
| 462 if (keywords_model && !keywords_model->loaded()) { | 470 if (keywords_model && !keywords_model->loaded()) { |
| 463 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( | 471 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( |
| 464 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded, | 472 base::Bind(&BrowsingDataRemover::OnKeywordsLoaded, |
| 465 weak_ptr_factory_.GetWeakPtr())); | 473 weak_ptr_factory_.GetWeakPtr())); |
| 466 keywords_model->Load(); | 474 keywords_model->Load(); |
| 467 waiting_for_clear_keyword_data_ = true; | 475 waiting_for_clear_keyword_data_ = true; |
| 468 } else if (keywords_model) { | 476 } else if (keywords_model) { |
| 469 keywords_model->RemoveAutoGeneratedForOriginBetween( | 477 keywords_model->RemoveAutoGeneratedForOriginBetween(GURL(), delete_begin_, |
| 470 remove_url, delete_begin_, delete_end_); | 478 delete_end_); |
| 471 } | 479 } |
| 472 | 480 |
| 473 // The PrerenderManager keeps history of prerendered pages, so clear that. | 481 // The PrerenderManager keeps history of prerendered pages, so clear that. |
| 474 // It also may have a prerendered page. If so, the page could be | 482 // 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 | 483 // considered to have a small amount of historical information, so delete |
| 476 // it, too. | 484 // it, too. |
| 477 prerender::PrerenderManager* prerender_manager = | 485 prerender::PrerenderManager* prerender_manager = |
| 478 prerender::PrerenderManagerFactory::GetForProfile(profile_); | 486 prerender::PrerenderManagerFactory::GetForProfile(profile_); |
| 479 if (prerender_manager) { | 487 if (prerender_manager) { |
| 488 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 480 prerender_manager->ClearData( | 489 prerender_manager->ClearData( |
| 481 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | | 490 prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS | |
| 482 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); | 491 prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY); |
| 483 } | 492 } |
| 484 | 493 |
| 485 // If the caller is removing history for all hosts, then clear ancillary | 494 // If the caller is removing history for all hosts, then clear ancillary |
| 486 // historical information. | 495 // historical information. |
| 487 if (remove_url.is_empty()) { | 496 if (origin_filter.IsEmptyBlacklist()) { |
| 488 // We also delete the list of recently closed tabs. Since these expire, | 497 // 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. | 498 // they can't be more than a day old, so we can simply clear them all. |
| 490 sessions::TabRestoreService* tab_service = | 499 sessions::TabRestoreService* tab_service = |
| 491 TabRestoreServiceFactory::GetForProfile(profile_); | 500 TabRestoreServiceFactory::GetForProfile(profile_); |
| 492 if (tab_service) { | 501 if (tab_service) { |
| 493 tab_service->ClearEntries(); | 502 tab_service->ClearEntries(); |
| 494 tab_service->DeleteLastSession(); | 503 tab_service->DeleteLastSession(); |
| 495 } | 504 } |
| 496 | 505 |
| 497 #if defined(ENABLE_SESSION_SERVICE) | 506 #if defined(ENABLE_SESSION_SERVICE) |
| 498 // We also delete the last session when we delete the history. | 507 // We also delete the last session when we delete the history. |
| 499 SessionService* session_service = | 508 SessionService* session_service = |
| 500 SessionServiceFactory::GetForProfile(profile_); | 509 SessionServiceFactory::GetForProfile(profile_); |
| 501 if (session_service) | 510 if (session_service) |
| 502 session_service->DeleteLastSession(); | 511 session_service->DeleteLastSession(); |
| 503 #endif | 512 #endif |
| 504 } | 513 } |
| 505 | 514 |
| 506 // The saved Autofill profiles and credit cards can include the origin from | 515 // 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 | 516 // which these profiles and credit cards were learned. These are a form of |
| 508 // history, so clear them as well. | 517 // history, so clear them as well. |
| 518 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 509 scoped_refptr<autofill::AutofillWebDataService> web_data_service = | 519 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
| 510 WebDataServiceFactory::GetAutofillWebDataForProfile( | 520 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 511 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 521 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 512 if (web_data_service.get()) { | 522 if (web_data_service.get()) { |
| 513 waiting_for_clear_autofill_origin_urls_ = true; | 523 waiting_for_clear_autofill_origin_urls_ = true; |
| 514 web_data_service->RemoveOriginURLsModifiedBetween( | 524 web_data_service->RemoveOriginURLsModifiedBetween( |
| 515 delete_begin_, delete_end_); | 525 delete_begin_, delete_end_); |
| 516 // The above calls are done on the UI thread but do their work on the DB | 526 // The above calls are done on the UI thread but do their work on the DB |
| 517 // thread. So wait for it. | 527 // thread. So wait for it. |
| 518 BrowserThread::PostTaskAndReply( | 528 BrowserThread::PostTaskAndReply( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { | 607 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { |
| 598 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); | 608 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies")); |
| 599 | 609 |
| 600 storage_partition_remove_mask |= | 610 storage_partition_remove_mask |= |
| 601 content::StoragePartition::REMOVE_DATA_MASK_COOKIES; | 611 content::StoragePartition::REMOVE_DATA_MASK_COOKIES; |
| 602 | 612 |
| 603 // Clear the safebrowsing cookies only if time period is for "all time". It | 613 // Clear the safebrowsing cookies only if time period is for "all time". It |
| 604 // doesn't make sense to apply the time period of deleting in the last X | 614 // 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 | 615 // hours/days to the safebrowsing cookies since they aren't the result of |
| 606 // any user action. | 616 // any user action. |
| 617 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 607 if (delete_begin_ == base::Time()) { | 618 if (delete_begin_ == base::Time()) { |
| 608 safe_browsing::SafeBrowsingService* sb_service = | 619 safe_browsing::SafeBrowsingService* sb_service = |
| 609 g_browser_process->safe_browsing_service(); | 620 g_browser_process->safe_browsing_service(); |
| 610 if (sb_service) { | 621 if (sb_service) { |
| 611 scoped_refptr<net::URLRequestContextGetter> sb_context = | 622 scoped_refptr<net::URLRequestContextGetter> sb_context = |
| 612 sb_service->url_request_context(); | 623 sb_service->url_request_context(); |
| 613 ++waiting_for_clear_cookies_count_; | 624 ++waiting_for_clear_cookies_count_; |
| 625 // TODONOW |
| 614 BrowserThread::PostTask( | 626 BrowserThread::PostTask( |
| 615 BrowserThread::IO, FROM_HERE, | 627 BrowserThread::IO, FROM_HERE, |
| 616 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_, | 628 base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_, |
| 617 std::move(sb_context), | 629 std::move(sb_context), |
| 618 UIThreadTrampoline( | 630 UIThreadTrampoline( |
| 619 base::Bind(&BrowsingDataRemover::OnClearedCookies, | 631 base::Bind(&BrowsingDataRemover::OnClearedCookies, |
| 620 weak_ptr_factory_.GetWeakPtr())))); | 632 weak_ptr_factory_.GetWeakPtr())))); |
| 621 } | 633 } |
| 622 } | 634 } |
| 623 | 635 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 plugin_data_remover_->StartRemoving(delete_begin_); | 700 plugin_data_remover_->StartRemoving(delete_begin_); |
| 689 | 701 |
| 690 base::WaitableEventWatcher::EventCallback watcher_callback = | 702 base::WaitableEventWatcher::EventCallback watcher_callback = |
| 691 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, | 703 base::Bind(&BrowsingDataRemover::OnWaitableEventSignaled, |
| 692 weak_ptr_factory_.GetWeakPtr()); | 704 weak_ptr_factory_.GetWeakPtr()); |
| 693 watcher_.StartWatching(event, watcher_callback); | 705 watcher_.StartWatching(event, watcher_callback); |
| 694 } | 706 } |
| 695 #endif | 707 #endif |
| 696 | 708 |
| 697 if (remove_mask & REMOVE_SITE_USAGE_DATA) { | 709 if (remove_mask & REMOVE_SITE_USAGE_DATA) { |
| 698 HostContentSettingsMapFactory::GetForProfile(profile_) | 710 ClearSettingsForOneTypeWithPredicate( |
| 699 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT); | 711 HostContentSettingsMapFactory::GetForProfile(profile_), |
| 712 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| 713 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter)); |
| 700 } | 714 } |
| 701 | 715 |
| 702 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) { | 716 if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) { |
| 703 HostContentSettingsMapFactory::GetForProfile(profile_) | 717 ClearSettingsForOneTypeWithPredicate( |
| 704 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_APP_BANNER); | 718 HostContentSettingsMapFactory::GetForProfile(profile_), |
| 719 CONTENT_SETTINGS_TYPE_APP_BANNER, |
| 720 base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter)); |
| 705 } | 721 } |
| 706 | 722 |
| 707 if (remove_mask & REMOVE_PASSWORDS) { | 723 if (remove_mask & REMOVE_PASSWORDS) { |
| 708 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); | 724 content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords")); |
| 709 password_manager::PasswordStore* password_store = | 725 password_manager::PasswordStore* password_store = |
| 710 PasswordStoreFactory::GetForProfile( | 726 PasswordStoreFactory::GetForProfile( |
| 711 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); | 727 profile_, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 712 | 728 |
| 713 if (password_store) { | 729 if (password_store) { |
| 714 waiting_for_clear_passwords_ = true; | 730 waiting_for_clear_passwords_ = true; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 742 | 758 |
| 743 if (password_store) { | 759 if (password_store) { |
| 744 waiting_for_clear_passwords_stats_ = true; | 760 waiting_for_clear_passwords_stats_ = true; |
| 745 password_store->RemoveStatisticsCreatedBetween( | 761 password_store->RemoveStatisticsCreatedBetween( |
| 746 delete_begin_, delete_end_, | 762 delete_begin_, delete_end_, |
| 747 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats, | 763 base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats, |
| 748 weak_ptr_factory_.GetWeakPtr())); | 764 weak_ptr_factory_.GetWeakPtr())); |
| 749 } | 765 } |
| 750 } | 766 } |
| 751 | 767 |
| 768 // TODO(dmurph): Support all backends with filter (crbug.com/113621). |
| 752 if (remove_mask & REMOVE_FORM_DATA) { | 769 if (remove_mask & REMOVE_FORM_DATA) { |
| 753 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); | 770 content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill")); |
| 754 scoped_refptr<autofill::AutofillWebDataService> web_data_service = | 771 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
| 755 WebDataServiceFactory::GetAutofillWebDataForProfile( | 772 WebDataServiceFactory::GetAutofillWebDataForProfile( |
| 756 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 773 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 757 | 774 |
| 758 if (web_data_service.get()) { | 775 if (web_data_service.get()) { |
| 759 waiting_for_clear_form_ = true; | 776 waiting_for_clear_form_ = true; |
| 760 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, | 777 web_data_service->RemoveFormElementsAddedBetween(delete_begin_, |
| 761 delete_end_); | 778 delete_end_); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 | 862 |
| 846 if (delete_begin_ == base::Time() || | 863 if (delete_begin_ == base::Time() || |
| 847 origin_type_mask_ & | 864 origin_type_mask_ & |
| 848 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { | 865 (BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) { |
| 849 // If we're deleting since the beginning of time, or we're removing | 866 // If we're deleting since the beginning of time, or we're removing |
| 850 // protected origins, then remove persistent quota data. | 867 // protected origins, then remove persistent quota data. |
| 851 quota_storage_remove_mask |= | 868 quota_storage_remove_mask |= |
| 852 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; | 869 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; |
| 853 } | 870 } |
| 854 | 871 |
| 872 content::StoragePartition::CookieMatcherFunction cookie_matcher; |
| 873 if (!origin_filter.IsEmptyBlacklist()) { |
| 874 cookie_matcher = origin_filter.BuildCookieFilter(); |
| 875 } |
| 855 storage_partition->ClearData( | 876 storage_partition->ClearData( |
| 856 storage_partition_remove_mask, quota_storage_remove_mask, remove_url, | 877 storage_partition_remove_mask, quota_storage_remove_mask, |
| 857 base::Bind(&DoesOriginMatchMask, origin_type_mask_), delete_begin_, | 878 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, |
| 858 delete_end_, | 879 same_origin_filter), |
| 880 cookie_matcher, delete_begin_, delete_end_, |
| 859 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData, | 881 base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData, |
| 860 weak_ptr_factory_.GetWeakPtr())); | 882 weak_ptr_factory_.GetWeakPtr())); |
| 861 } | 883 } |
| 862 | 884 |
| 863 #if defined(ENABLE_PLUGINS) | 885 #if defined(ENABLE_PLUGINS) |
| 864 if (remove_mask & REMOVE_CONTENT_LICENSES) { | 886 if (remove_mask & REMOVE_CONTENT_LICENSES) { |
| 865 content::RecordAction( | 887 content::RecordAction( |
| 866 UserMetricsAction("ClearBrowsingData_ContentLicenses")); | 888 UserMetricsAction("ClearBrowsingData_ContentLicenses")); |
| 867 | 889 |
| 868 waiting_for_clear_content_licenses_ = true; | 890 waiting_for_clear_content_licenses_ = true; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 waiting_for_clear_webapp_data_ = true; | 951 waiting_for_clear_webapp_data_ = true; |
| 930 WebappRegistry::UnregisterWebapps( | 952 WebappRegistry::UnregisterWebapps( |
| 931 base::Bind(&BrowsingDataRemover::OnClearedWebappData, | 953 base::Bind(&BrowsingDataRemover::OnClearedWebappData, |
| 932 weak_ptr_factory_.GetWeakPtr())); | 954 weak_ptr_factory_.GetWeakPtr())); |
| 933 } | 955 } |
| 934 | 956 |
| 935 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) && | 957 if ((remove_mask & REMOVE_OFFLINE_PAGE_DATA) && |
| 936 offline_pages::IsOfflinePagesEnabled()) { | 958 offline_pages::IsOfflinePagesEnabled()) { |
| 937 waiting_for_clear_offline_page_data_ = true; | 959 waiting_for_clear_offline_page_data_ = true; |
| 938 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_) | 960 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_) |
| 939 ->ClearAll(base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData, | 961 ->ClearWithURLPredicate( |
| 940 weak_ptr_factory_.GetWeakPtr())); | 962 same_origin_filter, |
| 963 base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData, |
| 964 weak_ptr_factory_.GetWeakPtr())); |
| 941 } | 965 } |
| 942 #endif | 966 #endif |
| 943 | 967 |
| 944 // Record the combined deletion of cookies and cache. | 968 // Record the combined deletion of cookies and cache. |
| 945 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; | 969 CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE; |
| 946 if (remove_mask & REMOVE_COOKIES && | 970 if (remove_mask & REMOVE_COOKIES && |
| 947 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { | 971 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { |
| 948 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE | 972 choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE |
| 949 : ONLY_COOKIES; | 973 : ONLY_COOKIES; |
| 950 } else if (remove_mask & REMOVE_CACHE) { | 974 } else if (remove_mask & REMOVE_CACHE) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 962 | 986 |
| 963 void BrowsingDataRemover::RemoveObserver(Observer* observer) { | 987 void BrowsingDataRemover::RemoveObserver(Observer* observer) { |
| 964 observer_list_.RemoveObserver(observer); | 988 observer_list_.RemoveObserver(observer); |
| 965 } | 989 } |
| 966 | 990 |
| 967 void BrowsingDataRemover::OverrideStoragePartitionForTesting( | 991 void BrowsingDataRemover::OverrideStoragePartitionForTesting( |
| 968 content::StoragePartition* storage_partition) { | 992 content::StoragePartition* storage_partition) { |
| 969 storage_partition_for_testing_ = storage_partition; | 993 storage_partition_for_testing_ = storage_partition; |
| 970 } | 994 } |
| 971 | 995 |
| 996 void BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( |
| 997 HostContentSettingsMap* content_settings_map, |
| 998 ContentSettingsType content_type, |
| 999 const base::Callback<bool(const ContentSettingsPattern& primary_pattern, |
| 1000 const ContentSettingsPattern& secondary_pattern)>& |
| 1001 predicate) { |
| 1002 ContentSettingsForOneType settings; |
| 1003 content_settings_map->GetSettingsForOneType(content_type, std::string(), |
| 1004 &settings); |
| 1005 for (const ContentSettingPatternSource& setting : settings) { |
| 1006 if (predicate.Run(setting.primary_pattern, setting.secondary_pattern)) { |
| 1007 content_settings_map->SetWebsiteSettingCustomScope( |
| 1008 setting.primary_pattern, setting.secondary_pattern, content_type, |
| 1009 std::string(), nullptr); |
| 1010 } |
| 1011 } |
| 1012 } |
| 1013 |
| 972 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( | 1014 base::Time BrowsingDataRemover::CalculateBeginDeleteTime( |
| 973 TimePeriod time_period) { | 1015 TimePeriod time_period) { |
| 974 base::TimeDelta diff; | 1016 base::TimeDelta diff; |
| 975 base::Time delete_begin_time = base::Time::Now(); | 1017 base::Time delete_begin_time = base::Time::Now(); |
| 976 switch (time_period) { | 1018 switch (time_period) { |
| 977 case LAST_HOUR: | 1019 case LAST_HOUR: |
| 978 diff = base::TimeDelta::FromHours(1); | 1020 diff = base::TimeDelta::FromHours(1); |
| 979 break; | 1021 break; |
| 980 case LAST_DAY: | 1022 case LAST_DAY: |
| 981 diff = base::TimeDelta::FromHours(24); | 1023 diff = base::TimeDelta::FromHours(24); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 waiting_for_clear_domain_reliability_monitor_ = false; | 1262 waiting_for_clear_domain_reliability_monitor_ = false; |
| 1221 NotifyIfDone(); | 1263 NotifyIfDone(); |
| 1222 } | 1264 } |
| 1223 | 1265 |
| 1224 // static | 1266 // static |
| 1225 BrowsingDataRemover::CallbackSubscription | 1267 BrowsingDataRemover::CallbackSubscription |
| 1226 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | 1268 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( |
| 1227 const BrowsingDataRemover::Callback& callback) { | 1269 const BrowsingDataRemover::Callback& callback) { |
| 1228 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); | 1270 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); |
| 1229 } | 1271 } |
| OLD | NEW |