Chromium Code Reviews| 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 const std::string& value, | 424 const std::string& value, |
| 425 const std::string& domain, | 425 const std::string& domain, |
| 426 const std::string& path, | 426 const std::string& path, |
| 427 base::Time creation_time, | 427 base::Time creation_time, |
| 428 base::Time expiration_time, | 428 base::Time expiration_time, |
| 429 base::Time last_access_time, | 429 base::Time last_access_time, |
| 430 bool secure, | 430 bool secure, |
| 431 bool http_only, | 431 bool http_only, |
| 432 CookieSameSite same_site, | 432 CookieSameSite same_site, |
| 433 CookiePriority priority, | 433 CookiePriority priority, |
| 434 const SetCookiesCallback& callback) | 434 SetCookiesCallback callback) |
| 435 : CookieMonsterTask(cookie_monster), | 435 : CookieMonsterTask(cookie_monster), |
| 436 url_(url), | 436 url_(url), |
| 437 name_(name), | 437 name_(name), |
| 438 value_(value), | 438 value_(value), |
| 439 domain_(domain), | 439 domain_(domain), |
| 440 path_(path), | 440 path_(path), |
| 441 creation_time_(creation_time), | 441 creation_time_(creation_time), |
| 442 expiration_time_(expiration_time), | 442 expiration_time_(expiration_time), |
| 443 last_access_time_(last_access_time), | 443 last_access_time_(last_access_time), |
| 444 secure_(secure), | 444 secure_(secure), |
| 445 http_only_(http_only), | 445 http_only_(http_only), |
| 446 same_site_(same_site), | 446 same_site_(same_site), |
| 447 priority_(priority), | 447 priority_(priority), |
| 448 callback_(callback) {} | 448 callback_(std::move(callback)) {} |
| 449 | 449 |
| 450 // CookieMonsterTask: | 450 // CookieMonsterTask: |
| 451 void Run() override; | 451 void Run() override; |
| 452 | 452 |
| 453 protected: | 453 protected: |
| 454 ~SetCookieWithDetailsTask() override {} | 454 ~SetCookieWithDetailsTask() override {} |
| 455 | 455 |
| 456 private: | 456 private: |
| 457 GURL url_; | 457 GURL url_; |
| 458 std::string name_; | 458 std::string name_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 469 SetCookiesCallback callback_; | 469 SetCookiesCallback callback_; |
| 470 | 470 |
| 471 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); | 471 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); |
| 472 }; | 472 }; |
| 473 | 473 |
| 474 void CookieMonster::SetCookieWithDetailsTask::Run() { | 474 void CookieMonster::SetCookieWithDetailsTask::Run() { |
| 475 bool success = this->cookie_monster()->SetCookieWithDetails( | 475 bool success = this->cookie_monster()->SetCookieWithDetails( |
| 476 url_, name_, value_, domain_, path_, creation_time_, expiration_time_, | 476 url_, name_, value_, domain_, path_, creation_time_, expiration_time_, |
| 477 last_access_time_, secure_, http_only_, same_site_, priority_); | 477 last_access_time_, secure_, http_only_, same_site_, priority_); |
| 478 if (!callback_.is_null()) | 478 if (!callback_.is_null()) |
| 479 callback_.Run(success); | 479 std::move(callback_).Run(success); |
| 480 } | 480 } |
| 481 | 481 |
| 482 // Task class for GetAllCookies call. | 482 // Task class for GetAllCookies call. |
| 483 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { | 483 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { |
| 484 public: | 484 public: |
| 485 GetAllCookiesTask(CookieMonster* cookie_monster, | 485 GetAllCookiesTask(CookieMonster* cookie_monster, |
| 486 const GetCookieListCallback& callback) | 486 GetCookieListCallback callback) |
| 487 : CookieMonsterTask(cookie_monster), callback_(callback) {} | 487 : CookieMonsterTask(cookie_monster), callback_(std::move(callback)) {} |
| 488 | 488 |
| 489 // CookieMonsterTask | 489 // CookieMonsterTask |
| 490 void Run() override; | 490 void Run() override; |
| 491 | 491 |
| 492 protected: | 492 protected: |
| 493 ~GetAllCookiesTask() override {} | 493 ~GetAllCookiesTask() override {} |
| 494 | 494 |
| 495 private: | 495 private: |
| 496 GetCookieListCallback callback_; | 496 GetCookieListCallback callback_; |
| 497 | 497 |
| 498 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); | 498 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); |
| 499 }; | 499 }; |
| 500 | 500 |
| 501 void CookieMonster::GetAllCookiesTask::Run() { | 501 void CookieMonster::GetAllCookiesTask::Run() { |
| 502 if (!callback_.is_null()) { | 502 if (!callback_.is_null()) { |
| 503 CookieList cookies = this->cookie_monster()->GetAllCookies(); | 503 CookieList cookies = this->cookie_monster()->GetAllCookies(); |
| 504 callback_.Run(cookies); | 504 std::move(callback_).Run(cookies); |
| 505 } | 505 } |
| 506 } | 506 } |
| 507 | 507 |
| 508 // Task class for GetCookieListWithOptionsAsync call. | 508 // Task class for GetCookieListWithOptionsAsync call. |
| 509 class CookieMonster::GetCookieListWithOptionsTask : public CookieMonsterTask { | 509 class CookieMonster::GetCookieListWithOptionsTask : public CookieMonsterTask { |
| 510 public: | 510 public: |
| 511 GetCookieListWithOptionsTask(CookieMonster* cookie_monster, | 511 GetCookieListWithOptionsTask(CookieMonster* cookie_monster, |
| 512 const GURL& url, | 512 const GURL& url, |
| 513 const CookieOptions& options, | 513 const CookieOptions& options, |
| 514 const GetCookieListCallback& callback) | 514 GetCookieListCallback callback) |
| 515 : CookieMonsterTask(cookie_monster), | 515 : CookieMonsterTask(cookie_monster), |
| 516 url_(url), | 516 url_(url), |
| 517 options_(options), | 517 options_(options), |
| 518 callback_(callback) {} | 518 callback_(std::move(callback)) {} |
| 519 | 519 |
| 520 // CookieMonsterTask: | 520 // CookieMonsterTask: |
| 521 void Run() override; | 521 void Run() override; |
| 522 | 522 |
| 523 protected: | 523 protected: |
| 524 ~GetCookieListWithOptionsTask() override {} | 524 ~GetCookieListWithOptionsTask() override {} |
| 525 | 525 |
| 526 private: | 526 private: |
| 527 GURL url_; | 527 GURL url_; |
| 528 CookieOptions options_; | 528 CookieOptions options_; |
| 529 GetCookieListCallback callback_; | 529 GetCookieListCallback callback_; |
| 530 | 530 |
| 531 DISALLOW_COPY_AND_ASSIGN(GetCookieListWithOptionsTask); | 531 DISALLOW_COPY_AND_ASSIGN(GetCookieListWithOptionsTask); |
| 532 }; | 532 }; |
| 533 | 533 |
| 534 void CookieMonster::GetCookieListWithOptionsTask::Run() { | 534 void CookieMonster::GetCookieListWithOptionsTask::Run() { |
| 535 if (!callback_.is_null()) { | 535 if (!callback_.is_null()) { |
| 536 CookieList cookies = | 536 CookieList cookies = |
| 537 this->cookie_monster()->GetCookieListWithOptions(url_, options_); | 537 this->cookie_monster()->GetCookieListWithOptions(url_, options_); |
| 538 callback_.Run(cookies); | 538 std::move(callback_).Run(cookies); |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 | 541 |
| 542 template <typename Result> | 542 template <typename Result> |
| 543 struct CallbackType { | 543 struct CallbackType { |
| 544 typedef base::Callback<void(Result)> Type; | 544 typedef base::OnceCallback<void(Result)> Type; |
| 545 }; | 545 }; |
| 546 | 546 |
| 547 template <> | 547 template <> |
| 548 struct CallbackType<void> { | 548 struct CallbackType<void> { |
| 549 typedef base::Closure Type; | 549 typedef base::OnceClosure Type; |
| 550 }; | 550 }; |
| 551 | 551 |
| 552 // Base task class for Delete*Task. | 552 // Base task class for Delete*Task. |
| 553 template <typename Result> | 553 template <typename Result> |
| 554 class CookieMonster::DeleteTask : public CookieMonsterTask { | 554 class CookieMonster::DeleteTask : public CookieMonsterTask { |
| 555 public: | 555 public: |
| 556 DeleteTask(CookieMonster* cookie_monster, | 556 DeleteTask(CookieMonster* cookie_monster, |
| 557 const typename CallbackType<Result>::Type& callback) | 557 typename CallbackType<Result>::Type callback) |
| 558 : CookieMonsterTask(cookie_monster), callback_(callback) {} | 558 : CookieMonsterTask(cookie_monster), callback_(std::move(callback)) {} |
| 559 | 559 |
| 560 // CookieMonsterTask: | 560 // CookieMonsterTask: |
| 561 void Run() override; | 561 void Run() override; |
| 562 | 562 |
| 563 protected: | 563 protected: |
| 564 ~DeleteTask() override; | 564 ~DeleteTask() override; |
| 565 | 565 |
| 566 private: | 566 private: |
| 567 // Runs the delete task and returns a result. | 567 // Runs the delete task and returns a result. |
| 568 virtual Result RunDeleteTask() = 0; | 568 virtual Result RunDeleteTask() = 0; |
| 569 // Runs the delete task and then returns a callback to be called after | 569 // Runs the delete task and then returns a callback to be called after |
| 570 // flushing the persistent store. | 570 // flushing the persistent store. |
| 571 // TODO(mmenke): This seems like a pretty ugly and needlessly confusing API. | 571 // TODO(mmenke): This seems like a pretty ugly and needlessly confusing API. |
| 572 // Simplify it? | 572 // Simplify it? |
| 573 base::Closure RunDeleteTaskAndBindCallback(); | 573 base::OnceClosure RunDeleteTaskAndBindCallback(); |
| 574 | 574 |
| 575 typename CallbackType<Result>::Type callback_; | 575 typename CallbackType<Result>::Type callback_; |
| 576 | 576 |
| 577 DISALLOW_COPY_AND_ASSIGN(DeleteTask); | 577 DISALLOW_COPY_AND_ASSIGN(DeleteTask); |
| 578 }; | 578 }; |
| 579 | 579 |
| 580 template <typename Result> | 580 template <typename Result> |
| 581 CookieMonster::DeleteTask<Result>::~DeleteTask() { | 581 CookieMonster::DeleteTask<Result>::~DeleteTask() { |
| 582 } | 582 } |
| 583 | 583 |
| 584 template <typename Result> | 584 template <typename Result> |
| 585 base::Closure | 585 base::OnceClosure |
| 586 CookieMonster::DeleteTask<Result>::RunDeleteTaskAndBindCallback() { | 586 CookieMonster::DeleteTask<Result>::RunDeleteTaskAndBindCallback() { |
| 587 Result result = RunDeleteTask(); | 587 Result result = RunDeleteTask(); |
| 588 if (callback_.is_null()) | 588 if (callback_.is_null()) |
| 589 return base::Closure(); | 589 return base::OnceClosure(); |
| 590 return base::Bind(callback_, result); | 590 return base::BindOnce(std::move(callback_), result); |
| 591 } | 591 } |
| 592 | 592 |
| 593 template <> | 593 template <> |
| 594 base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { | 594 base::OnceClosure |
| 595 CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { | |
| 595 RunDeleteTask(); | 596 RunDeleteTask(); |
| 596 return callback_; | 597 return std::move(callback_); |
| 597 } | 598 } |
| 598 | 599 |
| 599 template <typename Result> | 600 template <typename Result> |
| 600 void CookieMonster::DeleteTask<Result>::Run() { | 601 void CookieMonster::DeleteTask<Result>::Run() { |
| 601 base::Closure callback = RunDeleteTaskAndBindCallback(); | 602 base::OnceClosure callback = RunDeleteTaskAndBindCallback(); |
| 602 if (!callback.is_null()) { | 603 if (!callback.is_null()) { |
| 603 callback = base::Bind( | 604 callback = |
| 604 &CookieMonster::RunCallback, | 605 base::BindOnce(&CookieMonster::RunCallback, |
| 605 this->cookie_monster()->weak_ptr_factory_.GetWeakPtr(), callback); | 606 this->cookie_monster()->weak_ptr_factory_.GetWeakPtr(), |
| 607 std::move(callback)); | |
| 606 } | 608 } |
| 607 this->cookie_monster()->FlushStore(callback); | 609 this->cookie_monster()->FlushStore(std::move(callback)); |
| 608 } | 610 } |
| 609 | 611 |
| 610 // Task class for DeleteAllCreatedBetween call. | 612 // Task class for DeleteAllCreatedBetween call. |
| 611 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { | 613 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { |
| 612 public: | 614 public: |
| 613 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, | 615 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, |
| 614 const Time& delete_begin, | 616 const Time& delete_begin, |
| 615 const Time& delete_end, | 617 const Time& delete_end, |
| 616 const DeleteCallback& callback) | 618 DeleteCallback callback) |
| 617 : DeleteTask<int>(cookie_monster, callback), | 619 : DeleteTask<int>(cookie_monster, std::move(callback)), |
| 618 delete_begin_(delete_begin), | 620 delete_begin_(delete_begin), |
| 619 delete_end_(delete_end) {} | 621 delete_end_(delete_end) {} |
| 620 | 622 |
| 621 // DeleteTask: | 623 // DeleteTask: |
| 622 int RunDeleteTask() override; | 624 int RunDeleteTask() override; |
| 623 | 625 |
| 624 protected: | 626 protected: |
| 625 ~DeleteAllCreatedBetweenTask() override {} | 627 ~DeleteAllCreatedBetweenTask() override {} |
| 626 | 628 |
| 627 private: | 629 private: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 638 | 640 |
| 639 // Task class for DeleteAllCreatedBetweenWithPredicate call. | 641 // Task class for DeleteAllCreatedBetweenWithPredicate call. |
| 640 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask | 642 class CookieMonster::DeleteAllCreatedBetweenWithPredicateTask |
| 641 : public DeleteTask<int> { | 643 : public DeleteTask<int> { |
| 642 public: | 644 public: |
| 643 DeleteAllCreatedBetweenWithPredicateTask( | 645 DeleteAllCreatedBetweenWithPredicateTask( |
| 644 CookieMonster* cookie_monster, | 646 CookieMonster* cookie_monster, |
| 645 Time delete_begin, | 647 Time delete_begin, |
| 646 Time delete_end, | 648 Time delete_end, |
| 647 base::Callback<bool(const CanonicalCookie&)> predicate, | 649 base::Callback<bool(const CanonicalCookie&)> predicate, |
| 648 const DeleteCallback& callback) | 650 DeleteCallback callback) |
| 649 : DeleteTask<int>(cookie_monster, callback), | 651 : DeleteTask<int>(cookie_monster, std::move(callback)), |
| 650 delete_begin_(delete_begin), | 652 delete_begin_(delete_begin), |
| 651 delete_end_(delete_end), | 653 delete_end_(delete_end), |
| 652 predicate_(predicate) {} | 654 predicate_(predicate) {} |
| 653 | 655 |
| 654 // DeleteTask: | 656 // DeleteTask: |
| 655 int RunDeleteTask() override; | 657 int RunDeleteTask() override; |
| 656 | 658 |
| 657 protected: | 659 protected: |
| 658 ~DeleteAllCreatedBetweenWithPredicateTask() override {} | 660 ~DeleteAllCreatedBetweenWithPredicateTask() override {} |
| 659 | 661 |
| 660 private: | 662 private: |
| 661 Time delete_begin_; | 663 Time delete_begin_; |
| 662 Time delete_end_; | 664 Time delete_end_; |
| 663 base::Callback<bool(const CanonicalCookie&)> predicate_; | 665 base::Callback<bool(const CanonicalCookie&)> predicate_; |
| 664 | 666 |
| 665 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask); | 667 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenWithPredicateTask); |
| 666 }; | 668 }; |
| 667 | 669 |
| 668 int CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() { | 670 int CookieMonster::DeleteAllCreatedBetweenWithPredicateTask::RunDeleteTask() { |
| 669 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate( | 671 return this->cookie_monster()->DeleteAllCreatedBetweenWithPredicate( |
| 670 delete_begin_, delete_end_, predicate_); | 672 delete_begin_, delete_end_, predicate_); |
| 671 } | 673 } |
| 672 | 674 |
| 673 // Task class for DeleteCanonicalCookie call. | 675 // Task class for DeleteCanonicalCookie call. |
| 674 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { | 676 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { |
| 675 public: | 677 public: |
| 676 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, | 678 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, |
| 677 const CanonicalCookie& cookie, | 679 const CanonicalCookie& cookie, |
| 678 const DeleteCallback& callback) | 680 DeleteCallback callback) |
| 679 : DeleteTask<int>(cookie_monster, callback), cookie_(cookie) {} | 681 : DeleteTask<int>(cookie_monster, std::move(callback)), cookie_(cookie) {} |
| 680 | 682 |
| 681 // DeleteTask: | 683 // DeleteTask: |
| 682 int RunDeleteTask() override; | 684 int RunDeleteTask() override; |
| 683 | 685 |
| 684 protected: | 686 protected: |
| 685 ~DeleteCanonicalCookieTask() override {} | 687 ~DeleteCanonicalCookieTask() override {} |
| 686 | 688 |
| 687 private: | 689 private: |
| 688 CanonicalCookie cookie_; | 690 CanonicalCookie cookie_; |
| 689 | 691 |
| 690 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); | 692 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); |
| 691 }; | 693 }; |
| 692 | 694 |
| 693 int CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { | 695 int CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { |
| 694 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); | 696 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); |
| 695 } | 697 } |
| 696 | 698 |
| 697 // Task class for SetCanonicalCookie call. | 699 // Task class for SetCanonicalCookie call. |
| 698 class CookieMonster::SetCanonicalCookieTask : public CookieMonsterTask { | 700 class CookieMonster::SetCanonicalCookieTask : public CookieMonsterTask { |
| 699 public: | 701 public: |
| 700 SetCanonicalCookieTask(CookieMonster* cookie_monster, | 702 SetCanonicalCookieTask(CookieMonster* cookie_monster, |
| 701 std::unique_ptr<CanonicalCookie> cookie, | 703 std::unique_ptr<CanonicalCookie> cookie, |
| 702 bool secure_source, | 704 bool secure_source, |
| 703 bool modify_http_only, | 705 bool modify_http_only, |
| 704 const SetCookiesCallback& callback) | 706 SetCookiesCallback callback) |
| 705 : CookieMonsterTask(cookie_monster), | 707 : CookieMonsterTask(cookie_monster), |
| 706 cookie_(std::move(cookie)), | 708 cookie_(std::move(cookie)), |
| 707 secure_source_(secure_source), | 709 secure_source_(secure_source), |
| 708 modify_http_only_(modify_http_only), | 710 modify_http_only_(modify_http_only), |
| 709 callback_(callback) {} | 711 callback_(std::move(callback)) {} |
| 710 | 712 |
| 711 // CookieMonsterTask: | 713 // CookieMonsterTask: |
| 712 void Run() override; | 714 void Run() override; |
| 713 | 715 |
| 714 protected: | 716 protected: |
| 715 ~SetCanonicalCookieTask() override {} | 717 ~SetCanonicalCookieTask() override {} |
| 716 | 718 |
| 717 private: | 719 private: |
| 718 std::unique_ptr<CanonicalCookie> cookie_; | 720 std::unique_ptr<CanonicalCookie> cookie_; |
| 719 bool secure_source_; | 721 bool secure_source_; |
| 720 bool modify_http_only_; | 722 bool modify_http_only_; |
| 721 SetCookiesCallback callback_; | 723 SetCookiesCallback callback_; |
| 722 | 724 |
| 723 DISALLOW_COPY_AND_ASSIGN(SetCanonicalCookieTask); | 725 DISALLOW_COPY_AND_ASSIGN(SetCanonicalCookieTask); |
| 724 }; | 726 }; |
| 725 | 727 |
| 726 void CookieMonster::SetCanonicalCookieTask::Run() { | 728 void CookieMonster::SetCanonicalCookieTask::Run() { |
| 727 bool result = this->cookie_monster()->SetCanonicalCookie( | 729 bool result = this->cookie_monster()->SetCanonicalCookie( |
| 728 std::move(cookie_), secure_source_, modify_http_only_); | 730 std::move(cookie_), secure_source_, modify_http_only_); |
| 729 if (!callback_.is_null()) | 731 if (!callback_.is_null()) |
| 730 callback_.Run(result); | 732 std::move(callback_).Run(result); |
| 731 } | 733 } |
| 732 | 734 |
| 733 // Task class for SetCookieWithOptions call. | 735 // Task class for SetCookieWithOptions call. |
| 734 class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { | 736 class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { |
| 735 public: | 737 public: |
| 736 SetCookieWithOptionsTask(CookieMonster* cookie_monster, | 738 SetCookieWithOptionsTask(CookieMonster* cookie_monster, |
| 737 const GURL& url, | 739 const GURL& url, |
| 738 const std::string& cookie_line, | 740 const std::string& cookie_line, |
| 739 const CookieOptions& options, | 741 const CookieOptions& options, |
| 740 const SetCookiesCallback& callback) | 742 SetCookiesCallback callback) |
| 741 : CookieMonsterTask(cookie_monster), | 743 : CookieMonsterTask(cookie_monster), |
| 742 url_(url), | 744 url_(url), |
| 743 cookie_line_(cookie_line), | 745 cookie_line_(cookie_line), |
| 744 options_(options), | 746 options_(options), |
| 745 callback_(callback) {} | 747 callback_(std::move(callback)) {} |
| 746 | 748 |
| 747 // CookieMonsterTask: | 749 // CookieMonsterTask: |
| 748 void Run() override; | 750 void Run() override; |
| 749 | 751 |
| 750 protected: | 752 protected: |
| 751 ~SetCookieWithOptionsTask() override {} | 753 ~SetCookieWithOptionsTask() override {} |
| 752 | 754 |
| 753 private: | 755 private: |
| 754 GURL url_; | 756 GURL url_; |
| 755 std::string cookie_line_; | 757 std::string cookie_line_; |
| 756 CookieOptions options_; | 758 CookieOptions options_; |
| 757 SetCookiesCallback callback_; | 759 SetCookiesCallback callback_; |
| 758 | 760 |
| 759 DISALLOW_COPY_AND_ASSIGN(SetCookieWithOptionsTask); | 761 DISALLOW_COPY_AND_ASSIGN(SetCookieWithOptionsTask); |
| 760 }; | 762 }; |
| 761 | 763 |
| 762 void CookieMonster::SetCookieWithOptionsTask::Run() { | 764 void CookieMonster::SetCookieWithOptionsTask::Run() { |
| 763 bool result = this->cookie_monster()->SetCookieWithOptions(url_, cookie_line_, | 765 bool result = this->cookie_monster()->SetCookieWithOptions(url_, cookie_line_, |
| 764 options_); | 766 options_); |
| 765 if (!callback_.is_null()) | 767 if (!callback_.is_null()) |
| 766 callback_.Run(result); | 768 std::move(callback_).Run(result); |
| 767 } | 769 } |
| 768 | 770 |
| 769 // Task class for SetAllCookies call. | 771 // Task class for SetAllCookies call. |
| 770 class CookieMonster::SetAllCookiesTask : public CookieMonsterTask { | 772 class CookieMonster::SetAllCookiesTask : public CookieMonsterTask { |
| 771 public: | 773 public: |
| 772 SetAllCookiesTask(CookieMonster* cookie_monster, | 774 SetAllCookiesTask(CookieMonster* cookie_monster, |
| 773 const CookieList& list, | 775 const CookieList& list, |
| 774 const SetCookiesCallback& callback) | 776 SetCookiesCallback callback) |
| 775 : CookieMonsterTask(cookie_monster), list_(list), callback_(callback) {} | 777 : CookieMonsterTask(cookie_monster), |
| 778 list_(list), | |
| 779 callback_(std::move(callback)) {} | |
| 776 | 780 |
| 777 // CookieMonsterTask: | 781 // CookieMonsterTask: |
| 778 void Run() override; | 782 void Run() override; |
| 779 | 783 |
| 780 protected: | 784 protected: |
| 781 ~SetAllCookiesTask() override {} | 785 ~SetAllCookiesTask() override {} |
| 782 | 786 |
| 783 private: | 787 private: |
| 784 CookieList list_; | 788 CookieList list_; |
| 785 SetCookiesCallback callback_; | 789 SetCookiesCallback callback_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 797 for (CookieList::const_iterator it = negative_diff.begin(); | 801 for (CookieList::const_iterator it = negative_diff.begin(); |
| 798 it != negative_diff.end(); ++it) { | 802 it != negative_diff.end(); ++it) { |
| 799 this->cookie_monster()->DeleteCanonicalCookie(*it); | 803 this->cookie_monster()->DeleteCanonicalCookie(*it); |
| 800 } | 804 } |
| 801 | 805 |
| 802 bool result = true; | 806 bool result = true; |
| 803 if (positive_diff.size() > 0) | 807 if (positive_diff.size() > 0) |
| 804 result = this->cookie_monster()->SetAllCookies(list_); | 808 result = this->cookie_monster()->SetAllCookies(list_); |
| 805 | 809 |
| 806 if (!callback_.is_null()) | 810 if (!callback_.is_null()) |
| 807 callback_.Run(result); | 811 std::move(callback_).Run(result); |
| 808 } | 812 } |
| 809 | 813 |
| 810 // Task class for GetCookiesWithOptions call. | 814 // Task class for GetCookiesWithOptions call. |
| 811 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { | 815 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { |
| 812 public: | 816 public: |
| 813 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, | 817 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, |
| 814 const GURL& url, | 818 const GURL& url, |
| 815 const CookieOptions& options, | 819 const CookieOptions& options, |
| 816 const GetCookiesCallback& callback) | 820 GetCookiesCallback callback) |
| 817 : CookieMonsterTask(cookie_monster), | 821 : CookieMonsterTask(cookie_monster), |
| 818 url_(url), | 822 url_(url), |
| 819 options_(options), | 823 options_(options), |
| 820 callback_(callback) {} | 824 callback_(std::move(callback)) {} |
| 821 | 825 |
| 822 // CookieMonsterTask: | 826 // CookieMonsterTask: |
| 823 void Run() override; | 827 void Run() override; |
| 824 | 828 |
| 825 protected: | 829 protected: |
| 826 ~GetCookiesWithOptionsTask() override {} | 830 ~GetCookiesWithOptionsTask() override {} |
| 827 | 831 |
| 828 private: | 832 private: |
| 829 GURL url_; | 833 GURL url_; |
| 830 CookieOptions options_; | 834 CookieOptions options_; |
| 831 GetCookiesCallback callback_; | 835 GetCookiesCallback callback_; |
| 832 | 836 |
| 833 DISALLOW_COPY_AND_ASSIGN(GetCookiesWithOptionsTask); | 837 DISALLOW_COPY_AND_ASSIGN(GetCookiesWithOptionsTask); |
| 834 }; | 838 }; |
| 835 | 839 |
| 836 void CookieMonster::GetCookiesWithOptionsTask::Run() { | 840 void CookieMonster::GetCookiesWithOptionsTask::Run() { |
| 837 std::string cookie = | 841 std::string cookie = |
| 838 this->cookie_monster()->GetCookiesWithOptions(url_, options_); | 842 this->cookie_monster()->GetCookiesWithOptions(url_, options_); |
| 839 if (!callback_.is_null()) | 843 if (!callback_.is_null()) |
| 840 callback_.Run(cookie); | 844 std::move(callback_).Run(cookie); |
| 841 } | 845 } |
| 842 | 846 |
| 843 // Task class for DeleteCookie call. | 847 // Task class for DeleteCookie call. |
| 844 class CookieMonster::DeleteCookieTask : public DeleteTask<void> { | 848 class CookieMonster::DeleteCookieTask : public DeleteTask<void> { |
| 845 public: | 849 public: |
| 846 DeleteCookieTask(CookieMonster* cookie_monster, | 850 DeleteCookieTask(CookieMonster* cookie_monster, |
| 847 const GURL& url, | 851 const GURL& url, |
| 848 const std::string& cookie_name, | 852 const std::string& cookie_name, |
| 849 const base::Closure& callback) | 853 base::OnceClosure callback) |
| 850 : DeleteTask<void>(cookie_monster, callback), | 854 : DeleteTask<void>(cookie_monster, std::move(callback)), |
| 851 url_(url), | 855 url_(url), |
| 852 cookie_name_(cookie_name) {} | 856 cookie_name_(cookie_name) {} |
| 853 | 857 |
| 854 // DeleteTask: | 858 // DeleteTask: |
| 855 void RunDeleteTask() override; | 859 void RunDeleteTask() override; |
| 856 | 860 |
| 857 protected: | 861 protected: |
| 858 ~DeleteCookieTask() override {} | 862 ~DeleteCookieTask() override {} |
| 859 | 863 |
| 860 private: | 864 private: |
| 861 GURL url_; | 865 GURL url_; |
| 862 std::string cookie_name_; | 866 std::string cookie_name_; |
| 863 | 867 |
| 864 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); | 868 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); |
| 865 }; | 869 }; |
| 866 | 870 |
| 867 void CookieMonster::DeleteCookieTask::RunDeleteTask() { | 871 void CookieMonster::DeleteCookieTask::RunDeleteTask() { |
| 868 this->cookie_monster()->DeleteCookie(url_, cookie_name_); | 872 this->cookie_monster()->DeleteCookie(url_, cookie_name_); |
| 869 } | 873 } |
| 870 | 874 |
| 871 // Task class for DeleteSessionCookies call. | 875 // Task class for DeleteSessionCookies call. |
| 872 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { | 876 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { |
| 873 public: | 877 public: |
| 874 DeleteSessionCookiesTask(CookieMonster* cookie_monster, | 878 DeleteSessionCookiesTask(CookieMonster* cookie_monster, |
| 875 const DeleteCallback& callback) | 879 DeleteCallback callback) |
| 876 : DeleteTask<int>(cookie_monster, callback) {} | 880 : DeleteTask<int>(cookie_monster, std::move(callback)) {} |
| 877 | 881 |
| 878 // DeleteTask: | 882 // DeleteTask: |
| 879 int RunDeleteTask() override; | 883 int RunDeleteTask() override; |
| 880 | 884 |
| 881 protected: | 885 protected: |
| 882 ~DeleteSessionCookiesTask() override {} | 886 ~DeleteSessionCookiesTask() override {} |
| 883 | 887 |
| 884 private: | 888 private: |
| 885 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); | 889 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); |
| 886 }; | 890 }; |
| 887 | 891 |
| 888 int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { | 892 int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { |
| 889 return this->cookie_monster()->DeleteSessionCookies(); | 893 return this->cookie_monster()->DeleteSessionCookies(); |
| 890 } | 894 } |
| 891 | 895 |
| 892 // Asynchronous CookieMonster API | 896 // Asynchronous CookieMonster API |
| 893 | 897 |
| 894 void CookieMonster::SetCookieWithDetailsAsync( | 898 void CookieMonster::SetCookieWithDetailsAsync(const GURL& url, |
| 895 const GURL& url, | 899 const std::string& name, |
| 896 const std::string& name, | 900 const std::string& value, |
| 897 const std::string& value, | 901 const std::string& domain, |
| 898 const std::string& domain, | 902 const std::string& path, |
| 899 const std::string& path, | 903 Time creation_time, |
| 900 Time creation_time, | 904 Time expiration_time, |
| 901 Time expiration_time, | 905 Time last_access_time, |
| 902 Time last_access_time, | 906 bool secure, |
| 903 bool secure, | 907 bool http_only, |
| 904 bool http_only, | 908 CookieSameSite same_site, |
| 905 CookieSameSite same_site, | 909 CookiePriority priority, |
| 906 CookiePriority priority, | 910 SetCookiesCallback callback) { |
| 907 const SetCookiesCallback& callback) { | |
| 908 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( | 911 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( |
| 909 this, url, name, value, domain, path, creation_time, expiration_time, | 912 this, url, name, value, domain, path, creation_time, expiration_time, |
| 910 last_access_time, secure, http_only, same_site, priority, callback); | 913 last_access_time, secure, http_only, same_site, priority, |
| 914 std::move(callback)); | |
| 911 DoCookieTaskForURL(task, url); | 915 DoCookieTaskForURL(task, url); |
| 912 } | 916 } |
| 913 | 917 |
| 914 void CookieMonster::FlushStore(const base::Closure& callback) { | 918 void CookieMonster::FlushStore(base::OnceClosure callback) { |
| 915 DCHECK(thread_checker_.CalledOnValidThread()); | 919 DCHECK(thread_checker_.CalledOnValidThread()); |
| 916 | 920 |
| 917 if (initialized_ && store_.get()) { | 921 if (initialized_ && store_.get()) { |
| 918 if (channel_id_service_) { | 922 if (channel_id_service_) { |
| 919 channel_id_service_->GetChannelIDStore()->Flush(); | 923 channel_id_service_->GetChannelIDStore()->Flush(); |
| 920 } | 924 } |
| 921 store_->Flush(callback); | 925 store_->Flush(std::move(callback)); |
| 922 } else if (!callback.is_null()) { | 926 } else if (!callback.is_null()) { |
| 923 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 927 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 928 std::move(callback)); | |
| 924 } | 929 } |
| 925 } | 930 } |
| 926 | 931 |
| 927 void CookieMonster::SetForceKeepSessionState() { | 932 void CookieMonster::SetForceKeepSessionState() { |
| 928 DCHECK(thread_checker_.CalledOnValidThread()); | 933 DCHECK(thread_checker_.CalledOnValidThread()); |
| 929 | 934 |
| 930 if (store_) | 935 if (store_) |
| 931 store_->SetForceKeepSessionState(); | 936 store_->SetForceKeepSessionState(); |
| 932 } | 937 } |
| 933 | 938 |
| 934 void CookieMonster::SetAllCookiesAsync(const CookieList& list, | 939 void CookieMonster::SetAllCookiesAsync(const CookieList& list, |
| 935 const SetCookiesCallback& callback) { | 940 SetCookiesCallback callback) { |
| 936 scoped_refptr<SetAllCookiesTask> task = | 941 scoped_refptr<SetAllCookiesTask> task = |
| 937 new SetAllCookiesTask(this, list, callback); | 942 new SetAllCookiesTask(this, list, std::move(callback)); |
|
kinuko
2017/06/19 10:52:07
I wonder if (eventually) these all CookieMonsterTa
Randy Smith (Not in Mondays)
2017/06/21 17:54:53
Yes, I think that would be a good design. I'd als
| |
| 938 DoCookieTask(task); | 943 DoCookieTask(task); |
| 939 } | 944 } |
| 940 | 945 |
| 941 void CookieMonster::SetCanonicalCookieAsync( | 946 void CookieMonster::SetCanonicalCookieAsync( |
| 942 std::unique_ptr<CanonicalCookie> cookie, | 947 std::unique_ptr<CanonicalCookie> cookie, |
| 943 bool secure_source, | 948 bool secure_source, |
| 944 bool modify_http_only, | 949 bool modify_http_only, |
| 945 const SetCookiesCallback& callback) { | 950 SetCookiesCallback callback) { |
| 946 DCHECK(cookie->IsCanonical()); | 951 DCHECK(cookie->IsCanonical()); |
| 947 scoped_refptr<SetCanonicalCookieTask> task = new SetCanonicalCookieTask( | 952 scoped_refptr<SetCanonicalCookieTask> task = |
| 948 this, std::move(cookie), secure_source, modify_http_only, callback); | 953 new SetCanonicalCookieTask(this, std::move(cookie), secure_source, |
| 954 modify_http_only, std::move(callback)); | |
| 949 | 955 |
| 950 // TODO(rdsmith): Switch to DoCookieTaskForURL (or the equivalent). | 956 // TODO(rdsmith): Switch to DoCookieTaskForURL (or the equivalent). |
| 951 // This is tricky because we don't have the scheme in this routine | 957 // This is tricky because we don't have the scheme in this routine |
| 952 // and DoCookieTaskForURL uses cookie_util::GetEffectiveDomain(scheme, host) | 958 // and DoCookieTaskForURL uses cookie_util::GetEffectiveDomain(scheme, host) |
| 953 // to generate the database key to block behind. | 959 // to generate the database key to block behind. |
| 954 DoCookieTask(task); | 960 DoCookieTask(task); |
| 955 } | 961 } |
| 956 | 962 |
| 957 void CookieMonster::SetCookieWithOptionsAsync( | 963 void CookieMonster::SetCookieWithOptionsAsync(const GURL& url, |
| 958 const GURL& url, | 964 const std::string& cookie_line, |
| 959 const std::string& cookie_line, | 965 const CookieOptions& options, |
| 960 const CookieOptions& options, | 966 SetCookiesCallback callback) { |
| 961 const SetCookiesCallback& callback) { | 967 scoped_refptr<SetCookieWithOptionsTask> task = new SetCookieWithOptionsTask( |
| 962 scoped_refptr<SetCookieWithOptionsTask> task = | 968 this, url, cookie_line, options, std::move(callback)); |
| 963 new SetCookieWithOptionsTask(this, url, cookie_line, options, callback); | |
| 964 | 969 |
| 965 DoCookieTaskForURL(task, url); | 970 DoCookieTaskForURL(task, url); |
| 966 } | 971 } |
| 967 | 972 |
| 968 void CookieMonster::GetCookiesWithOptionsAsync( | 973 void CookieMonster::GetCookiesWithOptionsAsync(const GURL& url, |
| 969 const GURL& url, | 974 const CookieOptions& options, |
| 970 const CookieOptions& options, | 975 GetCookiesCallback callback) { |
| 971 const GetCookiesCallback& callback) { | |
| 972 scoped_refptr<GetCookiesWithOptionsTask> task = | 976 scoped_refptr<GetCookiesWithOptionsTask> task = |
| 973 new GetCookiesWithOptionsTask(this, url, options, callback); | 977 new GetCookiesWithOptionsTask(this, url, options, std::move(callback)); |
| 974 | 978 |
| 975 DoCookieTaskForURL(task, url); | 979 DoCookieTaskForURL(task, url); |
| 976 } | 980 } |
| 977 | 981 |
| 978 void CookieMonster::GetCookieListWithOptionsAsync( | 982 void CookieMonster::GetCookieListWithOptionsAsync( |
| 979 const GURL& url, | 983 const GURL& url, |
| 980 const CookieOptions& options, | 984 const CookieOptions& options, |
| 981 const GetCookieListCallback& callback) { | 985 GetCookieListCallback callback) { |
| 982 scoped_refptr<GetCookieListWithOptionsTask> task = | 986 scoped_refptr<GetCookieListWithOptionsTask> task = |
| 983 new GetCookieListWithOptionsTask(this, url, options, callback); | 987 new GetCookieListWithOptionsTask(this, url, options, std::move(callback)); |
| 984 | 988 |
| 985 DoCookieTaskForURL(task, url); | 989 DoCookieTaskForURL(task, url); |
| 986 } | 990 } |
| 987 | 991 |
| 988 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { | 992 void CookieMonster::GetAllCookiesAsync(GetCookieListCallback callback) { |
| 989 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); | 993 scoped_refptr<GetAllCookiesTask> task = |
| 994 new GetAllCookiesTask(this, std::move(callback)); | |
| 990 | 995 |
| 991 DoCookieTask(task); | 996 DoCookieTask(task); |
| 992 } | 997 } |
| 993 | 998 |
| 994 void CookieMonster::DeleteCookieAsync(const GURL& url, | 999 void CookieMonster::DeleteCookieAsync(const GURL& url, |
| 995 const std::string& cookie_name, | 1000 const std::string& cookie_name, |
| 996 const base::Closure& callback) { | 1001 base::OnceClosure callback) { |
| 997 scoped_refptr<DeleteCookieTask> task = | 1002 scoped_refptr<DeleteCookieTask> task = |
| 998 new DeleteCookieTask(this, url, cookie_name, callback); | 1003 new DeleteCookieTask(this, url, cookie_name, std::move(callback)); |
| 999 | 1004 |
| 1000 DoCookieTaskForURL(task, url); | 1005 DoCookieTaskForURL(task, url); |
| 1001 } | 1006 } |
| 1002 | 1007 |
| 1003 void CookieMonster::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, | 1008 void CookieMonster::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
| 1004 const DeleteCallback& callback) { | 1009 DeleteCallback callback) { |
| 1005 scoped_refptr<DeleteCanonicalCookieTask> task = | 1010 scoped_refptr<DeleteCanonicalCookieTask> task = |
| 1006 new DeleteCanonicalCookieTask(this, cookie, callback); | 1011 new DeleteCanonicalCookieTask(this, cookie, std::move(callback)); |
| 1007 | 1012 |
| 1008 DoCookieTask(task); | 1013 DoCookieTask(task); |
| 1009 } | 1014 } |
| 1010 | 1015 |
| 1011 void CookieMonster::DeleteAllCreatedBetweenAsync( | 1016 void CookieMonster::DeleteAllCreatedBetweenAsync(const Time& delete_begin, |
| 1012 const Time& delete_begin, | 1017 const Time& delete_end, |
| 1013 const Time& delete_end, | 1018 DeleteCallback callback) { |
| 1014 const DeleteCallback& callback) { | |
| 1015 scoped_refptr<DeleteAllCreatedBetweenTask> task = | 1019 scoped_refptr<DeleteAllCreatedBetweenTask> task = |
| 1016 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback); | 1020 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, |
| 1021 std::move(callback)); | |
| 1017 | 1022 |
| 1018 DoCookieTask(task); | 1023 DoCookieTask(task); |
| 1019 } | 1024 } |
| 1020 | 1025 |
| 1021 void CookieMonster::DeleteAllCreatedBetweenWithPredicateAsync( | 1026 void CookieMonster::DeleteAllCreatedBetweenWithPredicateAsync( |
| 1022 const Time& delete_begin, | 1027 const Time& delete_begin, |
| 1023 const Time& delete_end, | 1028 const Time& delete_end, |
| 1024 const base::Callback<bool(const CanonicalCookie&)>& predicate, | 1029 const base::Callback<bool(const CanonicalCookie&)>& predicate, |
| 1025 const DeleteCallback& callback) { | 1030 DeleteCallback callback) { |
| 1026 if (predicate.is_null()) { | 1031 if (predicate.is_null()) { |
| 1027 callback.Run(0); | 1032 std::move(callback).Run(0); |
| 1028 return; | 1033 return; |
| 1029 } | 1034 } |
| 1030 scoped_refptr<DeleteAllCreatedBetweenWithPredicateTask> task = | 1035 scoped_refptr<DeleteAllCreatedBetweenWithPredicateTask> task = |
| 1031 new DeleteAllCreatedBetweenWithPredicateTask( | 1036 new DeleteAllCreatedBetweenWithPredicateTask( |
| 1032 this, delete_begin, delete_end, predicate, callback); | 1037 this, delete_begin, delete_end, predicate, std::move(callback)); |
| 1033 DoCookieTask(task); | 1038 DoCookieTask(task); |
| 1034 } | 1039 } |
| 1035 | 1040 |
| 1036 void CookieMonster::DeleteSessionCookiesAsync( | 1041 void CookieMonster::DeleteSessionCookiesAsync( |
| 1037 const CookieStore::DeleteCallback& callback) { | 1042 CookieStore::DeleteCallback callback) { |
| 1038 scoped_refptr<DeleteSessionCookiesTask> task = | 1043 scoped_refptr<DeleteSessionCookiesTask> task = |
| 1039 new DeleteSessionCookiesTask(this, callback); | 1044 new DeleteSessionCookiesTask(this, std::move(callback)); |
| 1040 | 1045 |
| 1041 DoCookieTask(task); | 1046 DoCookieTask(task); |
| 1042 } | 1047 } |
| 1043 | 1048 |
| 1044 void CookieMonster::SetCookieableSchemes( | 1049 void CookieMonster::SetCookieableSchemes( |
| 1045 const std::vector<std::string>& schemes) { | 1050 const std::vector<std::string>& schemes) { |
| 1046 DCHECK(thread_checker_.CalledOnValidThread()); | 1051 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1047 | 1052 |
| 1048 // Calls to this method will have no effect if made after a WebView or | 1053 // Calls to this method will have no effect if made after a WebView or |
| 1049 // CookieManager instance has been created. | 1054 // CookieManager instance has been created. |
| (...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2466 PartialDiffCookieSorter); | 2471 PartialDiffCookieSorter); |
| 2467 | 2472 |
| 2468 // Select any new cookie for addition (or update) if no old cookie is exactly | 2473 // Select any new cookie for addition (or update) if no old cookie is exactly |
| 2469 // equivalent. | 2474 // equivalent. |
| 2470 std::set_difference(new_cookies->begin(), new_cookies->end(), | 2475 std::set_difference(new_cookies->begin(), new_cookies->end(), |
| 2471 old_cookies->begin(), old_cookies->end(), | 2476 old_cookies->begin(), old_cookies->end(), |
| 2472 std::inserter(*cookies_to_add, cookies_to_add->begin()), | 2477 std::inserter(*cookies_to_add, cookies_to_add->begin()), |
| 2473 FullDiffCookieSorter); | 2478 FullDiffCookieSorter); |
| 2474 } | 2479 } |
| 2475 | 2480 |
| 2476 void CookieMonster::RunCallback(const base::Closure& callback) { | 2481 void CookieMonster::RunCallback(base::OnceClosure callback) { |
| 2477 DCHECK(thread_checker_.CalledOnValidThread()); | 2482 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2478 callback.Run(); | 2483 std::move(callback).Run(); |
| 2479 } | 2484 } |
| 2480 | 2485 |
| 2481 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, | 2486 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, |
| 2482 ChangeCause cause) { | 2487 ChangeCause cause) { |
| 2483 DCHECK(thread_checker_.CalledOnValidThread()); | 2488 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2484 | 2489 |
| 2485 CookieOptions opts; | 2490 CookieOptions opts; |
| 2486 opts.set_include_httponly(); | 2491 opts.set_include_httponly(); |
| 2487 opts.set_same_site_cookie_mode( | 2492 opts.set_same_site_cookie_mode( |
| 2488 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | 2493 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
| 2489 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they | 2494 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they |
| 2490 // are guaranteed to not take long - they just post a RunAsync task back to | 2495 // are guaranteed to not take long - they just post a RunAsync task back to |
| 2491 // the appropriate thread's message loop and return. | 2496 // the appropriate thread's message loop and return. |
| 2492 // TODO(mmenke): Consider running these synchronously? | 2497 // TODO(mmenke): Consider running these synchronously? |
| 2493 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2498 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
| 2494 it != hook_map_.end(); ++it) { | 2499 it != hook_map_.end(); ++it) { |
| 2495 std::pair<GURL, std::string> key = it->first; | 2500 std::pair<GURL, std::string> key = it->first; |
| 2496 if (cookie.IncludeForRequestURL(key.first, opts) && | 2501 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2497 cookie.Name() == key.second) { | 2502 cookie.Name() == key.second) { |
| 2498 it->second->Notify(cookie, cause); | 2503 it->second->Notify(cookie, cause); |
| 2499 } | 2504 } |
| 2500 } | 2505 } |
| 2501 } | 2506 } |
| 2502 | 2507 |
| 2503 } // namespace net | 2508 } // namespace net |
| OLD | NEW |