diff options
-rw-r--r-- | chrome/browser/cookies_tree_model.cc | 3 | ||||
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.cc | 6 | ||||
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.h | 2 | ||||
-rw-r--r-- | net/base/cookie_monster.cc | 24 | ||||
-rw-r--r-- | net/base/cookie_monster.h | 7 | ||||
-rw-r--r-- | net/base/cookie_monster_perftest.cc | 8 | ||||
-rw-r--r-- | net/base/cookie_monster_store_test.h | 16 | ||||
-rw-r--r-- | net/base/cookie_monster_unittest.cc | 104 |
8 files changed, 68 insertions, 102 deletions
diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index 37d682f..7c33067 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -59,8 +59,7 @@ void CookieTreeCookieNode::DeleteStoredObjects() { // vector storing the cookies in-tact and not delete from there (that would // invalidate our pointers), and the fact that it contains semi out-of-date // data is not problematic as we don't re-build the model based on that. - GetModel()->cookie_monster_-> - DeleteCookie(cookie_->Domain(), *cookie_, true); + GetModel()->cookie_monster_->DeleteCanonicalCookie(*cookie_); } namespace { diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc index 8649eb5..f8d46d3 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.cc +++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc @@ -308,7 +308,7 @@ bool InitTable(sql::Connection* db) { } // namespace bool SQLitePersistentCookieStore::Load( - std::vector<net::CookieMonster::KeyedCanonicalCookie>* cookies) { + std::vector<net::CookieMonster::CanonicalCookie*>* cookies) { scoped_ptr<sql::Connection> db(new sql::Connection); if (!db->Open(path_)) { NOTREACHED() << "Unable to open cookie DB."; @@ -348,9 +348,7 @@ bool SQLitePersistentCookieStore::Load( Time::FromInternalValue(smt.ColumnInt64(5)))); // expires_utc DLOG_IF(WARNING, cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; - cookies->push_back( - net::CookieMonster::KeyedCanonicalCookie(smt.ColumnString(1), - cc.release())); + cookies->push_back(cc.release()); } // Create the backend, this will take ownership of the db pointer. diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.h b/chrome/browser/net/sqlite_persistent_cookie_store.h index 998965d..6ba945e 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.h +++ b/chrome/browser/net/sqlite_persistent_cookie_store.h @@ -28,7 +28,7 @@ class SQLitePersistentCookieStore explicit SQLitePersistentCookieStore(const FilePath& path); ~SQLitePersistentCookieStore(); - virtual bool Load(std::vector<net::CookieMonster::KeyedCanonicalCookie>*); + virtual bool Load(std::vector<net::CookieMonster::CanonicalCookie*>*); virtual void AddCookie(const std::string&, const net::CookieMonster::CanonicalCookie&); diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index bd86772..029d841 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -180,7 +180,7 @@ void CookieMonster::InitStore() { // Initialize the store and sync in any saved persistent cookies. We don't // care if it's expired, insert it so it can be garbage collected, removed, // and sync'd. - std::vector<KeyedCanonicalCookie> cookies; + std::vector<CanonicalCookie*> cookies; // Reserve space for the maximum amount of cookies a database should have. // This prevents multiple vector growth / copies as we append cookies. cookies.reserve(kNumCookiesTotal); @@ -190,22 +190,22 @@ void CookieMonster::InitStore() { // that way we don't have to worry about what sections of code are safe // to call while it's in that state. std::set<int64> creation_times; - for (std::vector<KeyedCanonicalCookie>::const_iterator it = cookies.begin(); + for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); it != cookies.end(); ++it) { - int64 cookie_creation_time = it->second->CreationDate().ToInternalValue(); + int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue(); if (creation_times.insert(cookie_creation_time).second) { - InternalInsertCookie(it->first, it->second, false); + InternalInsertCookie((*it)->Domain(), *it, false); } else { LOG(ERROR) << StringPrintf("Found cookies with duplicate creation " "times in backing store: " "{name='%s', domain='%s', path='%s'}", - it->second->Name().c_str(), - it->first.c_str(), - it->second->Path().c_str()); + (*it)->Name().c_str(), + (*it)->Domain().c_str(), + (*it)->Path().c_str()); // We've been given ownership of the cookie and are throwing it // away; reclaim the space. - delete it->second; + delete (*it); } } @@ -1031,17 +1031,15 @@ int CookieMonster::DeleteAllForHost(const GURL& url) { return num_deleted; } -bool CookieMonster::DeleteCookie(const std::string& domain, - const CanonicalCookie& cookie, - bool sync_to_store) { +bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { AutoLock autolock(lock_); InitIfNecessary(); - for (CookieMapItPair its = cookies_.equal_range(domain); + for (CookieMapItPair its = cookies_.equal_range(cookie.Domain()); its.first != its.second; ++its.first) { // The creation date acts as our unique index... if (its.first->second->CreationDate() == cookie.CreationDate()) { - InternalDeleteCookie(its.first, sync_to_store, DELETE_COOKIE_EXPLICIT); + InternalDeleteCookie(its.first, true, DELETE_COOKIE_EXPLICIT); return true; } } diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index 8172857..e6aa48dc 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -52,7 +52,6 @@ class CookieMonster : public CookieStore { // a multimap. Also, multimap is standard, another reason to use it. typedef std::multimap<std::string, CanonicalCookie*> CookieMap; typedef std::pair<CookieMap::iterator, CookieMap::iterator> CookieMapItPair; - typedef std::pair<std::string, CanonicalCookie*> KeyedCanonicalCookie; typedef std::vector<CanonicalCookie> CookieList; // The store passed in should not have had Init() called on it yet. This @@ -135,9 +134,7 @@ class CookieMonster : public CookieStore { int DeleteAllForHost(const GURL& url); // Delete one specific cookie. - bool DeleteCookie(const std::string& domain, - const CanonicalCookie& cookie, - bool sync_to_store); + bool DeleteCanonicalCookie(const CanonicalCookie& cookie); // Override the default list of schemes that are allowed to be set in // this cookie store. Calling his overrides the value of @@ -542,7 +539,7 @@ class CookieMonster::PersistentCookieStore // Initializes the store and retrieves the existing cookies. This will be // called only once at startup. - virtual bool Load(std::vector<CookieMonster::KeyedCanonicalCookie>*) = 0; + virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>*) = 0; virtual void AddCookie(const std::string&, const CanonicalCookie&) = 0; virtual void UpdateCookieAccessTime(const CanonicalCookie&) = 0; diff --git a/net/base/cookie_monster_perftest.cc b/net/base/cookie_monster_perftest.cc index 042f971..0081141 100644 --- a/net/base/cookie_monster_perftest.cc +++ b/net/base/cookie_monster_perftest.cc @@ -165,7 +165,7 @@ TEST(CookieMonsterTest, TestDomainTree) { TEST(CookieMonsterTest, TestImport) { scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); - std::vector<net::CookieMonster::KeyedCanonicalCookie> initial_cookies; + std::vector<net::CookieMonster::CanonicalCookie*> initial_cookies; // We want to setup a fairly large backing store, with 300 domains of 50 // cookies each. Creation times must be unique. @@ -176,9 +176,9 @@ TEST(CookieMonsterTest, TestImport) { std::string gurl("www" + domain_name); for (int cookie_num = 0; cookie_num < 50; cookie_num++) { std::string cookie_line(StringPrintf("Cookie_%d=1; Path=/", cookie_num)); - AddKeyedCookieToList(gurl, cookie_line, - base::Time::FromInternalValue(time_tick++), - &initial_cookies); + AddCookieToList(gurl, cookie_line, + base::Time::FromInternalValue(time_tick++), + &initial_cookies); } } diff --git a/net/base/cookie_monster_store_test.h b/net/base/cookie_monster_store_test.h index 4b1cc52..cd070a7 100644 --- a/net/base/cookie_monster_store_test.h +++ b/net/base/cookie_monster_store_test.h @@ -42,7 +42,7 @@ class MockPersistentCookieStore } virtual bool Load( - std::vector<net::CookieMonster::KeyedCanonicalCookie>* out_cookies) { + std::vector<net::CookieMonster::CanonicalCookie*>* out_cookies) { bool ok = load_return_value_; if (ok) *out_cookies = load_result_; @@ -69,7 +69,7 @@ class MockPersistentCookieStore void SetLoadExpectation( bool return_value, - const std::vector<net::CookieMonster::KeyedCanonicalCookie>& result) { + const std::vector<net::CookieMonster::CanonicalCookie*>& result) { load_return_value_ = return_value; load_result_ = result; } @@ -83,7 +83,7 @@ class MockPersistentCookieStore // Deferred result to use when Load() is called. bool load_return_value_; - std::vector<net::CookieMonster::KeyedCanonicalCookie> load_result_; + std::vector<net::CookieMonster::CanonicalCookie*> load_result_; DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); }; @@ -115,12 +115,12 @@ class MockCookieMonsterDelegate : public net::CookieMonster::Delegate { DISALLOW_COPY_AND_ASSIGN(MockCookieMonsterDelegate); }; -// Helper to build a list of KeyedCanonicalCookies. -static void AddKeyedCookieToList( +// Helper to build a list of CanonicalCookie*s. +static void AddCookieToList( const std::string& key, const std::string& cookie_line, const base::Time& creation_time, - std::vector<net::CookieMonster::KeyedCanonicalCookie>* out_list) { + std::vector<net::CookieMonster::CanonicalCookie*>* out_list) { // Parse the cookie line. net::CookieMonster::ParsedCookie pc(cookie_line); @@ -143,9 +143,7 @@ static void AddKeyedCookieToList( !cookie_expires.is_null(), cookie_expires)); - out_list->push_back( - net::CookieMonster::KeyedCanonicalCookie( - key, cookie.release())); + out_list->push_back(cookie.release()); } } // namespace diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc index 39bfbf5..3ab9953 100644 --- a/net/base/cookie_monster_unittest.cc +++ b/net/base/cookie_monster_unittest.cc @@ -1111,7 +1111,7 @@ static bool FindAndDeleteCookie(net::CookieMonster* cm, for (net::CookieMonster::CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) if (it->Domain() == domain && it->Name() == name) - return cm->DeleteCookie(domain, *it, false); + return cm->DeleteCanonicalCookie(*it); return false; } @@ -1360,52 +1360,52 @@ TEST(CookieMonsterTest, DontImportDuplicateCookies) { // be careful not to have any duplicate creation times at all (as it's a // violation of a CookieMonster invariant) even if Time::Now() doesn't // move between calls. - std::vector<net::CookieMonster::KeyedCanonicalCookie> initial_cookies; + std::vector<net::CookieMonster::CanonicalCookie*> initial_cookies; // Insert 4 cookies with name "X" on path "/", with varying creation // dates. We expect only the most recent one to be preserved following // the import. - AddKeyedCookieToList("www.google.com", - "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", - Time::Now() + TimeDelta::FromDays(3), - &initial_cookies); + AddCookieToList("www.google.com", + "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", + Time::Now() + TimeDelta::FromDays(3), + &initial_cookies); - AddKeyedCookieToList("www.google.com", - "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", - Time::Now() + TimeDelta::FromDays(1), - &initial_cookies); + AddCookieToList("www.google.com", + "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", + Time::Now() + TimeDelta::FromDays(1), + &initial_cookies); // ===> This one is the WINNER (biggest creation time). <==== - AddKeyedCookieToList("www.google.com", - "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", - Time::Now() + TimeDelta::FromDays(4), - &initial_cookies); + AddCookieToList("www.google.com", + "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", + Time::Now() + TimeDelta::FromDays(4), + &initial_cookies); - AddKeyedCookieToList("www.google.com", - "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", - Time::Now(), - &initial_cookies); + AddCookieToList("www.google.com", + "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", + Time::Now(), + &initial_cookies); // Insert 2 cookies with name "X" on path "/2", with varying creation // dates. We expect only the most recent one to be preserved the import. // ===> This one is the WINNER (biggest creation time). <==== - AddKeyedCookieToList("www.google.com", - "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", - Time::Now() + TimeDelta::FromDays(9), - &initial_cookies); + AddCookieToList("www.google.com", + "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", + Time::Now() + TimeDelta::FromDays(9), + &initial_cookies); - AddKeyedCookieToList("www.google.com", - "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", - Time::Now() + TimeDelta::FromDays(2), - &initial_cookies); + AddCookieToList("www.google.com", + "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", + Time::Now() + TimeDelta::FromDays(2), + &initial_cookies); // Insert 1 cookie with name "Y" on path "/". - AddKeyedCookieToList("www.google.com", - "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", - Time::Now() + TimeDelta::FromDays(10), - &initial_cookies); + AddCookieToList("www.google.com", + "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", + Time::Now() + TimeDelta::FromDays(10), + &initial_cookies); // Inject our initial cookies into the mock PersistentCookieStore. store->SetLoadExpectation(true, initial_cookies); @@ -1447,40 +1447,16 @@ TEST(CookieMonsterTest, DontImportDuplicateCreationTimes) { // four with the earlier time as creation times. We should only get // two cookies remaining, but which two (other than that there should // be one from each set) will be random. - std::vector<net::CookieMonster::KeyedCanonicalCookie> initial_cookies; - AddKeyedCookieToList("www.google.com", - "X=1; path=/", - now, - &initial_cookies); - AddKeyedCookieToList("www.google.com", - "X=2; path=/", - now, - &initial_cookies); - AddKeyedCookieToList("www.google.com", - "X=3; path=/", - now, - &initial_cookies); - AddKeyedCookieToList("www.google.com", - "X=4; path=/", - now, - &initial_cookies); - - AddKeyedCookieToList("www.google.com", - "Y=1; path=/", - earlier, - &initial_cookies); - AddKeyedCookieToList("www.google.com", - "Y=2; path=/", - earlier, - &initial_cookies); - AddKeyedCookieToList("www.google.com", - "Y=3; path=/", - earlier, - &initial_cookies); - AddKeyedCookieToList("www.google.com", - "Y=4; path=/", - earlier, - &initial_cookies); + std::vector<net::CookieMonster::CanonicalCookie*> initial_cookies; + AddCookieToList("www.google.com", "X=1; path=/", now, &initial_cookies); + AddCookieToList("www.google.com", "X=2; path=/", now, &initial_cookies); + AddCookieToList("www.google.com", "X=3; path=/", now, &initial_cookies); + AddCookieToList("www.google.com", "X=4; path=/", now, &initial_cookies); + + AddCookieToList("www.google.com", "Y=1; path=/", earlier, &initial_cookies); + AddCookieToList("www.google.com", "Y=2; path=/", earlier, &initial_cookies); + AddCookieToList("www.google.com", "Y=3; path=/", earlier, &initial_cookies); + AddCookieToList("www.google.com", "Y=4; path=/", earlier, &initial_cookies); // Inject our initial cookies into the mock PersistentCookieStore. store->SetLoadExpectation(true, initial_cookies); |