| 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_impl.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "components/browsing_data/content/storage_partition_http_cache_data_rem
over.h" | 24 #include "components/browsing_data/content/storage_partition_http_cache_data_rem
over.h" |
| 25 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 26 #include "components/web_cache/browser/web_cache_manager.h" | 26 #include "components/web_cache/browser/web_cache_manager.h" |
| 27 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
| 30 #include "content/public/browser/download_manager.h" | 30 #include "content/public/browser/download_manager.h" |
| 31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/plugin_data_remover.h" | |
| 33 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
| 34 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 35 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 36 #include "net/cookies/cookie_store.h" | 35 #include "net/cookies/cookie_store.h" |
| 37 #include "net/http/http_network_session.h" | 36 #include "net/http/http_network_session.h" |
| 38 #include "net/http/http_transaction_factory.h" | 37 #include "net/http/http_transaction_factory.h" |
| 39 #include "net/http/transport_security_state.h" | 38 #include "net/http/transport_security_state.h" |
| 40 #include "net/ssl/channel_id_service.h" | 39 #include "net/ssl/channel_id_service.h" |
| 41 #include "net/ssl/channel_id_store.h" | 40 #include "net/ssl/channel_id_store.h" |
| 42 #include "net/url_request/url_request_context.h" | 41 #include "net/url_request/url_request_context.h" |
| 43 #include "net/url_request/url_request_context_getter.h" | 42 #include "net/url_request/url_request_context_getter.h" |
| 44 #include "ppapi/features/features.h" | 43 #include "ppapi/features/features.h" |
| 45 #include "storage/browser/quota/special_storage_policy.h" | 44 #include "storage/browser/quota/special_storage_policy.h" |
| 46 #include "url/origin.h" | 45 #include "url/origin.h" |
| 47 | 46 |
| 48 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 49 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" | |
| 50 #endif | |
| 51 | |
| 52 using base::UserMetricsAction; | 47 using base::UserMetricsAction; |
| 53 using content::BrowserContext; | 48 using content::BrowserContext; |
| 54 using content::BrowserThread; | 49 using content::BrowserThread; |
| 55 using content::DOMStorageContext; | 50 using content::DOMStorageContext; |
| 56 | 51 |
| 57 namespace { | 52 namespace { |
| 58 | 53 |
| 59 template <typename T> | 54 template <typename T> |
| 60 void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) { | 55 void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) { |
| 61 callback.Run(); | 56 callback.Run(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 is_pending_ = false; | 148 is_pending_ = false; |
| 154 forward_callback_.Run(); | 149 forward_callback_.Run(); |
| 155 } | 150 } |
| 156 | 151 |
| 157 BrowsingDataRemoverImpl::BrowsingDataRemoverImpl( | 152 BrowsingDataRemoverImpl::BrowsingDataRemoverImpl( |
| 158 content::BrowserContext* browser_context) | 153 content::BrowserContext* browser_context) |
| 159 : browser_context_(browser_context), | 154 : browser_context_(browser_context), |
| 160 remove_mask_(-1), | 155 remove_mask_(-1), |
| 161 origin_type_mask_(-1), | 156 origin_type_mask_(-1), |
| 162 is_removing_(false), | 157 is_removing_(false), |
| 163 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 164 flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(browser_context_)), | |
| 165 #endif | |
| 166 sub_task_forward_callback_( | 158 sub_task_forward_callback_( |
| 167 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, | 159 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, |
| 168 base::Unretained(this))), | 160 base::Unretained(this))), |
| 169 synchronous_clear_operations_(sub_task_forward_callback_), | 161 synchronous_clear_operations_(sub_task_forward_callback_), |
| 170 clear_embedder_data_(sub_task_forward_callback_), | 162 clear_embedder_data_(sub_task_forward_callback_), |
| 171 clear_cache_(sub_task_forward_callback_), | 163 clear_cache_(sub_task_forward_callback_), |
| 172 clear_channel_ids_(sub_task_forward_callback_), | 164 clear_channel_ids_(sub_task_forward_callback_), |
| 173 clear_http_auth_cache_(sub_task_forward_callback_), | 165 clear_http_auth_cache_(sub_task_forward_callback_), |
| 174 clear_storage_partition_data_(sub_task_forward_callback_), | 166 clear_storage_partition_data_(sub_task_forward_callback_), |
| 175 weak_ptr_factory_(this) { | 167 weak_ptr_factory_(this) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 } | 486 } |
| 495 | 487 |
| 496 storage_partition->ClearData( | 488 storage_partition->ClearData( |
| 497 storage_partition_remove_mask, quota_storage_remove_mask, | 489 storage_partition_remove_mask, quota_storage_remove_mask, |
| 498 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, filter), | 490 base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, filter), |
| 499 cookie_matcher, delete_begin_, delete_end_, | 491 cookie_matcher, delete_begin_, delete_end_, |
| 500 clear_storage_partition_data_.GetCompletionCallback()); | 492 clear_storage_partition_data_.GetCompletionCallback()); |
| 501 } | 493 } |
| 502 | 494 |
| 503 ////////////////////////////////////////////////////////////////////////////// | 495 ////////////////////////////////////////////////////////////////////////////// |
| 504 // REMOVE_PLUGINS | |
| 505 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 506 // Plugin is data not separated for protected and unprotected web origins. We | |
| 507 // check the origin_type_mask_ to prevent unintended deletion. | |
| 508 if (remove_mask & REMOVE_PLUGIN_DATA && | |
| 509 origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { | |
| 510 content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); | |
| 511 clear_plugin_data_count_ = 1; | |
| 512 | |
| 513 if (filter_builder.IsEmptyBlacklist()) { | |
| 514 DCHECK(!plugin_data_remover_); | |
| 515 plugin_data_remover_.reset( | |
| 516 content::PluginDataRemover::Create(browser_context_)); | |
| 517 base::WaitableEvent* event = | |
| 518 plugin_data_remover_->StartRemoving(delete_begin_); | |
| 519 | |
| 520 base::WaitableEventWatcher::EventCallback watcher_callback = | |
| 521 base::Bind(&BrowsingDataRemoverImpl::OnWaitableEventSignaled, | |
| 522 weak_ptr_factory_.GetWeakPtr()); | |
| 523 watcher_.StartWatching(event, watcher_callback); | |
| 524 } else { | |
| 525 // TODO(msramek): Store filters from the currently executed task on the | |
| 526 // object to avoid having to copy them to callback methods. | |
| 527 flash_lso_helper_->StartFetching(base::Bind( | |
| 528 &BrowsingDataRemoverImpl::OnSitesWithFlashDataFetched, | |
| 529 weak_ptr_factory_.GetWeakPtr(), | |
| 530 filter_builder.BuildPluginFilter())); | |
| 531 } | |
| 532 } | |
| 533 #endif | |
| 534 | |
| 535 ////////////////////////////////////////////////////////////////////////////// | |
| 536 // CACHE | 496 // CACHE |
| 537 if (remove_mask & REMOVE_CACHE) { | 497 if (remove_mask & REMOVE_CACHE) { |
| 538 // Tell the renderers to clear their cache. | 498 // Tell the renderers to clear their cache. |
| 539 web_cache::WebCacheManager::GetInstance()->ClearCache(); | 499 web_cache::WebCacheManager::GetInstance()->ClearCache(); |
| 540 | 500 |
| 541 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); | 501 content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); |
| 542 | 502 |
| 543 clear_cache_.Start(); | 503 clear_cache_.Start(); |
| 544 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. | 504 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. |
| 545 if (filter_builder.IsEmptyBlacklist()) { | 505 if (filter_builder.IsEmptyBlacklist()) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 558 |
| 599 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { | 559 void BrowsingDataRemoverImpl::RemoveObserver(Observer* observer) { |
| 600 observer_list_.RemoveObserver(observer); | 560 observer_list_.RemoveObserver(observer); |
| 601 } | 561 } |
| 602 | 562 |
| 603 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( | 563 void BrowsingDataRemoverImpl::OverrideStoragePartitionForTesting( |
| 604 content::StoragePartition* storage_partition) { | 564 content::StoragePartition* storage_partition) { |
| 605 storage_partition_for_testing_ = storage_partition; | 565 storage_partition_for_testing_ = storage_partition; |
| 606 } | 566 } |
| 607 | 567 |
| 608 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 609 void BrowsingDataRemoverImpl::OverrideFlashLSOHelperForTesting( | |
| 610 scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper) { | |
| 611 flash_lso_helper_ = flash_lso_helper; | |
| 612 } | |
| 613 #endif | |
| 614 | |
| 615 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { | 568 const base::Time& BrowsingDataRemoverImpl::GetLastUsedBeginTime() { |
| 616 return delete_begin_; | 569 return delete_begin_; |
| 617 } | 570 } |
| 618 | 571 |
| 619 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { | 572 const base::Time& BrowsingDataRemoverImpl::GetLastUsedEndTime() { |
| 620 return delete_end_; | 573 return delete_end_; |
| 621 } | 574 } |
| 622 | 575 |
| 623 int BrowsingDataRemoverImpl::GetLastUsedRemovalMask() { | 576 int BrowsingDataRemoverImpl::GetLastUsedRemovalMask() { |
| 624 return remove_mask_; | 577 return remove_mask_; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 643 observer(observer) {} | 596 observer(observer) {} |
| 644 | 597 |
| 645 BrowsingDataRemoverImpl::RemovalTask::~RemovalTask() {} | 598 BrowsingDataRemoverImpl::RemovalTask::~RemovalTask() {} |
| 646 | 599 |
| 647 bool BrowsingDataRemoverImpl::AllDone() { | 600 bool BrowsingDataRemoverImpl::AllDone() { |
| 648 return !synchronous_clear_operations_.is_pending() && | 601 return !synchronous_clear_operations_.is_pending() && |
| 649 !clear_embedder_data_.is_pending() && | 602 !clear_embedder_data_.is_pending() && |
| 650 !clear_cache_.is_pending() && | 603 !clear_cache_.is_pending() && |
| 651 !clear_channel_ids_.is_pending() && | 604 !clear_channel_ids_.is_pending() && |
| 652 !clear_http_auth_cache_.is_pending() && | 605 !clear_http_auth_cache_.is_pending() && |
| 653 !clear_storage_partition_data_.is_pending() && | 606 !clear_storage_partition_data_.is_pending(); |
| 654 !clear_plugin_data_count_; | |
| 655 } | 607 } |
| 656 | 608 |
| 657 void BrowsingDataRemoverImpl::Notify() { | 609 void BrowsingDataRemoverImpl::Notify() { |
| 658 // Some tests call |RemoveImpl| directly, without using the task scheduler. | 610 // Some tests call |RemoveImpl| directly, without using the task scheduler. |
| 659 // TODO(msramek): Improve those tests so we don't have to do this. Tests | 611 // TODO(msramek): Improve those tests so we don't have to do this. Tests |
| 660 // relying on |RemoveImpl| do so because they need to pass in | 612 // relying on |RemoveImpl| do so because they need to pass in |
| 661 // BrowsingDataFilterBuilder while still keeping ownership of it. Making | 613 // BrowsingDataFilterBuilder while still keeping ownership of it. Making |
| 662 // BrowsingDataFilterBuilder copyable would solve this. | 614 // BrowsingDataFilterBuilder copyable would solve this. |
| 663 if (!is_removing_) { | 615 if (!is_removing_) { |
| 664 DCHECK(task_queue_.empty()); | 616 DCHECK(task_queue_.empty()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 | 653 |
| 702 if (completion_inhibitor_) { | 654 if (completion_inhibitor_) { |
| 703 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( | 655 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( |
| 704 this, base::Bind(&BrowsingDataRemoverImpl::Notify, | 656 this, base::Bind(&BrowsingDataRemoverImpl::Notify, |
| 705 weak_ptr_factory_.GetWeakPtr())); | 657 weak_ptr_factory_.GetWeakPtr())); |
| 706 return; | 658 return; |
| 707 } | 659 } |
| 708 | 660 |
| 709 Notify(); | 661 Notify(); |
| 710 } | 662 } |
| 711 | |
| 712 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 713 void BrowsingDataRemoverImpl::OnWaitableEventSignaled( | |
| 714 base::WaitableEvent* waitable_event) { | |
| 715 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 716 | |
| 717 DCHECK_EQ(1, clear_plugin_data_count_); | |
| 718 clear_plugin_data_count_ = 0; | |
| 719 | |
| 720 plugin_data_remover_.reset(); | |
| 721 watcher_.StopWatching(); | |
| 722 NotifyIfDone(); | |
| 723 } | |
| 724 | |
| 725 void BrowsingDataRemoverImpl::OnSitesWithFlashDataFetched( | |
| 726 base::Callback<bool(const std::string&)> plugin_filter, | |
| 727 const std::vector<std::string>& sites) { | |
| 728 DCHECK_EQ(1, clear_plugin_data_count_); | |
| 729 clear_plugin_data_count_ = 0; | |
| 730 | |
| 731 std::vector<std::string> sites_to_delete; | |
| 732 for (const std::string& site : sites) { | |
| 733 if (plugin_filter.Run(site)) | |
| 734 sites_to_delete.push_back(site); | |
| 735 } | |
| 736 | |
| 737 clear_plugin_data_count_ = sites_to_delete.size(); | |
| 738 | |
| 739 for (const std::string& site : sites_to_delete) { | |
| 740 flash_lso_helper_->DeleteFlashLSOsForSite( | |
| 741 site, | |
| 742 base::Bind(&BrowsingDataRemoverImpl::OnFlashDataDeleted, | |
| 743 weak_ptr_factory_.GetWeakPtr())); | |
| 744 } | |
| 745 | |
| 746 NotifyIfDone(); | |
| 747 } | |
| 748 | |
| 749 void BrowsingDataRemoverImpl::OnFlashDataDeleted() { | |
| 750 clear_plugin_data_count_--; | |
| 751 NotifyIfDone(); | |
| 752 } | |
| 753 #endif | |
| OLD | NEW |