| 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_remover.h" | 5 #include "chrome/browser/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "net/base/server_bound_cert_service.h" | 54 #include "net/base/server_bound_cert_service.h" |
| 55 #include "net/base/server_bound_cert_store.h" | 55 #include "net/base/server_bound_cert_store.h" |
| 56 #include "net/base/transport_security_state.h" | 56 #include "net/base/transport_security_state.h" |
| 57 #include "net/cookies/cookie_store.h" | 57 #include "net/cookies/cookie_store.h" |
| 58 #include "net/disk_cache/disk_cache.h" | 58 #include "net/disk_cache/disk_cache.h" |
| 59 #include "net/http/http_cache.h" | 59 #include "net/http/http_cache.h" |
| 60 #include "net/url_request/url_request_context.h" | 60 #include "net/url_request/url_request_context.h" |
| 61 #include "net/url_request/url_request_context_getter.h" | 61 #include "net/url_request/url_request_context_getter.h" |
| 62 #include "webkit/quota/quota_manager.h" | 62 #include "webkit/quota/quota_manager.h" |
| 63 #include "webkit/quota/quota_types.h" | 63 #include "webkit/quota/quota_types.h" |
| 64 #include "webkit/quota/special_storage_policy.h" |
| 64 | 65 |
| 65 using content::BrowserContext; | 66 using content::BrowserContext; |
| 66 using content::BrowserThread; | 67 using content::BrowserThread; |
| 67 using content::DOMStorageContext; | 68 using content::DOMStorageContext; |
| 68 using content::DownloadManager; | 69 using content::DownloadManager; |
| 69 using content::UserMetricsAction; | 70 using content::UserMetricsAction; |
| 70 | 71 |
| 72 namespace { |
| 73 |
| 74 // Converts BrowsingDataRemover::OriginSetMask data to |
| 75 // quota::SpecialStoragePolicy::OriginType data. |
| 76 int GetDomStorageContextMask(int origin_set_mask) { |
| 77 int result = 0; |
| 78 if (origin_set_mask & BrowsingDataRemover::PROTECTED_WEB) |
| 79 result |= quota::SpecialStoragePolicy::PROTECTED_WEB; |
| 80 if (origin_set_mask & BrowsingDataRemover::UNPROTECTED_WEB) |
| 81 result |= quota::SpecialStoragePolicy::UNPROTECTED_WEB; |
| 82 if (origin_set_mask & BrowsingDataRemover::EXTENSION) |
| 83 result |= quota::SpecialStoragePolicy::EXTENSION; |
| 84 return result; |
| 85 } |
| 86 |
| 87 } // namespace |
| 88 |
| 71 bool BrowsingDataRemover::removing_ = false; | 89 bool BrowsingDataRemover::removing_ = false; |
| 72 | 90 |
| 73 BrowsingDataRemover::NotificationDetails::NotificationDetails() | 91 BrowsingDataRemover::NotificationDetails::NotificationDetails() |
| 74 : removal_begin(base::Time()), | 92 : removal_begin(base::Time()), |
| 75 removal_mask(-1) { | 93 removal_mask(-1) { |
| 76 } | 94 } |
| 77 | 95 |
| 78 BrowsingDataRemover::NotificationDetails::NotificationDetails( | 96 BrowsingDataRemover::NotificationDetails::NotificationDetails( |
| 79 const BrowsingDataRemover::NotificationDetails& details) | 97 const BrowsingDataRemover::NotificationDetails& details) |
| 80 : removal_begin(details.removal_begin), | 98 : removal_begin(details.removal_begin), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 104 media_context_getter_(profile->GetRequestContextForMedia()), | 122 media_context_getter_(profile->GetRequestContextForMedia()), |
| 105 waiting_for_clear_cache_(false), | 123 waiting_for_clear_cache_(false), |
| 106 waiting_for_clear_cookies_count_(0), | 124 waiting_for_clear_cookies_count_(0), |
| 107 waiting_for_clear_history_(false), | 125 waiting_for_clear_history_(false), |
| 108 waiting_for_clear_networking_history_(false), | 126 waiting_for_clear_networking_history_(false), |
| 109 waiting_for_clear_server_bound_certs_(false), | 127 waiting_for_clear_server_bound_certs_(false), |
| 110 waiting_for_clear_plugin_data_(false), | 128 waiting_for_clear_plugin_data_(false), |
| 111 waiting_for_clear_quota_managed_data_(false), | 129 waiting_for_clear_quota_managed_data_(false), |
| 112 remove_mask_(0), | 130 remove_mask_(0), |
| 113 remove_origin_(GURL()), | 131 remove_origin_(GURL()), |
| 114 remove_protected_(false) { | 132 origin_set_mask_(0) { |
| 115 DCHECK(profile); | 133 DCHECK(profile); |
| 116 } | 134 } |
| 117 | 135 |
| 118 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, | 136 BrowsingDataRemover::BrowsingDataRemover(Profile* profile, |
| 119 TimePeriod time_period, | 137 TimePeriod time_period, |
| 120 base::Time delete_end) | 138 base::Time delete_end) |
| 121 : profile_(profile), | 139 : profile_(profile), |
| 122 quota_manager_(NULL), | 140 quota_manager_(NULL), |
| 123 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), | 141 special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), |
| 124 delete_begin_(CalculateBeginDeleteTime(time_period)), | 142 delete_begin_(CalculateBeginDeleteTime(time_period)), |
| 125 delete_end_(delete_end), | 143 delete_end_(delete_end), |
| 126 next_cache_state_(STATE_NONE), | 144 next_cache_state_(STATE_NONE), |
| 127 cache_(NULL), | 145 cache_(NULL), |
| 128 main_context_getter_(profile->GetRequestContext()), | 146 main_context_getter_(profile->GetRequestContext()), |
| 129 media_context_getter_(profile->GetRequestContextForMedia()), | 147 media_context_getter_(profile->GetRequestContextForMedia()), |
| 130 waiting_for_clear_cache_(false), | 148 waiting_for_clear_cache_(false), |
| 131 waiting_for_clear_cookies_count_(0), | 149 waiting_for_clear_cookies_count_(0), |
| 132 waiting_for_clear_history_(false), | 150 waiting_for_clear_history_(false), |
| 133 waiting_for_clear_networking_history_(false), | 151 waiting_for_clear_networking_history_(false), |
| 134 waiting_for_clear_server_bound_certs_(false), | 152 waiting_for_clear_server_bound_certs_(false), |
| 135 waiting_for_clear_plugin_data_(false), | 153 waiting_for_clear_plugin_data_(false), |
| 136 waiting_for_clear_quota_managed_data_(false), | 154 waiting_for_clear_quota_managed_data_(false), |
| 137 remove_mask_(0), | 155 remove_mask_(0), |
| 138 remove_origin_(GURL()), | 156 remove_origin_(GURL()), |
| 139 remove_protected_(false) { | 157 origin_set_mask_(0) { |
| 140 DCHECK(profile); | 158 DCHECK(profile); |
| 141 } | 159 } |
| 142 | 160 |
| 143 BrowsingDataRemover::~BrowsingDataRemover() { | 161 BrowsingDataRemover::~BrowsingDataRemover() { |
| 144 DCHECK(all_done()); | 162 DCHECK(all_done()); |
| 145 } | 163 } |
| 146 | 164 |
| 147 // Static. | 165 // Static. |
| 148 void BrowsingDataRemover::set_removing(bool removing) { | 166 void BrowsingDataRemover::set_removing(bool removing) { |
| 149 DCHECK(removing_ != removing); | 167 DCHECK(removing_ != removing); |
| 150 removing_ = removing; | 168 removing_ = removing; |
| 151 } | 169 } |
| 152 | 170 |
| 153 // Static. | 171 // Static. |
| 154 int BrowsingDataRemover::GenerateQuotaClientMask(int remove_mask) { | 172 int BrowsingDataRemover::GenerateQuotaClientMask(int remove_mask) { |
| 155 int quota_client_mask = 0; | 173 int quota_client_mask = 0; |
| 156 if (remove_mask & BrowsingDataRemover::REMOVE_FILE_SYSTEMS) | 174 if (remove_mask & BrowsingDataRemover::REMOVE_FILE_SYSTEMS) |
| 157 quota_client_mask |= quota::QuotaClient::kFileSystem; | 175 quota_client_mask |= quota::QuotaClient::kFileSystem; |
| 158 if (remove_mask & BrowsingDataRemover::REMOVE_WEBSQL) | 176 if (remove_mask & BrowsingDataRemover::REMOVE_WEBSQL) |
| 159 quota_client_mask |= quota::QuotaClient::kDatabase; | 177 quota_client_mask |= quota::QuotaClient::kDatabase; |
| 160 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) | 178 if (remove_mask & BrowsingDataRemover::REMOVE_APPCACHE) |
| 161 quota_client_mask |= quota::QuotaClient::kAppcache; | 179 quota_client_mask |= quota::QuotaClient::kAppcache; |
| 162 if (remove_mask & BrowsingDataRemover::REMOVE_INDEXEDDB) | 180 if (remove_mask & BrowsingDataRemover::REMOVE_INDEXEDDB) |
| 163 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; | 181 quota_client_mask |= quota::QuotaClient::kIndexedDatabase; |
| 164 | 182 |
| 165 return quota_client_mask; | 183 return quota_client_mask; |
| 166 } | 184 } |
| 167 | 185 |
| 168 void BrowsingDataRemover::Remove(int remove_mask) { | 186 void BrowsingDataRemover::Remove(int remove_mask, int origin_set_mask) { |
| 169 RemoveImpl(remove_mask, GURL(), false); | 187 RemoveImpl(remove_mask, GURL(), origin_set_mask); |
| 170 } | 188 } |
| 171 | 189 |
| 172 void BrowsingDataRemover::RemoveImpl(int remove_mask, | 190 void BrowsingDataRemover::RemoveImpl(int remove_mask, |
| 173 const GURL& origin, | 191 const GURL& origin, |
| 174 bool remove_protected_origins) { | 192 int origin_set_mask) { |
| 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 176 set_removing(true); | 194 set_removing(true); |
| 177 remove_mask_ = remove_mask; | 195 remove_mask_ = remove_mask; |
| 178 remove_origin_ = origin; | 196 remove_origin_ = origin; |
| 179 remove_protected_ = remove_protected_origins; | 197 origin_set_mask_ = origin_set_mask; |
| 180 | 198 |
| 181 if (remove_mask & REMOVE_HISTORY) { | 199 if (remove_mask & REMOVE_HISTORY) { |
| 182 HistoryService* history_service = | 200 HistoryService* history_service = |
| 183 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 201 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 184 if (history_service) { | 202 if (history_service) { |
| 185 std::set<GURL> restrict_urls; | 203 std::set<GURL> restrict_urls; |
| 186 if (!remove_origin_.is_empty()) | 204 if (!remove_origin_.is_empty()) |
| 187 restrict_urls.insert(remove_origin_); | 205 restrict_urls.insert(remove_origin_); |
| 188 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); | 206 content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); |
| 189 waiting_for_clear_history_ = true; | 207 waiting_for_clear_history_ = true; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 waiting_for_clear_server_bound_certs_ = true; | 319 waiting_for_clear_server_bound_certs_ = true; |
| 302 BrowserThread::PostTask( | 320 BrowserThread::PostTask( |
| 303 BrowserThread::IO, FROM_HERE, | 321 BrowserThread::IO, FROM_HERE, |
| 304 base::Bind(&BrowsingDataRemover::ClearServerBoundCertsOnIOThread, | 322 base::Bind(&BrowsingDataRemover::ClearServerBoundCertsOnIOThread, |
| 305 base::Unretained(this), base::Unretained(rq_context))); | 323 base::Unretained(this), base::Unretained(rq_context))); |
| 306 } | 324 } |
| 307 } | 325 } |
| 308 | 326 |
| 309 if (remove_mask & REMOVE_LOCAL_STORAGE) { | 327 if (remove_mask & REMOVE_LOCAL_STORAGE) { |
| 310 BrowserContext::GetDOMStorageContext(profile_)->DeleteDataModifiedSince( | 328 BrowserContext::GetDOMStorageContext(profile_)->DeleteDataModifiedSince( |
| 311 delete_begin_); | 329 delete_begin_, GetDomStorageContextMask(origin_set_mask_)); |
| 312 } | 330 } |
| 313 | 331 |
| 314 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL || | 332 if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL || |
| 315 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) { | 333 remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) { |
| 316 if (!quota_manager_) | 334 if (!quota_manager_) |
| 317 quota_manager_ = content::BrowserContext::GetQuotaManager(profile_); | 335 quota_manager_ = content::BrowserContext::GetQuotaManager(profile_); |
| 318 waiting_for_clear_quota_managed_data_ = true; | 336 waiting_for_clear_quota_managed_data_ = true; |
| 319 BrowserThread::PostTask( | 337 BrowserThread::PostTask( |
| 320 BrowserThread::IO, FROM_HERE, | 338 BrowserThread::IO, FROM_HERE, |
| 321 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, | 339 base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 599 |
| 582 void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() { | 600 void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() { |
| 583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 584 | 602 |
| 585 // Ask the QuotaManager for all origins with temporary quota modified within | 603 // Ask the QuotaManager for all origins with temporary quota modified within |
| 586 // the user-specified timeframe, and deal with the resulting set in | 604 // the user-specified timeframe, and deal with the resulting set in |
| 587 // OnGotQuotaManagedOrigins(). | 605 // OnGotQuotaManagedOrigins(). |
| 588 quota_managed_origins_to_delete_count_ = 0; | 606 quota_managed_origins_to_delete_count_ = 0; |
| 589 quota_managed_storage_types_to_delete_count_ = 2; | 607 quota_managed_storage_types_to_delete_count_ = 2; |
| 590 | 608 |
| 591 if (delete_begin_ == base::Time()) { | 609 if (delete_begin_ == base::Time() || |
| 592 // If we're deleting since the beginning of time, ask the QuotaManager for | 610 origin_set_mask_ & (PROTECTED_WEB | EXTENSION) ) { |
| 593 // all origins with persistent quota modified within the user-specified | 611 // If we're deleting since the beginning of time, or we're removing |
| 594 // timeframe, and deal with the resulting set in | 612 // protected origins, then ask the QuotaManager for all origins with |
| 595 // OnGotPersistentQuotaManagedOrigins. | 613 // persistent quota modified within the user-specified timeframe, and deal |
| 614 // with the resulting set in OnGotPersistentQuotaManagedOrigins. |
| 596 quota_manager_->GetOriginsModifiedSince( | 615 quota_manager_->GetOriginsModifiedSince( |
| 597 quota::kStorageTypePersistent, delete_begin_, | 616 quota::kStorageTypePersistent, delete_begin_, |
| 598 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, | 617 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, |
| 599 base::Unretained(this))); | 618 base::Unretained(this))); |
| 600 } else { | 619 } else { |
| 601 // Otherwise, we don't need to deal with persistent storage. | 620 // Otherwise, we don't need to deal with persistent storage. |
| 602 --quota_managed_storage_types_to_delete_count_; | 621 --quota_managed_storage_types_to_delete_count_; |
| 603 } | 622 } |
| 604 | 623 |
| 605 // Do the same for temporary quota, regardless, passing the resulting set into | 624 if (origin_set_mask_ & UNPROTECTED_WEB) { |
| 606 // OnGotTemporaryQuotaManagedOrigins. | 625 // Do the same for temporary quota, if we're removing unprotected origins, |
| 607 quota_manager_->GetOriginsModifiedSince( | 626 // by passing the resulting set into OnGotTemporaryQuotaManagedOrigins. |
| 608 quota::kStorageTypeTemporary, delete_begin_, | 627 quota_manager_->GetOriginsModifiedSince( |
| 609 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, | 628 quota::kStorageTypeTemporary, delete_begin_, |
| 610 base::Unretained(this))); | 629 base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, |
| 630 base::Unretained(this))); |
| 631 } |
| 611 } | 632 } |
| 612 | 633 |
| 613 void BrowsingDataRemover::OnGotQuotaManagedOrigins( | 634 void BrowsingDataRemover::OnGotQuotaManagedOrigins( |
| 614 const std::set<GURL>& origins, quota::StorageType type) { | 635 const std::set<GURL>& origins, quota::StorageType type) { |
| 615 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0); | 636 DCHECK_GT(quota_managed_storage_types_to_delete_count_, 0); |
| 616 // Walk through the origins passed in, delete quota of |type| from each that | 637 // Walk through the origins passed in, delete quota of |type| from each that |
| 617 // isn't protected. | 638 // matches the |origin_set_mask_|. |
| 618 std::set<GURL>::const_iterator origin; | 639 std::set<GURL>::const_iterator origin; |
| 619 for (origin = origins.begin(); origin != origins.end(); ++origin) { | 640 for (origin = origins.begin(); origin != origins.end(); ++origin) { |
| 620 if (!BrowsingDataHelper::IsValidScheme(origin->scheme())) | |
| 621 continue; | |
| 622 if (special_storage_policy_->IsStorageProtected(origin->GetOrigin())) | |
| 623 continue; | |
| 624 if (!remove_origin_.is_empty() && remove_origin_ != origin->GetOrigin()) | 641 if (!remove_origin_.is_empty() && remove_origin_ != origin->GetOrigin()) |
| 625 continue; | 642 continue; |
| 643 |
| 644 // Skip packaged apps and extensions (non-websafe origin) unless |
| 645 // EXTENSION is set. |
| 646 if (!(origin_set_mask_ & EXTENSION) && |
| 647 !BrowsingDataHelper::IsValidScheme(origin->scheme())) |
| 648 continue; |
| 649 |
| 650 // Skip the open web (unprotected and websafe origins) unless |
| 651 // UNPROTECTED_WEB is set. |
| 652 if (!(origin_set_mask_ & UNPROTECTED_WEB) && |
| 653 special_storage_policy_->IsStorageProtected(origin->GetOrigin())) |
| 654 continue; |
| 655 |
| 656 // Skip hosted applications (protected and websafe origins) unless |
| 657 // PROTECTED_WEB is set. |
| 658 if (!(origin_set_mask_ & PROTECTED_WEB) && |
| 659 BrowsingDataHelper::IsValidScheme(origin->scheme()) && |
| 660 special_storage_policy_->IsStorageProtected(origin->GetOrigin())) |
| 661 continue; |
| 662 |
| 626 ++quota_managed_origins_to_delete_count_; | 663 ++quota_managed_origins_to_delete_count_; |
| 627 quota_manager_->DeleteOriginData( | 664 quota_manager_->DeleteOriginData( |
| 628 origin->GetOrigin(), type, | 665 origin->GetOrigin(), type, |
| 629 BrowsingDataRemover::GenerateQuotaClientMask(remove_mask_), | 666 BrowsingDataRemover::GenerateQuotaClientMask(remove_mask_), |
| 630 base::Bind(&BrowsingDataRemover::OnQuotaManagedOriginDeletion, | 667 base::Bind(&BrowsingDataRemover::OnQuotaManagedOriginDeletion, |
| 631 base::Unretained(this))); | 668 base::Unretained(this))); |
| 632 } | 669 } |
| 633 | 670 |
| 634 --quota_managed_storage_types_to_delete_count_; | 671 --quota_managed_storage_types_to_delete_count_; |
| 635 CheckQuotaManagedDataDeletionStatus(); | 672 CheckQuotaManagedDataDeletionStatus(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 BrowserThread::UI, FROM_HERE, | 745 BrowserThread::UI, FROM_HERE, |
| 709 base::Bind(&BrowsingDataRemover::OnClearedServerBoundCerts, | 746 base::Bind(&BrowsingDataRemover::OnClearedServerBoundCerts, |
| 710 base::Unretained(this))); | 747 base::Unretained(this))); |
| 711 } | 748 } |
| 712 | 749 |
| 713 void BrowsingDataRemover::OnClearedServerBoundCerts() { | 750 void BrowsingDataRemover::OnClearedServerBoundCerts() { |
| 714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 751 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 715 waiting_for_clear_server_bound_certs_ = false; | 752 waiting_for_clear_server_bound_certs_ = false; |
| 716 NotifyAndDeleteIfDone(); | 753 NotifyAndDeleteIfDone(); |
| 717 } | 754 } |
| OLD | NEW |