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