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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 Time delete_end_; | 584 Time delete_end_; |
585 | 585 |
586 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); | 586 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); |
587 }; | 587 }; |
588 | 588 |
589 int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { | 589 int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { |
590 return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, | 590 return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, |
591 delete_end_); | 591 delete_end_); |
592 } | 592 } |
593 | 593 |
594 // Task class for DeleteAllCreatedBetweenForHost call. | 594 // Task class for DeleteAllCreatedBetweenWithPredicate call. |
595 class CookieMonster::DeleteAllCreatedBetweenForHostTask | 595 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask |
596 : public DeleteTask<int> { | 596 : public DeleteTask<int> { |
597 public: | 597 public: |
598 DeleteAllCreatedBetweenForHostTask(CookieMonster* cookie_monster, | 598 DeleteAllCreatedBetweenWithPredicateTask( |
599 Time delete_begin, | 599 CookieMonster* cookie_monster, |
600 Time delete_end, | 600 Time delete_begin, |
601 const GURL& url, | 601 Time delete_end, |
602 const DeleteCallback& callback) | 602 base::Callback<bool(const CanonicalCookie&)> predicate, |
| 603 const DeleteCallback& callback) |
603 : DeleteTask<int>(cookie_monster, callback), | 604 : DeleteTask<int>(cookie_monster, callback), |
604 delete_begin_(delete_begin), | 605 delete_begin_(delete_begin), |
605 delete_end_(delete_end), | 606 delete_end_(delete_end), |
606 url_(url) {} | 607 predicate_(predicate) {} |
607 | 608 |
608 // DeleteTask: | 609 // DeleteTask: |
609 int RunDeleteTask() override; | 610 int RunDeleteTask() override; |
610 | 611 |
611 protected: | 612 protected: |
612 ~DeleteAllCreatedBetweenForHostTask() override {} | 613 ~DeleteAllCreatedBetweenWithPredicateTask() override {} |
613 | 614 |
614 private: | 615 private: |
615 Time delete_begin_; | 616 Time delete_begin_; |
616 Time delete_end_; | 617 Time delete_end_; |
617 GURL url_; | 618 base::Callback<bool(const CanonicalCookie&)> predicate_; |
618 | 619 |
619 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); | 620 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask); |
620 }; | 621 }; |
621 | 622 |
622 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { | 623 int CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() { |
623 return this->cookie_monster()->DeleteAllCreatedBetweenForHost( | 624 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate( |
624 delete_begin_, delete_end_, url_); | 625 delete_begin_, delete_end_, predicate_); |
625 } | 626 } |
626 | 627 |
627 // Task class for DeleteCanonicalCookie call. | 628 // Task class for DeleteCanonicalCookie call. |
628 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { | 629 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { |
629 public: | 630 public: |
630 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, | 631 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, |
631 const CanonicalCookie& cookie, | 632 const CanonicalCookie& cookie, |
632 const DeleteCallback& callback) | 633 const DeleteCallback& callback) |
633 : DeleteTask<int>(cookie_monster, callback), cookie_(cookie) {} | 634 : DeleteTask<int>(cookie_monster, callback), cookie_(cookie) {} |
634 | 635 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 void CookieMonster::DeleteAllCreatedBetweenAsync( | 916 void CookieMonster::DeleteAllCreatedBetweenAsync( |
916 const Time& delete_begin, | 917 const Time& delete_begin, |
917 const Time& delete_end, | 918 const Time& delete_end, |
918 const DeleteCallback& callback) { | 919 const DeleteCallback& callback) { |
919 scoped_refptr<DeleteAllCreatedBetweenTask> task = | 920 scoped_refptr<DeleteAllCreatedBetweenTask> task = |
920 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback); | 921 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback); |
921 | 922 |
922 DoCookieTask(task); | 923 DoCookieTask(task); |
923 } | 924 } |
924 | 925 |
925 void CookieMonster::DeleteAllCreatedBetweenForHostAsync( | 926 void CookieMonster::DeleteAllCreatedBetweenWithPredicateAsync( |
926 const Time delete_begin, | 927 const Time& delete_begin, |
927 const Time delete_end, | 928 const Time& delete_end, |
928 const GURL& url, | 929 const base::Callback<bool(const CanonicalCookie&)>& predicate, |
929 const DeleteCallback& callback) { | 930 const DeleteCallback& callback) { |
930 scoped_refptr<DeleteAllCreatedBetweenForHostTask> task = | 931 if (predicate.is_null()) { |
931 new DeleteAllCreatedBetweenForHostTask(this, delete_begin, delete_end, | 932 callback.Run(0); |
932 url, callback); | 933 return; |
933 | 934 } |
934 DoCookieTaskForURL(task, url); | 935 scoped_refptr<DeleteAllCreatedBetweenWithPredicateTask> task = |
| 936 new DeleteAllCreatedBetweenWithPredicateTask( |
| 937 this, delete_begin, delete_end, predicate, callback); |
| 938 DoCookieTask(task); |
935 } | 939 } |
936 | 940 |
937 void CookieMonster::DeleteSessionCookiesAsync( | 941 void CookieMonster::DeleteSessionCookiesAsync( |
938 const CookieStore::DeleteCallback& callback) { | 942 const CookieStore::DeleteCallback& callback) { |
939 scoped_refptr<DeleteSessionCookiesTask> task = | 943 scoped_refptr<DeleteSessionCookiesTask> task = |
940 new DeleteSessionCookiesTask(this, callback); | 944 new DeleteSessionCookiesTask(this, callback); |
941 | 945 |
942 DoCookieTask(task); | 946 DoCookieTask(task); |
943 } | 947 } |
944 | 948 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 (delete_end.is_null() || cc->CreationDate() < delete_end)) { | 1121 (delete_end.is_null() || cc->CreationDate() < delete_end)) { |
1118 InternalDeleteCookie(curit, true, /*sync_to_store*/ | 1122 InternalDeleteCookie(curit, true, /*sync_to_store*/ |
1119 DELETE_COOKIE_EXPLICIT); | 1123 DELETE_COOKIE_EXPLICIT); |
1120 ++num_deleted; | 1124 ++num_deleted; |
1121 } | 1125 } |
1122 } | 1126 } |
1123 | 1127 |
1124 return num_deleted; | 1128 return num_deleted; |
1125 } | 1129 } |
1126 | 1130 |
1127 int CookieMonster::DeleteAllCreatedBetweenForHost(const Time delete_begin, | 1131 int CookieMonster::DeleteAllCreatedBetweenWithPredicate( |
1128 const Time delete_end, | 1132 const base::Time& delete_begin, |
1129 const GURL& url) { | 1133 const base::Time& delete_end, |
1130 DCHECK(thread_checker_.CalledOnValidThread()); | 1134 const base::Callback<bool(const CanonicalCookie&)>& predicate) { |
| 1135 int num_deleted = 0; |
| 1136 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1137 CookieMap::iterator curit = it; |
| 1138 CanonicalCookie* cc = curit->second; |
| 1139 ++it; |
1131 | 1140 |
1132 if (!HasCookieableScheme(url)) | 1141 if (cc->CreationDate() >= delete_begin && |
1133 return 0; | |
1134 | |
1135 const std::string host(url.host()); | |
1136 | |
1137 // We store host cookies in the store by their canonical host name; | |
1138 // domain cookies are stored with a leading ".". So this is a pretty | |
1139 // simple lookup and per-cookie delete. | |
1140 int num_deleted = 0; | |
1141 for (CookieMapItPair its = cookies_.equal_range(GetKey(host)); | |
1142 its.first != its.second;) { | |
1143 CookieMap::iterator curit = its.first; | |
1144 ++its.first; | |
1145 | |
1146 const CanonicalCookie* const cc = curit->second; | |
1147 | |
1148 // Delete only on a match as a host cookie. | |
1149 if (cc->IsHostCookie() && cc->IsDomainMatch(host) && | |
1150 cc->CreationDate() >= delete_begin && | |
1151 // The assumption that null |delete_end| is equivalent to | 1142 // The assumption that null |delete_end| is equivalent to |
1152 // Time::Max() is confusing. | 1143 // Time::Max() is confusing. |
1153 (delete_end.is_null() || cc->CreationDate() < delete_end)) { | 1144 (delete_end.is_null() || cc->CreationDate() < delete_end) && |
1154 num_deleted++; | 1145 predicate.Run(*cc)) { |
1155 | 1146 InternalDeleteCookie(curit, true, /*sync_to_store*/ |
1156 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); | 1147 DELETE_COOKIE_EXPLICIT); |
| 1148 ++num_deleted; |
1157 } | 1149 } |
1158 } | 1150 } |
| 1151 |
1159 return num_deleted; | 1152 return num_deleted; |
1160 } | 1153 } |
1161 | 1154 |
1162 | |
1163 bool CookieMonster::SetCookieWithOptions(const GURL& url, | 1155 bool CookieMonster::SetCookieWithOptions(const GURL& url, |
1164 const std::string& cookie_line, | 1156 const std::string& cookie_line, |
1165 const CookieOptions& options) { | 1157 const CookieOptions& options) { |
1166 DCHECK(thread_checker_.CalledOnValidThread()); | 1158 DCHECK(thread_checker_.CalledOnValidThread()); |
1167 | 1159 |
1168 if (!HasCookieableScheme(url)) { | 1160 if (!HasCookieableScheme(url)) { |
1169 return false; | 1161 return false; |
1170 } | 1162 } |
1171 | 1163 |
1172 return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options); | 1164 return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options); |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2339 it != hook_map_.end(); ++it) { | 2331 it != hook_map_.end(); ++it) { |
2340 std::pair<GURL, std::string> key = it->first; | 2332 std::pair<GURL, std::string> key = it->first; |
2341 if (cookie.IncludeForRequestURL(key.first, opts) && | 2333 if (cookie.IncludeForRequestURL(key.first, opts) && |
2342 cookie.Name() == key.second) { | 2334 cookie.Name() == key.second) { |
2343 it->second->Notify(cookie, removed); | 2335 it->second->Notify(cookie, removed); |
2344 } | 2336 } |
2345 } | 2337 } |
2346 } | 2338 } |
2347 | 2339 |
2348 } // namespace net | 2340 } // namespace net |
OLD | NEW |