| 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 "content/browser/storage_partition_impl.h" | 5 #include "content/browser/storage_partition_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 44 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 45 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 46 BrowserThread::UI, FROM_HERE, | 46 BrowserThread::UI, FROM_HERE, |
| 47 base::Bind(&OnClearedCookies, callback, num_deleted)); | 47 base::Bind(&OnClearedCookies, callback, num_deleted)); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 | 50 |
| 51 callback.Run(); | 51 callback.Run(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Cookie matcher and storage_origin are never both populated. |
| 54 void ClearCookiesOnIOThread( | 55 void ClearCookiesOnIOThread( |
| 55 const scoped_refptr<net::URLRequestContextGetter>& rq_context, | 56 const scoped_refptr<net::URLRequestContextGetter>& rq_context, |
| 56 const base::Time begin, | 57 const base::Time begin, const base::Time end, const GURL& storage_origin, |
| 57 const base::Time end, | 58 const StoragePartition::CookieMatcherFunction& cookie_matcher, |
| 58 const GURL& storage_origin, | |
| 59 const base::Closure& callback) { | 59 const base::Closure& callback) { |
| 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 61 net::CookieStore* cookie_store = rq_context-> | 61 net::CookieStore* cookie_store = |
| 62 GetURLRequestContext()->cookie_store(); | 62 rq_context->GetURLRequestContext()->cookie_store(); |
| 63 if (storage_origin.is_empty()) { | 63 if (!cookie_matcher.is_null()) { |
| 64 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( |
| 65 begin, end, cookie_matcher, base::Bind(&OnClearedCookies, callback)); |
| 66 } else if (!storage_origin.is_empty()) { |
| 67 cookie_store->DeleteAllCreatedBetweenForHostAsync( |
| 68 begin, end, storage_origin, base::Bind(&OnClearedCookies, callback)); |
| 69 } else { |
| 64 cookie_store->DeleteAllCreatedBetweenAsync( | 70 cookie_store->DeleteAllCreatedBetweenAsync( |
| 65 begin, | 71 begin, end, base::Bind(&OnClearedCookies, callback)); |
| 66 end, | |
| 67 base::Bind(&OnClearedCookies, callback)); | |
| 68 } else { | |
| 69 cookie_store->DeleteAllCreatedBetweenForHostAsync( | |
| 70 begin, | |
| 71 end, | |
| 72 storage_origin, base::Bind(&OnClearedCookies, callback)); | |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 | 74 |
| 76 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, | 75 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, |
| 77 const base::Closure& callback) { | 76 const base::Closure& callback) { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 79 if (*deletion_task_count == 0) { | 78 if (*deletion_task_count == 0) { |
| 80 delete deletion_task_count; | 79 delete deletion_task_count; |
| 81 callback.Run(); | 80 callback.Run(); |
| 82 } | 81 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 void DecrementTaskCountOnIO(); | 239 void DecrementTaskCountOnIO(); |
| 241 | 240 |
| 242 void ClearDataOnIOThread( | 241 void ClearDataOnIOThread( |
| 243 const scoped_refptr<storage::QuotaManager>& quota_manager, | 242 const scoped_refptr<storage::QuotaManager>& quota_manager, |
| 244 const base::Time begin, | 243 const base::Time begin, |
| 245 const scoped_refptr<storage::SpecialStoragePolicy>& | 244 const scoped_refptr<storage::SpecialStoragePolicy>& |
| 246 special_storage_policy, | 245 special_storage_policy, |
| 247 const StoragePartition::OriginMatcherFunction& origin_matcher); | 246 const StoragePartition::OriginMatcherFunction& origin_matcher); |
| 248 | 247 |
| 249 void ClearOriginsOnIOThread( | 248 void ClearOriginsOnIOThread( |
| 249 |
| 250 storage::QuotaManager* quota_manager, | 250 storage::QuotaManager* quota_manager, |
| 251 const scoped_refptr<storage::SpecialStoragePolicy>& | 251 const scoped_refptr<storage::SpecialStoragePolicy>& |
| 252 special_storage_policy, | 252 special_storage_policy, |
| 253 const StoragePartition::OriginMatcherFunction& origin_matcher, | 253 const StoragePartition::OriginMatcherFunction& origin_matcher, |
| 254 const base::Closure& callback, | 254 const base::Closure& callback, |
| 255 const std::set<GURL>& origins, | 255 const std::set<GURL>& origins, |
| 256 storage::StorageType quota_storage_type); | 256 storage::StorageType quota_storage_type); |
| 257 | 257 |
| 258 // All of these data are accessed on IO thread. | 258 // All of these data are accessed on IO thread. |
| 259 uint32_t remove_mask; | 259 uint32_t remove_mask; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 281 quota_storage_remove_mask(quota_storage_remove_mask), | 281 quota_storage_remove_mask(quota_storage_remove_mask), |
| 282 callback(callback), | 282 callback(callback), |
| 283 task_count(0) {} | 283 task_count(0) {} |
| 284 | 284 |
| 285 void IncrementTaskCountOnUI(); | 285 void IncrementTaskCountOnUI(); |
| 286 void DecrementTaskCountOnUI(); | 286 void DecrementTaskCountOnUI(); |
| 287 | 287 |
| 288 void ClearDataOnUIThread( | 288 void ClearDataOnUIThread( |
| 289 const GURL& storage_origin, | 289 const GURL& storage_origin, |
| 290 const OriginMatcherFunction& origin_matcher, | 290 const OriginMatcherFunction& origin_matcher, |
| 291 const CookieMatcherFunction& cookie_matcher, |
| 291 const base::FilePath& path, | 292 const base::FilePath& path, |
| 292 net::URLRequestContextGetter* rq_context, | 293 net::URLRequestContextGetter* rq_context, |
| 293 DOMStorageContextWrapper* dom_storage_context, | 294 DOMStorageContextWrapper* dom_storage_context, |
| 294 storage::QuotaManager* quota_manager, | 295 storage::QuotaManager* quota_manager, |
| 295 storage::SpecialStoragePolicy* special_storage_policy, | 296 storage::SpecialStoragePolicy* special_storage_policy, |
| 296 WebRTCIdentityStore* webrtc_identity_store, | 297 WebRTCIdentityStore* webrtc_identity_store, |
| 297 const base::Time begin, | 298 const base::Time begin, |
| 298 const base::Time end); | 299 const base::Time end); |
| 299 | 300 |
| 300 void ClearQuotaManagedDataOnIOThread( | 301 void ClearQuotaManagedDataOnIOThread( |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 const mojo::String& origin, | 595 const mojo::String& origin, |
| 595 mojo::InterfaceRequest<LevelDBWrapper> request) { | 596 mojo::InterfaceRequest<LevelDBWrapper> request) { |
| 596 dom_storage_context_->OpenLocalStorage(origin, std::move(request)); | 597 dom_storage_context_->OpenLocalStorage(origin, std::move(request)); |
| 597 } | 598 } |
| 598 | 599 |
| 599 void StoragePartitionImpl::ClearDataImpl( | 600 void StoragePartitionImpl::ClearDataImpl( |
| 600 uint32_t remove_mask, | 601 uint32_t remove_mask, |
| 601 uint32_t quota_storage_remove_mask, | 602 uint32_t quota_storage_remove_mask, |
| 602 const GURL& storage_origin, | 603 const GURL& storage_origin, |
| 603 const OriginMatcherFunction& origin_matcher, | 604 const OriginMatcherFunction& origin_matcher, |
| 605 const CookieMatcherFunction& cookie_matcher, |
| 604 net::URLRequestContextGetter* rq_context, | 606 net::URLRequestContextGetter* rq_context, |
| 605 const base::Time begin, | 607 const base::Time begin, |
| 606 const base::Time end, | 608 const base::Time end, |
| 607 const base::Closure& callback) { | 609 const base::Closure& callback) { |
| 608 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 610 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 609 DataDeletionHelper* helper = new DataDeletionHelper(remove_mask, | 611 DataDeletionHelper* helper = new DataDeletionHelper(remove_mask, |
| 610 quota_storage_remove_mask, | 612 quota_storage_remove_mask, |
| 611 callback); | 613 callback); |
| 612 // |helper| deletes itself when done in | 614 // |helper| deletes itself when done in |
| 613 // DataDeletionHelper::DecrementTaskCountOnUI(). | 615 // DataDeletionHelper::DecrementTaskCountOnUI(). |
| 614 helper->ClearDataOnUIThread(storage_origin, | 616 helper->ClearDataOnUIThread( |
| 615 origin_matcher, | 617 storage_origin, origin_matcher, cookie_matcher, GetPath(), rq_context, |
| 616 GetPath(), | 618 dom_storage_context_.get(), quota_manager_.get(), |
| 617 rq_context, | 619 special_storage_policy_.get(), webrtc_identity_store_.get(), begin, end); |
| 618 dom_storage_context_.get(), | |
| 619 quota_manager_.get(), | |
| 620 special_storage_policy_.get(), | |
| 621 webrtc_identity_store_.get(), | |
| 622 begin, | |
| 623 end); | |
| 624 } | 620 } |
| 625 | 621 |
| 626 void StoragePartitionImpl:: | 622 void StoragePartitionImpl:: |
| 627 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() { | 623 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() { |
| 628 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 624 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 629 ++task_count; | 625 ++task_count; |
| 630 } | 626 } |
| 631 | 627 |
| 632 void StoragePartitionImpl:: | 628 void StoragePartitionImpl:: |
| 633 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() { | 629 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 --task_count; | 754 --task_count; |
| 759 if (!task_count) { | 755 if (!task_count) { |
| 760 callback.Run(); | 756 callback.Run(); |
| 761 delete this; | 757 delete this; |
| 762 } | 758 } |
| 763 } | 759 } |
| 764 | 760 |
| 765 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( | 761 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( |
| 766 const GURL& storage_origin, | 762 const GURL& storage_origin, |
| 767 const OriginMatcherFunction& origin_matcher, | 763 const OriginMatcherFunction& origin_matcher, |
| 764 const CookieMatcherFunction& cookie_matcher, |
| 768 const base::FilePath& path, | 765 const base::FilePath& path, |
| 769 net::URLRequestContextGetter* rq_context, | 766 net::URLRequestContextGetter* rq_context, |
| 770 DOMStorageContextWrapper* dom_storage_context, | 767 DOMStorageContextWrapper* dom_storage_context, |
| 771 storage::QuotaManager* quota_manager, | 768 storage::QuotaManager* quota_manager, |
| 772 storage::SpecialStoragePolicy* special_storage_policy, | 769 storage::SpecialStoragePolicy* special_storage_policy, |
| 773 WebRTCIdentityStore* webrtc_identity_store, | 770 WebRTCIdentityStore* webrtc_identity_store, |
| 774 const base::Time begin, | 771 const base::Time begin, |
| 775 const base::Time end) { | 772 const base::Time end) { |
| 776 DCHECK_NE(remove_mask, 0u); | 773 DCHECK_NE(remove_mask, 0u); |
| 777 DCHECK(!callback.is_null()); | 774 DCHECK(!callback.is_null()); |
| 778 | 775 |
| 779 IncrementTaskCountOnUI(); | 776 IncrementTaskCountOnUI(); |
| 780 base::Closure decrement_callback = base::Bind( | 777 base::Closure decrement_callback = base::Bind( |
| 781 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); | 778 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); |
| 782 | 779 |
| 783 if (remove_mask & REMOVE_DATA_MASK_COOKIES) { | 780 if (remove_mask & REMOVE_DATA_MASK_COOKIES) { |
| 784 // Handle the cookies. | 781 // Handle the cookies. |
| 785 IncrementTaskCountOnUI(); | 782 IncrementTaskCountOnUI(); |
| 786 BrowserThread::PostTask( | 783 BrowserThread::PostTask( |
| 787 BrowserThread::IO, FROM_HERE, | 784 BrowserThread::IO, FROM_HERE, |
| 788 base::Bind(&ClearCookiesOnIOThread, | 785 base::Bind(&ClearCookiesOnIOThread, make_scoped_refptr(rq_context), |
| 789 make_scoped_refptr(rq_context), begin, end, storage_origin, | 786 begin, end, storage_origin, cookie_matcher, |
| 790 decrement_callback)); | 787 decrement_callback)); |
| 791 } | 788 } |
| 792 | 789 |
| 793 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || | 790 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || |
| 794 remove_mask & REMOVE_DATA_MASK_WEBSQL || | 791 remove_mask & REMOVE_DATA_MASK_WEBSQL || |
| 795 remove_mask & REMOVE_DATA_MASK_APPCACHE || | 792 remove_mask & REMOVE_DATA_MASK_APPCACHE || |
| 796 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS || | 793 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS || |
| 797 remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS || | 794 remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS || |
| 798 remove_mask & REMOVE_DATA_MASK_CACHE_STORAGE) { | 795 remove_mask & REMOVE_DATA_MASK_CACHE_STORAGE) { |
| 799 IncrementTaskCountOnUI(); | 796 IncrementTaskCountOnUI(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 DecrementTaskCountOnUI(); | 851 DecrementTaskCountOnUI(); |
| 855 } | 852 } |
| 856 | 853 |
| 857 void StoragePartitionImpl::ClearDataForOrigin( | 854 void StoragePartitionImpl::ClearDataForOrigin( |
| 858 uint32_t remove_mask, | 855 uint32_t remove_mask, |
| 859 uint32_t quota_storage_remove_mask, | 856 uint32_t quota_storage_remove_mask, |
| 860 const GURL& storage_origin, | 857 const GURL& storage_origin, |
| 861 net::URLRequestContextGetter* request_context_getter, | 858 net::URLRequestContextGetter* request_context_getter, |
| 862 const base::Closure& callback) { | 859 const base::Closure& callback) { |
| 863 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 860 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 864 ClearDataImpl(remove_mask, | 861 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, |
| 865 quota_storage_remove_mask, | 862 OriginMatcherFunction(), CookieMatcherFunction(), |
| 866 storage_origin, | 863 request_context_getter, base::Time(), base::Time::Max(), |
| 867 OriginMatcherFunction(), | |
| 868 request_context_getter, | |
| 869 base::Time(), | |
| 870 base::Time::Max(), | |
| 871 callback); | 864 callback); |
| 872 } | 865 } |
| 873 | 866 |
| 874 void StoragePartitionImpl::ClearData( | 867 void StoragePartitionImpl::ClearData( |
| 875 uint32_t remove_mask, | 868 uint32_t remove_mask, |
| 876 uint32_t quota_storage_remove_mask, | 869 uint32_t quota_storage_remove_mask, |
| 877 const GURL& storage_origin, | 870 const GURL& storage_origin, |
| 878 const OriginMatcherFunction& origin_matcher, | 871 const OriginMatcherFunction& origin_matcher, |
| 879 const base::Time begin, | 872 const base::Time begin, |
| 880 const base::Time end, | 873 const base::Time end, |
| 881 const base::Closure& callback) { | 874 const base::Closure& callback) { |
| 882 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, | 875 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, |
| 883 origin_matcher, GetURLRequestContext(), begin, end, callback); | 876 origin_matcher, CookieMatcherFunction(), GetURLRequestContext(), |
| 877 begin, end, callback); |
| 878 } |
| 879 |
| 880 void StoragePartitionImpl::ClearData( |
| 881 uint32_t remove_mask, |
| 882 uint32_t quota_storage_remove_mask, |
| 883 const OriginMatcherFunction& origin_matcher, |
| 884 const CookieMatcherFunction& cookie_matcher, |
| 885 const base::Time begin, |
| 886 const base::Time end, |
| 887 const base::Closure& callback) { |
| 888 ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), origin_matcher, |
| 889 cookie_matcher, GetURLRequestContext(), begin, end, callback); |
| 884 } | 890 } |
| 885 | 891 |
| 886 void StoragePartitionImpl::Flush() { | 892 void StoragePartitionImpl::Flush() { |
| 887 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 893 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 888 if (GetDOMStorageContext()) | 894 if (GetDOMStorageContext()) |
| 889 GetDOMStorageContext()->Flush(); | 895 GetDOMStorageContext()->Flush(); |
| 890 } | 896 } |
| 891 | 897 |
| 892 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() { | 898 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() { |
| 893 return webrtc_identity_store_.get(); | 899 return webrtc_identity_store_.get(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 916 net::URLRequestContextGetter* url_request_context) { | 922 net::URLRequestContextGetter* url_request_context) { |
| 917 url_request_context_ = url_request_context; | 923 url_request_context_ = url_request_context; |
| 918 } | 924 } |
| 919 | 925 |
| 920 void StoragePartitionImpl::SetMediaURLRequestContext( | 926 void StoragePartitionImpl::SetMediaURLRequestContext( |
| 921 net::URLRequestContextGetter* media_url_request_context) { | 927 net::URLRequestContextGetter* media_url_request_context) { |
| 922 media_url_request_context_ = media_url_request_context; | 928 media_url_request_context_ = media_url_request_context; |
| 923 } | 929 } |
| 924 | 930 |
| 925 } // namespace content | 931 } // namespace content |
| OLD | NEW |