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

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

Issue 23551005: Revert 219709 "Remove the Extensions URLRequestContext." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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;
41 class ParsedCookie; 40 class ParsedCookie;
42 41
43 // The cookie monster is the system for storing and retrieving cookies. It has 42 // The cookie monster is the system for storing and retrieving cookies. It has
44 // an in-memory list of all cookies, and synchronizes non-session cookies to an 43 // an in-memory list of all cookies, and synchronizes non-session cookies to an
45 // optional permanent storage that implements the PersistentCookieStore 44 // optional permanent storage that implements the PersistentCookieStore
46 // interface. 45 // interface.
47 // 46 //
48 // This class IS thread-safe. Normally, it is only used on the I/O thread, but 47 // This class IS thread-safe. Normally, it is only used on the I/O thread, but
49 // is also accessed directly through Automation for UI testing. 48 // is also accessed directly through Automation for UI testing.
50 // 49 //
51 // All cookie tasks are handled asynchronously. Tasks may be deferred if 50 // All cookie tasks are handled asynchronously. Tasks may be deferred if
52 // all affected cookies are not yet loaded from the backing store. Otherwise, 51 // all affected cookies are not yet loaded from the backing store. Otherwise,
53 // the callback may be invoked immediately (prior to return of the asynchronous 52 // the callback may be invoked immediately (prior to return of the asynchronous
54 // function). 53 // function).
55 // 54 //
56 // A cookie task is either pending loading of the entire cookie store, or 55 // A cookie task is either pending loading of the entire cookie store, or
57 // loading of cookies for a specfic domain key(eTLD+1). In the former case, the 56 // loading of cookies for a specfic domain key(eTLD+1). In the former case, the
58 // cookie task will be queued in tasks_pending_ while PersistentCookieStore 57 // cookie task will be queued in tasks_pending_ while PersistentCookieStore
59 // chain loads the cookie store on DB thread. In the latter case, the cookie 58 // chain loads the cookie store on DB thread. In the latter case, the cookie
60 // task will be queued in tasks_pending_for_key_ while PermanentCookieStore 59 // task will be queued in tasks_pending_for_key_ while PermanentCookieStore
61 // loads cookies for the specified domain key(eTLD+1) on DB thread. 60 // loads cookies for the specified domain key(eTLD+1) on DB thread.
62 // 61 //
63 // Callbacks are guaranteed to be invoked on the calling thread. 62 // Callbacks are guaranteed to be invoked on the calling thread.
64 // 63 //
65 // TODO(deanm) Implement CookieMonster, the cookie database. 64 // TODO(deanm) Implement CookieMonster, the cookie database.
66 // - Verify that our domain enforcement and non-dotted handling is correct 65 // - Verify that our domain enforcement and non-dotted handling is correct
67 class NET_EXPORT CookieMonster : public CookieStore { 66 class NET_EXPORT CookieMonster : public CookieStore {
68 public: 67 public:
68 class Delegate;
69 class PersistentCookieStore; 69 class PersistentCookieStore;
70 typedef CookieMonsterDelegate Delegate;
71 70
72 // Terminology: 71 // Terminology:
73 // * The 'top level domain' (TLD) of an internet domain name is 72 // * The 'top level domain' (TLD) of an internet domain name is
74 // the terminal "." free substring (e.g. "com" for google.com 73 // the terminal "." free substring (e.g. "com" for google.com
75 // or world.std.com). 74 // or world.std.com).
76 // * The 'effective top level domain' (eTLD) is the longest 75 // * The 'effective top level domain' (eTLD) is the longest
77 // "." initiated terminal substring of an internet domain name 76 // "." initiated terminal substring of an internet domain name
78 // that is controlled by a general domain registrar. 77 // that is controlled by a general domain registrar.
79 // (e.g. "co.uk" for news.bbc.co.uk). 78 // (e.g. "co.uk" for news.bbc.co.uk).
80 // * The 'effective top level domain plus one' (eTLD+1) is the 79 // * The 'effective top level domain plus one' (eTLD+1) is the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 static const size_t kDomainCookiesQuotaLow; 131 static const size_t kDomainCookiesQuotaLow;
133 static const size_t kDomainCookiesQuotaMedium; 132 static const size_t kDomainCookiesQuotaMedium;
134 static const size_t kDomainCookiesQuotaHigh; 133 static const size_t kDomainCookiesQuotaHigh;
135 134
136 // The store passed in should not have had Init() called on it yet. This 135 // The store passed in should not have had Init() called on it yet. This
137 // class will take care of initializing it. The backing store is NOT owned by 136 // class will take care of initializing it. The backing store is NOT owned by
138 // this class, but it must remain valid for the duration of the cookie 137 // this class, but it must remain valid for the duration of the cookie
139 // monster's existence. If |store| is NULL, then no backing store will be 138 // monster's existence. If |store| is NULL, then no backing store will be
140 // updated. If |delegate| is non-NULL, it will be notified on 139 // updated. If |delegate| is non-NULL, it will be notified on
141 // creation/deletion of cookies. 140 // creation/deletion of cookies.
142 CookieMonster(PersistentCookieStore* store, CookieMonsterDelegate* delegate); 141 CookieMonster(PersistentCookieStore* store, Delegate* delegate);
143 142
144 // Only used during unit testing. 143 // Only used during unit testing.
145 CookieMonster(PersistentCookieStore* store, 144 CookieMonster(PersistentCookieStore* store,
146 CookieMonsterDelegate* delegate, 145 Delegate* delegate,
147 int last_access_threshold_milliseconds); 146 int last_access_threshold_milliseconds);
148 147
149 // Helper function that adds all cookies from |list| into this instance. 148 // Helper function that adds all cookies from |list| into this instance.
150 bool InitializeFrom(const CookieList& list); 149 bool InitializeFrom(const CookieList& list);
151 150
152 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; 151 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback;
153 typedef base::Callback<void(bool success)> DeleteCookieCallback; 152 typedef base::Callback<void(bool success)> DeleteCookieCallback;
154 typedef base::Callback<void(bool cookies_exist)> HasCookiesForETLDP1Callback; 153 typedef base::Callback<void(bool cookies_exist)> HasCookiesForETLDP1Callback;
155 154
156 // Sets a cookie given explicit user-provided cookie attributes. The cookie 155 // Sets a cookie given explicit user-provided cookie attributes. The cookie
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 void HasCookiesForETLDP1Async(const std::string& etldp1, 217 void HasCookiesForETLDP1Async(const std::string& etldp1,
219 const HasCookiesForETLDP1Callback& callback); 218 const HasCookiesForETLDP1Callback& callback);
220 219
221 // Resets the list of cookieable schemes to the supplied schemes. 220 // Resets the list of cookieable schemes to the supplied schemes.
222 // If this this method is called, it must be called before first use of 221 // If this this method is called, it must be called before first use of
223 // the instance (i.e. as part of the instance initialization process). 222 // the instance (i.e. as part of the instance initialization process).
224 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); 223 void SetCookieableSchemes(const char* schemes[], size_t num_schemes);
225 224
226 // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or 225 // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or
227 // without 'file' being included. 226 // without 'file' being included.
228 //
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 void SetEnableFileScheme(bool accept); 227 void SetEnableFileScheme(bool accept);
233 228
234 // Instructs the cookie monster to not delete expired cookies. This is used 229 // Instructs the cookie monster to not delete expired cookies. This is used
235 // in cases where the cookie monster is used as a data structure to keep 230 // in cases where the cookie monster is used as a data structure to keep
236 // arbitrary cookies. 231 // arbitrary cookies.
237 void SetKeepExpiredCookies(); 232 void SetKeepExpiredCookies();
238 233
239 // Protects session cookies from deletion on shutdown. 234 // Protects session cookies from deletion on shutdown.
240 void SetForceKeepSessionState(); 235 void SetForceKeepSessionState();
241 236
237 // There are some unknowns about how to correctly handle file:// cookies,
238 // and our implementation for this is not robust enough. This allows you
239 // to enable support, but it should only be used for testing. Bug 1157243.
240 // Must be called before creating a CookieMonster instance.
241 static void EnableFileScheme();
242
242 // Flush the backing store (if any) to disk and post the given callback when 243 // Flush the backing store (if any) to disk and post the given callback when
243 // done. 244 // done.
244 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. 245 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE.
245 // It may be posted to the current thread, or it may run on the thread that 246 // It may be posted to the current thread, or it may run on the thread that
246 // actually does the flushing. Your Task should generally post a notification 247 // actually does the flushing. Your Task should generally post a notification
247 // to the thread you actually want to be notified on. 248 // to the thread you actually want to be notified on.
248 void FlushStore(const base::Closure& callback); 249 void FlushStore(const base::Closure& callback);
249 250
250 // CookieStore implementation. 251 // CookieStore implementation.
251 252
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey); 345 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey);
345 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey); 346 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey);
346 347
347 // For FindCookiesForKey. 348 // For FindCookiesForKey.
348 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies); 349 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies);
349 350
350 // Internal reasons for deletion, used to populate informative histograms 351 // Internal reasons for deletion, used to populate informative histograms
351 // and to provide a public cause for onCookieChange notifications. 352 // and to provide a public cause for onCookieChange notifications.
352 // 353 //
353 // If you add or remove causes from this list, please be sure to also update 354 // If you add or remove causes from this list, please be sure to also update
354 // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping. 355 // the Delegate::ChangeCause mapping inside ChangeCauseMapping. Moreover,
355 // Moreover, these are used as array indexes, so avoid reordering to keep the 356 // these are used as array indexes, so avoid reordering to keep the
356 // histogram buckets consistent. New items (if necessary) should be added 357 // histogram buckets consistent. New items (if necessary) should be added
357 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. 358 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY.
358 enum DeletionCause { 359 enum DeletionCause {
359 DELETE_COOKIE_EXPLICIT = 0, 360 DELETE_COOKIE_EXPLICIT = 0,
360 DELETE_COOKIE_OVERWRITE, 361 DELETE_COOKIE_OVERWRITE,
361 DELETE_COOKIE_EXPIRED, 362 DELETE_COOKIE_EXPIRED,
362 DELETE_COOKIE_EVICTED, 363 DELETE_COOKIE_EVICTED,
363 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE, 364 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE,
364 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store. 365 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store.
365 DELETE_COOKIE_EVICTED_DOMAIN, 366 DELETE_COOKIE_EVICTED_DOMAIN,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // Helper function that sets a canonical cookie, deleting equivalents and 533 // Helper function that sets a canonical cookie, deleting equivalents and
533 // performing garbage collection. 534 // performing garbage collection.
534 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, 535 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
535 const base::Time& creation_time, 536 const base::Time& creation_time,
536 const CookieOptions& options); 537 const CookieOptions& options);
537 538
538 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, 539 void InternalUpdateCookieAccessTime(CanonicalCookie* cc,
539 const base::Time& current_time); 540 const base::Time& current_time);
540 541
541 // |deletion_cause| argument is used for collecting statistics and choosing 542 // |deletion_cause| argument is used for collecting statistics and choosing
542 // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged 543 // the correct Delegate::ChangeCause for OnCookieChanged notifications.
543 // notifications.
544 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store, 544 void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store,
545 DeletionCause deletion_cause); 545 DeletionCause deletion_cause);
546 546
547 // If the number of cookies for CookieMap key |key|, or globally, are 547 // If the number of cookies for CookieMap key |key|, or globally, are
548 // over the preset maximums above, garbage collect, first for the host and 548 // over the preset maximums above, garbage collect, first for the host and
549 // then globally. See comments above garbage collection threshold 549 // then globally. See comments above garbage collection threshold
550 // constants for details. 550 // constants for details.
551 // 551 //
552 // Returns the number of cookies deleted (useful for debugging). 552 // Returns the number of cookies deleted (useful for debugging).
553 int GarbageCollect(const base::Time& current, const std::string& key); 553 int GarbageCollect(const base::Time& current, const std::string& key);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 base::Time earliest_access_time_; 655 base::Time earliest_access_time_;
656 656
657 // During loading, holds the set of all loaded cookie creation times. Used to 657 // During loading, holds the set of all loaded cookie creation times. Used to
658 // avoid ever letting cookies with duplicate creation times into the store; 658 // avoid ever letting cookies with duplicate creation times into the store;
659 // that way we don't have to worry about what sections of code are safe 659 // that way we don't have to worry about what sections of code are safe
660 // to call while it's in that state. 660 // to call while it's in that state.
661 std::set<int64> creation_times_; 661 std::set<int64> creation_times_;
662 662
663 std::vector<std::string> cookieable_schemes_; 663 std::vector<std::string> cookieable_schemes_;
664 664
665 scoped_refptr<CookieMonsterDelegate> delegate_; 665 scoped_refptr<Delegate> delegate_;
666 666
667 // Lock for thread-safety 667 // Lock for thread-safety
668 base::Lock lock_; 668 base::Lock lock_;
669 669
670 base::Time last_statistic_record_time_; 670 base::Time last_statistic_record_time_;
671 671
672 bool keep_expired_cookies_; 672 bool keep_expired_cookies_;
673 bool persist_session_cookies_; 673 bool persist_session_cookies_;
674 bool priority_aware_garbage_collection_; 674 bool priority_aware_garbage_collection_;
675 675
676 // Static setting for whether or not file scheme cookies are allows when 676 // Static setting for whether or not file scheme cookies are allows when
677 // a new CookieMonster is created, or the accepted schemes on a CookieMonster 677 // a new CookieMonster is created, or the accepted schemes on a CookieMonster
678 // instance are reset back to defaults. 678 // instance are reset back to defaults.
679 static bool default_enable_file_scheme_; 679 static bool default_enable_file_scheme_;
680 680
681 DISALLOW_COPY_AND_ASSIGN(CookieMonster); 681 DISALLOW_COPY_AND_ASSIGN(CookieMonster);
682 }; 682 };
683 683
684 class NET_EXPORT CookieMonsterDelegate 684 class NET_EXPORT CookieMonster::Delegate
685 : public base::RefCountedThreadSafe<CookieMonsterDelegate> { 685 : public base::RefCountedThreadSafe<CookieMonster::Delegate> {
686 public: 686 public:
687 // The publicly relevant reasons a cookie might be changed. 687 // The publicly relevant reasons a cookie might be changed.
688 enum ChangeCause { 688 enum ChangeCause {
689 // The cookie was changed directly by a consumer's action. 689 // The cookie was changed directly by a consumer's action.
690 CHANGE_COOKIE_EXPLICIT, 690 CHANGE_COOKIE_EXPLICIT,
691 // The cookie was automatically removed due to an insert operation that 691 // The cookie was automatically removed due to an insert operation that
692 // overwrote it. 692 // overwrote it.
693 CHANGE_COOKIE_OVERWRITE, 693 CHANGE_COOKIE_OVERWRITE,
694 // The cookie was automatically removed as it expired. 694 // The cookie was automatically removed as it expired.
695 CHANGE_COOKIE_EXPIRED, 695 CHANGE_COOKIE_EXPIRED,
(...skipping 11 matching lines...) Expand all
707 // 707 //
708 // As a special case, note that updating a cookie's properties is implemented 708 // As a special case, note that updating a cookie's properties is implemented
709 // as a two step process: the cookie to be updated is first removed entirely, 709 // as a two step process: the cookie to be updated is first removed entirely,
710 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards, 710 // generating a notification with cause CHANGE_COOKIE_OVERWRITE. Afterwards,
711 // a new cookie is written with the updated values, generating a notification 711 // a new cookie is written with the updated values, generating a notification
712 // with cause CHANGE_COOKIE_EXPLICIT. 712 // with cause CHANGE_COOKIE_EXPLICIT.
713 virtual void OnCookieChanged(const CanonicalCookie& cookie, 713 virtual void OnCookieChanged(const CanonicalCookie& cookie,
714 bool removed, 714 bool removed,
715 ChangeCause cause) = 0; 715 ChangeCause cause) = 0;
716 protected: 716 protected:
717 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>; 717 friend class base::RefCountedThreadSafe<CookieMonster::Delegate>;
718 virtual ~CookieMonsterDelegate() {} 718 virtual ~Delegate() {}
719 }; 719 };
720 720
721 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> 721 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore>
722 RefcountedPersistentCookieStore; 722 RefcountedPersistentCookieStore;
723 723
724 class NET_EXPORT CookieMonster::PersistentCookieStore 724 class NET_EXPORT CookieMonster::PersistentCookieStore
725 : public RefcountedPersistentCookieStore { 725 : public RefcountedPersistentCookieStore {
726 public: 726 public:
727 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)> 727 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)>
728 LoadedCallback; 728 LoadedCallback;
(...skipping 26 matching lines...) Expand all
755 virtual ~PersistentCookieStore() {} 755 virtual ~PersistentCookieStore() {}
756 756
757 private: 757 private:
758 friend class base::RefCountedThreadSafe<PersistentCookieStore>; 758 friend class base::RefCountedThreadSafe<PersistentCookieStore>;
759 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); 759 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
760 }; 760 };
761 761
762 } // namespace net 762 } // namespace net
763 763
764 #endif // NET_COOKIES_COOKIE_MONSTER_H_ 764 #endif // NET_COOKIES_COOKIE_MONSTER_H_
OLDNEW
« no previous file with comments | « trunk/src/content/test/test_content_browser_client.cc ('k') | trunk/src/net/cookies/cookie_monster.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698