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

Side by Side Diff: net/cookies/cookie_monster.cc

Issue 2971733002: Change CookieStore::DeleteCallback to take uint32_t. (Closed)
Patch Set: Fixed Android webview compilation errors. Created 3 years, 5 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
OLDNEW
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 26 matching lines...) Expand all
37 * use your version of this file under the terms of the MPL, indicate your 37 * use your version of this file under the terms of the MPL, indicate your
38 * decision by deleting the provisions above and replace them with the notice 38 * decision by deleting the provisions above and replace them with the notice
39 * and other provisions required by the GPL or the LGPL. If you do not delete 39 * and other provisions required by the GPL or the LGPL. If you do not delete
40 * the provisions above, a recipient may use your version of this file under 40 * the provisions above, a recipient may use your version of this file under
41 * the terms of any one of the MPL, the GPL or the LGPL. 41 * the terms of any one of the MPL, the GPL or the LGPL.
42 * 42 *
43 * ***** END LICENSE BLOCK ***** */ 43 * ***** END LICENSE BLOCK ***** */
44 44
45 #include "net/cookies/cookie_monster.h" 45 #include "net/cookies/cookie_monster.h"
46 46
47 #include <cstdint>
mmenke 2017/07/05 16:58:49 This should be in the header file instead (And sho
Randy Smith (Not in Mondays) 2017/07/08 13:03:26 Done.
47 #include <functional> 48 #include <functional>
48 #include <memory> 49 #include <memory>
49 #include <set> 50 #include <set>
50 51
51 #include "base/bind.h" 52 #include "base/bind.h"
52 #include "base/callback.h" 53 #include "base/callback.h"
53 #include "base/location.h" 54 #include "base/location.h"
54 #include "base/logging.h" 55 #include "base/logging.h"
55 #include "base/macros.h" 56 #include "base/macros.h"
56 #include "base/memory/ptr_util.h" 57 #include "base/memory/ptr_util.h"
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 if (!callback.is_null()) { 604 if (!callback.is_null()) {
604 callback = 605 callback =
605 base::BindOnce(&CookieMonster::RunCallback, 606 base::BindOnce(&CookieMonster::RunCallback,
606 this->cookie_monster()->weak_ptr_factory_.GetWeakPtr(), 607 this->cookie_monster()->weak_ptr_factory_.GetWeakPtr(),
607 std::move(callback)); 608 std::move(callback));
608 } 609 }
609 this->cookie_monster()->FlushStore(std::move(callback)); 610 this->cookie_monster()->FlushStore(std::move(callback));
610 } 611 }
611 612
612 // Task class for DeleteAllCreatedBetween call. 613 // Task class for DeleteAllCreatedBetween call.
613 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { 614 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<uint32_t> {
614 public: 615 public:
615 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, 616 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster,
616 const Time& delete_begin, 617 const Time& delete_begin,
617 const Time& delete_end, 618 const Time& delete_end,
618 DeleteCallback callback) 619 DeleteCallback callback)
619 : DeleteTask<int>(cookie_monster, std::move(callback)), 620 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)),
620 delete_begin_(delete_begin), 621 delete_begin_(delete_begin),
621 delete_end_(delete_end) {} 622 delete_end_(delete_end) {}
622 623
623 // DeleteTask: 624 // DeleteTask:
624 int RunDeleteTask() override; 625 uint32_t RunDeleteTask() override;
625 626
626 protected: 627 protected:
627 ~DeleteAllCreatedBetweenTask() override {} 628 ~DeleteAllCreatedBetweenTask() override {}
628 629
629 private: 630 private:
630 Time delete_begin_; 631 Time delete_begin_;
631 Time delete_end_; 632 Time delete_end_;
632 633
633 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); 634 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask);
634 }; 635 };
635 636
636 int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { 637 uint32_t CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() {
637 return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, 638 return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_,
638 delete_end_); 639 delete_end_);
639 } 640 }
640 641
641 // Task class for DeleteAllCreatedBetweenWithPredicate call. 642 // Task class for DeleteAllCreatedBetweenWithPredicate call.
642 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask 643 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask
643 : public DeleteTask<int> { 644 : public DeleteTask<uint32_t> {
644 public: 645 public:
645 DeleteAllCreatedBetweenWithPredicateTask( 646 DeleteAllCreatedBetweenWithPredicateTask(
646 CookieMonster* cookie_monster, 647 CookieMonster* cookie_monster,
647 Time delete_begin, 648 Time delete_begin,
648 Time delete_end, 649 Time delete_end,
649 base::Callback<bool(const CanonicalCookie&)> predicate, 650 base::Callback<bool(const CanonicalCookie&)> predicate,
650 DeleteCallback callback) 651 DeleteCallback callback)
651 : DeleteTask<int>(cookie_monster, std::move(callback)), 652 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)),
652 delete_begin_(delete_begin), 653 delete_begin_(delete_begin),
653 delete_end_(delete_end), 654 delete_end_(delete_end),
654 predicate_(predicate) {} 655 predicate_(predicate) {}
655 656
656 // DeleteTask: 657 // DeleteTask:
657 int RunDeleteTask() override; 658 uint32_t RunDeleteTask() override;
658 659
659 protected: 660 protected:
660 ~DeleteAllCreatedBetweenWithPredicateTask() override {} 661 ~DeleteAllCreatedBetweenWithPredicateTask() override {}
661 662
662 private: 663 private:
663 Time delete_begin_; 664 Time delete_begin_;
664 Time delete_end_; 665 Time delete_end_;
665 base::Callback<bool(const CanonicalCookie&)> predicate_; 666 base::Callback<bool(const CanonicalCookie&)> predicate_;
666 667
667 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask); 668 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask);
668 }; 669 };
669 670
670 int CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() { 671 uint32_t
672 CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() {
671 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate( 673 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate(
672 delete_begin_, delete_end_, predicate_); 674 delete_begin_, delete_end_, predicate_);
673 } 675 }
674 676
675 // Task class for DeleteCanonicalCookie call. 677 // Task class for DeleteCanonicalCookie call.
676 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { 678 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<uint32_t> {
677 public: 679 public:
678 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, 680 DeleteCanonicalCookieTask(CookieMonster* cookie_monster,
679 const CanonicalCookie& cookie, 681 const CanonicalCookie& cookie,
680 DeleteCallback callback) 682 DeleteCallback callback)
681 : DeleteTask<int>(cookie_monster, std::move(callback)), cookie_(cookie) {} 683 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)),
684 cookie_(cookie) {}
682 685
683 // DeleteTask: 686 // DeleteTask:
684 int RunDeleteTask() override; 687 uint32_t RunDeleteTask() override;
685 688
686 protected: 689 protected:
687 ~DeleteCanonicalCookieTask() override {} 690 ~DeleteCanonicalCookieTask() override {}
688 691
689 private: 692 private:
690 CanonicalCookie cookie_; 693 CanonicalCookie cookie_;
691 694
692 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); 695 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask);
693 }; 696 };
694 697
695 int CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { 698 uint32_t CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() {
696 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); 699 return this->cookie_monster()->DeleteCanonicalCookie(cookie_);
697 } 700 }
698 701
699 // Task class for SetCanonicalCookie call. 702 // Task class for SetCanonicalCookie call.
700 class CookieMonster::SetCanonicalCookieTask : public CookieMonsterTask { 703 class CookieMonster::SetCanonicalCookieTask : public CookieMonsterTask {
701 public: 704 public:
702 SetCanonicalCookieTask(CookieMonster* cookie_monster, 705 SetCanonicalCookieTask(CookieMonster* cookie_monster,
703 std::unique_ptr<CanonicalCookie> cookie, 706 std::unique_ptr<CanonicalCookie> cookie,
704 bool secure_source, 707 bool secure_source,
705 bool modify_http_only, 708 bool modify_http_only,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 std::string cookie_name_; 869 std::string cookie_name_;
867 870
868 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); 871 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask);
869 }; 872 };
870 873
871 void CookieMonster::DeleteCookieTask::RunDeleteTask() { 874 void CookieMonster::DeleteCookieTask::RunDeleteTask() {
872 this->cookie_monster()->DeleteCookie(url_, cookie_name_); 875 this->cookie_monster()->DeleteCookie(url_, cookie_name_);
873 } 876 }
874 877
875 // Task class for DeleteSessionCookies call. 878 // Task class for DeleteSessionCookies call.
876 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { 879 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<uint32_t> {
877 public: 880 public:
878 DeleteSessionCookiesTask(CookieMonster* cookie_monster, 881 DeleteSessionCookiesTask(CookieMonster* cookie_monster,
879 DeleteCallback callback) 882 DeleteCallback callback)
880 : DeleteTask<int>(cookie_monster, std::move(callback)) {} 883 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)) {}
881 884
882 // DeleteTask: 885 // DeleteTask:
883 int RunDeleteTask() override; 886 uint32_t RunDeleteTask() override;
884 887
885 protected: 888 protected:
886 ~DeleteSessionCookiesTask() override {} 889 ~DeleteSessionCookiesTask() override {}
887 890
888 private: 891 private:
889 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); 892 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask);
890 }; 893 };
891 894
892 int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { 895 uint32_t CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() {
893 return this->cookie_monster()->DeleteSessionCookies(); 896 return this->cookie_monster()->DeleteSessionCookies();
894 } 897 }
895 898
896 // Asynchronous CookieMonster API 899 // Asynchronous CookieMonster API
897 900
898 void CookieMonster::SetCookieWithDetailsAsync(const GURL& url, 901 void CookieMonster::SetCookieWithDetailsAsync(const GURL& url,
899 const std::string& name, 902 const std::string& name,
900 const std::string& value, 903 const std::string& value,
901 const std::string& domain, 904 const std::string& domain,
902 const std::string& path, 905 const std::string& path,
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); 1203 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter);
1201 1204
1202 cookies.reserve(cookie_ptrs.size()); 1205 cookies.reserve(cookie_ptrs.size());
1203 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); 1206 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin();
1204 it != cookie_ptrs.end(); it++) 1207 it != cookie_ptrs.end(); it++)
1205 cookies.push_back(**it); 1208 cookies.push_back(**it);
1206 1209
1207 return cookies; 1210 return cookies;
1208 } 1211 }
1209 1212
1210 int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, 1213 uint32_t CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin,
1211 const Time& delete_end) { 1214 const Time& delete_end) {
1212 DCHECK(thread_checker_.CalledOnValidThread()); 1215 DCHECK(thread_checker_.CalledOnValidThread());
1213 1216
1214 int num_deleted = 0; 1217 uint32_t num_deleted = 0;
1215 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { 1218 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
1216 CookieMap::iterator curit = it; 1219 CookieMap::iterator curit = it;
1217 CanonicalCookie* cc = curit->second.get(); 1220 CanonicalCookie* cc = curit->second.get();
1218 ++it; 1221 ++it;
1219 1222
1220 if (cc->CreationDate() >= delete_begin && 1223 if (cc->CreationDate() >= delete_begin &&
1221 (delete_end.is_null() || cc->CreationDate() < delete_end)) { 1224 (delete_end.is_null() || cc->CreationDate() < delete_end)) {
1222 InternalDeleteCookie(curit, true, /*sync_to_store*/ 1225 InternalDeleteCookie(curit, true, /*sync_to_store*/
1223 DELETE_COOKIE_CREATED_BETWEEN); 1226 DELETE_COOKIE_CREATED_BETWEEN);
1224 ++num_deleted; 1227 ++num_deleted;
1225 } 1228 }
1226 } 1229 }
1227 1230
1228 return num_deleted; 1231 return num_deleted;
1229 } 1232 }
1230 1233
1231 int CookieMonster::DeleteAllCreatedBetweenWithPredicate( 1234 uint32_t CookieMonster::DeleteAllCreatedBetweenWithPredicate(
1232 const base::Time& delete_begin, 1235 const base::Time& delete_begin,
1233 const base::Time& delete_end, 1236 const base::Time& delete_end,
1234 const base::Callback<bool(const CanonicalCookie&)>& predicate) { 1237 const base::Callback<bool(const CanonicalCookie&)>& predicate) {
1235 int num_deleted = 0; 1238 uint32_t num_deleted = 0;
1236 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { 1239 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
1237 CookieMap::iterator curit = it; 1240 CookieMap::iterator curit = it;
1238 CanonicalCookie* cc = curit->second.get(); 1241 CanonicalCookie* cc = curit->second.get();
1239 ++it; 1242 ++it;
1240 1243
1241 if (cc->CreationDate() >= delete_begin && 1244 if (cc->CreationDate() >= delete_begin &&
1242 // The assumption that null |delete_end| is equivalent to 1245 // The assumption that null |delete_end| is equivalent to
1243 // Time::Max() is confusing. 1246 // Time::Max() is confusing.
1244 (delete_end.is_null() || cc->CreationDate() < delete_end) && 1247 (delete_end.is_null() || cc->CreationDate() < delete_end) &&
1245 predicate.Run(*cc)) { 1248 predicate.Run(*cc)) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 1311
1309 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { 1312 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
1310 CookieMap::iterator curit = it; 1313 CookieMap::iterator curit = it;
1311 ++it; 1314 ++it;
1312 if (matching_cookies.find(curit->second.get()) != matching_cookies.end()) { 1315 if (matching_cookies.find(curit->second.get()) != matching_cookies.end()) {
1313 InternalDeleteCookie(curit, true, DELETE_COOKIE_SINGLE); 1316 InternalDeleteCookie(curit, true, DELETE_COOKIE_SINGLE);
1314 } 1317 }
1315 } 1318 }
1316 } 1319 }
1317 1320
1318 int CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { 1321 uint32_t CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) {
1319 DCHECK(thread_checker_.CalledOnValidThread()); 1322 DCHECK(thread_checker_.CalledOnValidThread());
1320 1323
1321 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain())); 1324 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain()));
1322 its.first != its.second; ++its.first) { 1325 its.first != its.second; ++its.first) {
1323 // The creation date acts as the unique index... 1326 // The creation date acts as the unique index...
1324 if (its.first->second->CreationDate() == cookie.CreationDate()) { 1327 if (its.first->second->CreationDate() == cookie.CreationDate()) {
1325 InternalDeleteCookie(its.first, true, DELETE_COOKIE_CANONICAL); 1328 InternalDeleteCookie(its.first, true, DELETE_COOKIE_CANONICAL);
1326 return 1; 1329 return 1u;
1327 } 1330 }
1328 } 1331 }
1329 return 0; 1332 return 0u;
1330 } 1333 }
1331 1334
1332 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, 1335 bool CookieMonster::SetCookieWithCreationTime(const GURL& url,
1333 const std::string& cookie_line, 1336 const std::string& cookie_line,
1334 const base::Time& creation_time) { 1337 const base::Time& creation_time) {
1335 DCHECK(thread_checker_.CalledOnValidThread()); 1338 DCHECK(thread_checker_.CalledOnValidThread());
1336 DCHECK(!store_.get()) << "This method is only to be used by unit-tests."; 1339 DCHECK(!store_.get()) << "This method is only to be used by unit-tests.";
1337 1340
1338 if (!HasCookieableScheme(url)) { 1341 if (!HasCookieableScheme(url)) {
1339 return false; 1342 return false;
1340 } 1343 }
1341 1344
1342 MarkCookieStoreAsInitialized(); 1345 MarkCookieStoreAsInitialized();
1343 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) 1346 if (ShouldFetchAllCookiesWhenFetchingAnyCookie())
1344 FetchAllCookiesIfNecessary(); 1347 FetchAllCookiesIfNecessary();
1345 1348
1346 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, 1349 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time,
1347 CookieOptions()); 1350 CookieOptions());
1348 } 1351 }
1349 1352
1350 int CookieMonster::DeleteSessionCookies() { 1353 uint32_t CookieMonster::DeleteSessionCookies() {
1351 DCHECK(thread_checker_.CalledOnValidThread()); 1354 DCHECK(thread_checker_.CalledOnValidThread());
1352 1355
1353 int num_deleted = 0; 1356 uint32_t num_deleted = 0;
1354 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { 1357 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
1355 CookieMap::iterator curit = it; 1358 CookieMap::iterator curit = it;
1356 CanonicalCookie* cc = curit->second.get(); 1359 CanonicalCookie* cc = curit->second.get();
1357 ++it; 1360 ++it;
1358 1361
1359 if (!cc->IsPersistent()) { 1362 if (!cc->IsPersistent()) {
1360 InternalDeleteCookie(curit, true, /*sync_to_store*/ 1363 InternalDeleteCookie(curit, true, /*sync_to_store*/
1361 DELETE_COOKIE_EXPIRED); 1364 DELETE_COOKIE_EXPIRED);
1362 ++num_deleted; 1365 ++num_deleted;
1363 } 1366 }
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 it != hook_map_.end(); ++it) { 2502 it != hook_map_.end(); ++it) {
2500 std::pair<GURL, std::string> key = it->first; 2503 std::pair<GURL, std::string> key = it->first;
2501 if (cookie.IncludeForRequestURL(key.first, opts) && 2504 if (cookie.IncludeForRequestURL(key.first, opts) &&
2502 cookie.Name() == key.second) { 2505 cookie.Name() == key.second) {
2503 it->second->Notify(cookie, cause); 2506 it->second->Notify(cookie, cause);
2504 } 2507 }
2505 } 2508 }
2506 } 2509 }
2507 2510
2508 } // namespace net 2511 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698