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

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: android webview init fix merged in. 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
« no previous file with comments | « content/test/test_content_browser_client.cc ('k') | net/cookies/cookie_monster.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void HasCookiesForETLDP1Async(const std::string& etldp1, 218 void HasCookiesForETLDP1Async(const std::string& etldp1,
218 const HasCookiesForETLDP1Callback& callback); 219 const HasCookiesForETLDP1Callback& callback);
219 220
220 // Resets the list of cookieable schemes to the supplied schemes. 221 // Resets the list of cookieable schemes to the supplied schemes.
221 // If this this method is called, it must be called before first use of 222 // If this this method is called, it must be called before first use of
222 // the instance (i.e. as part of the instance initialization process). 223 // the instance (i.e. as part of the instance initialization process).
223 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); 224 void SetCookieableSchemes(const char* schemes[], size_t num_schemes);
224 225
225 // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or 226 // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or
226 // without 'file' being included. 227 // 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.
227 void SetEnableFileScheme(bool accept); 232 void SetEnableFileScheme(bool accept);
228 233
229 // Instructs the cookie monster to not delete expired cookies. This is used 234 // Instructs the cookie monster to not delete expired cookies. This is used
230 // in cases where the cookie monster is used as a data structure to keep 235 // in cases where the cookie monster is used as a data structure to keep
231 // arbitrary cookies. 236 // arbitrary cookies.
232 void SetKeepExpiredCookies(); 237 void SetKeepExpiredCookies();
233 238
234 // Protects session cookies from deletion on shutdown. 239 // Protects session cookies from deletion on shutdown.
235 void SetForceKeepSessionState(); 240 void SetForceKeepSessionState();
236 241
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
243 // Flush the backing store (if any) to disk and post the given callback when 242 // Flush the backing store (if any) to disk and post the given callback when
244 // done. 243 // done.
245 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. 244 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE.
246 // It may be posted to the current thread, or it may run on the thread that 245 // It may be posted to the current thread, or it may run on the thread that
247 // actually does the flushing. Your Task should generally post a notification 246 // actually does the flushing. Your Task should generally post a notification
248 // to the thread you actually want to be notified on. 247 // to the thread you actually want to be notified on.
249 void FlushStore(const base::Closure& callback); 248 void FlushStore(const base::Closure& callback);
250 249
251 // CookieStore implementation. 250 // CookieStore implementation.
252 251
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey); 344 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey);
346 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey); 345 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey);
347 346
348 // For FindCookiesForKey. 347 // For FindCookiesForKey.
349 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies); 348 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies);
350 349
351 // Internal reasons for deletion, used to populate informative histograms 350 // Internal reasons for deletion, used to populate informative histograms
352 // and to provide a public cause for onCookieChange notifications. 351 // and to provide a public cause for onCookieChange notifications.
353 // 352 //
354 // If you add or remove causes from this list, please be sure to also update 353 // If you add or remove causes from this list, please be sure to also update
355 // the Delegate::ChangeCause mapping inside ChangeCauseMapping. Moreover, 354 // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping.
356 // these are used as array indexes, so avoid reordering to keep the 355 // Moreover, these are used as array indexes, so avoid reordering to keep the
357 // histogram buckets consistent. New items (if necessary) should be added 356 // histogram buckets consistent. New items (if necessary) should be added
358 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. 357 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY.
359 enum DeletionCause { 358 enum DeletionCause {
360 DELETE_COOKIE_EXPLICIT = 0, 359 DELETE_COOKIE_EXPLICIT = 0,
361 DELETE_COOKIE_OVERWRITE, 360 DELETE_COOKIE_OVERWRITE,
362 DELETE_COOKIE_EXPIRED, 361 DELETE_COOKIE_EXPIRED,
363 DELETE_COOKIE_EVICTED, 362 DELETE_COOKIE_EVICTED,
364 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE, 363 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE,
365 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store. 364 DELETE_COOKIE_DONT_RECORD, // e.g. For final cleanup after flush to store.
366 DELETE_COOKIE_EVICTED_DOMAIN, 365 DELETE_COOKIE_EVICTED_DOMAIN,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // Helper function that sets a canonical cookie, deleting equivalents and 532 // Helper function that sets a canonical cookie, deleting equivalents and
534 // performing garbage collection. 533 // performing garbage collection.
535 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, 534 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
536 const base::Time& creation_time, 535 const base::Time& creation_time,
537 const CookieOptions& options); 536 const CookieOptions& options);
538 537
539 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, 538 void InternalUpdateCookieAccessTime(CanonicalCookie* cc,
540 const base::Time& current_time); 539 const base::Time& current_time);
541 540
542 // |deletion_cause| argument is used for collecting statistics and choosing 541 // |deletion_cause| argument is used for collecting statistics and choosing
543 // the correct Delegate::ChangeCause for OnCookieChanged notifications. 542 // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged
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<Delegate> delegate_; 665 scoped_refptr<CookieMonsterDelegate> 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 CookieMonster::Delegate 684 class NET_EXPORT CookieMonsterDelegate
685 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { 685 : public base::RefCountedThreadSafe<CookieMonsterDelegate> {
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<CookieMonster::Delegate>; 717 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>;
718 virtual ~Delegate() {} 718 virtual ~CookieMonsterDelegate() {}
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 | « content/test/test_content_browser_client.cc ('k') | net/cookies/cookie_monster.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698