diff options
author | esprehn@chromium.org <esprehn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-03 20:54:20 +0000 |
---|---|---|
committer | esprehn@chromium.org <esprehn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-03 20:54:20 +0000 |
commit | 03e13d488458d91c493f95d4b88dc384a3e29ff7 (patch) | |
tree | eb8fddc954adab3d39e20298ba9cfd3d4988420d /net | |
parent | 575b212443311616dc6c1b218896146b7d611988 (diff) | |
download | chromium_src-03e13d488458d91c493f95d4b88dc384a3e29ff7.zip chromium_src-03e13d488458d91c493f95d4b88dc384a3e29ff7.tar.gz chromium_src-03e13d488458d91c493f95d4b88dc384a3e29ff7.tar.bz2 |
Revert 242913 "Make CookieMonster::Delegate top-level and remove..."
This is making fast/cookies/local-file-can-set-cookies.html fail:
http://test-results.appspot.com/dashboards/flakiness_dashboard.html#tests=fast%2Fcookies%2Flocal-file-can-set-cookies.html
> Make CookieMonster::Delegate top-level and remove global CookieMonster::EnableFileScheme().
>
> Relanding parts of https://chromiumcodereview.appspot.com/12546016
>
> R=rsleevi@chromium.org
> TBR=jam
> BUG=159193,331424
>
> Review URL: https://codereview.chromium.org/93593005
TBR=ajwong@chromium.org
Review URL: https://codereview.chromium.org/124093004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242920 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/cookies/cookie_monster.cc | 55 | ||||
-rw-r--r-- | net/cookies/cookie_monster.h | 37 | ||||
-rw-r--r-- | net/cookies/cookie_monster_store_test.h | 6 | ||||
-rw-r--r-- | net/cookies/cookie_monster_unittest.cc | 2 | ||||
-rw-r--r-- | net/cookies/cookie_store.h | 1 |
5 files changed, 55 insertions, 46 deletions
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index d6eccf4..15c7143 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc @@ -254,40 +254,40 @@ CookieMonster::CookieItVector::iterator LowerBoundAccessDate( LowerBoundAccessDateComparator); } -// Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the -// mapping also provides a boolean that specifies whether or not an -// OnCookieChanged notification ought to be generated. +// Mapping between DeletionCause and Delegate::ChangeCause; the mapping also +// provides a boolean that specifies whether or not an OnCookieChanged +// notification ought to be generated. typedef struct ChangeCausePair_struct { - CookieMonsterDelegate::ChangeCause cause; + CookieMonster::Delegate::ChangeCause cause; bool notify; } ChangeCausePair; ChangeCausePair ChangeCauseMapping[] = { // DELETE_COOKIE_EXPLICIT - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, true }, // DELETE_COOKIE_OVERWRITE - { CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_OVERWRITE, true }, // DELETE_COOKIE_EXPIRED - { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED, true }, // DELETE_COOKIE_EVICTED - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, + { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }, // DELETE_COOKIE_DONT_RECORD - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, + { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }, // DELETE_COOKIE_EVICTED_DOMAIN - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EVICTED_GLOBAL - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EXPIRED_OVERWRITE - { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, + { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, // DELETE_COOKIE_CONTROL_CHAR - { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, + { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true}, // DELETE_COOKIE_LAST_ENTRY - { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false } + { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false } }; std::string BuildCookieLine(const CanonicalCookieVector& cookies) { @@ -308,8 +308,10 @@ std::string BuildCookieLine(const CanonicalCookieVector& cookies) { } // namespace -CookieMonster::CookieMonster(PersistentCookieStore* store, - CookieMonsterDelegate* delegate) +// static +bool CookieMonster::default_enable_file_scheme_ = false; + +CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) : initialized_(false), loaded_(false), store_(store), @@ -324,7 +326,7 @@ CookieMonster::CookieMonster(PersistentCookieStore* store, } CookieMonster::CookieMonster(PersistentCookieStore* store, - CookieMonsterDelegate* delegate, + Delegate* delegate, int last_access_threshold_milliseconds) : initialized_(false), loaded_(false), @@ -1287,6 +1289,11 @@ void CookieMonster::SetKeepExpiredCookies() { keep_expired_cookies_ = true; } +// static +void CookieMonster::EnableFileScheme() { + default_enable_file_scheme_ = true; +} + void CookieMonster::FlushStore(const base::Closure& callback) { base::AutoLock autolock(lock_); if (initialized_ && store_.get()) @@ -1666,9 +1673,9 @@ const int CookieMonster::kDefaultCookieableSchemesCount = arraysize(kDefaultCookieableSchemes); void CookieMonster::SetDefaultCookieableSchemes() { - // Always disable file scheme unless SetEnableFileScheme(true) is called. - SetCookieableSchemes(kDefaultCookieableSchemes, - kDefaultCookieableSchemesCount - 1); + int num_schemes = default_enable_file_scheme_ ? + kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1; + SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); } void CookieMonster::FindCookiesForHostAndDomain( @@ -1770,7 +1777,7 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( cookies_.insert(CookieMap::value_type(key, cc)); if (delegate_.get()) { delegate_->OnCookieChanged( - *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); + *cc, false, Delegate::CHANGE_COOKIE_EXPLICIT); } return inserted; diff --git a/net/cookies/cookie_monster.h b/net/cookies/cookie_monster.h index 455484e..3e2ed6d 100644 --- a/net/cookies/cookie_monster.h +++ b/net/cookies/cookie_monster.h @@ -37,7 +37,6 @@ class TimeTicks; namespace net { -class CookieMonsterDelegate; class ParsedCookie; // The cookie monster is the system for storing and retrieving cookies. It has @@ -66,8 +65,8 @@ class ParsedCookie; // - Verify that our domain enforcement and non-dotted handling is correct class NET_EXPORT CookieMonster : public CookieStore { public: + class Delegate; class PersistentCookieStore; - typedef CookieMonsterDelegate Delegate; // Terminology: // * The 'top level domain' (TLD) of an internet domain name is @@ -139,11 +138,11 @@ class NET_EXPORT CookieMonster : public CookieStore { // monster's existence. If |store| is NULL, then no backing store will be // updated. If |delegate| is non-NULL, it will be notified on // creation/deletion of cookies. - CookieMonster(PersistentCookieStore* store, CookieMonsterDelegate* delegate); + CookieMonster(PersistentCookieStore* store, Delegate* delegate); // Only used during unit testing. CookieMonster(PersistentCookieStore* store, - CookieMonsterDelegate* delegate, + Delegate* delegate, int last_access_threshold_milliseconds); // Helper function that adds all cookies from |list| into this instance. @@ -217,10 +216,6 @@ class NET_EXPORT CookieMonster : public CookieStore { // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or // without 'file' being included. - // - // There are some unknowns about how to correctly handle file:// cookies, - // and our implementation for this is not robust enough. This allows you - // to enable support, but it should only be used for testing. Bug 1157243. void SetEnableFileScheme(bool accept); // Instructs the cookie monster to not delete expired cookies. This is used @@ -231,6 +226,12 @@ class NET_EXPORT CookieMonster : public CookieStore { // Protects session cookies from deletion on shutdown. void SetForceKeepSessionState(); + // There are some unknowns about how to correctly handle file:// cookies, + // and our implementation for this is not robust enough. This allows you + // to enable support, but it should only be used for testing. Bug 1157243. + // Must be called before creating a CookieMonster instance. + static void EnableFileScheme(); + // Flush the backing store (if any) to disk and post the given callback when // done. // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. @@ -351,8 +352,8 @@ class NET_EXPORT CookieMonster : public CookieStore { // and to provide a public cause for onCookieChange notifications. // // If you add or remove causes from this list, please be sure to also update - // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping. - // Moreover, these are used as array indexes, so avoid reordering to keep the + // the Delegate::ChangeCause mapping inside ChangeCauseMapping. Moreover, + // these are used as array indexes, so avoid reordering to keep the // histogram buckets consistent. New items (if necessary) should be added // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. enum DeletionCause { @@ -545,9 +546,9 @@ class NET_EXPORT CookieMonster : public CookieStore { const base::Time& current_time); // |deletion_cause| argument is used for collecting statistics and choosing - // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged - // notifications. Guarantee: All iterators to cookies_ except to the - // deleted entry remain vaild. + // the correct Delegate::ChangeCause for OnCookieChanged notifications. + // Guarantee: All iterators to cookies_ except to the deleted entry remain + // vaild. void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store, DeletionCause deletion_cause); @@ -669,7 +670,7 @@ class NET_EXPORT CookieMonster : public CookieStore { std::vector<std::string> cookieable_schemes_; - scoped_refptr<CookieMonsterDelegate> delegate_; + scoped_refptr<Delegate> delegate_; // Lock for thread-safety base::Lock lock_; @@ -687,8 +688,8 @@ class NET_EXPORT CookieMonster : public CookieStore { DISALLOW_COPY_AND_ASSIGN(CookieMonster); }; -class NET_EXPORT CookieMonsterDelegate - : public base::RefCountedThreadSafe<CookieMonsterDelegate> { +class NET_EXPORT CookieMonster::Delegate + : public base::RefCountedThreadSafe<CookieMonster::Delegate> { public: // The publicly relevant reasons a cookie might be changed. enum ChangeCause { @@ -720,8 +721,8 @@ class NET_EXPORT CookieMonsterDelegate bool removed, ChangeCause cause) = 0; protected: - friend class base::RefCountedThreadSafe<CookieMonsterDelegate>; - virtual ~CookieMonsterDelegate() {} + friend class base::RefCountedThreadSafe<CookieMonster::Delegate>; + virtual ~Delegate() {} }; typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> diff --git a/net/cookies/cookie_monster_store_test.h b/net/cookies/cookie_monster_store_test.h index ec40de6..d7da521 100644 --- a/net/cookies/cookie_monster_store_test.h +++ b/net/cookies/cookie_monster_store_test.h @@ -115,8 +115,8 @@ class MockPersistentCookieStore DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); }; -// Mock for CookieMonsterDelegate -class MockCookieMonsterDelegate : public CookieMonsterDelegate { +// Mock for CookieMonster::Delegate +class MockCookieMonsterDelegate : public CookieMonster::Delegate { public: typedef std::pair<CanonicalCookie, bool> CookieNotification; @@ -130,7 +130,7 @@ class MockCookieMonsterDelegate : public CookieMonsterDelegate { virtual void OnCookieChanged( const CanonicalCookie& cookie, bool removed, - CookieMonsterDelegate::ChangeCause cause) OVERRIDE; + CookieMonster::Delegate::ChangeCause cause) OVERRIDE; private: virtual ~MockCookieMonsterDelegate(); diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc index 0e01f28..69d98a1 100644 --- a/net/cookies/cookie_monster_unittest.cc +++ b/net/cookies/cookie_monster_unittest.cc @@ -1546,7 +1546,7 @@ TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { EXPECT_NE(name1, name2); } -TEST_F(CookieMonsterTest, CookieMonsterDelegate) { +TEST_F(CookieMonsterTest, Delegate) { scoped_refptr<MockPersistentCookieStore> store( new MockPersistentCookieStore); scoped_refptr<MockCookieMonsterDelegate> delegate( diff --git a/net/cookies/cookie_store.h b/net/cookies/cookie_store.h index 730f710..7dee857 100644 --- a/net/cookies/cookie_store.h +++ b/net/cookies/cookie_store.h @@ -33,6 +33,7 @@ class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { typedef base::Callback<void(bool success)> SetCookiesCallback; typedef base::Callback<void(int num_deleted)> DeleteCallback; + // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". // // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie |