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. | |
kinuko
2016/04/07 09:03:08
Maybe have a DCHECK for this?
dmurph
2016/04/08 23:33:45
Done.
| |
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 net::CookieStore* cookie_store = |
68 GetURLRequestContext()->cookie_store(); | 70 rq_context->GetURLRequestContext()->cookie_store(); |
69 if (storage_origin.is_empty()) { | 71 if (!cookie_matcher.is_null()) { |
70 cookie_store->DeleteAllCreatedBetweenAsync( | 72 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( |
71 begin, | 73 begin, end, cookie_matcher, base::Bind(&OnClearedCookies, callback)); |
kinuko
2016/04/07 09:03:08
nit: if - if else - else could be revised with ear
dmurph
2016/04/08 23:33:45
Done.
| |
72 end, | 74 } else if (!storage_origin.is_empty()) { |
73 base::Bind(&OnClearedCookies, callback)); | |
74 } else { | |
75 // TODO(mkwst): It's not clear whether removing host cookies is the correct | 75 // 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. | 76 // behavior. We might want to remove all domain-matching cookies instead. |
77 // Also, this code path may be dead anyways. | 77 // Also, this code path may be dead anyways. |
78 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( | 78 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( |
79 begin, end, | 79 begin, end, |
80 StoragePartitionImpl::CreatePredicateForHostCookies(storage_origin), | 80 StoragePartitionImpl::CreatePredicateForHostCookies(storage_origin), |
81 base::Bind(&OnClearedCookies, callback)); | 81 base::Bind(&OnClearedCookies, callback)); |
82 } else { | |
83 cookie_store->DeleteAllCreatedBetweenAsync( | |
84 begin, end, base::Bind(&OnClearedCookies, callback)); | |
82 } | 85 } |
83 } | 86 } |
84 | 87 |
85 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, | 88 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, |
86 const base::Closure& callback) { | 89 const base::Closure& callback) { |
87 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
88 if (*deletion_task_count == 0) { | 91 if (*deletion_task_count == 0) { |
89 delete deletion_task_count; | 92 delete deletion_task_count; |
90 callback.Run(); | 93 callback.Run(); |
91 } | 94 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 void DecrementTaskCountOnIO(); | 258 void DecrementTaskCountOnIO(); |
256 | 259 |
257 void ClearDataOnIOThread( | 260 void ClearDataOnIOThread( |
258 const scoped_refptr<storage::QuotaManager>& quota_manager, | 261 const scoped_refptr<storage::QuotaManager>& quota_manager, |
259 const base::Time begin, | 262 const base::Time begin, |
260 const scoped_refptr<storage::SpecialStoragePolicy>& | 263 const scoped_refptr<storage::SpecialStoragePolicy>& |
261 special_storage_policy, | 264 special_storage_policy, |
262 const StoragePartition::OriginMatcherFunction& origin_matcher); | 265 const StoragePartition::OriginMatcherFunction& origin_matcher); |
263 | 266 |
264 void ClearOriginsOnIOThread( | 267 void ClearOriginsOnIOThread( |
268 | |
kinuko
2016/04/07 09:03:08
? remove this line
dmurph
2016/04/08 23:33:45
Done.
| |
265 storage::QuotaManager* quota_manager, | 269 storage::QuotaManager* quota_manager, |
266 const scoped_refptr<storage::SpecialStoragePolicy>& | 270 const scoped_refptr<storage::SpecialStoragePolicy>& |
267 special_storage_policy, | 271 special_storage_policy, |
268 const StoragePartition::OriginMatcherFunction& origin_matcher, | 272 const StoragePartition::OriginMatcherFunction& origin_matcher, |
269 const base::Closure& callback, | 273 const base::Closure& callback, |
270 const std::set<GURL>& origins, | 274 const std::set<GURL>& origins, |
271 storage::StorageType quota_storage_type); | 275 storage::StorageType quota_storage_type); |
272 | 276 |
273 // All of these data are accessed on IO thread. | 277 // All of these data are accessed on IO thread. |
274 uint32_t remove_mask; | 278 uint32_t remove_mask; |
(...skipping 21 matching lines...) Expand all Loading... | |
296 quota_storage_remove_mask(quota_storage_remove_mask), | 300 quota_storage_remove_mask(quota_storage_remove_mask), |
297 callback(callback), | 301 callback(callback), |
298 task_count(0) {} | 302 task_count(0) {} |
299 | 303 |
300 void IncrementTaskCountOnUI(); | 304 void IncrementTaskCountOnUI(); |
301 void DecrementTaskCountOnUI(); | 305 void DecrementTaskCountOnUI(); |
302 | 306 |
303 void ClearDataOnUIThread( | 307 void ClearDataOnUIThread( |
304 const GURL& storage_origin, | 308 const GURL& storage_origin, |
305 const OriginMatcherFunction& origin_matcher, | 309 const OriginMatcherFunction& origin_matcher, |
310 const CookieMatcherFunction& cookie_matcher, | |
306 const base::FilePath& path, | 311 const base::FilePath& path, |
307 net::URLRequestContextGetter* rq_context, | 312 net::URLRequestContextGetter* rq_context, |
308 DOMStorageContextWrapper* dom_storage_context, | 313 DOMStorageContextWrapper* dom_storage_context, |
309 storage::QuotaManager* quota_manager, | 314 storage::QuotaManager* quota_manager, |
310 storage::SpecialStoragePolicy* special_storage_policy, | 315 storage::SpecialStoragePolicy* special_storage_policy, |
311 WebRTCIdentityStore* webrtc_identity_store, | 316 WebRTCIdentityStore* webrtc_identity_store, |
312 const base::Time begin, | 317 const base::Time begin, |
313 const base::Time end); | 318 const base::Time end); |
314 | 319 |
315 void ClearQuotaManagedDataOnIOThread( | 320 void ClearQuotaManagedDataOnIOThread( |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 const url::Origin& origin, | 610 const url::Origin& origin, |
606 mojo::InterfaceRequest<mojom::LevelDBWrapper> request) { | 611 mojo::InterfaceRequest<mojom::LevelDBWrapper> request) { |
607 dom_storage_context_->OpenLocalStorage(origin, std::move(request)); | 612 dom_storage_context_->OpenLocalStorage(origin, std::move(request)); |
608 } | 613 } |
609 | 614 |
610 void StoragePartitionImpl::ClearDataImpl( | 615 void StoragePartitionImpl::ClearDataImpl( |
611 uint32_t remove_mask, | 616 uint32_t remove_mask, |
612 uint32_t quota_storage_remove_mask, | 617 uint32_t quota_storage_remove_mask, |
613 const GURL& storage_origin, | 618 const GURL& storage_origin, |
614 const OriginMatcherFunction& origin_matcher, | 619 const OriginMatcherFunction& origin_matcher, |
620 const CookieMatcherFunction& cookie_matcher, | |
615 net::URLRequestContextGetter* rq_context, | 621 net::URLRequestContextGetter* rq_context, |
616 const base::Time begin, | 622 const base::Time begin, |
617 const base::Time end, | 623 const base::Time end, |
618 const base::Closure& callback) { | 624 const base::Closure& callback) { |
619 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 625 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
620 DataDeletionHelper* helper = new DataDeletionHelper(remove_mask, | 626 DataDeletionHelper* helper = new DataDeletionHelper(remove_mask, |
621 quota_storage_remove_mask, | 627 quota_storage_remove_mask, |
622 callback); | 628 callback); |
623 // |helper| deletes itself when done in | 629 // |helper| deletes itself when done in |
624 // DataDeletionHelper::DecrementTaskCountOnUI(). | 630 // DataDeletionHelper::DecrementTaskCountOnUI(). |
625 helper->ClearDataOnUIThread(storage_origin, | 631 helper->ClearDataOnUIThread( |
626 origin_matcher, | 632 storage_origin, origin_matcher, cookie_matcher, GetPath(), rq_context, |
627 GetPath(), | 633 dom_storage_context_.get(), quota_manager_.get(), |
628 rq_context, | 634 special_storage_policy_.get(), webrtc_identity_store_.get(), begin, end); |
629 dom_storage_context_.get(), | |
630 quota_manager_.get(), | |
631 special_storage_policy_.get(), | |
632 webrtc_identity_store_.get(), | |
633 begin, | |
634 end); | |
635 } | 635 } |
636 | 636 |
637 void StoragePartitionImpl:: | 637 void StoragePartitionImpl:: |
638 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() { | 638 QuotaManagedDataDeletionHelper::IncrementTaskCountOnIO() { |
639 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 639 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
640 ++task_count; | 640 ++task_count; |
641 } | 641 } |
642 | 642 |
643 void StoragePartitionImpl:: | 643 void StoragePartitionImpl:: |
644 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() { | 644 QuotaManagedDataDeletionHelper::DecrementTaskCountOnIO() { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
757 --task_count; | 757 --task_count; |
758 if (!task_count) { | 758 if (!task_count) { |
759 callback.Run(); | 759 callback.Run(); |
760 delete this; | 760 delete this; |
761 } | 761 } |
762 } | 762 } |
763 | 763 |
764 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( | 764 void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread( |
765 const GURL& storage_origin, | 765 const GURL& storage_origin, |
766 const OriginMatcherFunction& origin_matcher, | 766 const OriginMatcherFunction& origin_matcher, |
767 const CookieMatcherFunction& cookie_matcher, | |
767 const base::FilePath& path, | 768 const base::FilePath& path, |
768 net::URLRequestContextGetter* rq_context, | 769 net::URLRequestContextGetter* rq_context, |
769 DOMStorageContextWrapper* dom_storage_context, | 770 DOMStorageContextWrapper* dom_storage_context, |
770 storage::QuotaManager* quota_manager, | 771 storage::QuotaManager* quota_manager, |
771 storage::SpecialStoragePolicy* special_storage_policy, | 772 storage::SpecialStoragePolicy* special_storage_policy, |
772 WebRTCIdentityStore* webrtc_identity_store, | 773 WebRTCIdentityStore* webrtc_identity_store, |
773 const base::Time begin, | 774 const base::Time begin, |
774 const base::Time end) { | 775 const base::Time end) { |
775 DCHECK_NE(remove_mask, 0u); | 776 DCHECK_NE(remove_mask, 0u); |
776 DCHECK(!callback.is_null()); | 777 DCHECK(!callback.is_null()); |
777 | 778 |
778 IncrementTaskCountOnUI(); | 779 IncrementTaskCountOnUI(); |
779 base::Closure decrement_callback = base::Bind( | 780 base::Closure decrement_callback = base::Bind( |
780 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); | 781 &DataDeletionHelper::DecrementTaskCountOnUI, base::Unretained(this)); |
781 | 782 |
782 if (remove_mask & REMOVE_DATA_MASK_COOKIES) { | 783 if (remove_mask & REMOVE_DATA_MASK_COOKIES) { |
783 // Handle the cookies. | 784 // Handle the cookies. |
784 IncrementTaskCountOnUI(); | 785 IncrementTaskCountOnUI(); |
785 BrowserThread::PostTask( | 786 BrowserThread::PostTask( |
786 BrowserThread::IO, FROM_HERE, | 787 BrowserThread::IO, FROM_HERE, |
787 base::Bind(&ClearCookiesOnIOThread, | 788 base::Bind(&ClearCookiesOnIOThread, make_scoped_refptr(rq_context), |
788 make_scoped_refptr(rq_context), begin, end, storage_origin, | 789 begin, end, storage_origin, cookie_matcher, |
789 decrement_callback)); | 790 decrement_callback)); |
790 } | 791 } |
791 | 792 |
792 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || | 793 if (remove_mask & REMOVE_DATA_MASK_INDEXEDDB || |
793 remove_mask & REMOVE_DATA_MASK_WEBSQL || | 794 remove_mask & REMOVE_DATA_MASK_WEBSQL || |
794 remove_mask & REMOVE_DATA_MASK_APPCACHE || | 795 remove_mask & REMOVE_DATA_MASK_APPCACHE || |
795 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS || | 796 remove_mask & REMOVE_DATA_MASK_FILE_SYSTEMS || |
796 remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS || | 797 remove_mask & REMOVE_DATA_MASK_SERVICE_WORKERS || |
797 remove_mask & REMOVE_DATA_MASK_CACHE_STORAGE) { | 798 remove_mask & REMOVE_DATA_MASK_CACHE_STORAGE) { |
798 IncrementTaskCountOnUI(); | 799 IncrementTaskCountOnUI(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 DecrementTaskCountOnUI(); | 854 DecrementTaskCountOnUI(); |
854 } | 855 } |
855 | 856 |
856 void StoragePartitionImpl::ClearDataForOrigin( | 857 void StoragePartitionImpl::ClearDataForOrigin( |
857 uint32_t remove_mask, | 858 uint32_t remove_mask, |
858 uint32_t quota_storage_remove_mask, | 859 uint32_t quota_storage_remove_mask, |
859 const GURL& storage_origin, | 860 const GURL& storage_origin, |
860 net::URLRequestContextGetter* request_context_getter, | 861 net::URLRequestContextGetter* request_context_getter, |
861 const base::Closure& callback) { | 862 const base::Closure& callback) { |
862 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 863 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
863 ClearDataImpl(remove_mask, | 864 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, |
864 quota_storage_remove_mask, | 865 OriginMatcherFunction(), CookieMatcherFunction(), |
865 storage_origin, | 866 request_context_getter, base::Time(), base::Time::Max(), |
866 OriginMatcherFunction(), | |
867 request_context_getter, | |
868 base::Time(), | |
869 base::Time::Max(), | |
870 callback); | 867 callback); |
871 } | 868 } |
872 | 869 |
873 void StoragePartitionImpl::ClearData( | 870 void StoragePartitionImpl::ClearData( |
874 uint32_t remove_mask, | 871 uint32_t remove_mask, |
875 uint32_t quota_storage_remove_mask, | 872 uint32_t quota_storage_remove_mask, |
876 const GURL& storage_origin, | 873 const GURL& storage_origin, |
877 const OriginMatcherFunction& origin_matcher, | 874 const OriginMatcherFunction& origin_matcher, |
878 const base::Time begin, | 875 const base::Time begin, |
879 const base::Time end, | 876 const base::Time end, |
880 const base::Closure& callback) { | 877 const base::Closure& callback) { |
881 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, | 878 ClearDataImpl(remove_mask, quota_storage_remove_mask, storage_origin, |
882 origin_matcher, GetURLRequestContext(), begin, end, callback); | 879 origin_matcher, CookieMatcherFunction(), GetURLRequestContext(), |
880 begin, end, callback); | |
881 } | |
882 | |
883 void StoragePartitionImpl::ClearData( | |
884 uint32_t remove_mask, | |
885 uint32_t quota_storage_remove_mask, | |
886 const OriginMatcherFunction& origin_matcher, | |
887 const CookieMatcherFunction& cookie_matcher, | |
888 const base::Time begin, | |
889 const base::Time end, | |
890 const base::Closure& callback) { | |
891 ClearDataImpl(remove_mask, quota_storage_remove_mask, GURL(), origin_matcher, | |
892 cookie_matcher, GetURLRequestContext(), begin, end, callback); | |
883 } | 893 } |
884 | 894 |
885 void StoragePartitionImpl::Flush() { | 895 void StoragePartitionImpl::Flush() { |
886 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 896 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
887 if (GetDOMStorageContext()) | 897 if (GetDOMStorageContext()) |
888 GetDOMStorageContext()->Flush(); | 898 GetDOMStorageContext()->Flush(); |
889 } | 899 } |
890 | 900 |
891 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() { | 901 WebRTCIdentityStore* StoragePartitionImpl::GetWebRTCIdentityStore() { |
892 return webrtc_identity_store_.get(); | 902 return webrtc_identity_store_.get(); |
(...skipping 22 matching lines...) Expand all Loading... | |
915 net::URLRequestContextGetter* url_request_context) { | 925 net::URLRequestContextGetter* url_request_context) { |
916 url_request_context_ = url_request_context; | 926 url_request_context_ = url_request_context; |
917 } | 927 } |
918 | 928 |
919 void StoragePartitionImpl::SetMediaURLRequestContext( | 929 void StoragePartitionImpl::SetMediaURLRequestContext( |
920 net::URLRequestContextGetter* media_url_request_context) { | 930 net::URLRequestContextGetter* media_url_request_context) { |
921 media_url_request_context_ = media_url_request_context; | 931 media_url_request_context_ = media_url_request_context; |
922 } | 932 } |
923 | 933 |
924 } // namespace content | 934 } // namespace content |
OLD | NEW |