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 // Brought to you by the letter D and the number 2. | 5 // Brought to you by the letter D and the number 2. |
6 | 6 |
7 #ifndef NET_COOKIES_COOKIE_MONSTER_H_ | 7 #ifndef NET_COOKIES_COOKIE_MONSTER_H_ |
8 #define NET_COOKIES_COOKIE_MONSTER_H_ | 8 #define NET_COOKIES_COOKIE_MONSTER_H_ |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 void ValidateMap(int arg); | 300 void ValidateMap(int arg); |
301 | 301 |
302 // Determines if the scheme of the URL is a scheme that cookies will be | 302 // Determines if the scheme of the URL is a scheme that cookies will be |
303 // stored for. | 303 // stored for. |
304 bool IsCookieableScheme(const std::string& scheme); | 304 bool IsCookieableScheme(const std::string& scheme); |
305 | 305 |
306 // The default list of schemes the cookie monster can handle. | 306 // The default list of schemes the cookie monster can handle. |
307 static const char* kDefaultCookieableSchemes[]; | 307 static const char* kDefaultCookieableSchemes[]; |
308 static const int kDefaultCookieableSchemesCount; | 308 static const int kDefaultCookieableSchemesCount; |
309 | 309 |
| 310 // Copies all keys for the given |key| to another cookie monster |other|. |
| 311 // Both |other| and |this| must be loaded for this operation to succeed. |
| 312 // Furthermore, there may not be any cookies stored in |other| for |key|. |
| 313 // Returns false if any of these conditions is not met. |
| 314 bool CopyCookiesForKeyToOtherCookieMonster(std::string key, |
| 315 CookieMonster* other); |
| 316 |
| 317 // Find the key (for lookup in cookies_) based on the given domain. |
| 318 // See comment on keys before the CookieMap typedef. |
| 319 std::string GetKey(const std::string& domain) const; |
| 320 |
| 321 bool loaded(); |
| 322 |
310 private: | 323 private: |
311 // For queueing the cookie monster calls. | 324 // For queueing the cookie monster calls. |
312 class CookieMonsterTask; | 325 class CookieMonsterTask; |
313 template <typename Result> class DeleteTask; | 326 template <typename Result> class DeleteTask; |
314 class DeleteAllCreatedBetweenTask; | 327 class DeleteAllCreatedBetweenTask; |
315 class DeleteAllCreatedBetweenForHostTask; | 328 class DeleteAllCreatedBetweenForHostTask; |
316 class DeleteAllForHostTask; | 329 class DeleteAllForHostTask; |
317 class DeleteAllTask; | 330 class DeleteAllTask; |
318 class DeleteCookieTask; | 331 class DeleteCookieTask; |
319 class DeleteCanonicalCookieTask; | 332 class DeleteCanonicalCookieTask; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 // Called by all non-static functions to ensure that the cookies store has | 461 // Called by all non-static functions to ensure that the cookies store has |
449 // been initialized. This is not done during creating so it doesn't block | 462 // been initialized. This is not done during creating so it doesn't block |
450 // the window showing. | 463 // the window showing. |
451 // Note: this method should always be called with lock_ held. | 464 // Note: this method should always be called with lock_ held. |
452 void InitIfNecessary() { | 465 void InitIfNecessary() { |
453 if (!initialized_) { | 466 if (!initialized_) { |
454 if (store_.get()) { | 467 if (store_.get()) { |
455 InitStore(); | 468 InitStore(); |
456 } else { | 469 } else { |
457 loaded_ = true; | 470 loaded_ = true; |
| 471 ReportLoaded(); |
458 } | 472 } |
459 initialized_ = true; | 473 initialized_ = true; |
460 } | 474 } |
461 } | 475 } |
462 | 476 |
463 // Initializes the backing store and reads existing cookies from it. | 477 // Initializes the backing store and reads existing cookies from it. |
464 // Should only be called by InitIfNecessary(). | 478 // Should only be called by InitIfNecessary(). |
465 void InitStore(); | 479 void InitStore(); |
466 | 480 |
| 481 // Reports to the delegate that the cookie monster was loaded. |
| 482 void ReportLoaded(); |
| 483 |
467 // Stores cookies loaded from the backing store and invokes any deferred | 484 // Stores cookies loaded from the backing store and invokes any deferred |
468 // calls. |beginning_time| should be the moment PersistentCookieStore::Load | 485 // calls. |beginning_time| should be the moment PersistentCookieStore::Load |
469 // was invoked and is used for reporting histogram_time_blocked_on_load_. | 486 // was invoked and is used for reporting histogram_time_blocked_on_load_. |
470 // See PersistentCookieStore::Load for details on the contents of cookies. | 487 // See PersistentCookieStore::Load for details on the contents of cookies. |
471 void OnLoaded(base::TimeTicks beginning_time, | 488 void OnLoaded(base::TimeTicks beginning_time, |
472 const std::vector<CanonicalCookie*>& cookies); | 489 const std::vector<CanonicalCookie*>& cookies); |
473 | 490 |
474 // Stores cookies loaded from the backing store and invokes the deferred | 491 // Stores cookies loaded from the backing store and invokes the deferred |
475 // task(s) pending loading of cookies associated with the domain key | 492 // task(s) pending loading of cookies associated with the domain key |
476 // (eTLD+1). Called when all cookies for the domain key(eTLD+1) have been | 493 // (eTLD+1). Called when all cookies for the domain key(eTLD+1) have been |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 const CookieMapItPair& itpair, | 586 const CookieMapItPair& itpair, |
570 std::vector<CookieMap::iterator>* cookie_its); | 587 std::vector<CookieMap::iterator>* cookie_its); |
571 | 588 |
572 // Helper for GarbageCollect(). Deletes all cookies in the range specified by | 589 // Helper for GarbageCollect(). Deletes all cookies in the range specified by |
573 // [|it_begin|, |it_end|). Returns the number of cookies deleted. | 590 // [|it_begin|, |it_end|). Returns the number of cookies deleted. |
574 int GarbageCollectDeleteRange(const base::Time& current, | 591 int GarbageCollectDeleteRange(const base::Time& current, |
575 DeletionCause cause, | 592 DeletionCause cause, |
576 CookieItVector::iterator cookie_its_begin, | 593 CookieItVector::iterator cookie_its_begin, |
577 CookieItVector::iterator cookie_its_end); | 594 CookieItVector::iterator cookie_its_end); |
578 | 595 |
579 // Find the key (for lookup in cookies_) based on the given domain. | |
580 // See comment on keys before the CookieMap typedef. | |
581 std::string GetKey(const std::string& domain) const; | |
582 | |
583 bool HasCookieableScheme(const GURL& url); | 596 bool HasCookieableScheme(const GURL& url); |
584 | 597 |
585 // Statistics support | 598 // Statistics support |
586 | 599 |
587 // This function should be called repeatedly, and will record | 600 // This function should be called repeatedly, and will record |
588 // statistics if a sufficient time period has passed. | 601 // statistics if a sufficient time period has passed. |
589 void RecordPeriodicStats(const base::Time& current_time); | 602 void RecordPeriodicStats(const base::Time& current_time); |
590 | 603 |
591 // Initialize the above variables; should only be called from | 604 // Initialize the above variables; should only be called from |
592 // the constructor. | 605 // the constructor. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 // added, and |cause| will be set to CHANGE_COOKIE_EXPLICIT. | 726 // added, and |cause| will be set to CHANGE_COOKIE_EXPLICIT. |
714 // | 727 // |
715 // As a special case, note that updating a cookie's properties is implemented | 728 // As a special case, note that updating a cookie's properties is implemented |
716 // as a two step process: the cookie to be updated is first removed entirely, | 729 // as a two step process: the cookie to be updated is first removed entirely, |
717 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards, | 730 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards, |
718 // a new cookie is written with the updated values, generating a notification | 731 // a new cookie is written with the updated values, generating a notification |
719 // with cause CHANGE_COOKIE_EXPLICIT. | 732 // with cause CHANGE_COOKIE_EXPLICIT. |
720 virtual void OnCookieChanged(const CanonicalCookie& cookie, | 733 virtual void OnCookieChanged(const CanonicalCookie& cookie, |
721 bool removed, | 734 bool removed, |
722 ChangeCause cause) = 0; | 735 ChangeCause cause) = 0; |
| 736 // Indicates that the cookie store has fully loaded. |
| 737 virtual void OnLoaded() = 0; |
| 738 |
723 protected: | 739 protected: |
724 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>; | 740 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>; |
725 virtual ~CookieMonsterDelegate() {} | 741 virtual ~CookieMonsterDelegate() {} |
726 }; | 742 }; |
727 | 743 |
728 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 744 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
729 RefcountedPersistentCookieStore; | 745 RefcountedPersistentCookieStore; |
730 | 746 |
731 class NET_EXPORT CookieMonster::PersistentCookieStore | 747 class NET_EXPORT CookieMonster::PersistentCookieStore |
732 : public RefcountedPersistentCookieStore { | 748 : public RefcountedPersistentCookieStore { |
(...skipping 29 matching lines...) Expand all Loading... |
762 virtual ~PersistentCookieStore() {} | 778 virtual ~PersistentCookieStore() {} |
763 | 779 |
764 private: | 780 private: |
765 friend class base::RefCountedThreadSafe<PersistentCookieStore>; | 781 friend class base::RefCountedThreadSafe<PersistentCookieStore>; |
766 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 782 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
767 }; | 783 }; |
768 | 784 |
769 } // namespace net | 785 } // namespace net |
770 | 786 |
771 #endif // NET_COOKIES_COOKIE_MONSTER_H_ | 787 #endif // NET_COOKIES_COOKIE_MONSTER_H_ |
OLD | NEW |