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

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 SetPersistSessionCookies(bool persist_session_cookies);
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // the CookieMap typedef for details. 526 // the CookieMap typedef for details.
511 // NOTE: There should never be more than a single matching equivalent cookie. 527 // NOTE: There should never be more than a single matching equivalent cookie.
512 bool DeleteAnyEquivalentCookie(const std::string& key, 528 bool DeleteAnyEquivalentCookie(const std::string& key,
513 const CanonicalCookie& ecc, 529 const CanonicalCookie& ecc,
514 bool skip_httponly, 530 bool skip_httponly,
515 bool already_expired); 531 bool already_expired);
516 532
517 // Takes ownership of *cc. 533 // Takes ownership of *cc.
518 void InternalInsertCookie(const std::string& key, 534 void InternalInsertCookie(const std::string& key,
519 CanonicalCookie* cc, 535 CanonicalCookie* cc,
520 bool sync_to_store); 536 bool sync_to_store,
537 bool notify);
521 538
522 // Helper function that sets cookies with more control. 539 // Helper function that sets cookies with more control.
523 // Not exposed as we don't want callers to have the ability 540 // Not exposed as we don't want callers to have the ability
524 // to specify (potentially duplicate) creation times. 541 // to specify (potentially duplicate) creation times.
525 bool SetCookieWithCreationTimeAndOptions(const GURL& url, 542 bool SetCookieWithCreationTimeAndOptions(const GURL& url,
526 const std::string& cookie_line, 543 const std::string& cookie_line,
527 const base::Time& creation_time, 544 const base::Time& creation_time,
528 const CookieOptions& options); 545 const CookieOptions& options);
529 546
530 // Helper function that sets a canonical cookie, deleting equivalents and 547 // Helper function that sets a canonical cookie, deleting equivalents and
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 std::vector<std::string> cookieable_schemes_; 683 std::vector<std::string> cookieable_schemes_;
667 684
668 scoped_refptr<Delegate> delegate_; 685 scoped_refptr<Delegate> delegate_;
669 686
670 // Lock for thread-safety 687 // Lock for thread-safety
671 base::Lock lock_; 688 base::Lock lock_;
672 689
673 base::Time last_statistic_record_time_; 690 base::Time last_statistic_record_time_;
674 691
675 bool keep_expired_cookies_; 692 bool keep_expired_cookies_;
693 bool persist_session_cookies_;
694
695 // Describes what to do with old session cookies.
696 enum SessionCookieBehavior {
697 // Keep old session cookies separate, don't return them when cookies are
698 // read.
699 SESSION_COOKIES_UNDECIDED,
700 // Merge old session cookies in and treat them as normal cookies.
701 SESSION_COOKIES_MERGE,
702 // Discard old session cookies.
703 SESSION_COOKIES_DELETE
704 };
705 SessionCookieBehavior old_session_cookie_behavior_;
676 706
677 static bool enable_file_scheme_; 707 static bool enable_file_scheme_;
678 708
679 DISALLOW_COPY_AND_ASSIGN(CookieMonster); 709 DISALLOW_COPY_AND_ASSIGN(CookieMonster);
680 }; 710 };
681 711
682 class NET_EXPORT CookieMonster::CanonicalCookie { 712 class NET_EXPORT CookieMonster::CanonicalCookie {
683 public: 713 public:
684 714
685 // These constructors do no validation or canonicalization of their inputs; 715 // 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_; } 778 bool IsSecure() const { return secure_; }
749 bool IsHttpOnly() const { return httponly_; } 779 bool IsHttpOnly() const { return httponly_; }
750 bool IsDomainCookie() const { 780 bool IsDomainCookie() const {
751 return !domain_.empty() && domain_[0] == '.'; } 781 return !domain_.empty() && domain_[0] == '.'; }
752 bool IsHostCookie() const { return !IsDomainCookie(); } 782 bool IsHostCookie() const { return !IsDomainCookie(); }
753 783
754 bool IsExpired(const base::Time& current) { 784 bool IsExpired(const base::Time& current) {
755 return has_expires_ && current >= expiry_date_; 785 return has_expires_ && current >= expiry_date_;
756 } 786 }
757 787
788 bool IsOldSessionCookie() const {
789 return is_old_session_cookie_;
790 }
791
792 void SetIsOldSessionCookie(bool is_old_session_cookie) {
793 is_old_session_cookie_ = is_old_session_cookie;
794 }
795
758 // Are the cookies considered equivalent in the eyes of RFC 2965. 796 // Are the cookies considered equivalent in the eyes of RFC 2965.
759 // The RFC says that name must match (case-sensitive), domain must 797 // The RFC says that name must match (case-sensitive), domain must
760 // match (case insensitive), and path must match (case sensitive). 798 // match (case insensitive), and path must match (case sensitive).
761 // For the case insensitive domain compare, we rely on the domain 799 // For the case insensitive domain compare, we rely on the domain
762 // having been canonicalized (in 800 // having been canonicalized (in
763 // GetCookieDomainWithString->CanonicalizeHost). 801 // GetCookieDomainWithString->CanonicalizeHost).
764 bool IsEquivalent(const CanonicalCookie& ecc) const { 802 bool IsEquivalent(const CanonicalCookie& ecc) const {
765 // It seems like it would make sense to take secure and httponly into 803 // It seems like it would make sense to take secure and httponly into
766 // account, but the RFC doesn't specify this. 804 // account, but the RFC doesn't specify this.
767 // NOTE: Keep this logic in-sync with TrimDuplicateCookiesForHost(). 805 // NOTE: Keep this logic in-sync with TrimDuplicateCookiesForHost().
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 std::string path_; 840 std::string path_;
803 std::string mac_key_; // TODO(abarth): Persist to disk. 841 std::string mac_key_; // TODO(abarth): Persist to disk.
804 std::string mac_algorithm_; // TODO(abarth): Persist to disk. 842 std::string mac_algorithm_; // TODO(abarth): Persist to disk.
805 base::Time creation_date_; 843 base::Time creation_date_;
806 base::Time expiry_date_; 844 base::Time expiry_date_;
807 base::Time last_access_date_; 845 base::Time last_access_date_;
808 bool secure_; 846 bool secure_;
809 bool httponly_; 847 bool httponly_;
810 bool has_expires_; 848 bool has_expires_;
811 bool is_persistent_; 849 bool is_persistent_;
850 bool is_old_session_cookie_;
812 }; 851 };
813 852
814 class CookieMonster::Delegate 853 class CookieMonster::Delegate
815 : public base::RefCountedThreadSafe<CookieMonster::Delegate> { 854 : public base::RefCountedThreadSafe<CookieMonster::Delegate> {
816 public: 855 public:
817 // The publicly relevant reasons a cookie might be changed. 856 // The publicly relevant reasons a cookie might be changed.
818 enum ChangeCause { 857 enum ChangeCause {
819 // The cookie was changed directly by a consumer's action. 858 // The cookie was changed directly by a consumer's action.
820 CHANGE_COOKIE_EXPLICIT, 859 CHANGE_COOKIE_EXPLICIT,
821 // The cookie was automatically removed due to an insert operation that 860 // The cookie was automatically removed due to an insert operation that
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; 1016 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0;
978 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; 1017 virtual void DeleteCookie(const CanonicalCookie& cc) = 0;
979 1018
980 // Sets the value of the user preference whether the persistent storage 1019 // Sets the value of the user preference whether the persistent storage
981 // must be deleted upon destruction. 1020 // must be deleted upon destruction.
982 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; 1021 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0;
983 1022
984 // Flush the store and post the given Task when complete. 1023 // Flush the store and post the given Task when complete.
985 virtual void Flush(Task* completion_task) = 0; 1024 virtual void Flush(Task* completion_task) = 0;
986 1025
1026 virtual void DeleteSessionCookies() = 0;
1027
987 protected: 1028 protected:
988 PersistentCookieStore() {} 1029 PersistentCookieStore() {}
989 1030
990 private: 1031 private:
991 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); 1032 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
992 }; 1033 };
993 1034
994 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { 1035 class CookieList : public std::vector<CookieMonster::CanonicalCookie> {
995 }; 1036 };
996 1037
997 } // namespace net 1038 } // namespace net
998 1039
999 #endif // NET_BASE_COOKIE_MONSTER_H_ 1040 #endif // NET_BASE_COOKIE_MONSTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698