| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 callback.Run(); | 53 callback.Run(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Another convenience method to turn a callback without arguments into one that | 56 // Another convenience method to turn a callback without arguments into one that |
| 57 // accepts (and ignores) a single argument. | 57 // accepts (and ignores) a single argument. |
| 58 template <typename T> | 58 template <typename T> |
| 59 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { | 59 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { |
| 60 return base::Bind(&IgnoreArgumentHelper<T>, callback); | 60 return base::Bind(&IgnoreArgumentHelper<T>, callback); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool DoesOriginMatchMaskAndUrls( | 63 // Returns whether |origin| matches |origin_type_mask| given the special |
| 64 const base::WeakPtr<BrowsingDataRemoverImpl>& remover_weak_ptr, | 64 // storage |policy|; and if |predicate| is not null, then also whether |
| 65 // it matches |predicate|. If |origin_type_mask| contains embedder-specific |
| 66 // datatypes, |embedder_matcher| must not be null; the decision for those |
| 67 // datatypes will be delegated to it. |
| 68 bool DoesOriginMatchMaskAndURLs( |
| 65 int origin_type_mask, | 69 int origin_type_mask, |
| 66 const base::Callback<bool(const GURL&)>& predicate, | 70 const base::Callback<bool(const GURL&)>& predicate, |
| 71 const BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher& |
| 72 embedder_matcher, |
| 67 const GURL& origin, | 73 const GURL& origin, |
| 68 storage::SpecialStoragePolicy* special_storage_policy) { | 74 storage::SpecialStoragePolicy* policy) { |
| 69 // If BrowsingDataRemoverImpl is null, it is not possible to determine which | 75 if (!predicate.is_null() && !predicate.Run(origin)) |
| 70 // origins should have their data deleted, and so we do not delete | |
| 71 // anything. This is not a problem, because this can only happen shortly | |
| 72 // before shutdown and thus the deletion would likely not be able to | |
| 73 // finish anyway. | |
| 74 if (!remover_weak_ptr) | |
| 75 return false; | 76 return false; |
| 76 | 77 |
| 77 return predicate.Run(origin) && | 78 const std::vector<std::string>& schemes = url::GetWebStorageSchemes(); |
| 78 remover_weak_ptr->DoesOriginMatchMask(origin_type_mask, origin, | 79 bool is_web_scheme = |
| 79 special_storage_policy); | 80 (std::find(schemes.begin(), schemes.end(), origin.GetOrigin().scheme()) != |
| 81 schemes.end()); |
| 82 |
| 83 // If a websafe origin is unprotected, it matches iff UNPROTECTED_WEB. |
| 84 if ((!policy || !policy->IsStorageProtected(origin.GetOrigin())) && |
| 85 is_web_scheme && |
| 86 (origin_type_mask & BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB)) { |
| 87 return true; |
| 88 } |
| 89 origin_type_mask &= ~BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; |
| 90 |
| 91 // Hosted applications (protected and websafe origins) iff PROTECTED_WEB. |
| 92 if (policy && policy->IsStorageProtected(origin.GetOrigin()) && |
| 93 is_web_scheme && |
| 94 (origin_type_mask & BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB)) { |
| 95 return true; |
| 96 } |
| 97 origin_type_mask &= ~BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; |
| 98 |
| 99 DCHECK(embedder_matcher || !origin_type_mask) |
| 100 << "The mask contains embedder-defined origin types, but there is no " |
| 101 << "embedder delegate matcher to process them."; |
| 102 |
| 103 if (!embedder_matcher.is_null()) |
| 104 return embedder_matcher.Run(origin_type_mask, origin, policy); |
| 105 |
| 106 return false; |
| 80 } | 107 } |
| 81 | 108 |
| 82 void ClearHttpAuthCacheOnIOThread( | 109 void ClearHttpAuthCacheOnIOThread( |
| 83 scoped_refptr<net::URLRequestContextGetter> context_getter, | 110 scoped_refptr<net::URLRequestContextGetter> context_getter, |
| 84 base::Time delete_begin) { | 111 base::Time delete_begin) { |
| 85 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 112 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 86 | 113 |
| 87 net::HttpNetworkSession* http_session = context_getter->GetURLRequestContext() | 114 net::HttpNetworkSession* http_session = context_getter->GetURLRequestContext() |
| 88 ->http_transaction_factory() | 115 ->http_transaction_factory() |
| 89 ->GetSession(); | 116 ->GetSession(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 233 |
| 207 BrowsingDataRemoverDelegate* | 234 BrowsingDataRemoverDelegate* |
| 208 BrowsingDataRemoverImpl::GetEmbedderDelegate() const { | 235 BrowsingDataRemoverImpl::GetEmbedderDelegate() const { |
| 209 return embedder_delegate_.get(); | 236 return embedder_delegate_.get(); |
| 210 } | 237 } |
| 211 | 238 |
| 212 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( | 239 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( |
| 213 int origin_type_mask, | 240 int origin_type_mask, |
| 214 const GURL& origin, | 241 const GURL& origin, |
| 215 storage::SpecialStoragePolicy* policy) const { | 242 storage::SpecialStoragePolicy* policy) const { |
| 216 const std::vector<std::string>& schemes = url::GetWebStorageSchemes(); | 243 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; |
| 217 bool is_web_scheme = | 244 if (embedder_delegate_) |
| 218 (std::find(schemes.begin(), schemes.end(), origin.GetOrigin().scheme()) != | 245 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); |
| 219 schemes.end()); | |
| 220 | 246 |
| 221 // If a websafe origin is unprotected, it matches iff UNPROTECTED_WEB. | 247 return DoesOriginMatchMaskAndURLs(origin_type_mask, |
| 222 if ((!policy || !policy->IsStorageProtected(origin.GetOrigin())) && | 248 base::Callback<bool(const GURL&)>(), |
| 223 is_web_scheme && (origin_type_mask & ORIGIN_TYPE_UNPROTECTED_WEB)) { | 249 embedder_matcher, origin, policy); |
| 224 return true; | |
| 225 } | |
| 226 origin_type_mask &= ~ORIGIN_TYPE_UNPROTECTED_WEB; | |
| 227 | |
| 228 // Hosted applications (protected and websafe origins) iff PROTECTED_WEB. | |
| 229 if (policy && policy->IsStorageProtected(origin.GetOrigin()) && | |
| 230 is_web_scheme && (origin_type_mask & ORIGIN_TYPE_PROTECTED_WEB)) { | |
| 231 return true; | |
| 232 } | |
| 233 origin_type_mask &= ~ORIGIN_TYPE_PROTECTED_WEB; | |
| 234 | |
| 235 DCHECK(embedder_delegate_ || !origin_type_mask) | |
| 236 << "The mask contains embedder-defined origin types, but there is no " | |
| 237 << "embedder delegate to process them."; | |
| 238 | |
| 239 if (embedder_delegate_) { | |
| 240 return embedder_delegate_->DoesOriginMatchEmbedderMask(origin_type_mask, | |
| 241 origin, policy); | |
| 242 } | |
| 243 | |
| 244 return false; | |
| 245 } | 250 } |
| 246 | 251 |
| 247 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, | 252 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, |
| 248 const base::Time& delete_end, | 253 const base::Time& delete_end, |
| 249 int remove_mask, | 254 int remove_mask, |
| 250 int origin_type_mask) { | 255 int origin_type_mask) { |
| 251 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, | 256 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, |
| 252 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); | 257 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); |
| 253 } | 258 } |
| 254 | 259 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 499 |
| 495 // If cookies are supposed to be conditionally deleted from the storage | 500 // If cookies are supposed to be conditionally deleted from the storage |
| 496 // partition, create a cookie matcher function. | 501 // partition, create a cookie matcher function. |
| 497 content::StoragePartition::CookieMatcherFunction cookie_matcher; | 502 content::StoragePartition::CookieMatcherFunction cookie_matcher; |
| 498 if (!filter_builder.IsEmptyBlacklist() && | 503 if (!filter_builder.IsEmptyBlacklist() && |
| 499 (storage_partition_remove_mask & | 504 (storage_partition_remove_mask & |
| 500 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) { | 505 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) { |
| 501 cookie_matcher = filter_builder.BuildCookieFilter(); | 506 cookie_matcher = filter_builder.BuildCookieFilter(); |
| 502 } | 507 } |
| 503 | 508 |
| 509 BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher embedder_matcher; |
| 510 if (embedder_delegate_) |
| 511 embedder_matcher = embedder_delegate_->GetOriginTypeMatcher(); |
| 512 |
| 504 storage_partition->ClearData( | 513 storage_partition->ClearData( |
| 505 storage_partition_remove_mask, quota_storage_remove_mask, | 514 storage_partition_remove_mask, quota_storage_remove_mask, |
| 506 base::Bind(&DoesOriginMatchMaskAndUrls, weak_ptr_factory_.GetWeakPtr(), | 515 base::Bind(&DoesOriginMatchMaskAndURLs, origin_type_mask_, filter, |
| 507 origin_type_mask_, filter), | 516 embedder_matcher), |
| 508 cookie_matcher, delete_begin_, delete_end_, | 517 cookie_matcher, delete_begin_, delete_end_, |
| 509 clear_storage_partition_data_.GetCompletionCallback()); | 518 clear_storage_partition_data_.GetCompletionCallback()); |
| 510 } | 519 } |
| 511 | 520 |
| 512 ////////////////////////////////////////////////////////////////////////////// | 521 ////////////////////////////////////////////////////////////////////////////// |
| 513 // CACHE | 522 // CACHE |
| 514 if (remove_mask & DATA_TYPE_CACHE) { | 523 if (remove_mask & DATA_TYPE_CACHE) { |
| 515 base::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); | 524 base::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); |
| 516 | 525 |
| 517 // TODO(msramek): Clear the cache of all renderers. | 526 // TODO(msramek): Clear the cache of all renderers. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 // All removal tasks have finished. Inform the observers that we're idle. | 649 // All removal tasks have finished. Inform the observers that we're idle. |
| 641 SetRemoving(false); | 650 SetRemoving(false); |
| 642 return; | 651 return; |
| 643 } | 652 } |
| 644 | 653 |
| 645 // Yield to the UI thread before executing the next removal task. | 654 // Yield to the UI thread before executing the next removal task. |
| 646 // TODO(msramek): Consider also adding a backoff if too many tasks | 655 // TODO(msramek): Consider also adding a backoff if too many tasks |
| 647 // are scheduled. | 656 // are scheduled. |
| 648 BrowserThread::PostTask( | 657 BrowserThread::PostTask( |
| 649 BrowserThread::UI, FROM_HERE, | 658 BrowserThread::UI, FROM_HERE, |
| 650 base::Bind(&BrowsingDataRemoverImpl::RunNextTask, | 659 base::Bind(&BrowsingDataRemoverImpl::RunNextTask, GetWeakPtr())); |
| 651 weak_ptr_factory_.GetWeakPtr())); | |
| 652 } | 660 } |
| 653 | 661 |
| 654 void BrowsingDataRemoverImpl::NotifyIfDone() { | 662 void BrowsingDataRemoverImpl::NotifyIfDone() { |
| 655 // TODO(brettw) http://crbug.com/305259: This should also observe session | 663 // TODO(brettw) http://crbug.com/305259: This should also observe session |
| 656 // clearing (what about other things such as passwords, etc.?) and wait for | 664 // clearing (what about other things such as passwords, etc.?) and wait for |
| 657 // them to complete before continuing. | 665 // them to complete before continuing. |
| 658 | 666 |
| 659 if (!AllDone()) | 667 if (!AllDone()) |
| 660 return; | 668 return; |
| 661 | 669 |
| 662 if (completion_inhibitor_) { | 670 if (completion_inhibitor_) { |
| 663 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( | 671 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( |
| 664 this, base::Bind(&BrowsingDataRemoverImpl::Notify, | 672 this, base::Bind(&BrowsingDataRemoverImpl::Notify, GetWeakPtr())); |
| 665 weak_ptr_factory_.GetWeakPtr())); | |
| 666 return; | 673 return; |
| 667 } | 674 } |
| 668 | 675 |
| 669 Notify(); | 676 Notify(); |
| 670 } | 677 } |
| 678 |
| 679 base::WeakPtr<BrowsingDataRemoverImpl> BrowsingDataRemoverImpl::GetWeakPtr() { |
| 680 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 681 base::WeakPtr<BrowsingDataRemoverImpl> weak_ptr = |
| 682 weak_ptr_factory_.GetWeakPtr(); |
| 683 |
| 684 // Immediately bind the weak pointer to the UI thread. This makes it easier |
| 685 // to discover potential misuse on the IO thread. |
| 686 weak_ptr.get(); |
| 687 |
| 688 return weak_ptr; |
| 689 } |
| OLD | NEW |