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

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: compile gdi. 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void HasCookiesForETLDP1Async(const std::string& etldp1, 210 void HasCookiesForETLDP1Async(const std::string& etldp1,
210 const HasCookiesForETLDP1Callback& callback); 211 const HasCookiesForETLDP1Callback& callback);
211 212
212 // Resets the list of cookieable schemes to the supplied schemes. 213 // Resets the list of cookieable schemes to the supplied schemes.
213 // If this this method is called, it must be called before first use of 214 // If this this method is called, it must be called before first use of
214 // the instance (i.e. as part of the instance initialization process). 215 // the instance (i.e. as part of the instance initialization process).
215 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); 216 void SetCookieableSchemes(const char* schemes[], size_t num_schemes);
216 217
217 // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or 218 // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or
218 // without 'file' being included. 219 // without 'file' being included.
220 //
221 // There are some unknowns about how to correctly handle file:// cookies,
222 // and our implementation for this is not robust enough. This allows you
223 // to enable support, but it should only be used for testing. Bug 1157243.
219 void SetEnableFileScheme(bool accept); 224 void SetEnableFileScheme(bool accept);
220 225
221 // Instructs the cookie monster to not delete expired cookies. This is used 226 // Instructs the cookie monster to not delete expired cookies. This is used
222 // in cases where the cookie monster is used as a data structure to keep 227 // in cases where the cookie monster is used as a data structure to keep
223 // arbitrary cookies. 228 // arbitrary cookies.
224 void SetKeepExpiredCookies(); 229 void SetKeepExpiredCookies();
225 230
226 // Protects session cookies from deletion on shutdown. 231 // Protects session cookies from deletion on shutdown.
227 void SetForceKeepSessionState(); 232 void SetForceKeepSessionState();
228 233
229 // There are some unknowns about how to correctly handle file:// cookies,
230 // and our implementation for this is not robust enough. This allows you
231 // to enable support, but it should only be used for testing. Bug 1157243.
232 // Must be called before creating a CookieMonster instance.
233 static void EnableFileScheme();
234
235 // Flush the backing store (if any) to disk and post the given callback when 234 // Flush the backing store (if any) to disk and post the given callback when
236 // done. 235 // done.
237 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. 236 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE.
238 // It may be posted to the current thread, or it may run on the thread that 237 // It may be posted to the current thread, or it may run on the thread that
239 // actually does the flushing. Your Task should generally post a notification 238 // actually does the flushing. Your Task should generally post a notification
240 // to the thread you actually want to be notified on. 239 // to the thread you actually want to be notified on.
241 void FlushStore(const base::Closure& callback); 240 void FlushStore(const base::Closure& callback);
242 241
243 // CookieStore implementation. 242 // CookieStore implementation.
244 243
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey); 332 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey);
334 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey); 333 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey);
335 334
336 // For FindCookiesForKey. 335 // For FindCookiesForKey.
337 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies); 336 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies);
338 337
339 // Internal reasons for deletion, used to populate informative histograms 338 // Internal reasons for deletion, used to populate informative histograms
340 // and to provide a public cause for onCookieChange notifications. 339 // and to provide a public cause for onCookieChange notifications.
341 // 340 //
342 // If you add or remove causes from this list, please be sure to also update 341 // If you add or remove causes from this list, please be sure to also update
343 // the Delegate::ChangeCause mapping inside ChangeCauseMapping. Moreover, 342 // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping.
344 // these are used as array indexes, so avoid reordering to keep the 343 // Moreover, these are used as array indexes, so avoid reordering to keep the
345 // histogram buckets consistent. New items (if necessary) should be added 344 // histogram buckets consistent. New items (if necessary) should be added
346 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. 345 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY.
347 enum DeletionCause { 346 enum DeletionCause {
348 DELETE_COOKIE_EXPLICIT = 0, 347 DELETE_COOKIE_EXPLICIT = 0,
349 DELETE_COOKIE_OVERWRITE, 348 DELETE_COOKIE_OVERWRITE,
350 DELETE_COOKIE_EXPIRED, 349 DELETE_COOKIE_EXPIRED,
351 DELETE_COOKIE_EVICTED, 350 DELETE_COOKIE_EVICTED,
352 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE, 351 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE,
353 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store. 352 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store.
354 DELETE_COOKIE_EVICTED_DOMAIN, 353 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 517 // Helper function that sets a canonical cookie, deleting equivalents and
519 // performing garbage collection. 518 // performing garbage collection.
520 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, 519 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
521 const base::Time& creation_time, 520 const base::Time& creation_time,
522 const CookieOptions& options); 521 const CookieOptions& options);
523 522
524 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, 523 void InternalUpdateCookieAccessTime(CanonicalCookie* cc,
525 const base::Time& current_time); 524 const base::Time& current_time);
526 525
527 // |deletion_cause| argument is used for collecting statistics and choosing 526 // |deletion_cause| argument is used for collecting statistics and choosing
528 // the correct Delegate::ChangeCause for OnCookieChanged notifications. 527 // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged
528 // notifications.
529 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store, 529 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store,
530 DeletionCause deletion_cause); 530 DeletionCause deletion_cause);
531 531
532 // If the number of cookies for CookieMap key |key|, or globally, are 532 // 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 533 // over the preset maximums above, garbage collect, first for the host and
534 // then globally. See comments above garbage collection threshold 534 // then globally. See comments above garbage collection threshold
535 // constants for details. 535 // constants for details.
536 // 536 //
537 // Returns the number of cookies deleted (useful for debugging). 537 // Returns the number of cookies deleted (useful for debugging).
538 int GarbageCollect(const base::Time& current, const std::string& key); 538 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_; 640 base::Time earliest_access_time_;
641 641
642 // During loading, holds the set of all loaded cookie creation times. Used to 642 // 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; 643 // 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 644 // that way we don't have to worry about what sections of code are safe
645 // to call while it's in that state. 645 // to call while it's in that state.
646 std::set<int64> creation_times_; 646 std::set<int64> creation_times_;
647 647
648 std::vector<std::string> cookieable_schemes_; 648 std::vector<std::string> cookieable_schemes_;
649 649
650 scoped_refptr<Delegate> delegate_; 650 scoped_refptr<CookieMonsterDelegate> delegate_;
651 651
652 // Lock for thread-safety 652 // Lock for thread-safety
653 base::Lock lock_; 653 base::Lock lock_;
654 654
655 base::Time last_statistic_record_time_; 655 base::Time last_statistic_record_time_;
656 656
657 bool keep_expired_cookies_; 657 bool keep_expired_cookies_;
658 bool persist_session_cookies_; 658 bool persist_session_cookies_;
659 bool priority_aware_garbage_collection_; 659 bool priority_aware_garbage_collection_;
660 660
661 // Static setting for whether or not file scheme cookies are allows when 661 // 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 662 // a new CookieMonster is created, or the accepted schemes on a CookieMonster
663 // instance are reset back to defaults. 663 // instance are reset back to defaults.
664 static bool default_enable_file_scheme_; 664 static bool default_enable_file_scheme_;
665 665
666 DISALLOW_COPY_AND_ASSIGN(CookieMonster); 666 DISALLOW_COPY_AND_ASSIGN(CookieMonster);
667 }; 667 };
668 668
669 class NET_EXPORT CookieMonster::Delegate 669 class NET_EXPORT CookieMonsterDelegate
670 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { 670 : public base::RefCountedThreadSafe<CookieMonsterDelegate> {
671 public: 671 public:
672 // The publicly relevant reasons a cookie might be changed. 672 // The publicly relevant reasons a cookie might be changed.
673 enum ChangeCause { 673 enum ChangeCause {
674 // The cookie was changed directly by a consumer's action. 674 // The cookie was changed directly by a consumer's action.
675 CHANGE_COOKIE_EXPLICIT, 675 CHANGE_COOKIE_EXPLICIT,
676 // The cookie was automatically removed due to an insert operation that 676 // The cookie was automatically removed due to an insert operation that
677 // overwrote it. 677 // overwrote it.
678 CHANGE_COOKIE_OVERWRITE, 678 CHANGE_COOKIE_OVERWRITE,
679 // The cookie was automatically removed as it expired. 679 // The cookie was automatically removed as it expired.
680 CHANGE_COOKIE_EXPIRED, 680 CHANGE_COOKIE_EXPIRED,
(...skipping 11 matching lines...) Expand all
692 // 692 //
693 // As a special case, note that updating a cookie's properties is implemented 693 // 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, 694 // as a two step process: the cookie to be updated is first removed entirely,
695 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards, 695 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards,
696 // a new cookie is written with the updated values, generating a notification 696 // a new cookie is written with the updated values, generating a notification
697 // with cause CHANGE_COOKIE_EXPLICIT. 697 // with cause CHANGE_COOKIE_EXPLICIT.
698 virtual void OnCookieChanged(const CanonicalCookie& cookie, 698 virtual void OnCookieChanged(const CanonicalCookie& cookie,
699 bool removed, 699 bool removed,
700 ChangeCause cause) = 0; 700 ChangeCause cause) = 0;
701 protected: 701 protected:
702 friend class base::RefCountedThreadSafe<CookieMonster::Delegate>; 702 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>;
703 virtual ~Delegate() {} 703 virtual ~CookieMonsterDelegate() {}
704 }; 704 };
705 705
706 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> 706 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore>
707 RefcountedPersistentCookieStore; 707 RefcountedPersistentCookieStore;
708 708
709 class NET_EXPORT CookieMonster::PersistentCookieStore 709 class NET_EXPORT CookieMonster::PersistentCookieStore
710 : public RefcountedPersistentCookieStore { 710 : public RefcountedPersistentCookieStore {
711 public: 711 public:
712 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)> 712 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)>
713 LoadedCallback; 713 LoadedCallback;
(...skipping 26 matching lines...) Expand all
740 virtual ~PersistentCookieStore() {} 740 virtual ~PersistentCookieStore() {}
741 741
742 private: 742 private:
743 friend class base::RefCountedThreadSafe<PersistentCookieStore>; 743 friend class base::RefCountedThreadSafe<PersistentCookieStore>;
744 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); 744 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
745 }; 745 };
746 746
747 } // namespace net 747 } // namespace net
748 748
749 #endif // NET_COOKIES_COOKIE_MONSTER_H_ 749 #endif // NET_COOKIES_COOKIE_MONSTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698