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

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

Issue 8533013: SessionRestore: Store session cookies and restore them if chrome crashes or auto-restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_BASE_COOKIE_MONSTER_H_ 7 #ifndef NET_BASE_COOKIE_MONSTER_H_
8 #define NET_BASE_COOKIE_MONSTER_H_ 8 #define NET_BASE_COOKIE_MONSTER_H_
9 #pragma once 9 #pragma once
10 10
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 const CookieOptions& options, 268 const CookieOptions& options,
269 const GetCookieInfoCallback& callback) OVERRIDE; 269 const GetCookieInfoCallback& callback) OVERRIDE;
270 270
271 // Deletes all cookies with that might apply to |url| that has |cookie_name|. 271 // Deletes all cookies with that might apply to |url| that has |cookie_name|.
272 virtual void DeleteCookieAsync( 272 virtual void DeleteCookieAsync(
273 const GURL& url, const std::string& cookie_name, 273 const GURL& url, const std::string& cookie_name,
274 const base::Closure& callback) OVERRIDE; 274 const base::Closure& callback) OVERRIDE;
275 275
276 virtual CookieMonster* GetCookieMonster() OVERRIDE; 276 virtual CookieMonster* GetCookieMonster() OVERRIDE;
277 277
278 // Enables writing session cookies into the cookie database.
279 void SetSyncSessionCookies(bool sync_session_cookies);
jochen (gone - plz use gerrit) 2011/11/25 14:45:14 I would use a different verb, as "sync" implies it
marja 2011/11/28 15:22:01 I was using sync because CookieMonster already use
280
281 // Protects session cookies from deletion on shutdown.
282 void SaveSessionCookies();
283
284 // Merges restored session cookies with other cookies.
285 void RestoreOldSessionCookies();
286
287 // Discards restored session cookies.
288 void DiscardOldSessionCookies();
289
278 // Debugging method to perform various validation checks on the map. 290 // Debugging method to perform various validation checks on the map.
279 // Currently just checking that there are no null CanonicalCookie pointers 291 // Currently just checking that there are no null CanonicalCookie pointers
280 // in the map. 292 // in the map.
281 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs 293 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs
282 // in the function trip. TODO(rdsmith):Remove hack. 294 // in the function trip. TODO(rdsmith):Remove hack.
283 void ValidateMap(int arg); 295 void ValidateMap(int arg);
284 296
285 // The default list of schemes the cookie monster can handle. 297 // The default list of schemes the cookie monster can handle.
286 static const char* kDefaultCookieableSchemes[]; 298 static const char* kDefaultCookieableSchemes[];
287 static const int kDefaultCookieableSchemesCount; 299 static const int kDefaultCookieableSchemesCount;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 357
346 // Cookies evicted during domain level garbage collection that 358 // Cookies evicted during domain level garbage collection that
347 // were accessed more recently than kSafeFromGlobalPurgeDays 359 // were accessed more recently than kSafeFromGlobalPurgeDays
348 // (and thus would have been preserved by global garbage collection). 360 // (and thus would have been preserved by global garbage collection).
349 DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE, 361 DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE,
350 362
351 // A common idiom is to remove a cookie by overwriting it with an 363 // A common idiom is to remove a cookie by overwriting it with an
352 // already-expired expiration date. This captures that case. 364 // already-expired expiration date. This captures that case.
353 DELETE_COOKIE_EXPIRED_OVERWRITE, 365 DELETE_COOKIE_EXPIRED_OVERWRITE,
354 366
367 // Old session cookies can be explicitly deleted, and they also get
368 // automatically deleted when trying to read / write them.
369 DELETE_COOKIE_OLD_SESSION_COOKIE,
370
355 DELETE_COOKIE_LAST_ENTRY 371 DELETE_COOKIE_LAST_ENTRY
356 }; 372 };
357 373
358 // Cookie garbage collection thresholds. Based off of the Mozilla defaults. 374 // Cookie garbage collection thresholds. Based off of the Mozilla defaults.
359 // When the number of cookies gets to k{Domain,}MaxCookies 375 // When the number of cookies gets to k{Domain,}MaxCookies
360 // purge down to k{Domain,}MaxCookies - k{Domain,}PurgeCookies. 376 // purge down to k{Domain,}MaxCookies - k{Domain,}PurgeCookies.
361 // It might seem scary to have a high purge value, but really it's not. 377 // It might seem scary to have a high purge value, but really it's not.
362 // You just make sure that you increase the max to cover the increase 378 // You just make sure that you increase the max to cover the increase
363 // in purge, and we would have been purging the same amount of cookies. 379 // in purge, and we would have been purging the same amount of cookies.
364 // We're just going through the garbage collection process less often. 380 // We're just going through the garbage collection process less often.
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 std::vector<std::string> cookieable_schemes_; 682 std::vector<std::string> cookieable_schemes_;
667 683
668 scoped_refptr<Delegate> delegate_; 684 scoped_refptr<Delegate> delegate_;
669 685
670 // Lock for thread-safety 686 // Lock for thread-safety
671 base::Lock lock_; 687 base::Lock lock_;
672 688
673 base::Time last_statistic_record_time_; 689 base::Time last_statistic_record_time_;
674 690
675 bool keep_expired_cookies_; 691 bool keep_expired_cookies_;
692 bool keep_old_session_cookies_;
693 bool sync_session_cookies_;
676 694
677 static bool enable_file_scheme_; 695 static bool enable_file_scheme_;
678 696
679 DISALLOW_COPY_AND_ASSIGN(CookieMonster); 697 DISALLOW_COPY_AND_ASSIGN(CookieMonster);
680 }; 698 };
681 699
682 class NET_EXPORT CookieMonster::CanonicalCookie { 700 class NET_EXPORT CookieMonster::CanonicalCookie {
683 public: 701 public:
684 702
685 // These constructors do no validation or canonicalization of their inputs; 703 // These constructors do no validation or canonicalization of their inputs;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 bool IsSecure() const { return secure_; } 766 bool IsSecure() const { return secure_; }
749 bool IsHttpOnly() const { return httponly_; } 767 bool IsHttpOnly() const { return httponly_; }
750 bool IsDomainCookie() const { 768 bool IsDomainCookie() const {
751 return !domain_.empty() && domain_[0] == '.'; } 769 return !domain_.empty() && domain_[0] == '.'; }
752 bool IsHostCookie() const { return !IsDomainCookie(); } 770 bool IsHostCookie() const { return !IsDomainCookie(); }
753 771
754 bool IsExpired(const base::Time& current) { 772 bool IsExpired(const base::Time& current) {
755 return has_expires_ && current >= expiry_date_; 773 return has_expires_ && current >= expiry_date_;
756 } 774 }
757 775
776 bool IsOldSessionCookie() const {
777 return is_old_session_cookie_;
778 }
779
780 void SetIsOldSessionCookie(bool is_old_session_cookie) {
781 is_old_session_cookie_ = is_old_session_cookie;
782 }
783
758 // Are the cookies considered equivalent in the eyes of RFC 2965. 784 // Are the cookies considered equivalent in the eyes of RFC 2965.
759 // The RFC says that name must match (case-sensitive), domain must 785 // The RFC says that name must match (case-sensitive), domain must
760 // match (case insensitive), and path must match (case sensitive). 786 // match (case insensitive), and path must match (case sensitive).
761 // For the case insensitive domain compare, we rely on the domain 787 // For the case insensitive domain compare, we rely on the domain
762 // having been canonicalized (in 788 // having been canonicalized (in
763 // GetCookieDomainWithString->CanonicalizeHost). 789 // GetCookieDomainWithString->CanonicalizeHost).
764 bool IsEquivalent(const CanonicalCookie& ecc) const { 790 bool IsEquivalent(const CanonicalCookie& ecc) const {
765 // It seems like it would make sense to take secure and httponly into 791 // It seems like it would make sense to take secure and httponly into
766 // account, but the RFC doesn't specify this. 792 // account, but the RFC doesn't specify this.
767 // NOTE: Keep this logic in-sync with TrimDuplicateCookiesForHost(). 793 // NOTE: Keep this logic in-sync with TrimDuplicateCookiesForHost().
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 std::string path_; 828 std::string path_;
803 std::string mac_key_; // TODO(abarth): Persist to disk. 829 std::string mac_key_; // TODO(abarth): Persist to disk.
804 std::string mac_algorithm_; // TODO(abarth): Persist to disk. 830 std::string mac_algorithm_; // TODO(abarth): Persist to disk.
805 base::Time creation_date_; 831 base::Time creation_date_;
806 base::Time expiry_date_; 832 base::Time expiry_date_;
807 base::Time last_access_date_; 833 base::Time last_access_date_;
808 bool secure_; 834 bool secure_;
809 bool httponly_; 835 bool httponly_;
810 bool has_expires_; 836 bool has_expires_;
811 bool is_persistent_; 837 bool is_persistent_;
838 bool is_old_session_cookie_;
812 }; 839 };
813 840
814 class CookieMonster::Delegate 841 class CookieMonster::Delegate
815 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { 842 : public base::RefCountedThreadSafe<CookieMonster::Delegate> {
816 public: 843 public:
817 // The publicly relevant reasons a cookie might be changed. 844 // The publicly relevant reasons a cookie might be changed.
818 enum ChangeCause { 845 enum ChangeCause {
819 // The cookie was changed directly by a consumer's action. 846 // The cookie was changed directly by a consumer's action.
820 CHANGE_COOKIE_EXPLICIT, 847 CHANGE_COOKIE_EXPLICIT,
821 // The cookie was automatically removed due to an insert operation that 848 // The cookie was automatically removed due to an insert operation that
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 const LoadedCallback& loaded_callback) = 0; 1001 const LoadedCallback& loaded_callback) = 0;
975 1002
976 virtual void AddCookie(const CanonicalCookie& cc) = 0; 1003 virtual void AddCookie(const CanonicalCookie& cc) = 0;
977 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; 1004 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0;
978 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; 1005 virtual void DeleteCookie(const CanonicalCookie& cc) = 0;
979 1006
980 // Sets the value of the user preference whether the persistent storage 1007 // Sets the value of the user preference whether the persistent storage
981 // must be deleted upon destruction. 1008 // must be deleted upon destruction.
982 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; 1009 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0;
983 1010
1011 // Sets the value of the user preference whether the session cookies must
1012 // must be deleted upon destruction.
1013 virtual void SetClearSessionStateOnExit(bool clear_session_cookies) = 0;
1014
984 // Flush the store and post the given Task when complete. 1015 // Flush the store and post the given Task when complete.
985 virtual void Flush(Task* completion_task) = 0; 1016 virtual void Flush(Task* completion_task) = 0;
986 1017
987 protected: 1018 protected:
988 PersistentCookieStore() {} 1019 PersistentCookieStore() {}
989 1020
990 private: 1021 private:
991 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); 1022 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
992 }; 1023 };
993 1024
994 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { 1025 class CookieList : public std::vector<CookieMonster::CanonicalCookie> {
995 }; 1026 };
996 1027
997 } // namespace net 1028 } // namespace net
998 1029
999 #endif // NET_BASE_COOKIE_MONSTER_H_ 1030 #endif // NET_BASE_COOKIE_MONSTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698