Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: net/cookies/cookie_monster.h

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: most unittests pass Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 class GURL; 30 class GURL;
31 31
32 namespace base { 32 namespace base {
33 class Histogram; 33 class Histogram;
34 class HistogramBase; 34 class HistogramBase;
35 class TimeTicks; 35 class TimeTicks;
36 } // namespace base 36 } // namespace base
37 37
38 namespace net { 38 namespace net {
39 39
40 class CookieMonsterDelegate;
40 class ParsedCookie; 41 class ParsedCookie;
41 42
42 // The cookie monster is the system for storing and retrieving cookies. It has 43 // The cookie monster is the system for storing and retrieving cookies. It has
43 // an in-memory list of all cookies, and synchronizes non-session cookies to an 44 // an in-memory list of all cookies, and synchronizes non-session cookies to an
44 // optional permanent storage that implements the PersistentCookieStore 45 // optional permanent storage that implements the PersistentCookieStore
45 // interface. 46 // interface.
46 // 47 //
47 // This class IS thread-safe. Normally, it is only used on the I/O thread, but 48 // This class IS thread-safe. Normally, it is only used on the I/O thread, but
48 // is also accessed directly through Automation for UI testing. 49 // is also accessed directly through Automation for UI testing.
49 // 50 //
50 // All cookie tasks are handled asynchronously. Tasks may be deferred if 51 // All cookie tasks are handled asynchronously. Tasks may be deferred if
51 // all affected cookies are not yet loaded from the backing store. Otherwise, 52 // all affected cookies are not yet loaded from the backing store. Otherwise,
52 // the callback may be invoked immediately (prior to return of the asynchronous 53 // the callback may be invoked immediately (prior to return of the asynchronous
53 // function). 54 // function).
54 // 55 //
55 // A cookie task is either pending loading of the entire cookie store, or 56 // A cookie task is either pending loading of the entire cookie store, or
56 // loading of cookies for a specfic domain key(eTLD+1). In the former case, the 57 // loading of cookies for a specfic domain key(eTLD+1). In the former case, the
57 // cookie task will be queued in tasks_pending_ while PersistentCookieStore 58 // cookie task will be queued in tasks_pending_ while PersistentCookieStore
58 // chain loads the cookie store on DB thread. In the latter case, the cookie 59 // chain loads the cookie store on DB thread. In the latter case, the cookie
59 // task will be queued in tasks_pending_for_key_ while PermanentCookieStore 60 // task will be queued in tasks_pending_for_key_ while PermanentCookieStore
60 // loads cookies for the specified domain key(eTLD+1) on DB thread. 61 // loads cookies for the specified domain key(eTLD+1) on DB thread.
61 // 62 //
62 // Callbacks are guaranteed to be invoked on the calling thread. 63 // Callbacks are guaranteed to be invoked on the calling thread.
63 // 64 //
64 // TODO(deanm) Implement CookieMonster, the cookie database. 65 // TODO(deanm) Implement CookieMonster, the cookie database.
65 // - Verify that our domain enforcement and non-dotted handling is correct 66 // - Verify that our domain enforcement and non-dotted handling is correct
66 class NET_EXPORT CookieMonster : public CookieStore { 67 class NET_EXPORT CookieMonster : public CookieStore {
67 public: 68 public:
68 class Delegate;
69 class PersistentCookieStore; 69 class PersistentCookieStore;
70 typedef CookieMonsterDelegate Delegate;
70 71
71 // Terminology: 72 // Terminology:
72 // * The 'top level domain' (TLD) of an internet domain name is 73 // * The 'top level domain' (TLD) of an internet domain name is
73 // the terminal "." free substring (e.g. "com" for google.com 74 // the terminal "." free substring (e.g. "com" for google.com
74 // or world.std.com). 75 // or world.std.com).
75 // * The 'effective top level domain' (eTLD) is the longest 76 // * The 'effective top level domain' (eTLD) is the longest
76 // "." initiated terminal substring of an internet domain name 77 // "." initiated terminal substring of an internet domain name
77 // that is controlled by a general domain registrar. 78 // that is controlled by a general domain registrar.
78 // (e.g. "co.uk" for news.bbc.co.uk). 79 // (e.g. "co.uk" for news.bbc.co.uk).
79 // * The 'effective top level domain plus one' (eTLD+1) is the 80 // * The 'effective top level domain plus one' (eTLD+1) is the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 static const size_t kDomainCookiesQuotaLow; 132 static const size_t kDomainCookiesQuotaLow;
132 static const size_t kDomainCookiesQuotaMedium; 133 static const size_t kDomainCookiesQuotaMedium;
133 static const size_t kDomainCookiesQuotaHigh; 134 static const size_t kDomainCookiesQuotaHigh;
134 135
135 // The store passed in should not have had Init() called on it yet. This 136 // The store passed in should not have had Init() called on it yet. This
136 // class will take care of initializing it. The backing store is NOT owned by 137 // class will take care of initializing it. The backing store is NOT owned by
137 // this class, but it must remain valid for the duration of the cookie 138 // this class, but it must remain valid for the duration of the cookie
138 // monster's existence. If |store| is NULL, then no backing store will be 139 // monster's existence. If |store| is NULL, then no backing store will be
139 // updated. If |delegate| is non-NULL, it will be notified on 140 // updated. If |delegate| is non-NULL, it will be notified on
140 // creation/deletion of cookies. 141 // creation/deletion of cookies.
141 CookieMonster(PersistentCookieStore* store, Delegate* delegate); 142 CookieMonster(PersistentCookieStore* store, CookieMonsterDelegate* delegate);
142 143
143 // Only used during unit testing. 144 // Only used during unit testing.
144 CookieMonster(PersistentCookieStore* store, 145 CookieMonster(PersistentCookieStore* store,
145 Delegate* delegate, 146 CookieMonsterDelegate* delegate,
146 int last_access_threshold_milliseconds); 147 int last_access_threshold_milliseconds);
147 148
148 // Helper function that adds all cookies from |list| into this instance. 149 // Helper function that adds all cookies from |list| into this instance.
149 bool InitializeFrom(const CookieList& list); 150 bool InitializeFrom(const CookieList& list);
150 151
151 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; 152 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback;
152 typedef base::Callback<void(bool success)> DeleteCookieCallback; 153 typedef base::Callback<void(bool success)> DeleteCookieCallback;
153 typedef base::Callback<void(bool cookies_exist)> HasCookiesForETLDP1Callback; 154 typedef base::Callback<void(bool cookies_exist)> HasCookiesForETLDP1Callback;
154 155
155 // Sets a cookie given explicit user-provided cookie attributes. The cookie 156 // Sets a cookie given explicit user-provided cookie attributes. The cookie
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey); 334 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey);
334 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey); 335 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey);
335 336
336 // For FindCookiesForKey. 337 // For FindCookiesForKey.
337 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies); 338 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies);
338 339
339 // Internal reasons for deletion, used to populate informative histograms 340 // Internal reasons for deletion, used to populate informative histograms
340 // and to provide a public cause for onCookieChange notifications. 341 // and to provide a public cause for onCookieChange notifications.
341 // 342 //
342 // If you add or remove causes from this list, please be sure to also update 343 // If you add or remove causes from this list, please be sure to also update
343 // the Delegate::ChangeCause mapping inside ChangeCauseMapping. Moreover, 344 // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping.
344 // these are used as array indexes, so avoid reordering to keep the 345 // Moreover, these are used as array indexes, so avoid reordering to keep the
345 // histogram buckets consistent. New items (if necessary) should be added 346 // histogram buckets consistent. New items (if necessary) should be added
346 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. 347 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY.
347 enum DeletionCause { 348 enum DeletionCause {
348 DELETE_COOKIE_EXPLICIT = 0, 349 DELETE_COOKIE_EXPLICIT = 0,
349 DELETE_COOKIE_OVERWRITE, 350 DELETE_COOKIE_OVERWRITE,
350 DELETE_COOKIE_EXPIRED, 351 DELETE_COOKIE_EXPIRED,
351 DELETE_COOKIE_EVICTED, 352 DELETE_COOKIE_EVICTED,
352 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE, 353 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE,
353 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store. 354 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store.
354 DELETE_COOKIE_EVICTED_DOMAIN, 355 DELETE_COOKIE_EVICTED_DOMAIN,
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // Helper function that sets a canonical cookie, deleting equivalents and 519 // Helper function that sets a canonical cookie, deleting equivalents and
519 // performing garbage collection. 520 // performing garbage collection.
520 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, 521 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
521 const base::Time& creation_time, 522 const base::Time& creation_time,
522 const CookieOptions& options); 523 const CookieOptions& options);
523 524
524 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, 525 void InternalUpdateCookieAccessTime(CanonicalCookie* cc,
525 const base::Time& current_time); 526 const base::Time& current_time);
526 527
527 // |deletion_cause| argument is used for collecting statistics and choosing 528 // |deletion_cause| argument is used for collecting statistics and choosing
528 // the correct Delegate::ChangeCause for OnCookieChanged notifications. 529 // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged
530 // notifications.
529 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store, 531 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store,
530 DeletionCause deletion_cause); 532 DeletionCause deletion_cause);
531 533
532 // If the number of cookies for CookieMap key |key|, or globally, are 534 // If the number of cookies for CookieMap key |key|, or globally, are
533 // over the preset maximums above, garbage collect, first for the host and 535 // over the preset maximums above, garbage collect, first for the host and
534 // then globally. See comments above garbage collection threshold 536 // then globally. See comments above garbage collection threshold
535 // constants for details. 537 // constants for details.
536 // 538 //
537 // Returns the number of cookies deleted (useful for debugging). 539 // Returns the number of cookies deleted (useful for debugging).
538 int GarbageCollect(const base::Time& current, const std::string& key); 540 int GarbageCollect(const base::Time& current, const std::string& key);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 base::Time earliest_access_time_; 642 base::Time earliest_access_time_;
641 643
642 // During loading, holds the set of all loaded cookie creation times. Used to 644 // During loading, holds the set of all loaded cookie creation times. Used to
643 // avoid ever letting cookies with duplicate creation times into the store; 645 // avoid ever letting cookies with duplicate creation times into the store;
644 // that way we don't have to worry about what sections of code are safe 646 // that way we don't have to worry about what sections of code are safe
645 // to call while it's in that state. 647 // to call while it's in that state.
646 std::set<int64> creation_times_; 648 std::set<int64> creation_times_;
647 649
648 std::vector<std::string> cookieable_schemes_; 650 std::vector<std::string> cookieable_schemes_;
649 651
650 scoped_refptr<Delegate> delegate_; 652 scoped_refptr<CookieMonsterDelegate> delegate_;
651 653
652 // Lock for thread-safety 654 // Lock for thread-safety
653 base::Lock lock_; 655 base::Lock lock_;
654 656
655 base::Time last_statistic_record_time_; 657 base::Time last_statistic_record_time_;
656 658
657 bool keep_expired_cookies_; 659 bool keep_expired_cookies_;
658 bool persist_session_cookies_; 660 bool persist_session_cookies_;
659 bool priority_aware_garbage_collection_; 661 bool priority_aware_garbage_collection_;
660 662
661 // Static setting for whether or not file scheme cookies are allows when 663 // Static setting for whether or not file scheme cookies are allows when
662 // a new CookieMonster is created, or the accepted schemes on a CookieMonster 664 // a new CookieMonster is created, or the accepted schemes on a CookieMonster
663 // instance are reset back to defaults. 665 // instance are reset back to defaults.
664 static bool default_enable_file_scheme_; 666 static bool default_enable_file_scheme_;
665 667
666 DISALLOW_COPY_AND_ASSIGN(CookieMonster); 668 DISALLOW_COPY_AND_ASSIGN(CookieMonster);
667 }; 669 };
668 670
669 class NET_EXPORT CookieMonster::Delegate 671 class NET_EXPORT CookieMonsterDelegate
670 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { 672 : public base::RefCountedThreadSafe<CookieMonsterDelegate> {
671 public: 673 public:
672 // The publicly relevant reasons a cookie might be changed. 674 // The publicly relevant reasons a cookie might be changed.
673 enum ChangeCause { 675 enum ChangeCause {
674 // The cookie was changed directly by a consumer's action. 676 // The cookie was changed directly by a consumer's action.
675 CHANGE_COOKIE_EXPLICIT, 677 CHANGE_COOKIE_EXPLICIT,
676 // The cookie was automatically removed due to an insert operation that 678 // The cookie was automatically removed due to an insert operation that
677 // overwrote it. 679 // overwrote it.
678 CHANGE_COOKIE_OVERWRITE, 680 CHANGE_COOKIE_OVERWRITE,
679 // The cookie was automatically removed as it expired. 681 // The cookie was automatically removed as it expired.
680 CHANGE_COOKIE_EXPIRED, 682 CHANGE_COOKIE_EXPIRED,
(...skipping 11 matching lines...) Expand all
692 // 694 //
693 // As a special case, note that updating a cookie's properties is implemented 695 // As a special case, note that updating a cookie's properties is implemented
694 // as a two step process: the cookie to be updated is first removed entirely, 696 // as a two step process: the cookie to be updated is first removed entirely,
695 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards, 697 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards,
696 // a new cookie is written with the updated values, generating a notification 698 // a new cookie is written with the updated values, generating a notification
697 // with cause CHANGE_COOKIE_EXPLICIT. 699 // with cause CHANGE_COOKIE_EXPLICIT.
698 virtual void OnCookieChanged(const CanonicalCookie& cookie, 700 virtual void OnCookieChanged(const CanonicalCookie& cookie,
699 bool removed, 701 bool removed,
700 ChangeCause cause) = 0; 702 ChangeCause cause) = 0;
701 protected: 703 protected:
702 friend class base::RefCountedThreadSafe<CookieMonster::Delegate>; 704 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>;
703 virtual ~Delegate() {} 705 virtual ~CookieMonsterDelegate() {}
704 }; 706 };
705 707
706 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> 708 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore>
707 RefcountedPersistentCookieStore; 709 RefcountedPersistentCookieStore;
708 710
709 class NET_EXPORT CookieMonster::PersistentCookieStore 711 class NET_EXPORT CookieMonster::PersistentCookieStore
710 : public RefcountedPersistentCookieStore { 712 : public RefcountedPersistentCookieStore {
711 public: 713 public:
712 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)> 714 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)>
713 LoadedCallback; 715 LoadedCallback;
(...skipping 26 matching lines...) Expand all
740 virtual ~PersistentCookieStore() {} 742 virtual ~PersistentCookieStore() {}
741 743
742 private: 744 private:
743 friend class base::RefCountedThreadSafe<PersistentCookieStore>; 745 friend class base::RefCountedThreadSafe<PersistentCookieStore>;
744 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); 746 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
745 }; 747 };
746 748
747 } // namespace net 749 } // namespace net
748 750
749 #endif // NET_COOKIES_COOKIE_MONSTER_H_ 751 #endif // NET_COOKIES_COOKIE_MONSTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698