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 <stddef.h> | 10 #include <stddef.h> |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // For CookieDeleteEquivalent histogram enum. | 270 // For CookieDeleteEquivalent histogram enum. |
271 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, | 271 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, |
272 CookieDeleteEquivalentHistogramTest); | 272 CookieDeleteEquivalentHistogramTest); |
273 FRIEND_TEST_ALL_PREFIXES(CookieMonsterStrictSecureTest, | 273 FRIEND_TEST_ALL_PREFIXES(CookieMonsterStrictSecureTest, |
274 CookieDeleteEquivalentHistogramTest); | 274 CookieDeleteEquivalentHistogramTest); |
275 | 275 |
276 // Internal reasons for deletion, used to populate informative histograms | 276 // Internal reasons for deletion, used to populate informative histograms |
277 // and to provide a public cause for onCookieChange notifications. | 277 // and to provide a public cause for onCookieChange notifications. |
278 // | 278 // |
279 // If you add or remove causes from this list, please be sure to also update | 279 // If you add or remove causes from this list, please be sure to also update |
280 // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping. | 280 // the CookieStore::ChangeCause mapping inside ChangeCauseMapping. |
281 // Moreover, these are used as array indexes, so avoid reordering to keep the | 281 // Moreover, these are used as array indexes, so avoid reordering to keep the |
282 // histogram buckets consistent. New items (if necessary) should be added | 282 // histogram buckets consistent. New items (if necessary) should be added |
283 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. | 283 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. |
284 enum DeletionCause { | 284 enum DeletionCause { |
285 DELETE_COOKIE_EXPLICIT = 0, | 285 DELETE_COOKIE_EXPLICIT = 0, |
286 DELETE_COOKIE_OVERWRITE = 1, | 286 DELETE_COOKIE_OVERWRITE = 1, |
287 DELETE_COOKIE_EXPIRED = 2, | 287 DELETE_COOKIE_EXPIRED = 2, |
288 DELETE_COOKIE_EVICTED = 3, | 288 DELETE_COOKIE_EVICTED = 3, |
289 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE = 4, | 289 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE = 4, |
290 DELETE_COOKIE_DONT_RECORD = 5, // For final cleanup after flush to store. | 290 DELETE_COOKIE_DONT_RECORD = 5, // For final cleanup after flush to store. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 const GURL& source_url, | 527 const GURL& source_url, |
528 const CookieOptions& options); | 528 const CookieOptions& options); |
529 | 529 |
530 // Helper function calling SetCanonicalCookie() for all cookies in |list|. | 530 // Helper function calling SetCanonicalCookie() for all cookies in |list|. |
531 bool SetCanonicalCookies(const CookieList& list); | 531 bool SetCanonicalCookies(const CookieList& list); |
532 | 532 |
533 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, | 533 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, |
534 const base::Time& current_time); | 534 const base::Time& current_time); |
535 | 535 |
536 // |deletion_cause| argument is used for collecting statistics and choosing | 536 // |deletion_cause| argument is used for collecting statistics and choosing |
537 // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged | 537 // the correct CookieStore::ChangeCause for OnCookieChanged |
538 // notifications. Guarantee: All iterators to cookies_ except to the | 538 // notifications. Guarantee: All iterators to cookies_ except to the |
539 // deleted entry remain vaild. | 539 // deleted entry remain vaild. |
540 void InternalDeleteCookie(CookieMap::iterator it, | 540 void InternalDeleteCookie(CookieMap::iterator it, |
541 bool sync_to_store, | 541 bool sync_to_store, |
542 DeletionCause deletion_cause); | 542 DeletionCause deletion_cause); |
543 | 543 |
544 // If the number of cookies for CookieMap key |key|, or globally, are | 544 // If the number of cookies for CookieMap key |key|, or globally, are |
545 // over the preset maximums above, garbage collect, first for the host and | 545 // over the preset maximums above, garbage collect, first for the host and |
546 // then globally. See comments above garbage collection threshold | 546 // then globally. See comments above garbage collection threshold |
547 // constants for details. | 547 // constants for details. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 CookieList* new_cookies, | 628 CookieList* new_cookies, |
629 CookieList* cookies_to_add, | 629 CookieList* cookies_to_add, |
630 CookieList* cookies_to_delete); | 630 CookieList* cookies_to_delete); |
631 | 631 |
632 // Runs the given callback. Used to avoid running callbacks after the store | 632 // Runs the given callback. Used to avoid running callbacks after the store |
633 // has been destroyed. | 633 // has been destroyed. |
634 void RunCallback(const base::Closure& callback); | 634 void RunCallback(const base::Closure& callback); |
635 | 635 |
636 // Run all cookie changed callbacks that are monitoring |cookie|. | 636 // Run all cookie changed callbacks that are monitoring |cookie|. |
637 // |removed| is true if the cookie was deleted. | 637 // |removed| is true if the cookie was deleted. |
638 void RunCookieChangedCallbacks(const CanonicalCookie& cookie, bool removed); | 638 void RunCookieChangedCallbacks(const CanonicalCookie& cookie, |
| 639 CookieStore::ChangeCause cause); |
639 | 640 |
640 // Histogram variables; see CookieMonster::InitializeHistograms() in | 641 // Histogram variables; see CookieMonster::InitializeHistograms() in |
641 // cookie_monster.cc for details. | 642 // cookie_monster.cc for details. |
642 base::HistogramBase* histogram_expiration_duration_minutes_; | 643 base::HistogramBase* histogram_expiration_duration_minutes_; |
643 base::HistogramBase* histogram_evicted_last_access_minutes_; | 644 base::HistogramBase* histogram_evicted_last_access_minutes_; |
644 base::HistogramBase* histogram_count_; | 645 base::HistogramBase* histogram_count_; |
645 base::HistogramBase* histogram_cookie_deletion_cause_; | 646 base::HistogramBase* histogram_cookie_deletion_cause_; |
646 base::HistogramBase* histogram_cookie_type_; | 647 base::HistogramBase* histogram_cookie_type_; |
647 base::HistogramBase* histogram_cookie_source_scheme_; | 648 base::HistogramBase* histogram_cookie_source_scheme_; |
648 base::HistogramBase* histogram_cookie_delete_equivalent_; | 649 base::HistogramBase* histogram_cookie_delete_equivalent_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 base::ThreadChecker thread_checker_; | 721 base::ThreadChecker thread_checker_; |
721 | 722 |
722 base::WeakPtrFactory<CookieMonster> weak_ptr_factory_; | 723 base::WeakPtrFactory<CookieMonster> weak_ptr_factory_; |
723 | 724 |
724 DISALLOW_COPY_AND_ASSIGN(CookieMonster); | 725 DISALLOW_COPY_AND_ASSIGN(CookieMonster); |
725 }; | 726 }; |
726 | 727 |
727 class NET_EXPORT CookieMonsterDelegate | 728 class NET_EXPORT CookieMonsterDelegate |
728 : public base::RefCountedThreadSafe<CookieMonsterDelegate> { | 729 : public base::RefCountedThreadSafe<CookieMonsterDelegate> { |
729 public: | 730 public: |
730 // The publicly relevant reasons a cookie might be changed. | |
731 enum ChangeCause { | |
732 // The cookie was changed directly by a consumer's action. | |
733 CHANGE_COOKIE_EXPLICIT, | |
734 // The cookie was automatically removed due to an insert operation that | |
735 // overwrote it. | |
736 CHANGE_COOKIE_OVERWRITE, | |
737 // The cookie was automatically removed as it expired. | |
738 CHANGE_COOKIE_EXPIRED, | |
739 // The cookie was automatically evicted during garbage collection. | |
740 CHANGE_COOKIE_EVICTED, | |
741 // The cookie was overwritten with an already-expired expiration date. | |
742 CHANGE_COOKIE_EXPIRED_OVERWRITE | |
743 }; | |
744 | |
745 // Will be called when a cookie is added or removed. The function is passed | 731 // Will be called when a cookie is added or removed. The function is passed |
746 // the respective |cookie| which was added to or removed from the cookies. | 732 // the respective |cookie| which was added to or removed from the cookies. |
747 // If |removed| is true, the cookie was deleted, and |cause| will be set | 733 // If |removed| is true, the cookie was deleted, and |cause| will be set |
748 // to the reason for its removal. If |removed| is false, the cookie was | 734 // to the reason for its removal. If |removed| is false, the cookie was |
749 // added, and |cause| will be set to CHANGE_COOKIE_EXPLICIT. | 735 // added, and |cause| will be set to CHANGE_COOKIE_EXPLICIT. |
750 // | 736 // |
751 // As a special case, note that updating a cookie's properties is implemented | 737 // As a special case, note that updating a cookie's properties is implemented |
752 // as a two step process: the cookie to be updated is first removed entirely, | 738 // as a two step process: the cookie to be updated is first removed entirely, |
753 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards, | 739 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards, |
754 // a new cookie is written with the updated values, generating a notification | 740 // a new cookie is written with the updated values, generating a notification |
755 // with cause CHANGE_COOKIE_EXPLICIT. | 741 // with cause CHANGE_COOKIE_EXPLICIT. |
756 virtual void OnCookieChanged(const CanonicalCookie& cookie, | 742 virtual void OnCookieChanged(const CanonicalCookie& cookie, |
757 bool removed, | 743 bool removed, |
758 ChangeCause cause) = 0; | 744 CookieStore::ChangeCause cause) = 0; |
| 745 |
759 protected: | 746 protected: |
760 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>; | 747 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>; |
761 virtual ~CookieMonsterDelegate() {} | 748 virtual ~CookieMonsterDelegate() {} |
762 }; | 749 }; |
763 | 750 |
764 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 751 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
765 RefcountedPersistentCookieStore; | 752 RefcountedPersistentCookieStore; |
766 | 753 |
767 class NET_EXPORT CookieMonster::PersistentCookieStore | 754 class NET_EXPORT CookieMonster::PersistentCookieStore |
768 : public RefcountedPersistentCookieStore { | 755 : public RefcountedPersistentCookieStore { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 virtual ~PersistentCookieStore() {} | 794 virtual ~PersistentCookieStore() {} |
808 | 795 |
809 private: | 796 private: |
810 friend class base::RefCountedThreadSafe<PersistentCookieStore>; | 797 friend class base::RefCountedThreadSafe<PersistentCookieStore>; |
811 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 798 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
812 }; | 799 }; |
813 | 800 |
814 } // namespace net | 801 } // namespace net |
815 | 802 |
816 #endif // NET_COOKIES_COOKIE_MONSTER_H_ | 803 #endif // NET_COOKIES_COOKIE_MONSTER_H_ |
OLD | NEW |