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