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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 // See comments at declaration of these variables in cookie_monster.h | 97 // See comments at declaration of these variables in cookie_monster.h |
98 // for details. | 98 // for details. |
99 const size_t CookieMonster::kDomainMaxCookies = 180; | 99 const size_t CookieMonster::kDomainMaxCookies = 180; |
100 const size_t CookieMonster::kDomainPurgeCookies = 30; | 100 const size_t CookieMonster::kDomainPurgeCookies = 30; |
101 const size_t CookieMonster::kMaxCookies = 3300; | 101 const size_t CookieMonster::kMaxCookies = 3300; |
102 const size_t CookieMonster::kPurgeCookies = 300; | 102 const size_t CookieMonster::kPurgeCookies = 300; |
103 | 103 |
104 const size_t CookieMonster::kDomainCookiesQuotaLow = 30; | 104 const size_t CookieMonster::kDomainCookiesQuotaLow = 30; |
105 const size_t CookieMonster::kDomainCookiesQuotaMedium = 50; | 105 const size_t CookieMonster::kDomainCookiesQuotaMedium = 50; |
106 const size_t CookieMonster::kDomainCookiesQuotaHigh = | 106 const size_t CookieMonster::kDomainCookiesQuotaHigh = |
107 CookieMonster::kDomainMaxCookies - CookieMonster::kDomainPurgeCookies | 107 kDomainMaxCookies - kDomainPurgeCookies |
108 - CookieMonster::kDomainCookiesQuotaLow | 108 - kDomainCookiesQuotaLow - kDomainCookiesQuotaMedium; |
109 - CookieMonster::kDomainCookiesQuotaMedium; | |
110 | 109 |
111 const int CookieMonster::kSafeFromGlobalPurgeDays = 30; | 110 const int CookieMonster::kSafeFromGlobalPurgeDays = 30; |
112 | 111 |
113 namespace { | 112 namespace { |
114 | 113 |
115 typedef std::vector<CanonicalCookie*> CanonicalCookieVector; | 114 typedef std::vector<CanonicalCookie*> CanonicalCookieVector; |
116 | 115 |
117 // Default minimum delay after updating a cookie's LastAccessDate before we | 116 // Default minimum delay after updating a cookie's LastAccessDate before we |
118 // will update it again. | 117 // will update it again. |
119 const int kDefaultAccessUpdateThresholdSeconds = 60; | 118 const int kDefaultAccessUpdateThresholdSeconds = 60; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 // message loop because the underlying instance may be destroyed (along with the | 391 // message loop because the underlying instance may be destroyed (along with the |
393 // CookieMonsterTask instance) in the interim. Therefore, we post a callback | 392 // CookieMonsterTask instance) in the interim. Therefore, we post a callback |
394 // bound to the CookieMonsterTask, which *is* reference counted (thus preventing | 393 // bound to the CookieMonsterTask, which *is* reference counted (thus preventing |
395 // destruction of the original callback), and which invokes the closure (which | 394 // destruction of the original callback), and which invokes the closure (which |
396 // invokes the original callback with the returned data). | 395 // invokes the original callback with the returned data). |
397 void CookieMonster::CookieMonsterTask::InvokeCallback(base::Closure callback) { | 396 void CookieMonster::CookieMonsterTask::InvokeCallback(base::Closure callback) { |
398 if (thread_->BelongsToCurrentThread()) { | 397 if (thread_->BelongsToCurrentThread()) { |
399 callback.Run(); | 398 callback.Run(); |
400 } else { | 399 } else { |
401 thread_->PostTask(FROM_HERE, base::Bind( | 400 thread_->PostTask(FROM_HERE, base::Bind( |
402 &CookieMonster::CookieMonsterTask::InvokeCallback, this, callback)); | 401 &CookieMonsterTask::InvokeCallback, this, callback)); |
403 } | 402 } |
404 } | 403 } |
405 | 404 |
406 // Task class for SetCookieWithDetails call. | 405 // Task class for SetCookieWithDetails call. |
407 class CookieMonster::SetCookieWithDetailsTask | 406 class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask { |
408 : public CookieMonster::CookieMonsterTask { | |
409 public: | 407 public: |
410 SetCookieWithDetailsTask(CookieMonster* cookie_monster, | 408 SetCookieWithDetailsTask(CookieMonster* cookie_monster, |
411 const GURL& url, | 409 const GURL& url, |
412 const std::string& name, | 410 const std::string& name, |
413 const std::string& value, | 411 const std::string& value, |
414 const std::string& domain, | 412 const std::string& domain, |
415 const std::string& path, | 413 const std::string& path, |
416 const base::Time& expiration_time, | 414 const base::Time& expiration_time, |
417 bool secure, | 415 bool secure, |
418 bool http_only, | 416 bool http_only, |
419 CookiePriority priority, | 417 CookiePriority priority, |
420 const CookieMonster::SetCookiesCallback& callback) | 418 const SetCookiesCallback& callback) |
421 : CookieMonsterTask(cookie_monster), | 419 : CookieMonsterTask(cookie_monster), |
422 url_(url), | 420 url_(url), |
423 name_(name), | 421 name_(name), |
424 value_(value), | 422 value_(value), |
425 domain_(domain), | 423 domain_(domain), |
426 path_(path), | 424 path_(path), |
427 expiration_time_(expiration_time), | 425 expiration_time_(expiration_time), |
428 secure_(secure), | 426 secure_(secure), |
429 http_only_(http_only), | 427 http_only_(http_only), |
430 priority_(priority), | 428 priority_(priority), |
431 callback_(callback) { | 429 callback_(callback) { |
432 } | 430 } |
433 | 431 |
434 // CookieMonster::CookieMonsterTask: | 432 // CookieMonsterTask: |
435 virtual void Run() OVERRIDE; | 433 virtual void Run() OVERRIDE; |
436 | 434 |
437 protected: | 435 protected: |
438 virtual ~SetCookieWithDetailsTask() {} | 436 virtual ~SetCookieWithDetailsTask() {} |
439 | 437 |
440 private: | 438 private: |
441 GURL url_; | 439 GURL url_; |
442 std::string name_; | 440 std::string name_; |
443 std::string value_; | 441 std::string value_; |
444 std::string domain_; | 442 std::string domain_; |
445 std::string path_; | 443 std::string path_; |
446 base::Time expiration_time_; | 444 base::Time expiration_time_; |
447 bool secure_; | 445 bool secure_; |
448 bool http_only_; | 446 bool http_only_; |
449 CookiePriority priority_; | 447 CookiePriority priority_; |
450 CookieMonster::SetCookiesCallback callback_; | 448 SetCookiesCallback callback_; |
451 | 449 |
452 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); | 450 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); |
453 }; | 451 }; |
454 | 452 |
455 void CookieMonster::SetCookieWithDetailsTask::Run() { | 453 void CookieMonster::SetCookieWithDetailsTask::Run() { |
456 bool success = this->cookie_monster()-> | 454 bool success = this->cookie_monster()-> |
457 SetCookieWithDetails(url_, name_, value_, domain_, path_, | 455 SetCookieWithDetails(url_, name_, value_, domain_, path_, |
458 expiration_time_, secure_, http_only_, priority_); | 456 expiration_time_, secure_, http_only_, priority_); |
459 if (!callback_.is_null()) { | 457 if (!callback_.is_null()) { |
460 this->InvokeCallback(base::Bind(&CookieMonster::SetCookiesCallback::Run, | 458 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, |
461 base::Unretained(&callback_), success)); | 459 base::Unretained(&callback_), success)); |
462 } | 460 } |
463 } | 461 } |
464 | 462 |
465 // Task class for GetAllCookies call. | 463 // Task class for GetAllCookies call. |
466 class CookieMonster::GetAllCookiesTask | 464 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { |
467 : public CookieMonster::CookieMonsterTask { | |
468 public: | 465 public: |
469 GetAllCookiesTask(CookieMonster* cookie_monster, | 466 GetAllCookiesTask(CookieMonster* cookie_monster, |
470 const CookieMonster::GetCookieListCallback& callback) | 467 const GetCookieListCallback& callback) |
471 : CookieMonsterTask(cookie_monster), | 468 : CookieMonsterTask(cookie_monster), |
472 callback_(callback) { | 469 callback_(callback) { |
473 } | 470 } |
474 | 471 |
475 // CookieMonster::CookieMonsterTask | 472 // CookieMonsterTask |
476 virtual void Run() OVERRIDE; | 473 virtual void Run() OVERRIDE; |
477 | 474 |
478 protected: | 475 protected: |
479 virtual ~GetAllCookiesTask() {} | 476 virtual ~GetAllCookiesTask() {} |
480 | 477 |
481 private: | 478 private: |
482 CookieMonster::GetCookieListCallback callback_; | 479 GetCookieListCallback callback_; |
483 | 480 |
484 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); | 481 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); |
485 }; | 482 }; |
486 | 483 |
487 void CookieMonster::GetAllCookiesTask::Run() { | 484 void CookieMonster::GetAllCookiesTask::Run() { |
488 if (!callback_.is_null()) { | 485 if (!callback_.is_null()) { |
489 CookieList cookies = this->cookie_monster()->GetAllCookies(); | 486 CookieList cookies = this->cookie_monster()->GetAllCookies(); |
490 this->InvokeCallback(base::Bind(&CookieMonster::GetCookieListCallback::Run, | 487 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, |
491 base::Unretained(&callback_), cookies)); | 488 base::Unretained(&callback_), cookies)); |
492 } | 489 } |
493 } | 490 } |
494 | 491 |
495 // Task class for GetAllCookiesForURLWithOptions call. | 492 // Task class for GetAllCookiesForURLWithOptions call. |
496 class CookieMonster::GetAllCookiesForURLWithOptionsTask | 493 class CookieMonster::GetAllCookiesForURLWithOptionsTask |
497 : public CookieMonster::CookieMonsterTask { | 494 : public CookieMonsterTask { |
498 public: | 495 public: |
499 GetAllCookiesForURLWithOptionsTask( | 496 GetAllCookiesForURLWithOptionsTask( |
500 CookieMonster* cookie_monster, | 497 CookieMonster* cookie_monster, |
501 const GURL& url, | 498 const GURL& url, |
502 const CookieOptions& options, | 499 const CookieOptions& options, |
503 const CookieMonster::GetCookieListCallback& callback) | 500 const GetCookieListCallback& callback) |
504 : CookieMonsterTask(cookie_monster), | 501 : CookieMonsterTask(cookie_monster), |
505 url_(url), | 502 url_(url), |
506 options_(options), | 503 options_(options), |
507 callback_(callback) { | 504 callback_(callback) { |
508 } | 505 } |
509 | 506 |
510 // CookieMonster::CookieMonsterTask: | 507 // CookieMonsterTask: |
511 virtual void Run() OVERRIDE; | 508 virtual void Run() OVERRIDE; |
512 | 509 |
513 protected: | 510 protected: |
514 virtual ~GetAllCookiesForURLWithOptionsTask() {} | 511 virtual ~GetAllCookiesForURLWithOptionsTask() {} |
515 | 512 |
516 private: | 513 private: |
517 GURL url_; | 514 GURL url_; |
518 CookieOptions options_; | 515 CookieOptions options_; |
519 CookieMonster::GetCookieListCallback callback_; | 516 GetCookieListCallback callback_; |
520 | 517 |
521 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesForURLWithOptionsTask); | 518 DISALLOW_COPY_AND_ASSIGN(GetAllCookiesForURLWithOptionsTask); |
522 }; | 519 }; |
523 | 520 |
524 void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() { | 521 void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() { |
525 if (!callback_.is_null()) { | 522 if (!callback_.is_null()) { |
526 CookieList cookies = this->cookie_monster()-> | 523 CookieList cookies = this->cookie_monster()-> |
527 GetAllCookiesForURLWithOptions(url_, options_); | 524 GetAllCookiesForURLWithOptions(url_, options_); |
528 this->InvokeCallback(base::Bind(&CookieMonster::GetCookieListCallback::Run, | 525 this->InvokeCallback(base::Bind(&GetCookieListCallback::Run, |
529 base::Unretained(&callback_), cookies)); | 526 base::Unretained(&callback_), cookies)); |
530 } | 527 } |
531 } | 528 } |
532 | 529 |
533 // Task class for DeleteAll call. | 530 template <typename Result> struct CallbackType { |
534 class CookieMonster::DeleteAllTask : public CookieMonster::CookieMonsterTask { | 531 typedef base::Callback<void(Result)> Type; |
532 }; | |
533 | |
534 template <> struct CallbackType<void> { | |
535 typedef base::Closure Type; | |
536 }; | |
537 | |
538 // Base task class for Delete*Task. | |
539 template <typename Result> | |
540 class CookieMonster::DeleteTask : public CookieMonsterTask { | |
535 public: | 541 public: |
536 DeleteAllTask(CookieMonster* cookie_monster, | 542 DeleteTask(CookieMonster* cookie_monster, |
537 const CookieMonster::DeleteCallback& callback) | 543 const typename CallbackType<Result>::Type& callback) |
538 : CookieMonsterTask(cookie_monster), | 544 : CookieMonsterTask(cookie_monster), |
539 callback_(callback) { | 545 callback_(callback) { |
540 } | 546 } |
541 | 547 |
542 // CookieMonster::CookieMonsterTask: | 548 // CookieMonsterTask: |
543 virtual void Run() OVERRIDE; | 549 virtual void Run() OVERRIDE; |
544 | 550 |
551 private: | |
552 // Runs the delete task and returns a result. | |
553 virtual Result RunDeleteTask() = 0; | |
554 | |
555 base::Closure RunDeleteTaskAndBindCallback(); | |
556 | |
erikwright (departed)
2013/09/13 14:54:30
nit remove blank between these internal helper fun
| |
557 void FlushDone(const base::Closure& callback); | |
558 | |
559 typename CallbackType<Result>::Type callback_; | |
560 | |
561 DISALLOW_COPY_AND_ASSIGN(DeleteTask); | |
562 }; | |
563 | |
564 template <typename Result> | |
565 base::Closure CookieMonster::DeleteTask<Result>:: | |
566 RunDeleteTaskAndBindCallback() { | |
567 Result result = RunDeleteTask(); | |
568 if (callback_.is_null()) | |
569 return base::Closure(); | |
570 return base::Bind(callback_, result); | |
571 } | |
572 | |
573 template <> | |
574 base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { | |
575 RunDeleteTask(); | |
576 return callback_; | |
577 } | |
578 | |
579 template <typename Result> | |
580 void CookieMonster::DeleteTask<Result>::Run() { | |
581 this->cookie_monster()->FlushStore( | |
582 base::Bind(&DeleteTask<Result>::FlushDone, this, | |
583 RunDeleteTaskAndBindCallback())); | |
584 } | |
585 | |
586 template <typename Result> | |
587 void CookieMonster::DeleteTask<Result>::FlushDone( | |
588 const base::Closure& callback) { | |
589 if (!callback.is_null()) { | |
590 this->InvokeCallback(callback); | |
591 } | |
592 } | |
593 | |
594 // Task class for DeleteAll call. | |
595 class CookieMonster::DeleteAllTask : public DeleteTask<int> { | |
596 public: | |
597 DeleteAllTask(CookieMonster* cookie_monster, | |
598 const DeleteCallback& callback) | |
599 : DeleteTask(cookie_monster, callback) { | |
600 } | |
601 | |
602 // DeleteTask: | |
603 virtual int RunDeleteTask() OVERRIDE; | |
604 | |
545 protected: | 605 protected: |
546 virtual ~DeleteAllTask() {} | 606 virtual ~DeleteAllTask() {} |
547 | 607 |
548 private: | 608 private: |
549 CookieMonster::DeleteCallback callback_; | |
550 | |
551 DISALLOW_COPY_AND_ASSIGN(DeleteAllTask); | 609 DISALLOW_COPY_AND_ASSIGN(DeleteAllTask); |
552 }; | 610 }; |
553 | 611 |
554 void CookieMonster::DeleteAllTask::Run() { | 612 int CookieMonster::DeleteAllTask::RunDeleteTask() { |
555 int num_deleted = this->cookie_monster()->DeleteAll(true); | 613 return this->cookie_monster()->DeleteAll(true); |
556 if (!callback_.is_null()) { | |
557 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | |
558 base::Unretained(&callback_), num_deleted)); | |
559 } | |
560 } | 614 } |
561 | 615 |
562 // Task class for DeleteAllCreatedBetween call. | 616 // Task class for DeleteAllCreatedBetween call. |
563 class CookieMonster::DeleteAllCreatedBetweenTask | 617 class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { |
564 : public CookieMonster::CookieMonsterTask { | |
565 public: | 618 public: |
566 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, | 619 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, |
567 const Time& delete_begin, | 620 const Time& delete_begin, |
568 const Time& delete_end, | 621 const Time& delete_end, |
569 const CookieMonster::DeleteCallback& callback) | 622 const DeleteCallback& callback) |
570 : CookieMonsterTask(cookie_monster), | 623 : DeleteTask(cookie_monster, callback), |
571 delete_begin_(delete_begin), | 624 delete_begin_(delete_begin), |
572 delete_end_(delete_end), | 625 delete_end_(delete_end) { |
573 callback_(callback) { | |
574 } | 626 } |
575 | 627 |
576 // CookieMonster::CookieMonsterTask: | 628 // DeleteTask: |
577 virtual void Run() OVERRIDE; | 629 virtual int RunDeleteTask() OVERRIDE; |
578 | 630 |
579 protected: | 631 protected: |
580 virtual ~DeleteAllCreatedBetweenTask() {} | 632 virtual ~DeleteAllCreatedBetweenTask() {} |
581 | 633 |
582 private: | 634 private: |
583 Time delete_begin_; | 635 Time delete_begin_; |
584 Time delete_end_; | 636 Time delete_end_; |
585 CookieMonster::DeleteCallback callback_; | |
586 | 637 |
587 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); | 638 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); |
588 }; | 639 }; |
589 | 640 |
590 void CookieMonster::DeleteAllCreatedBetweenTask::Run() { | 641 int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { |
591 int num_deleted = this->cookie_monster()-> | 642 return this->cookie_monster()-> |
592 DeleteAllCreatedBetween(delete_begin_, delete_end_); | 643 DeleteAllCreatedBetween(delete_begin_, delete_end_); |
593 if (!callback_.is_null()) { | |
594 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | |
595 base::Unretained(&callback_), num_deleted)); | |
596 } | |
597 } | 644 } |
598 | 645 |
599 // Task class for DeleteAllForHost call. | 646 // Task class for DeleteAllForHost call. |
600 class CookieMonster::DeleteAllForHostTask | 647 class CookieMonster::DeleteAllForHostTask : public DeleteTask<int> { |
601 : public CookieMonster::CookieMonsterTask { | |
602 public: | 648 public: |
603 DeleteAllForHostTask(CookieMonster* cookie_monster, | 649 DeleteAllForHostTask(CookieMonster* cookie_monster, |
604 const GURL& url, | 650 const GURL& url, |
605 const CookieMonster::DeleteCallback& callback) | 651 const DeleteCallback& callback) |
606 : CookieMonsterTask(cookie_monster), | 652 : DeleteTask(cookie_monster, callback), |
607 url_(url), | 653 url_(url) { |
608 callback_(callback) { | |
609 } | 654 } |
610 | 655 |
611 // CookieMonster::CookieMonsterTask: | 656 // DeleteTask: |
612 virtual void Run() OVERRIDE; | 657 virtual int RunDeleteTask() OVERRIDE; |
613 | 658 |
614 protected: | 659 protected: |
615 virtual ~DeleteAllForHostTask() {} | 660 virtual ~DeleteAllForHostTask() {} |
616 | 661 |
617 private: | 662 private: |
618 GURL url_; | 663 GURL url_; |
619 CookieMonster::DeleteCallback callback_; | |
620 | 664 |
621 DISALLOW_COPY_AND_ASSIGN(DeleteAllForHostTask); | 665 DISALLOW_COPY_AND_ASSIGN(DeleteAllForHostTask); |
622 }; | 666 }; |
623 | 667 |
624 void CookieMonster::DeleteAllForHostTask::Run() { | 668 int CookieMonster::DeleteAllForHostTask::RunDeleteTask() { |
625 int num_deleted = this->cookie_monster()->DeleteAllForHost(url_); | 669 return this->cookie_monster()->DeleteAllForHost(url_); |
626 if (!callback_.is_null()) { | |
627 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | |
628 base::Unretained(&callback_), num_deleted)); | |
629 } | |
630 } | 670 } |
631 | 671 |
632 // Task class for DeleteAllCreatedBetweenForHost call. | 672 // Task class for DeleteAllCreatedBetweenForHost call. |
633 class CookieMonster::DeleteAllCreatedBetweenForHostTask | 673 class CookieMonster::DeleteAllCreatedBetweenForHostTask |
634 : public CookieMonster::CookieMonsterTask { | 674 : public DeleteTask<int> { |
635 public: | 675 public: |
636 DeleteAllCreatedBetweenForHostTask( | 676 DeleteAllCreatedBetweenForHostTask( |
637 CookieMonster* cookie_monster, | 677 CookieMonster* cookie_monster, |
638 Time delete_begin, | 678 Time delete_begin, |
639 Time delete_end, | 679 Time delete_end, |
640 const GURL& url, | 680 const GURL& url, |
641 const CookieMonster::DeleteCallback& callback) | 681 const DeleteCallback& callback) |
642 : CookieMonsterTask(cookie_monster), | 682 : DeleteTask(cookie_monster, callback), |
643 delete_begin_(delete_begin), | 683 delete_begin_(delete_begin), |
644 delete_end_(delete_end), | 684 delete_end_(delete_end), |
645 url_(url), | 685 url_(url) { |
646 callback_(callback) { | |
647 } | 686 } |
648 | 687 |
649 // CookieMonster::CookieMonsterTask: | 688 // DeleteTask: |
650 virtual void Run() OVERRIDE; | 689 virtual int RunDeleteTask() OVERRIDE; |
651 | 690 |
652 protected: | 691 protected: |
653 virtual ~DeleteAllCreatedBetweenForHostTask() {} | 692 virtual ~DeleteAllCreatedBetweenForHostTask() {} |
654 | 693 |
655 private: | 694 private: |
656 Time delete_begin_; | 695 Time delete_begin_; |
657 Time delete_end_; | 696 Time delete_end_; |
658 GURL url_; | 697 GURL url_; |
659 CookieMonster::DeleteCallback callback_; | |
660 | 698 |
661 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); | 699 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); |
662 }; | 700 }; |
663 | 701 |
664 void CookieMonster::DeleteAllCreatedBetweenForHostTask::Run() { | 702 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { |
665 int num_deleted = this->cookie_monster()->DeleteAllCreatedBetweenForHost( | 703 return this->cookie_monster()->DeleteAllCreatedBetweenForHost( |
666 delete_begin_, delete_end_, url_); | 704 delete_begin_, delete_end_, url_); |
667 if (!callback_.is_null()) { | |
668 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | |
669 base::Unretained(&callback_), num_deleted)); | |
670 } | |
671 } | 705 } |
672 | 706 |
673 // Task class for DeleteCanonicalCookie call. | 707 // Task class for DeleteCanonicalCookie call. |
674 class CookieMonster::DeleteCanonicalCookieTask | 708 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<bool> { |
675 : public CookieMonster::CookieMonsterTask { | |
676 public: | 709 public: |
677 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, | 710 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, |
678 const CanonicalCookie& cookie, | 711 const CanonicalCookie& cookie, |
679 const CookieMonster::DeleteCookieCallback& callback) | 712 const DeleteCookieCallback& callback) |
680 : CookieMonsterTask(cookie_monster), | 713 : DeleteTask(cookie_monster, callback), |
681 cookie_(cookie), | 714 cookie_(cookie) { |
682 callback_(callback) { | |
683 } | 715 } |
684 | 716 |
685 // CookieMonster::CookieMonsterTask: | 717 // DeleteTask: |
686 virtual void Run() OVERRIDE; | 718 virtual bool RunDeleteTask() OVERRIDE; |
687 | 719 |
688 protected: | 720 protected: |
689 virtual ~DeleteCanonicalCookieTask() {} | 721 virtual ~DeleteCanonicalCookieTask() {} |
690 | 722 |
691 private: | 723 private: |
692 CanonicalCookie cookie_; | 724 CanonicalCookie cookie_; |
693 CookieMonster::DeleteCookieCallback callback_; | |
694 | 725 |
695 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); | 726 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); |
696 }; | 727 }; |
697 | 728 |
698 void CookieMonster::DeleteCanonicalCookieTask::Run() { | 729 bool CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { |
699 bool result = this->cookie_monster()->DeleteCanonicalCookie(cookie_); | 730 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); |
700 if (!callback_.is_null()) { | |
701 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCookieCallback::Run, | |
702 base::Unretained(&callback_), result)); | |
703 } | |
704 } | 731 } |
705 | 732 |
706 // Task class for SetCookieWithOptions call. | 733 // Task class for SetCookieWithOptions call. |
707 class CookieMonster::SetCookieWithOptionsTask | 734 class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { |
708 : public CookieMonster::CookieMonsterTask { | |
709 public: | 735 public: |
710 SetCookieWithOptionsTask(CookieMonster* cookie_monster, | 736 SetCookieWithOptionsTask(CookieMonster* cookie_monster, |
711 const GURL& url, | 737 const GURL& url, |
712 const std::string& cookie_line, | 738 const std::string& cookie_line, |
713 const CookieOptions& options, | 739 const CookieOptions& options, |
714 const CookieMonster::SetCookiesCallback& callback) | 740 const SetCookiesCallback& callback) |
715 : CookieMonsterTask(cookie_monster), | 741 : CookieMonsterTask(cookie_monster), |
716 url_(url), | 742 url_(url), |
717 cookie_line_(cookie_line), | 743 cookie_line_(cookie_line), |
718 options_(options), | 744 options_(options), |
719 callback_(callback) { | 745 callback_(callback) { |
720 } | 746 } |
721 | 747 |
722 // CookieMonster::CookieMonsterTask: | 748 // CookieMonsterTask: |
723 virtual void Run() OVERRIDE; | 749 virtual void Run() OVERRIDE; |
724 | 750 |
725 protected: | 751 protected: |
726 virtual ~SetCookieWithOptionsTask() {} | 752 virtual ~SetCookieWithOptionsTask() {} |
727 | 753 |
728 private: | 754 private: |
729 GURL url_; | 755 GURL url_; |
730 std::string cookie_line_; | 756 std::string cookie_line_; |
731 CookieOptions options_; | 757 CookieOptions options_; |
732 CookieMonster::SetCookiesCallback callback_; | 758 SetCookiesCallback callback_; |
733 | 759 |
734 DISALLOW_COPY_AND_ASSIGN(SetCookieWithOptionsTask); | 760 DISALLOW_COPY_AND_ASSIGN(SetCookieWithOptionsTask); |
735 }; | 761 }; |
736 | 762 |
737 void CookieMonster::SetCookieWithOptionsTask::Run() { | 763 void CookieMonster::SetCookieWithOptionsTask::Run() { |
738 bool result = this->cookie_monster()-> | 764 bool result = this->cookie_monster()-> |
739 SetCookieWithOptions(url_, cookie_line_, options_); | 765 SetCookieWithOptions(url_, cookie_line_, options_); |
740 if (!callback_.is_null()) { | 766 if (!callback_.is_null()) { |
741 this->InvokeCallback(base::Bind(&CookieMonster::SetCookiesCallback::Run, | 767 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, |
742 base::Unretained(&callback_), result)); | 768 base::Unretained(&callback_), result)); |
743 } | 769 } |
744 } | 770 } |
745 | 771 |
746 // Task class for GetCookiesWithOptions call. | 772 // Task class for GetCookiesWithOptions call. |
747 class CookieMonster::GetCookiesWithOptionsTask | 773 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { |
748 : public CookieMonster::CookieMonsterTask { | |
749 public: | 774 public: |
750 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, | 775 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, |
751 const GURL& url, | 776 const GURL& url, |
752 const CookieOptions& options, | 777 const CookieOptions& options, |
753 const CookieMonster::GetCookiesCallback& callback) | 778 const GetCookiesCallback& callback) |
754 : CookieMonsterTask(cookie_monster), | 779 : CookieMonsterTask(cookie_monster), |
755 url_(url), | 780 url_(url), |
756 options_(options), | 781 options_(options), |
757 callback_(callback) { | 782 callback_(callback) { |
758 } | 783 } |
759 | 784 |
760 // CookieMonster::CookieMonsterTask: | 785 // CookieMonsterTask: |
761 virtual void Run() OVERRIDE; | 786 virtual void Run() OVERRIDE; |
762 | 787 |
763 protected: | 788 protected: |
764 virtual ~GetCookiesWithOptionsTask() {} | 789 virtual ~GetCookiesWithOptionsTask() {} |
765 | 790 |
766 private: | 791 private: |
767 GURL url_; | 792 GURL url_; |
768 CookieOptions options_; | 793 CookieOptions options_; |
769 CookieMonster::GetCookiesCallback callback_; | 794 GetCookiesCallback callback_; |
770 | 795 |
771 DISALLOW_COPY_AND_ASSIGN(GetCookiesWithOptionsTask); | 796 DISALLOW_COPY_AND_ASSIGN(GetCookiesWithOptionsTask); |
772 }; | 797 }; |
773 | 798 |
774 void CookieMonster::GetCookiesWithOptionsTask::Run() { | 799 void CookieMonster::GetCookiesWithOptionsTask::Run() { |
775 std::string cookie = this->cookie_monster()-> | 800 std::string cookie = this->cookie_monster()-> |
776 GetCookiesWithOptions(url_, options_); | 801 GetCookiesWithOptions(url_, options_); |
777 if (!callback_.is_null()) { | 802 if (!callback_.is_null()) { |
778 this->InvokeCallback(base::Bind(&CookieMonster::GetCookiesCallback::Run, | 803 this->InvokeCallback(base::Bind(&GetCookiesCallback::Run, |
779 base::Unretained(&callback_), cookie)); | 804 base::Unretained(&callback_), cookie)); |
780 } | 805 } |
781 } | 806 } |
782 | 807 |
783 // Task class for DeleteCookie call. | 808 // Task class for DeleteCookie call. |
784 class CookieMonster::DeleteCookieTask | 809 class CookieMonster::DeleteCookieTask : public DeleteTask<void> { |
785 : public CookieMonster::CookieMonsterTask { | |
786 public: | 810 public: |
787 DeleteCookieTask(CookieMonster* cookie_monster, | 811 DeleteCookieTask(CookieMonster* cookie_monster, |
788 const GURL& url, | 812 const GURL& url, |
789 const std::string& cookie_name, | 813 const std::string& cookie_name, |
790 const base::Closure& callback) | 814 const base::Closure& callback) |
791 : CookieMonsterTask(cookie_monster), | 815 : DeleteTask(cookie_monster, callback), |
792 url_(url), | 816 url_(url), |
793 cookie_name_(cookie_name), | 817 cookie_name_(cookie_name) { |
794 callback_(callback) { } | 818 } |
795 | 819 |
796 // CookieMonster::CookieMonsterTask: | 820 // DeleteTask: |
797 virtual void Run() OVERRIDE; | 821 virtual void RunDeleteTask() OVERRIDE; |
798 | 822 |
799 protected: | 823 protected: |
800 virtual ~DeleteCookieTask() {} | 824 virtual ~DeleteCookieTask() {} |
801 | 825 |
802 private: | 826 private: |
803 GURL url_; | 827 GURL url_; |
804 std::string cookie_name_; | 828 std::string cookie_name_; |
805 base::Closure callback_; | |
806 | 829 |
807 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); | 830 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); |
808 }; | 831 }; |
809 | 832 |
810 void CookieMonster::DeleteCookieTask::Run() { | 833 void CookieMonster::DeleteCookieTask::RunDeleteTask() { |
811 this->cookie_monster()->DeleteCookie(url_, cookie_name_); | 834 this->cookie_monster()->DeleteCookie(url_, cookie_name_); |
812 if (!callback_.is_null()) { | |
813 this->InvokeCallback(callback_); | |
814 } | |
815 } | 835 } |
816 | 836 |
817 // Task class for DeleteSessionCookies call. | 837 // Task class for DeleteSessionCookies call. |
818 class CookieMonster::DeleteSessionCookiesTask | 838 class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { |
819 : public CookieMonster::CookieMonsterTask { | |
820 public: | 839 public: |
821 DeleteSessionCookiesTask(CookieMonster* cookie_monster, | 840 DeleteSessionCookiesTask(CookieMonster* cookie_monster, |
822 const CookieMonster::DeleteCallback& callback) | 841 const DeleteCallback& callback) |
823 : CookieMonsterTask(cookie_monster), callback_(callback) { | 842 : DeleteTask(cookie_monster, callback) { |
824 } | 843 } |
825 | 844 |
826 // CookieMonster::CookieMonsterTask: | 845 // DeleteTask: |
827 virtual void Run() OVERRIDE; | 846 virtual int RunDeleteTask() OVERRIDE; |
828 | 847 |
829 protected: | 848 protected: |
830 virtual ~DeleteSessionCookiesTask() {} | 849 virtual ~DeleteSessionCookiesTask() {} |
831 | 850 |
832 private: | 851 private: |
833 CookieMonster::DeleteCallback callback_; | |
834 | 852 |
835 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); | 853 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); |
836 }; | 854 }; |
837 | 855 |
838 void CookieMonster::DeleteSessionCookiesTask::Run() { | 856 int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { |
839 int num_deleted = this->cookie_monster()->DeleteSessionCookies(); | 857 return this->cookie_monster()->DeleteSessionCookies(); |
840 if (!callback_.is_null()) { | |
841 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | |
842 base::Unretained(&callback_), num_deleted)); | |
843 } | |
844 } | 858 } |
845 | 859 |
846 // Task class for HasCookiesForETLDP1Task call. | 860 // Task class for HasCookiesForETLDP1Task call. |
847 class CookieMonster::HasCookiesForETLDP1Task | 861 class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask { |
848 : public CookieMonster::CookieMonsterTask { | |
849 public: | 862 public: |
850 HasCookiesForETLDP1Task( | 863 HasCookiesForETLDP1Task( |
851 CookieMonster* cookie_monster, | 864 CookieMonster* cookie_monster, |
852 const std::string& etldp1, | 865 const std::string& etldp1, |
853 const CookieMonster::HasCookiesForETLDP1Callback& callback) | 866 const HasCookiesForETLDP1Callback& callback) |
854 : CookieMonsterTask(cookie_monster), | 867 : CookieMonsterTask(cookie_monster), |
855 etldp1_(etldp1), | 868 etldp1_(etldp1), |
856 callback_(callback) { | 869 callback_(callback) { |
857 } | 870 } |
858 | 871 |
859 // CookieMonster::CookieMonsterTask: | 872 // CookieMonsterTask: |
860 virtual void Run() OVERRIDE; | 873 virtual void Run() OVERRIDE; |
861 | 874 |
862 protected: | 875 protected: |
863 virtual ~HasCookiesForETLDP1Task() {} | 876 virtual ~HasCookiesForETLDP1Task() {} |
864 | 877 |
865 private: | 878 private: |
866 std::string etldp1_; | 879 std::string etldp1_; |
867 CookieMonster::HasCookiesForETLDP1Callback callback_; | 880 HasCookiesForETLDP1Callback callback_; |
868 | 881 |
869 DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task); | 882 DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task); |
870 }; | 883 }; |
871 | 884 |
872 void CookieMonster::HasCookiesForETLDP1Task::Run() { | 885 void CookieMonster::HasCookiesForETLDP1Task::Run() { |
873 bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); | 886 bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); |
874 if (!callback_.is_null()) { | 887 if (!callback_.is_null()) { |
875 this->InvokeCallback( | 888 this->InvokeCallback( |
876 base::Bind(&CookieMonster::HasCookiesForETLDP1Callback::Run, | 889 base::Bind(&HasCookiesForETLDP1Callback::Run, |
877 base::Unretained(&callback_), result)); | 890 base::Unretained(&callback_), result)); |
878 } | 891 } |
879 } | 892 } |
880 | 893 |
881 // Asynchronous CookieMonster API | 894 // Asynchronous CookieMonster API |
882 | 895 |
883 void CookieMonster::SetCookieWithDetailsAsync( | 896 void CookieMonster::SetCookieWithDetailsAsync( |
884 const GURL& url, | 897 const GURL& url, |
885 const std::string& name, | 898 const std::string& name, |
886 const std::string& value, | 899 const std::string& value, |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1632 } | 1645 } |
1633 DCHECK_EQ(num_duplicates, num_duplicates_found); | 1646 DCHECK_EQ(num_duplicates, num_duplicates_found); |
1634 | 1647 |
1635 return num_duplicates; | 1648 return num_duplicates; |
1636 } | 1649 } |
1637 | 1650 |
1638 // Note: file must be the last scheme. | 1651 // Note: file must be the last scheme. |
1639 const char* CookieMonster::kDefaultCookieableSchemes[] = | 1652 const char* CookieMonster::kDefaultCookieableSchemes[] = |
1640 { "http", "https", "file" }; | 1653 { "http", "https", "file" }; |
1641 const int CookieMonster::kDefaultCookieableSchemesCount = | 1654 const int CookieMonster::kDefaultCookieableSchemesCount = |
1642 arraysize(CookieMonster::kDefaultCookieableSchemes); | 1655 arraysize(kDefaultCookieableSchemes); |
1643 | 1656 |
1644 void CookieMonster::SetDefaultCookieableSchemes() { | 1657 void CookieMonster::SetDefaultCookieableSchemes() { |
1645 int num_schemes = default_enable_file_scheme_ ? | 1658 int num_schemes = default_enable_file_scheme_ ? |
1646 kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1; | 1659 kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1; |
1647 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); | 1660 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); |
1648 } | 1661 } |
1649 | 1662 |
1650 void CookieMonster::FindCookiesForHostAndDomain( | 1663 void CookieMonster::FindCookiesForHostAndDomain( |
1651 const GURL& url, | 1664 const GURL& url, |
1652 const CookieOptions& options, | 1665 const CookieOptions& options, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1737 CanonicalCookie* cc, | 1750 CanonicalCookie* cc, |
1738 bool sync_to_store) { | 1751 bool sync_to_store) { |
1739 lock_.AssertAcquired(); | 1752 lock_.AssertAcquired(); |
1740 | 1753 |
1741 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1754 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
1742 sync_to_store) | 1755 sync_to_store) |
1743 store_->AddCookie(*cc); | 1756 store_->AddCookie(*cc); |
1744 cookies_.insert(CookieMap::value_type(key, cc)); | 1757 cookies_.insert(CookieMap::value_type(key, cc)); |
1745 if (delegate_.get()) { | 1758 if (delegate_.get()) { |
1746 delegate_->OnCookieChanged( | 1759 delegate_->OnCookieChanged( |
1747 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT); | 1760 *cc, false, Delegate::CHANGE_COOKIE_EXPLICIT); |
1748 } | 1761 } |
1749 } | 1762 } |
1750 | 1763 |
1751 bool CookieMonster::SetCookieWithCreationTimeAndOptions( | 1764 bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
1752 const GURL& url, | 1765 const GURL& url, |
1753 const std::string& cookie_line, | 1766 const std::string& cookie_line, |
1754 const Time& creation_time_or_null, | 1767 const Time& creation_time_or_null, |
1755 const CookieOptions& options) { | 1768 const CookieOptions& options) { |
1756 lock_.AssertAcquired(); | 1769 lock_.AssertAcquired(); |
1757 | 1770 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2008 cookie_its->push_back(curit); | 2021 cookie_its->push_back(curit); |
2009 } | 2022 } |
2010 } | 2023 } |
2011 | 2024 |
2012 return num_deleted; | 2025 return num_deleted; |
2013 } | 2026 } |
2014 | 2027 |
2015 int CookieMonster::GarbageCollectDeleteRange( | 2028 int CookieMonster::GarbageCollectDeleteRange( |
2016 const Time& current, | 2029 const Time& current, |
2017 DeletionCause cause, | 2030 DeletionCause cause, |
2018 CookieMonster::CookieItVector::iterator it_begin, | 2031 CookieItVector::iterator it_begin, |
2019 CookieMonster::CookieItVector::iterator it_end) { | 2032 CookieItVector::iterator it_end) { |
2020 for (CookieItVector::iterator it = it_begin; it != it_end; it++) { | 2033 for (CookieItVector::iterator it = it_begin; it != it_end; it++) { |
2021 histogram_evicted_last_access_minutes_->Add( | 2034 histogram_evicted_last_access_minutes_->Add( |
2022 (current - (*it)->second->LastAccessDate()).InMinutes()); | 2035 (current - (*it)->second->LastAccessDate()).InMinutes()); |
2023 InternalDeleteCookie((*it), true, cause); | 2036 InternalDeleteCookie((*it), true, cause); |
2024 } | 2037 } |
2025 return it_end - it_begin; | 2038 return it_end - it_begin; |
2026 } | 2039 } |
2027 | 2040 |
2028 // A wrapper around registry_controlled_domains::GetDomainAndRegistry | 2041 // A wrapper around registry_controlled_domains::GetDomainAndRegistry |
2029 // to make clear we're creating a key for our local map. Here and | 2042 // to make clear we're creating a key for our local map. Here and |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2214 | 2227 |
2215 // The system resolution is not high enough, so we can have multiple | 2228 // The system resolution is not high enough, so we can have multiple |
2216 // set cookies that result in the same system time. When this happens, we | 2229 // set cookies that result in the same system time. When this happens, we |
2217 // increment by one Time unit. Let's hope computers don't get too fast. | 2230 // increment by one Time unit. Let's hope computers don't get too fast. |
2218 Time CookieMonster::CurrentTime() { | 2231 Time CookieMonster::CurrentTime() { |
2219 return std::max(Time::Now(), | 2232 return std::max(Time::Now(), |
2220 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2233 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
2221 } | 2234 } |
2222 | 2235 |
2223 } // namespace net | 2236 } // namespace net |
OLD | NEW |