| 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 GURL url_; | 644 GURL url_; |
| 645 | 645 |
| 646 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); | 646 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); |
| 647 }; | 647 }; |
| 648 | 648 |
| 649 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { | 649 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { |
| 650 return this->cookie_monster()->DeleteAllCreatedBetweenForHost( | 650 return this->cookie_monster()->DeleteAllCreatedBetweenForHost( |
| 651 delete_begin_, delete_end_, url_); | 651 delete_begin_, delete_end_, url_); |
| 652 } | 652 } |
| 653 | 653 |
| 654 // Task class for DeleteAllCreatedBetweenForHost call. |
| 655 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask |
| 656 : public DeleteTask<int> { |
| 657 public: |
| 658 DeleteAllCreatedBetweenWithPredicateTask( |
| 659 CookieMonster* cookie_monster, |
| 660 Time delete_begin, |
| 661 Time delete_end, |
| 662 base::Callback<bool(const CanonicalCookie&)> predicate, |
| 663 const DeleteCallback& callback) |
| 664 : DeleteTask<int>(cookie_monster, callback), |
| 665 delete_begin_(delete_begin), |
| 666 delete_end_(delete_end), |
| 667 predicate_(predicate) {} |
| 668 |
| 669 // DeleteTask: |
| 670 int RunDeleteTask() override; |
| 671 |
| 672 protected: |
| 673 ~DeleteAllCreatedBetweenWithPredicateTask() override {} |
| 674 |
| 675 private: |
| 676 Time delete_begin_; |
| 677 Time delete_end_; |
| 678 base::Callback<bool(const CanonicalCookie&)> predicate_; |
| 679 |
| 680 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask); |
| 681 }; |
| 682 |
| 683 int CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() { |
| 684 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate( |
| 685 delete_begin_, delete_end_, predicate_); |
| 686 } |
| 687 |
| 654 // Task class for DeleteCanonicalCookie call. | 688 // Task class for DeleteCanonicalCookie call. |
| 655 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { | 689 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { |
| 656 public: | 690 public: |
| 657 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, | 691 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, |
| 658 const CanonicalCookie& cookie, | 692 const CanonicalCookie& cookie, |
| 659 const DeleteCallback& callback) | 693 const DeleteCallback& callback) |
| 660 : DeleteTask<int>(cookie_monster, callback), cookie_(cookie) {} | 694 : DeleteTask<int>(cookie_monster, callback), cookie_(cookie) {} |
| 661 | 695 |
| 662 // DeleteTask: | 696 // DeleteTask: |
| 663 int RunDeleteTask() override; | 697 int RunDeleteTask() override; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 const Time delete_end, | 988 const Time delete_end, |
| 955 const GURL& url, | 989 const GURL& url, |
| 956 const DeleteCallback& callback) { | 990 const DeleteCallback& callback) { |
| 957 scoped_refptr<DeleteAllCreatedBetweenForHostTask> task = | 991 scoped_refptr<DeleteAllCreatedBetweenForHostTask> task = |
| 958 new DeleteAllCreatedBetweenForHostTask(this, delete_begin, delete_end, | 992 new DeleteAllCreatedBetweenForHostTask(this, delete_begin, delete_end, |
| 959 url, callback); | 993 url, callback); |
| 960 | 994 |
| 961 DoCookieTaskForURL(task, url); | 995 DoCookieTaskForURL(task, url); |
| 962 } | 996 } |
| 963 | 997 |
| 998 void CookieMonster::DeleteAllCreatedBetweenWithPredicateAsync( |
| 999 const Time& delete_begin, |
| 1000 const Time& delete_end, |
| 1001 const base::Callback<bool(const CanonicalCookie&)>& predicate, |
| 1002 const DeleteCallback& callback) { |
| 1003 if (predicate.is_null()) { |
| 1004 DeleteAllCreatedBetweenAsync(delete_begin, delete_end, callback); |
| 1005 return; |
| 1006 } |
| 1007 scoped_refptr<DeleteAllCreatedBetweenWithPredicateTask> task = |
| 1008 new DeleteAllCreatedBetweenWithPredicateTask( |
| 1009 this, delete_begin, delete_end, predicate, callback); |
| 1010 DoCookieTask(task); |
| 1011 } |
| 1012 |
| 964 void CookieMonster::DeleteSessionCookiesAsync( | 1013 void CookieMonster::DeleteSessionCookiesAsync( |
| 965 const CookieStore::DeleteCallback& callback) { | 1014 const CookieStore::DeleteCallback& callback) { |
| 966 scoped_refptr<DeleteSessionCookiesTask> task = | 1015 scoped_refptr<DeleteSessionCookiesTask> task = |
| 967 new DeleteSessionCookiesTask(this, callback); | 1016 new DeleteSessionCookiesTask(this, callback); |
| 968 | 1017 |
| 969 DoCookieTask(task); | 1018 DoCookieTask(task); |
| 970 } | 1019 } |
| 971 | 1020 |
| 972 void CookieMonster::SetCookieableSchemes( | 1021 void CookieMonster::SetCookieableSchemes( |
| 973 const std::vector<std::string>& schemes) { | 1022 const std::vector<std::string>& schemes) { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 // Time::Max() is confusing. | 1223 // Time::Max() is confusing. |
| 1175 (delete_end.is_null() || cc->CreationDate() < delete_end)) { | 1224 (delete_end.is_null() || cc->CreationDate() < delete_end)) { |
| 1176 num_deleted++; | 1225 num_deleted++; |
| 1177 | 1226 |
| 1178 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); | 1227 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); |
| 1179 } | 1228 } |
| 1180 } | 1229 } |
| 1181 return num_deleted; | 1230 return num_deleted; |
| 1182 } | 1231 } |
| 1183 | 1232 |
| 1233 int CookieMonster::DeleteAllCreatedBetweenWithPredicate( |
| 1234 const base::Time& delete_begin, |
| 1235 const base::Time& delete_end, |
| 1236 const base::Callback<bool(const CanonicalCookie&)>& predicate) { |
| 1237 int num_deleted = 0; |
| 1238 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1239 CookieMap::iterator curit = it; |
| 1240 CanonicalCookie* cc = curit->second; |
| 1241 ++it; |
| 1242 |
| 1243 if (cc->CreationDate() >= delete_begin && |
| 1244 (delete_end.is_null() || cc->CreationDate() < delete_end) && |
| 1245 predicate.Run(*cc)) { |
| 1246 InternalDeleteCookie(curit, true, /*sync_to_store*/ |
| 1247 DELETE_COOKIE_EXPLICIT); |
| 1248 ++num_deleted; |
| 1249 } |
| 1250 } |
| 1251 |
| 1252 return num_deleted; |
| 1253 } |
| 1184 | 1254 |
| 1185 bool CookieMonster::SetCookieWithOptions(const GURL& url, | 1255 bool CookieMonster::SetCookieWithOptions(const GURL& url, |
| 1186 const std::string& cookie_line, | 1256 const std::string& cookie_line, |
| 1187 const CookieOptions& options) { | 1257 const CookieOptions& options) { |
| 1188 DCHECK(thread_checker_.CalledOnValidThread()); | 1258 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1189 | 1259 |
| 1190 if (!HasCookieableScheme(url)) { | 1260 if (!HasCookieableScheme(url)) { |
| 1191 return false; | 1261 return false; |
| 1192 } | 1262 } |
| 1193 | 1263 |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 it != hook_map_.end(); ++it) { | 2416 it != hook_map_.end(); ++it) { |
| 2347 std::pair<GURL, std::string> key = it->first; | 2417 std::pair<GURL, std::string> key = it->first; |
| 2348 if (cookie.IncludeForRequestURL(key.first, opts) && | 2418 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2349 cookie.Name() == key.second) { | 2419 cookie.Name() == key.second) { |
| 2350 it->second->Notify(cookie, removed); | 2420 it->second->Notify(cookie, removed); |
| 2351 } | 2421 } |
| 2352 } | 2422 } |
| 2353 } | 2423 } |
| 2354 | 2424 |
| 2355 } // namespace net | 2425 } // namespace net |
| OLD | NEW |