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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 }; | 552 }; |
553 | 553 |
554 void CookieMonster::DeleteAllTask::Run() { | 554 void CookieMonster::DeleteAllTask::Run() { |
555 int num_deleted = this->cookie_monster()->DeleteAll(true); | 555 int num_deleted = this->cookie_monster()->DeleteAll(true); |
556 if (!callback_.is_null()) { | 556 if (!callback_.is_null()) { |
557 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | 557 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, |
558 base::Unretained(&callback_), num_deleted)); | 558 base::Unretained(&callback_), num_deleted)); |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 // Base task class for Delete*Task. | |
563 class CookieMonster::DeleteTask | |
564 : public CookieMonster::CookieMonsterTask { | |
565 public: | |
566 DeleteTask(CookieMonster* cookie_monster, | |
567 const CookieMonster::DeleteCallback& callback) | |
568 : CookieMonsterTask(cookie_monster), | |
569 callback_(callback) { | |
570 } | |
571 | |
572 void FlushDone(int num_deleted); | |
573 | |
574 private: | |
575 CookieMonster::DeleteCallback callback_; | |
576 | |
577 DISALLOW_COPY_AND_ASSIGN(DeleteTask); | |
578 }; | |
579 | |
580 void CookieMonster::DeleteTask::FlushDone(int num_deleted) { | |
581 if (!callback_.is_null()) { | |
582 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | |
583 base::Unretained(&callback_), num_deleted)); | |
584 } | |
585 } | |
586 | |
562 // Task class for DeleteAllCreatedBetween call. | 587 // Task class for DeleteAllCreatedBetween call. |
563 class CookieMonster::DeleteAllCreatedBetweenTask | 588 class CookieMonster::DeleteAllCreatedBetweenTask |
564 : public CookieMonster::CookieMonsterTask { | 589 : public CookieMonster::DeleteTask { |
565 public: | 590 public: |
566 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, | 591 DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, |
567 const Time& delete_begin, | 592 const Time& delete_begin, |
568 const Time& delete_end, | 593 const Time& delete_end, |
569 const CookieMonster::DeleteCallback& callback) | 594 const CookieMonster::DeleteCallback& callback) |
570 : CookieMonsterTask(cookie_monster), | 595 : DeleteTask(cookie_monster, callback), |
571 delete_begin_(delete_begin), | 596 delete_begin_(delete_begin), |
572 delete_end_(delete_end), | 597 delete_end_(delete_end) { |
573 callback_(callback) { | |
574 } | 598 } |
575 | 599 |
576 // CookieMonster::CookieMonsterTask: | 600 // CookieMonster::CookieMonsterTask: |
577 virtual void Run() OVERRIDE; | 601 virtual void Run() OVERRIDE; |
578 | 602 |
579 protected: | 603 protected: |
580 virtual ~DeleteAllCreatedBetweenTask() {} | 604 virtual ~DeleteAllCreatedBetweenTask() {} |
581 | 605 |
582 private: | 606 private: |
583 Time delete_begin_; | 607 Time delete_begin_; |
584 Time delete_end_; | 608 Time delete_end_; |
585 CookieMonster::DeleteCallback callback_; | |
586 | 609 |
587 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); | 610 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); |
588 }; | 611 }; |
589 | 612 |
590 void CookieMonster::DeleteAllCreatedBetweenTask::Run() { | 613 void CookieMonster::DeleteAllCreatedBetweenTask::Run() { |
erikwright (departed)
2013/08/09 17:31:51
Pull this method up to DeleteTask and delegate to
| |
591 int num_deleted = this->cookie_monster()-> | 614 int num_deleted = this->cookie_monster()-> |
592 DeleteAllCreatedBetween(delete_begin_, delete_end_); | 615 DeleteAllCreatedBetween(delete_begin_, delete_end_); |
593 if (!callback_.is_null()) { | 616 this->cookie_monster()->FlushStore( |
594 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | 617 base::Bind(&CookieMonster::DeleteTask::FlushDone, this, num_deleted)); |
595 base::Unretained(&callback_), num_deleted)); | |
596 } | |
597 } | 618 } |
598 | 619 |
599 // Task class for DeleteAllForHost call. | 620 // Task class for DeleteAllForHost call. |
600 class CookieMonster::DeleteAllForHostTask | 621 class CookieMonster::DeleteAllForHostTask |
601 : public CookieMonster::CookieMonsterTask { | 622 : public CookieMonster::CookieMonsterTask { |
602 public: | 623 public: |
603 DeleteAllForHostTask(CookieMonster* cookie_monster, | 624 DeleteAllForHostTask(CookieMonster* cookie_monster, |
604 const GURL& url, | 625 const GURL& url, |
605 const CookieMonster::DeleteCallback& callback) | 626 const CookieMonster::DeleteCallback& callback) |
606 : CookieMonsterTask(cookie_monster), | 627 : CookieMonsterTask(cookie_monster), |
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2150 | 2171 |
2151 // The system resolution is not high enough, so we can have multiple | 2172 // The system resolution is not high enough, so we can have multiple |
2152 // set cookies that result in the same system time. When this happens, we | 2173 // set cookies that result in the same system time. When this happens, we |
2153 // increment by one Time unit. Let's hope computers don't get too fast. | 2174 // increment by one Time unit. Let's hope computers don't get too fast. |
2154 Time CookieMonster::CurrentTime() { | 2175 Time CookieMonster::CurrentTime() { |
2155 return std::max(Time::Now(), | 2176 return std::max(Time::Now(), |
2156 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2177 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
2157 } | 2178 } |
2158 | 2179 |
2159 } // namespace net | 2180 } // namespace net |
OLD | NEW |