| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 50 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 51 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
| 52 BrowserThread::UI, FROM_HERE, | 52 BrowserThread::UI, FROM_HERE, |
| 53 base::Bind(&OnClearedCookies, callback, num_deleted)); | 53 base::Bind(&OnClearedCookies, callback, num_deleted)); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 callback.Run(); | 57 callback.Run(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Cookie matcher and storage_origin are never both populated. |
| 60 void ClearCookiesOnIOThread( | 61 void ClearCookiesOnIOThread( |
| 61 const scoped_refptr<net::URLRequestContextGetter>& rq_context, | 62 const scoped_refptr<net::URLRequestContextGetter>& rq_context, |
| 62 const base::Time begin, | 63 const base::Time begin, |
| 63 const base::Time end, | 64 const base::Time end, |
| 64 const GURL& storage_origin, | 65 const GURL& storage_origin, |
| 66 const StoragePartition::CookieMatcherFunction& cookie_matcher, |
| 65 const base::Closure& callback) { | 67 const base::Closure& callback) { |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 68 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 67 net::CookieStore* cookie_store = rq_context-> | 69 DCHECK(cookie_matcher.is_null() || storage_origin.is_empty()); |
| 68 GetURLRequestContext()->cookie_store(); | 70 net::CookieStore* cookie_store = |
| 69 if (storage_origin.is_empty()) { | 71 rq_context->GetURLRequestContext()->cookie_store(); |
| 70 cookie_store->DeleteAllCreatedBetweenAsync( | 72 if (!cookie_matcher.is_null()) { |
| 71 begin, | 73 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( |
| 72 end, | 74 begin, end, cookie_matcher, base::Bind(&OnClearedCookies, callback)); |
| 73 base::Bind(&OnClearedCookies, callback)); | 75 return; |
| 74 } else { | 76 } |
| 77 if (!storage_origin.is_empty()) { |
| 75 // TODO(mkwst): It's not clear whether removing host cookies is the correct | 78 // TODO(mkwst): It's not clear whether removing host cookies is the correct |
| 76 // behavior. We might want to remove all domain-matching cookies instead. | 79 // behavior. We might want to remove all domain-matching cookies instead. |
| 77 // Also, this code path may be dead anyways. | 80 // Also, this code path may be dead anyways. |
| 78 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( | 81 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( |
| 79 begin, end, | 82 begin, end, |
| 80 StoragePartitionImpl::CreatePredicateForHostCookies(storage_origin), | 83 StoragePartitionImpl::CreatePredicateForHostCookies(storage_origin), |
| 81 base::Bind(&OnClearedCookies, callback)); | 84 base::Bind(&OnClearedCookies, callback)); |
| 85 return; |
| 82 } | 86 } |
| 87 cookie_store->DeleteAllCreatedBetweenAsync( |
| 88 begin, end, base::Bind(&OnClearedCookies, callback)); |
| 83 } | 89 } |
| 84 | 90 |
| 85 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, | 91 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, |
| 86 const base::Closure& callback) { | 92 const base::Closure& callback) { |
| 87 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 88 if (*deletion_task_count == 0) { | 94 if (*deletion_task_count == 0) { |
| 89 delete deletion_task_count; | 95 delete deletion_task_count; |
| 90 callback.Run(); | 96 callback.Run(); |
| 91 } | 97 } |
| 92 } | 98 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 quota_storage_remove_mask(quota_storage_remove_mask), | 302 quota_storage_remove_mask(quota_storage_remove_mask), |
| 297 callback(callback), | 303 callback(callback), |
| 298 task_count(0) {} | 304 task_count(0) {} |
| 299 | 305 |
| 300 void IncrementTaskCountOnUI(); | 306 void IncrementTaskCountOnUI(); |
| 301 void DecrementTaskCountOnUI(); | 307 void DecrementTaskCountOnUI(); |
| 302 | 308 |
| 303 void ClearDataOnUIThread( | 309 void ClearDataOnUIThread( |
| 304 const GURL& storage_origin, | 310 const GURL& storage_origin, |
| 305 const OriginMatcherFunction& origin_matcher, | 311 const OriginMatcherFunction& origin_matcher, |
| 312 const CookieMatcherFunction& cookie_matcher, |
| 306 const base::FilePath& path, | 313 const base::FilePath& path, |
| 307 net::URLRequestContextGetter* rq_context, | 314 net::URLRequestContextGetter* rq_context, |
| 308 DOMStorageContextWrapper* dom_storage_context, | 315 DOMStorageContextWrapper* dom_storage_context, |
| 309 storage::QuotaManager* quota_manager, | 316 storage::QuotaManager* quota_manager, |
| 310 storage::SpecialStoragePolicy* special_storage_policy, | 317 storage::SpecialStoragePolicy* special_storage_policy, |
| 311 WebRTCIdentityStore* webrtc_identity_store, | 318 WebRTCIdentityStore* webrtc_identity_store, |
| 312 const base::Time begin, | 319 const base::Time begin, |
| 313 const base::Time end); | 320 const base::Time end); |
| 314 | 321 |
| 315 void ClearQuotaManagedDataOnIOThread( | 322 void ClearQuotaManagedDataOnIOThread( |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 mojo::InterfaceRequest<mojom::LevelDBWrapper> request) { | 614 mojo::InterfaceRequest<mojom::LevelDBWrapper> request) { |
| 608 dom_storage_context_->OpenLocalStorage( | 615 dom_storage_context_->OpenLocalStorage( |
| 609 origin, std::move(observer), std::move(request)); | 616 origin, std::move(observer), std::move(request)); |
| 610 } | 617 } |
| 611 | 618 |
| 612 void StoragePartitionImpl::ClearDataImpl( | 619 void StoragePartitionImpl::ClearDataImpl( |
| 613 uint32_t remove_mask, | 620 uint32_t remove_mask, |
| 614 uint32_t quota_storage_remove_mask, | 621 uint32_t quota_storage_remove_mask, |
| 615 const GURL& storage_origin, | 622 const GURL& storage_origin, |
| 616 const OriginMatcherFunction& origin_matcher, | 623 const OriginMatcherFunction& origin_matcher, |
| 624 const CookieMatcherFunction& cookie_matcher, |
| 617 net::URLRequestContextGetter* rq_context, | 625 net::URLRequestContextGetter* rq_context, |
| 618 const base::Time begin, | 626 const base::Time begin, |
| 619 const base::Time end, | 627 const base::Time end, |
| 620 const base::Closure& callback) { | 628 const base::Closure& callback) { |
| 621 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 629 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 622 DataDeletionHelper* helper = new DataDeletionHelper(remove_mask, | 630 DataDeletionHelper* helper = new DataDeletionHelper(remove_mask, |
| 623 quota_storage_remove_mask, | 631 quota_storage_remove_mask, |
| 624 callback); | 632 callback); |
| 625 // |helper| deletes itself when done in | 633 // |helper| deletes itself when done in |
| 626 // DataDeletionHelper::DecrementTaskCountOnUI(). | 634 // DataDeletionHelper::DecrementTaskCountOnUI(). |
| 627 helper->ClearDataOnUIThread(storage_origin, | 635 helper->ClearDataOnUIThread( |
| 628 origin_matcher, | 636 storage_origin, origin_matcher, cookie_matcher, GetPath(), rq_context, |
| 629 GetPath(), | 637 dom_storage_context_.get(), quota_manager_.get(), |
| 630 rq_context, | 638 special_storage_policy_.get(), webrtc_identity_store_.get(), begin, end); |
| 631 dom_storage_context_.get(), | |
| 632 quota_manager_.get(), | |
| 633 special_storage_policy_.get(), | |
| 634 webrtc_identity_store_.get(), | |
| 635 begin, | |
| 636 end); | |
| 637 } | 639 } |
| 638 | 640 |
| 639 void StoragePartitionImpl:: | 641 void StoragePartitionImpl:: |
| 640 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() { | 642 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() { |
| 641 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 643 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 642 ++task_count; | 644 ++task_count; |
| 643 } | 645 } |
| 644 | 646 |
| 645 void StoragePartitionImpl:: | 647 void StoragePartitionImpl:: |
| 646 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() { | 648 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 --task_count; | 761 --task_count; |
| 760 if (!task_count) { | 762 if (!task_count) { |
| 761 callback.Run(); | 763 callback.Run(); |
| 762 delete this; | 764 delete this; |
| 763 } | 765 } |
| 764 } | 766 } |
| 765 | 767 |
| 766 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( | 768 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( |
| 767 const GURL& storage_origin, | 769 const GURL& storage_origin, |
| 768 const OriginMatcherFunction& origin_matcher, | 770 const OriginMatcherFunction& origin_matcher, |
| 771 const CookieMatcherFunction& cookie_matcher, |
| 769 const base::FilePath& path, | 772 const base::FilePath& path, |
| 770 net::URLRequestContextGetter* rq_context, | 773 net::URLRequestContextGetter* rq_context, |
| 771 DOMStorageContextWrapper* dom_storage_context, | 774 DOMStorageContextWrapper* dom_storage_context, |
| 772 storage::QuotaManager* quota_manager, | 775 storage::QuotaManager* quota_manager, |
| 773 storage::SpecialStoragePolicy* special_storage_policy, | 776 storage::SpecialStoragePolicy* special_storage_policy, |
| 774 WebRTCIdentityStore* webrtc_identity_store, | 777 WebRTCIdentityStore* webrtc_identity_store, |
| 775 const base::Time begin, | 778 const base::Time begin, |
| 776 const base::Time end) { | 779 const base::Time end) { |
| 777 DCHECK_NE(remove_mask, 0u); | 780 DCHECK_NE(remove_mask, 0u); |
| 778 DCHECK(!callback.is_null()); | 781 DCHECK(!callback.is_null()); |
| 779 | 782 |
| 780 IncrementTaskCountOnUI(); | 783 IncrementTaskCountOnUI(); |
| 781 base::Closure decrement_callback = base::Bind( | 784 base::Closure decrement_callback = base::Bind( |
| 782 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); | 785 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); |
| 783 | 786 |
| 784 if (remove_mask & REMOVE_DATA_MASK_COOKIES) { | 787 if (remove_mask & REMOVE_DATA_MASK_COOKIES) { |
| 785 // Handle the cookies. | 788 // Handle the cookies. |
| 786 IncrementTaskCountOnUI(); | 789 IncrementTaskCountOnUI(); |
| 787 BrowserThread::PostTask( | 790 BrowserThread::PostTask( |
| 788 BrowserThread::IO, FROM_HERE, | 791 BrowserThread::IO, FROM_HERE, |
| 789 base::Bind(&ClearCookiesOnIOThread, | 792 base::Bind(&ClearCookiesOnIOThread, make_scoped_refptr(rq_context), |
| 790 make_scoped_refptr(rq_context), begin, end, storage_origin, | 793 begin, end, storage_origin, cookie_matcher, |
| 791 decrement_callback)); | 794 decrement_callback)); |
| 792 } | 795 } |
| 793 | 796 |
| 794 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || | 797 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || |
| 795 remove_mask & REMOVE_DATA_MASK_WEBSQL || | 798 remove_mask & REMOVE_DATA_MASK_WEBSQL || |
| 796 remove_mask & REMOVE_DATA_MASK_APPCACHE || | 799 remove_mask & REMOVE_DATA_MASK_APPCACHE || |
| 797 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS || | 800 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS || |
| 798 remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS || | 801 remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS || |
| 799 remove_mask & REMOVE_DATA_MASK_CACHE_STORAGE) { | 802 remove_mask & REMOVE_DATA_MASK_CACHE_STORAGE) { |
| 800 IncrementTaskCountOnUI(); | 803 IncrementTaskCountOnUI(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 DecrementTaskCountOnUI(); | 858 DecrementTaskCountOnUI(); |
| 856 } | 859 } |
| 857 | 860 |
| 858 void StoragePartitionImpl::ClearDataForOrigin( | 861 void StoragePartitionImpl::ClearDataForOrigin( |
| 859 uint32_t remove_mask, | 862 uint32_t remove_mask, |
| 860 uint32_t quota_storage_remove_mask, | 863 uint32_t quota_storage_remove_mask, |
| 861 const GURL& storage_origin, | 864 const GURL& storage_origin, |
| 862 net::URLRequestContextGetter* request_context_getter, | 865 net::URLRequestContextGetter* request_context_getter, |
| 863 const base::Closure& callback) { | 866 const base::Closure& callback) { |
| 864 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 867 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 865 ClearDataImpl(remove_mask, | 868 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, |
| 866 quota_storage_remove_mask, | 869 OriginMatcherFunction(), CookieMatcherFunction(), |
| 867 storage_origin, | 870 request_context_getter, base::Time(), base::Time::Max(), |
| 868 OriginMatcherFunction(), | |
| 869 request_context_getter, | |
| 870 base::Time(), | |
| 871 base::Time::Max(), | |
| 872 callback); | 871 callback); |
| 873 } | 872 } |
| 874 | 873 |
| 875 void StoragePartitionImpl::ClearData( | 874 void StoragePartitionImpl::ClearData( |
| 876 uint32_t remove_mask, | 875 uint32_t remove_mask, |
| 877 uint32_t quota_storage_remove_mask, | 876 uint32_t quota_storage_remove_mask, |
| 878 const GURL& storage_origin, | 877 const GURL& storage_origin, |
| 879 const OriginMatcherFunction& origin_matcher, | 878 const OriginMatcherFunction& origin_matcher, |
| 880 const base::Time begin, | 879 const base::Time begin, |
| 881 const base::Time end, | 880 const base::Time end, |
| 882 const base::Closure& callback) { | 881 const base::Closure& callback) { |
| 883 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, | 882 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, |
| 884 origin_matcher, GetURLRequestContext(), begin, end, callback); | 883 origin_matcher, CookieMatcherFunction(), GetURLRequestContext(), |
| 884 begin, end, callback); |
| 885 } |
| 886 |
| 887 void StoragePartitionImpl::ClearData( |
| 888 uint32_t remove_mask, |
| 889 uint32_t quota_storage_remove_mask, |
| 890 const OriginMatcherFunction& origin_matcher, |
| 891 const CookieMatcherFunction& cookie_matcher, |
| 892 const base::Time begin, |
| 893 const base::Time end, |
| 894 const base::Closure& callback) { |
| 895 ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), origin_matcher, |
| 896 cookie_matcher, GetURLRequestContext(), begin, end, callback); |
| 885 } | 897 } |
| 886 | 898 |
| 887 void StoragePartitionImpl::Flush() { | 899 void StoragePartitionImpl::Flush() { |
| 888 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 900 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 889 if (GetDOMStorageContext()) | 901 if (GetDOMStorageContext()) |
| 890 GetDOMStorageContext()->Flush(); | 902 GetDOMStorageContext()->Flush(); |
| 891 } | 903 } |
| 892 | 904 |
| 893 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() { | 905 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() { |
| 894 return webrtc_identity_store_.get(); | 906 return webrtc_identity_store_.get(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 917 net::URLRequestContextGetter* url_request_context) { | 929 net::URLRequestContextGetter* url_request_context) { |
| 918 url_request_context_ = url_request_context; | 930 url_request_context_ = url_request_context; |
| 919 } | 931 } |
| 920 | 932 |
| 921 void StoragePartitionImpl::SetMediaURLRequestContext( | 933 void StoragePartitionImpl::SetMediaURLRequestContext( |
| 922 net::URLRequestContextGetter* media_url_request_context) { | 934 net::URLRequestContextGetter* media_url_request_context) { |
| 923 media_url_request_context_ = media_url_request_context; | 935 media_url_request_context_ = media_url_request_context; |
| 924 } | 936 } |
| 925 | 937 |
| 926 } // namespace content | 938 } // namespace content |
| OLD | NEW |