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 = |
| 274 CanonicalCookieFromSystemCookie(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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 WrapDeleteCallback(callback))); | 696 WrapDeleteCallback(callback))); |
682 break; | 697 break; |
683 case SYNCHRONIZED: | 698 case SYNCHRONIZED: |
684 CookieFilterFunction filter = | 699 CookieFilterFunction filter = |
685 base::Bind(&IsCookieCreatedBetween, delete_begin, delete_end); | 700 base::Bind(&IsCookieCreatedBetween, delete_begin, delete_end); |
686 DeleteCookiesWithFilter(filter, callback); | 701 DeleteCookiesWithFilter(filter, callback); |
687 break; | 702 break; |
688 } | 703 } |
689 } | 704 } |
690 | 705 |
691 void CookieStoreIOS::DeleteAllCreatedBetweenForHostAsync( | 706 void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync( |
692 const base::Time delete_begin, | 707 const base::Time& delete_begin, |
693 const base::Time delete_end, | 708 const base::Time& delete_end, |
694 const GURL& url, | 709 const CookiePredicate& predicate, |
695 const DeleteCallback& callback) { | 710 const DeleteCallback& callback) { |
696 DCHECK(thread_checker_.CalledOnValidThread()); | 711 DCHECK(thread_checker_.CalledOnValidThread()); |
697 | 712 |
698 if (metrics_enabled_) | 713 if (metrics_enabled_) |
699 ResetCookieCountMetrics(); | 714 ResetCookieCountMetrics(); |
700 | 715 |
701 switch (synchronization_state_) { | 716 switch (synchronization_state_) { |
702 case NOT_SYNCHRONIZED: | 717 case NOT_SYNCHRONIZED: |
703 cookie_monster_->DeleteAllCreatedBetweenForHostAsync( | 718 cookie_monster_->DeleteAllCreatedBetweenWithPredicateAsync( |
704 delete_begin, delete_end, url, WrapDeleteCallback(callback)); | 719 delete_begin, delete_end, predicate, WrapDeleteCallback(callback)); |
705 break; | 720 break; |
706 case SYNCHRONIZING: | 721 case SYNCHRONIZING: |
707 tasks_pending_synchronization_.push_back( | 722 tasks_pending_synchronization_.push_back( |
708 base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenForHostAsync, | 723 base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync, |
709 weak_factory_.GetWeakPtr(), delete_begin, delete_end, url, | 724 weak_factory_.GetWeakPtr(), delete_begin, delete_end, |
710 WrapDeleteCallback(callback))); | 725 predicate, WrapDeleteCallback(callback))); |
711 break; | 726 break; |
712 case SYNCHRONIZED: | 727 case SYNCHRONIZED: |
713 NSString* host = base::SysUTF8ToNSString(url.host()); | 728 CookieFilterFunction filter = |
714 CookieFilterFunction filter = base::Bind(IsCookieCreatedBetweenForHost, | 729 base::Bind(IsCookieCreatedBetweenWithPredicate, delete_begin, |
715 delete_begin, delete_end, host); | 730 delete_end, predicate); |
716 DeleteCookiesWithFilter(filter, callback); | 731 DeleteCookiesWithFilter(filter, callback); |
717 break; | 732 break; |
718 } | 733 } |
719 } | 734 } |
720 | 735 |
721 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) { | 736 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) { |
722 DCHECK(thread_checker_.CalledOnValidThread()); | 737 DCHECK(thread_checker_.CalledOnValidThread()); |
723 | 738 |
724 if (metrics_enabled_) | 739 if (metrics_enabled_) |
725 ResetCookieCountMetrics(); | 740 ResetCookieCountMetrics(); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 weak_factory_.GetWeakPtr(), callback); | 1168 weak_factory_.GetWeakPtr(), callback); |
1154 } | 1169 } |
1155 | 1170 |
1156 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { | 1171 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { |
1157 DCHECK(thread_checker_.CalledOnValidThread()); | 1172 DCHECK(thread_checker_.CalledOnValidThread()); |
1158 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, | 1173 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, |
1159 weak_factory_.GetWeakPtr(), callback); | 1174 weak_factory_.GetWeakPtr(), callback); |
1160 } | 1175 } |
1161 | 1176 |
1162 } // namespace net | 1177 } // namespace net |
OLD | NEW |