diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 05:29:03 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 05:29:03 +0000 |
commit | f7449ff56a760fed21537e02949dee3c9d2cb4ed (patch) | |
tree | 3978068d1656eed47feae85585983520f8aeba9c /net/base/cookie_monster.cc | |
parent | 7947f2160b3d4413f5d70f9119ed00b3970e15e5 (diff) | |
download | chromium_src-f7449ff56a760fed21537e02949dee3c9d2cb4ed.zip chromium_src-f7449ff56a760fed21537e02949dee3c9d2cb4ed.tar.gz chromium_src-f7449ff56a760fed21537e02949dee3c9d2cb4ed.tar.bz2 |
Litter CookieMonster with some more assertions, to hopefully crash earlier when the |cookies_| map is malformed.
These checks will slow things down when there are lots of cookies, and will hopefully just be temporary.
BUG=74585
Review URL: http://codereview.chromium.org/6676017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77790 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/cookie_monster.cc')
-rw-r--r-- | net/base/cookie_monster.cc | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index 44204b5..c0d6130 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -508,6 +508,7 @@ bool CookieMonster::SetCookieWithDetails( const std::string& domain, const std::string& path, const base::Time& expiration_time, bool secure, bool http_only) { base::AutoLock autolock(lock_); + ValidateMapWhileLockHeld(0); if (!HasCookieableScheme(url)) return false; @@ -534,6 +535,7 @@ bool CookieMonster::SetCookieWithDetails( CookieList CookieMonster::GetAllCookies() { base::AutoLock autolock(lock_); + ValidateMapWhileLockHeld(0); InitIfNecessary(); // This function is being called to scrape the cookie list for management UI @@ -562,6 +564,7 @@ CookieList CookieMonster::GetAllCookies() { it != cookie_ptrs.end(); ++it) cookie_list.push_back(**it); + ValidateMapWhileLockHeld(0); return cookie_list; } @@ -569,6 +572,7 @@ CookieList CookieMonster::GetAllCookiesForURLWithOptions( const GURL& url, const CookieOptions& options) { base::AutoLock autolock(lock_); + ValidateMapWhileLockHeld(0); InitIfNecessary(); std::vector<CanonicalCookie*> cookie_ptrs; @@ -592,6 +596,7 @@ CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { int CookieMonster::DeleteAll(bool sync_to_store) { base::AutoLock autolock(lock_); + ValidateMapWhileLockHeld(0); if (sync_to_store) InitIfNecessary(); @@ -612,6 +617,7 @@ int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, const Time& delete_end, bool sync_to_store) { base::AutoLock autolock(lock_); + ValidateMapWhileLockHeld(0); InitIfNecessary(); int num_deleted = 0; @@ -637,6 +643,7 @@ int CookieMonster::DeleteAllCreatedAfter(const Time& delete_begin, int CookieMonster::DeleteAllForHost(const GURL& url) { base::AutoLock autolock(lock_); + ValidateMapWhileLockHeld(0); InitIfNecessary(); if (!HasCookieableScheme(url)) @@ -668,6 +675,7 @@ int CookieMonster::DeleteAllForHost(const GURL& url) { bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { base::AutoLock autolock(lock_); + ValidateMapWhileLockHeld(0); InitIfNecessary(); for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain())); @@ -805,8 +813,13 @@ CookieMonster* CookieMonster::GetCookieMonster() { void CookieMonster::ValidateMap(int arg) { base::AutoLock autolock(lock_); - // Skipping InitIfNecessary() to allow validation before first use. + ValidateMapWhileLockHeld(arg); +} + +void CookieMonster::ValidateMapWhileLockHeld(int arg) { + lock_.AssertAcquired(); + // Skipping InitIfNecessary() to allow validation before first use. CHECK_EQ(kMonsterAlive, monster_alive_); for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end(); ++it) CHECK(it->second); @@ -823,6 +836,7 @@ bool CookieMonster::SetCookieWithCreationTime(const GURL& url, const std::string& cookie_line, const base::Time& creation_time) { base::AutoLock autolock(lock_); + CHECK_EQ(kMonsterAlive, monster_alive_); if (!HasCookieableScheme(url)) { return false; @@ -890,6 +904,7 @@ void CookieMonster::InitStore() { void CookieMonster::EnsureCookiesMapIsValid() { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); int num_duplicates_trimmed = 0; @@ -916,6 +931,7 @@ int CookieMonster::TrimDuplicateCookiesForKey( CookieMap::iterator begin, CookieMap::iterator end) { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); // Set of cookies ordered by creation time. typedef std::set<CookieMap::iterator, OrderByCreationTimeDesc> CookieSet; @@ -1009,6 +1025,7 @@ void CookieMonster::FindCookiesForHostAndDomain( bool update_access_time, std::vector<CanonicalCookie*>* cookies) { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); const Time current_time(CurrentTime()); @@ -1107,6 +1124,7 @@ bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, const CanonicalCookie& ecc, bool skip_httponly) { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); bool found_equivalent_cookie = false; bool skipped_httponly = false; @@ -1136,6 +1154,7 @@ void CookieMonster::InternalInsertCookie(const std::string& key, CanonicalCookie* cc, bool sync_to_store) { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); if (cc->IsPersistent() && store_ && sync_to_store) store_->AddCookie(*cc); @@ -1150,6 +1169,7 @@ bool CookieMonster::SetCookieWithCreationTimeAndOptions( const Time& creation_time_or_null, const CookieOptions& options) { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; @@ -1229,6 +1249,7 @@ bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, const Time& current) { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); // Based off the Mozilla code. When a cookie has been accessed recently, // don't bother updating its access time again. This reduces the number of @@ -1264,6 +1285,8 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, delegate_->OnCookieChanged(*cc, true); cookies_.erase(it); delete cc; + + ValidateMapWhileLockHeld(0); } // Domain expiry behavior is unchanged by key/expiry scheme (the @@ -1274,6 +1297,7 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, int CookieMonster::GarbageCollect(const Time& current, const std::string& key) { lock_.AssertAcquired(); + ValidateMapWhileLockHeld(0); int num_deleted = 0; @@ -1347,6 +1371,8 @@ int CookieMonster::GarbageCollect(const Time& current, } } + ValidateMapWhileLockHeld(0); + return num_deleted; } |