| 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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 if (!callback.is_null()) { | 603 if (!callback.is_null()) { |
| 604 callback = | 604 callback = |
| 605 base::BindOnce(&CookieMonster::RunCallback, | 605 base::BindOnce(&CookieMonster::RunCallback, |
| 606 this->cookie_monster()->weak_ptr_factory_.GetWeakPtr(), | 606 this->cookie_monster()->weak_ptr_factory_.GetWeakPtr(), |
| 607 std::move(callback)); | 607 std::move(callback)); |
| 608 } | 608 } |
| 609 this->cookie_monster()->FlushStore(std::move(callback)); | 609 this->cookie_monster()->FlushStore(std::move(callback)); |
| 610 } | 610 } |
| 611 | 611 |
| 612 // Task class for DeleteAllCreatedBetween call. | 612 // Task class for DeleteAllCreatedBetween call. |
| 613 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { | 613 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<uint32_t> { |
| 614 public: | 614 public: |
| 615 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, | 615 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, |
| 616 const Time& delete_begin, | 616 const Time& delete_begin, |
| 617 const Time& delete_end, | 617 const Time& delete_end, |
| 618 DeleteCallback callback) | 618 DeleteCallback callback) |
| 619 : DeleteTask<int>(cookie_monster, std::move(callback)), | 619 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)), |
| 620 delete_begin_(delete_begin), | 620 delete_begin_(delete_begin), |
| 621 delete_end_(delete_end) {} | 621 delete_end_(delete_end) {} |
| 622 | 622 |
| 623 // DeleteTask: | 623 // DeleteTask: |
| 624 int RunDeleteTask() override; | 624 uint32_t RunDeleteTask() override; |
| 625 | 625 |
| 626 protected: | 626 protected: |
| 627 ~DeleteAllCreatedBetweenTask() override {} | 627 ~DeleteAllCreatedBetweenTask() override {} |
| 628 | 628 |
| 629 private: | 629 private: |
| 630 Time delete_begin_; | 630 Time delete_begin_; |
| 631 Time delete_end_; | 631 Time delete_end_; |
| 632 | 632 |
| 633 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); | 633 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); |
| 634 }; | 634 }; |
| 635 | 635 |
| 636 int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { | 636 uint32_t CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { |
| 637 return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, | 637 return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, |
| 638 delete_end_); | 638 delete_end_); |
| 639 } | 639 } |
| 640 | 640 |
| 641 // Task class for DeleteAllCreatedBetweenWithPredicate call. | 641 // Task class for DeleteAllCreatedBetweenWithPredicate call. |
| 642 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask | 642 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask |
| 643 : public DeleteTask<int> { | 643 : public DeleteTask<uint32_t> { |
| 644 public: | 644 public: |
| 645 DeleteAllCreatedBetweenWithPredicateTask( | 645 DeleteAllCreatedBetweenWithPredicateTask( |
| 646 CookieMonster* cookie_monster, | 646 CookieMonster* cookie_monster, |
| 647 Time delete_begin, | 647 Time delete_begin, |
| 648 Time delete_end, | 648 Time delete_end, |
| 649 base::Callback<bool(const CanonicalCookie&)> predicate, | 649 base::Callback<bool(const CanonicalCookie&)> predicate, |
| 650 DeleteCallback callback) | 650 DeleteCallback callback) |
| 651 : DeleteTask<int>(cookie_monster, std::move(callback)), | 651 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)), |
| 652 delete_begin_(delete_begin), | 652 delete_begin_(delete_begin), |
| 653 delete_end_(delete_end), | 653 delete_end_(delete_end), |
| 654 predicate_(predicate) {} | 654 predicate_(predicate) {} |
| 655 | 655 |
| 656 // DeleteTask: | 656 // DeleteTask: |
| 657 int RunDeleteTask() override; | 657 uint32_t RunDeleteTask() override; |
| 658 | 658 |
| 659 protected: | 659 protected: |
| 660 ~DeleteAllCreatedBetweenWithPredicateTask() override {} | 660 ~DeleteAllCreatedBetweenWithPredicateTask() override {} |
| 661 | 661 |
| 662 private: | 662 private: |
| 663 Time delete_begin_; | 663 Time delete_begin_; |
| 664 Time delete_end_; | 664 Time delete_end_; |
| 665 base::Callback<bool(const CanonicalCookie&)> predicate_; | 665 base::Callback<bool(const CanonicalCookie&)> predicate_; |
| 666 | 666 |
| 667 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask); | 667 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask); |
| 668 }; | 668 }; |
| 669 | 669 |
| 670 int CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() { | 670 uint32_t |
| 671 CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() { |
| 671 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate( | 672 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate( |
| 672 delete_begin_, delete_end_, predicate_); | 673 delete_begin_, delete_end_, predicate_); |
| 673 } | 674 } |
| 674 | 675 |
| 675 // Task class for DeleteCanonicalCookie call. | 676 // Task class for DeleteCanonicalCookie call. |
| 676 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { | 677 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<uint32_t> { |
| 677 public: | 678 public: |
| 678 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, | 679 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, |
| 679 const CanonicalCookie& cookie, | 680 const CanonicalCookie& cookie, |
| 680 DeleteCallback callback) | 681 DeleteCallback callback) |
| 681 : DeleteTask<int>(cookie_monster, std::move(callback)), cookie_(cookie) {} | 682 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)), |
| 683 cookie_(cookie) {} |
| 682 | 684 |
| 683 // DeleteTask: | 685 // DeleteTask: |
| 684 int RunDeleteTask() override; | 686 uint32_t RunDeleteTask() override; |
| 685 | 687 |
| 686 protected: | 688 protected: |
| 687 ~DeleteCanonicalCookieTask() override {} | 689 ~DeleteCanonicalCookieTask() override {} |
| 688 | 690 |
| 689 private: | 691 private: |
| 690 CanonicalCookie cookie_; | 692 CanonicalCookie cookie_; |
| 691 | 693 |
| 692 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); | 694 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); |
| 693 }; | 695 }; |
| 694 | 696 |
| 695 int CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { | 697 uint32_t CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { |
| 696 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); | 698 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); |
| 697 } | 699 } |
| 698 | 700 |
| 699 // Task class for SetCanonicalCookie call. | 701 // Task class for SetCanonicalCookie call. |
| 700 class CookieMonster::SetCanonicalCookieTask : public CookieMonsterTask { | 702 class CookieMonster::SetCanonicalCookieTask : public CookieMonsterTask { |
| 701 public: | 703 public: |
| 702 SetCanonicalCookieTask(CookieMonster* cookie_monster, | 704 SetCanonicalCookieTask(CookieMonster* cookie_monster, |
| 703 std::unique_ptr<CanonicalCookie> cookie, | 705 std::unique_ptr<CanonicalCookie> cookie, |
| 704 bool secure_source, | 706 bool secure_source, |
| 705 bool modify_http_only, | 707 bool modify_http_only, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 std::string cookie_name_; | 868 std::string cookie_name_; |
| 867 | 869 |
| 868 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); | 870 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); |
| 869 }; | 871 }; |
| 870 | 872 |
| 871 void CookieMonster::DeleteCookieTask::RunDeleteTask() { | 873 void CookieMonster::DeleteCookieTask::RunDeleteTask() { |
| 872 this->cookie_monster()->DeleteCookie(url_, cookie_name_); | 874 this->cookie_monster()->DeleteCookie(url_, cookie_name_); |
| 873 } | 875 } |
| 874 | 876 |
| 875 // Task class for DeleteSessionCookies call. | 877 // Task class for DeleteSessionCookies call. |
| 876 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { | 878 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<uint32_t> { |
| 877 public: | 879 public: |
| 878 DeleteSessionCookiesTask(CookieMonster* cookie_monster, | 880 DeleteSessionCookiesTask(CookieMonster* cookie_monster, |
| 879 DeleteCallback callback) | 881 DeleteCallback callback) |
| 880 : DeleteTask<int>(cookie_monster, std::move(callback)) {} | 882 : DeleteTask<uint32_t>(cookie_monster, std::move(callback)) {} |
| 881 | 883 |
| 882 // DeleteTask: | 884 // DeleteTask: |
| 883 int RunDeleteTask() override; | 885 uint32_t RunDeleteTask() override; |
| 884 | 886 |
| 885 protected: | 887 protected: |
| 886 ~DeleteSessionCookiesTask() override {} | 888 ~DeleteSessionCookiesTask() override {} |
| 887 | 889 |
| 888 private: | 890 private: |
| 889 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); | 891 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); |
| 890 }; | 892 }; |
| 891 | 893 |
| 892 int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { | 894 uint32_t CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { |
| 893 return this->cookie_monster()->DeleteSessionCookies(); | 895 return this->cookie_monster()->DeleteSessionCookies(); |
| 894 } | 896 } |
| 895 | 897 |
| 896 // Asynchronous CookieMonster API | 898 // Asynchronous CookieMonster API |
| 897 | 899 |
| 898 void CookieMonster::SetCookieWithDetailsAsync(const GURL& url, | 900 void CookieMonster::SetCookieWithDetailsAsync(const GURL& url, |
| 899 const std::string& name, | 901 const std::string& name, |
| 900 const std::string& value, | 902 const std::string& value, |
| 901 const std::string& domain, | 903 const std::string& domain, |
| 902 const std::string& path, | 904 const std::string& path, |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); | 1202 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); |
| 1201 | 1203 |
| 1202 cookies.reserve(cookie_ptrs.size()); | 1204 cookies.reserve(cookie_ptrs.size()); |
| 1203 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); | 1205 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); |
| 1204 it != cookie_ptrs.end(); it++) | 1206 it != cookie_ptrs.end(); it++) |
| 1205 cookies.push_back(**it); | 1207 cookies.push_back(**it); |
| 1206 | 1208 |
| 1207 return cookies; | 1209 return cookies; |
| 1208 } | 1210 } |
| 1209 | 1211 |
| 1210 int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, | 1212 uint32_t CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, |
| 1211 const Time& delete_end) { | 1213 const Time& delete_end) { |
| 1212 DCHECK(thread_checker_.CalledOnValidThread()); | 1214 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1213 | 1215 |
| 1214 int num_deleted = 0; | 1216 uint32_t num_deleted = 0; |
| 1215 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1217 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1216 CookieMap::iterator curit = it; | 1218 CookieMap::iterator curit = it; |
| 1217 CanonicalCookie* cc = curit->second.get(); | 1219 CanonicalCookie* cc = curit->second.get(); |
| 1218 ++it; | 1220 ++it; |
| 1219 | 1221 |
| 1220 if (cc->CreationDate() >= delete_begin && | 1222 if (cc->CreationDate() >= delete_begin && |
| 1221 (delete_end.is_null() || cc->CreationDate() < delete_end)) { | 1223 (delete_end.is_null() || cc->CreationDate() < delete_end)) { |
| 1222 InternalDeleteCookie(curit, true, /*sync_to_store*/ | 1224 InternalDeleteCookie(curit, true, /*sync_to_store*/ |
| 1223 DELETE_COOKIE_CREATED_BETWEEN); | 1225 DELETE_COOKIE_CREATED_BETWEEN); |
| 1224 ++num_deleted; | 1226 ++num_deleted; |
| 1225 } | 1227 } |
| 1226 } | 1228 } |
| 1227 | 1229 |
| 1228 return num_deleted; | 1230 return num_deleted; |
| 1229 } | 1231 } |
| 1230 | 1232 |
| 1231 int CookieMonster::DeleteAllCreatedBetweenWithPredicate( | 1233 uint32_t CookieMonster::DeleteAllCreatedBetweenWithPredicate( |
| 1232 const base::Time& delete_begin, | 1234 const base::Time& delete_begin, |
| 1233 const base::Time& delete_end, | 1235 const base::Time& delete_end, |
| 1234 const base::Callback<bool(const CanonicalCookie&)>& predicate) { | 1236 const base::Callback<bool(const CanonicalCookie&)>& predicate) { |
| 1235 int num_deleted = 0; | 1237 uint32_t num_deleted = 0; |
| 1236 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1238 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1237 CookieMap::iterator curit = it; | 1239 CookieMap::iterator curit = it; |
| 1238 CanonicalCookie* cc = curit->second.get(); | 1240 CanonicalCookie* cc = curit->second.get(); |
| 1239 ++it; | 1241 ++it; |
| 1240 | 1242 |
| 1241 if (cc->CreationDate() >= delete_begin && | 1243 if (cc->CreationDate() >= delete_begin && |
| 1242 // The assumption that null |delete_end| is equivalent to | 1244 // The assumption that null |delete_end| is equivalent to |
| 1243 // Time::Max() is confusing. | 1245 // Time::Max() is confusing. |
| 1244 (delete_end.is_null() || cc->CreationDate() < delete_end) && | 1246 (delete_end.is_null() || cc->CreationDate() < delete_end) && |
| 1245 predicate.Run(*cc)) { | 1247 predicate.Run(*cc)) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 | 1310 |
| 1309 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1311 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1310 CookieMap::iterator curit = it; | 1312 CookieMap::iterator curit = it; |
| 1311 ++it; | 1313 ++it; |
| 1312 if (matching_cookies.find(curit->second.get()) != matching_cookies.end()) { | 1314 if (matching_cookies.find(curit->second.get()) != matching_cookies.end()) { |
| 1313 InternalDeleteCookie(curit, true, DELETE_COOKIE_SINGLE); | 1315 InternalDeleteCookie(curit, true, DELETE_COOKIE_SINGLE); |
| 1314 } | 1316 } |
| 1315 } | 1317 } |
| 1316 } | 1318 } |
| 1317 | 1319 |
| 1318 int CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { | 1320 uint32_t CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { |
| 1319 DCHECK(thread_checker_.CalledOnValidThread()); | 1321 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1320 | 1322 |
| 1321 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain())); | 1323 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain())); |
| 1322 its.first != its.second; ++its.first) { | 1324 its.first != its.second; ++its.first) { |
| 1323 // The creation date acts as the unique index... | 1325 // The creation date acts as the unique index... |
| 1324 if (its.first->second->CreationDate() == cookie.CreationDate()) { | 1326 if (its.first->second->CreationDate() == cookie.CreationDate()) { |
| 1325 InternalDeleteCookie(its.first, true, DELETE_COOKIE_CANONICAL); | 1327 InternalDeleteCookie(its.first, true, DELETE_COOKIE_CANONICAL); |
| 1326 return 1; | 1328 return 1u; |
| 1327 } | 1329 } |
| 1328 } | 1330 } |
| 1329 return 0; | 1331 return 0u; |
| 1330 } | 1332 } |
| 1331 | 1333 |
| 1332 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, | 1334 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, |
| 1333 const std::string& cookie_line, | 1335 const std::string& cookie_line, |
| 1334 const base::Time& creation_time) { | 1336 const base::Time& creation_time) { |
| 1335 DCHECK(thread_checker_.CalledOnValidThread()); | 1337 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1336 DCHECK(!store_.get()) << "This method is only to be used by unit-tests."; | 1338 DCHECK(!store_.get()) << "This method is only to be used by unit-tests."; |
| 1337 | 1339 |
| 1338 if (!HasCookieableScheme(url)) { | 1340 if (!HasCookieableScheme(url)) { |
| 1339 return false; | 1341 return false; |
| 1340 } | 1342 } |
| 1341 | 1343 |
| 1342 MarkCookieStoreAsInitialized(); | 1344 MarkCookieStoreAsInitialized(); |
| 1343 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) | 1345 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) |
| 1344 FetchAllCookiesIfNecessary(); | 1346 FetchAllCookiesIfNecessary(); |
| 1345 | 1347 |
| 1346 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, | 1348 return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, |
| 1347 CookieOptions()); | 1349 CookieOptions()); |
| 1348 } | 1350 } |
| 1349 | 1351 |
| 1350 int CookieMonster::DeleteSessionCookies() { | 1352 uint32_t CookieMonster::DeleteSessionCookies() { |
| 1351 DCHECK(thread_checker_.CalledOnValidThread()); | 1353 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1352 | 1354 |
| 1353 int num_deleted = 0; | 1355 uint32_t num_deleted = 0; |
| 1354 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1356 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1355 CookieMap::iterator curit = it; | 1357 CookieMap::iterator curit = it; |
| 1356 CanonicalCookie* cc = curit->second.get(); | 1358 CanonicalCookie* cc = curit->second.get(); |
| 1357 ++it; | 1359 ++it; |
| 1358 | 1360 |
| 1359 if (!cc->IsPersistent()) { | 1361 if (!cc->IsPersistent()) { |
| 1360 InternalDeleteCookie(curit, true, /*sync_to_store*/ | 1362 InternalDeleteCookie(curit, true, /*sync_to_store*/ |
| 1361 DELETE_COOKIE_EXPIRED); | 1363 DELETE_COOKIE_EXPIRED); |
| 1362 ++num_deleted; | 1364 ++num_deleted; |
| 1363 } | 1365 } |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2499 it != hook_map_.end(); ++it) { | 2501 it != hook_map_.end(); ++it) { |
| 2500 std::pair<GURL, std::string> key = it->first; | 2502 std::pair<GURL, std::string> key = it->first; |
| 2501 if (cookie.IncludeForRequestURL(key.first, opts) && | 2503 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2502 cookie.Name() == key.second) { | 2504 cookie.Name() == key.second) { |
| 2503 it->second->Notify(cookie, cause); | 2505 it->second->Notify(cookie, cause); |
| 2504 } | 2506 } |
| 2505 } | 2507 } |
| 2506 } | 2508 } |
| 2507 | 2509 |
| 2508 } // namespace net | 2510 } // namespace net |
| OLD | NEW |