| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ios/net/cookies/cookie_store_ios.h" | 5 #include "ios/net/cookies/cookie_store_ios.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 base::Time time_end, | 254 base::Time time_end, |
| 255 NSString* host, | 255 NSString* host, |
| 256 NSHTTPCookie* cookie, | 256 NSHTTPCookie* cookie, |
| 257 base::Time creation_time) { | 257 base::Time creation_time) { |
| 258 NSString* domain = [cookie domain]; | 258 NSString* domain = [cookie domain]; |
| 259 return [domain characterAtIndex:0] != '.' && | 259 return [domain characterAtIndex:0] != '.' && |
| 260 [domain caseInsensitiveCompare:host] == NSOrderedSame && | 260 [domain caseInsensitiveCompare:host] == NSOrderedSame && |
| 261 IsCookieCreatedBetween(time_begin, time_end, cookie, creation_time); | 261 IsCookieCreatedBetween(time_begin, time_end, cookie, creation_time); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Tests whether the |creation_time| of |cookie| is in the time range defined |
| 265 // by |time_begin| and |time_end| and the cookie host match |host|. A null |
| 266 // |time_end| means end-of-time. |
| 267 bool IsCookieCreatedBetweenWithPredicate( |
| 268 base::Time time_begin, |
| 269 base::Time time_end, |
| 270 const net::CookieStore::CookiePredicate& predicate, |
| 271 NSHTTPCookie* cookie, |
| 272 base::Time creation_time) { |
| 273 CanonicalCookie canonical_cookie = CanonicalCookieFromSystemCookie( |
| 274 cookie, creation_time); |
| 275 return IsCookieCreatedBetween(time_begin, time_end, cookie, creation_time) && |
| 276 predicate.Run(canonical_cookie); |
| 277 } |
| 278 |
| 264 // Adds cookies in |cookies| with name |name| to |filtered|. | 279 // Adds cookies in |cookies| with name |name| to |filtered|. |
| 265 void OnlyCookiesWithName(const net::CookieList& cookies, | 280 void OnlyCookiesWithName(const net::CookieList& cookies, |
| 266 const std::string& name, | 281 const std::string& name, |
| 267 net::CookieList* filtered) { | 282 net::CookieList* filtered) { |
| 268 for (const auto& cookie : cookies) { | 283 for (const auto& cookie : cookies) { |
| 269 if (cookie.Name() == name) | 284 if (cookie.Name() == name) |
| 270 filtered->push_back(cookie); | 285 filtered->push_back(cookie); |
| 271 } | 286 } |
| 272 } | 287 } |
| 273 | 288 |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 break; | 726 break; |
| 712 case SYNCHRONIZED: | 727 case SYNCHRONIZED: |
| 713 NSString* host = base::SysUTF8ToNSString(url.host()); | 728 NSString* host = base::SysUTF8ToNSString(url.host()); |
| 714 CookieFilterFunction filter = base::Bind(IsCookieCreatedBetweenForHost, | 729 CookieFilterFunction filter = base::Bind(IsCookieCreatedBetweenForHost, |
| 715 delete_begin, delete_end, host); | 730 delete_begin, delete_end, host); |
| 716 DeleteCookiesWithFilter(filter, callback); | 731 DeleteCookiesWithFilter(filter, callback); |
| 717 break; | 732 break; |
| 718 } | 733 } |
| 719 } | 734 } |
| 720 | 735 |
| 736 void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync( |
| 737 const base::Time& delete_begin, |
| 738 const base::Time& delete_end, |
| 739 const CookiePredicate& predicate, |
| 740 const DeleteCallback& callback) { |
| 741 DCHECK(thread_checker_.CalledOnValidThread()); |
| 742 |
| 743 if (metrics_enabled_) |
| 744 ResetCookieCountMetrics(); |
| 745 |
| 746 switch (synchronization_state_) { |
| 747 case NOT_SYNCHRONIZED: |
| 748 cookie_monster_->DeleteAllCreatedBetweenWithPredicateAsync( |
| 749 delete_begin, delete_end, predicate, WrapDeleteCallback(callback)); |
| 750 break; |
| 751 case SYNCHRONIZING: |
| 752 tasks_pending_synchronization_.push_back( |
| 753 base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync, |
| 754 weak_factory_.GetWeakPtr(), delete_begin, delete_end, |
| 755 predicate, WrapDeleteCallback(callback))); |
| 756 break; |
| 757 case SYNCHRONIZED: |
| 758 CookieFilterFunction filter = |
| 759 base::Bind(IsCookieCreatedBetweenWithPredicate, |
| 760 delete_begin, delete_end, predicate); |
| 761 DeleteCookiesWithFilter(filter, callback); |
| 762 break; |
| 763 } |
| 764 } |
| 765 |
| 721 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) { | 766 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) { |
| 722 DCHECK(thread_checker_.CalledOnValidThread()); | 767 DCHECK(thread_checker_.CalledOnValidThread()); |
| 723 | 768 |
| 724 if (metrics_enabled_) | 769 if (metrics_enabled_) |
| 725 ResetCookieCountMetrics(); | 770 ResetCookieCountMetrics(); |
| 726 | 771 |
| 727 switch (synchronization_state_) { | 772 switch (synchronization_state_) { |
| 728 case NOT_SYNCHRONIZED: | 773 case NOT_SYNCHRONIZED: |
| 729 cookie_monster_->DeleteSessionCookiesAsync(WrapDeleteCallback(callback)); | 774 cookie_monster_->DeleteSessionCookiesAsync(WrapDeleteCallback(callback)); |
| 730 break; | 775 break; |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 weak_factory_.GetWeakPtr(), callback); | 1194 weak_factory_.GetWeakPtr(), callback); |
| 1150 } | 1195 } |
| 1151 | 1196 |
| 1152 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { | 1197 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { |
| 1153 DCHECK(thread_checker_.CalledOnValidThread()); | 1198 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1154 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, | 1199 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, |
| 1155 weak_factory_.GetWeakPtr(), callback); | 1200 weak_factory_.GetWeakPtr(), callback); |
| 1156 } | 1201 } |
| 1157 | 1202 |
| 1158 } // namespace net | 1203 } // namespace net |
| OLD | NEW |