Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: ios/net/cookies/cookie_store_ios.mm

Issue 1844243002: [CookieStore] Upgrading host-based deleting to predicate-based deleting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/net/cookies/cookie_store_ios.h ('k') | ios/net/cookies/cookie_store_ios_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 base::Time time_end, 243 base::Time time_end,
244 NSHTTPCookie* cookie, 244 NSHTTPCookie* cookie,
245 base::Time creation_time) { 245 base::Time creation_time) {
246 return time_begin <= creation_time && 246 return time_begin <= creation_time &&
247 (time_end.is_null() || creation_time <= time_end); 247 (time_end.is_null() || creation_time <= time_end);
248 } 248 }
249 249
250 // Tests whether the |creation_time| of |cookie| is in the time range defined 250 // Tests whether the |creation_time| of |cookie| is in the time range defined
251 // by |time_begin| and |time_end| and the cookie host match |host|. A null 251 // by |time_begin| and |time_end| and the cookie host match |host|. A null
252 // |time_end| means end-of-time. 252 // |time_end| means end-of-time.
253 bool IsCookieCreatedBetweenForHost(base::Time time_begin, 253 bool IsCookieCreatedBetweenWithPredicate(
254 base::Time time_end, 254 base::Time time_begin,
255 NSString* host, 255 base::Time time_end,
256 NSHTTPCookie* cookie, 256 const net::CookieStore::CookiePredicate& predicate,
257 base::Time creation_time) { 257 NSHTTPCookie* cookie,
258 NSString* domain = [cookie domain]; 258 base::Time creation_time) {
259 return [domain characterAtIndex:0] != '.' && 259 if (predicate.is_null())
260 [domain caseInsensitiveCompare:host] == NSOrderedSame && 260 return false;
261 IsCookieCreatedBetween(time_begin, time_end, cookie, creation_time); 261 CanonicalCookie canonical_cookie =
262 CanonicalCookieFromSystemCookie(cookie, creation_time);
263 return IsCookieCreatedBetween(time_begin, time_end, cookie, creation_time) &&
264 predicate.Run(canonical_cookie);
262 } 265 }
263 266
264 // Adds cookies in |cookies| with name |name| to |filtered|. 267 // Adds cookies in |cookies| with name |name| to |filtered|.
265 void OnlyCookiesWithName(const net::CookieList& cookies, 268 void OnlyCookiesWithName(const net::CookieList& cookies,
266 const std::string& name, 269 const std::string& name,
267 net::CookieList* filtered) { 270 net::CookieList* filtered) {
268 for (const auto& cookie : cookies) { 271 for (const auto& cookie : cookies) {
269 if (cookie.Name() == name) 272 if (cookie.Name() == name)
270 filtered->push_back(cookie); 273 filtered->push_back(cookie);
271 } 274 }
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 WrapDeleteCallback(callback))); 684 WrapDeleteCallback(callback)));
682 break; 685 break;
683 case SYNCHRONIZED: 686 case SYNCHRONIZED:
684 CookieFilterFunction filter = 687 CookieFilterFunction filter =
685 base::Bind(&IsCookieCreatedBetween, delete_begin, delete_end); 688 base::Bind(&IsCookieCreatedBetween, delete_begin, delete_end);
686 DeleteCookiesWithFilter(filter, callback); 689 DeleteCookiesWithFilter(filter, callback);
687 break; 690 break;
688 } 691 }
689 } 692 }
690 693
691 void CookieStoreIOS::DeleteAllCreatedBetweenForHostAsync( 694 void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync(
692 const base::Time delete_begin, 695 const base::Time& delete_begin,
693 const base::Time delete_end, 696 const base::Time& delete_end,
694 const GURL& url, 697 const CookiePredicate& predicate,
695 const DeleteCallback& callback) { 698 const DeleteCallback& callback) {
696 DCHECK(thread_checker_.CalledOnValidThread()); 699 DCHECK(thread_checker_.CalledOnValidThread());
697 700
698 if (metrics_enabled_) 701 if (metrics_enabled_)
699 ResetCookieCountMetrics(); 702 ResetCookieCountMetrics();
700 703
701 switch (synchronization_state_) { 704 switch (synchronization_state_) {
702 case NOT_SYNCHRONIZED: 705 case NOT_SYNCHRONIZED:
703 cookie_monster_->DeleteAllCreatedBetweenForHostAsync( 706 cookie_monster_->DeleteAllCreatedBetweenWithPredicateAsync(
704 delete_begin, delete_end, url, WrapDeleteCallback(callback)); 707 delete_begin, delete_end, predicate, WrapDeleteCallback(callback));
705 break; 708 break;
706 case SYNCHRONIZING: 709 case SYNCHRONIZING:
707 tasks_pending_synchronization_.push_back( 710 tasks_pending_synchronization_.push_back(
708 base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenForHostAsync, 711 base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync,
709 weak_factory_.GetWeakPtr(), delete_begin, delete_end, url, 712 weak_factory_.GetWeakPtr(), delete_begin, delete_end,
710 WrapDeleteCallback(callback))); 713 predicate, WrapDeleteCallback(callback)));
711 break; 714 break;
712 case SYNCHRONIZED: 715 case SYNCHRONIZED:
713 NSString* host = base::SysUTF8ToNSString(url.host()); 716 CookieFilterFunction filter =
714 CookieFilterFunction filter = base::Bind(IsCookieCreatedBetweenForHost, 717 base::Bind(IsCookieCreatedBetweenWithPredicate, delete_begin,
715 delete_begin, delete_end, host); 718 delete_end, predicate);
716 DeleteCookiesWithFilter(filter, callback); 719 DeleteCookiesWithFilter(filter, callback);
717 break; 720 break;
718 } 721 }
719 } 722 }
720 723
721 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) { 724 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) {
722 DCHECK(thread_checker_.CalledOnValidThread()); 725 DCHECK(thread_checker_.CalledOnValidThread());
723 726
724 if (metrics_enabled_) 727 if (metrics_enabled_)
725 ResetCookieCountMetrics(); 728 ResetCookieCountMetrics();
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 weak_factory_.GetWeakPtr(), callback); 1156 weak_factory_.GetWeakPtr(), callback);
1154 } 1157 }
1155 1158
1156 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { 1159 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) {
1157 DCHECK(thread_checker_.CalledOnValidThread()); 1160 DCHECK(thread_checker_.CalledOnValidThread());
1158 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, 1161 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure,
1159 weak_factory_.GetWeakPtr(), callback); 1162 weak_factory_.GetWeakPtr(), callback);
1160 } 1163 }
1161 1164
1162 } // namespace net 1165 } // namespace net
OLDNEW
« no previous file with comments | « ios/net/cookies/cookie_store_ios.h ('k') | ios/net/cookies/cookie_store_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698