diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 14:38:32 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 14:38:32 +0000 |
commit | c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d (patch) | |
tree | 25fdd97cc5c3366ff50093088f7531f403f6c9b9 /net | |
parent | 11abcfcb82657d248355fa2f5215a29b3e41a9ae (diff) | |
download | chromium_src-c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d.zip chromium_src-c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d.tar.gz chromium_src-c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d.tar.bz2 |
Reland r42467. Clear cookies, local storage and databases when an extension gets uninstalled.
BUG=27938,39177
TEST=Unittest in extension_service_unitttest.cc
Review URL: http://codereview.chromium.org/1257005
Patch from Mattias Nissler.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42611 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/cookie_monster.cc | 79 | ||||
-rw-r--r-- | net/base/cookie_monster.h | 7 |
2 files changed, 55 insertions, 31 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index 5a1e492..f0cf00a 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -787,6 +787,20 @@ int CookieMonster::DeleteAllCreatedAfter(const Time& delete_begin, return DeleteAllCreatedBetween(delete_begin, Time(), sync_to_store); } +int CookieMonster::DeleteAllForURL(const GURL& url, + bool sync_to_store) { + AutoLock autolock(lock_); + InitIfNecessary(); + CookieList cookies = InternalGetAllCookiesForURL(url); + int num_deleted = 0; + for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { + CookieMap::iterator curit = it; + ++it; + InternalDeleteCookie(curit, sync_to_store); + } + return num_deleted; +} + bool CookieMonster::DeleteCookie(const std::string& domain, const CanonicalCookie& cookie, bool sync_to_store) { @@ -916,37 +930,7 @@ CookieMonster::CookieList CookieMonster::GetAllCookies() { CookieMonster::CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { AutoLock autolock(lock_); InitIfNecessary(); - - // Do not return removed cookies. - GarbageCollectExpired(Time::Now(), - CookieMapItPair(cookies_.begin(), cookies_.end()), - NULL); - - CookieList cookie_list; - if (!HasCookieableScheme(url)) - return cookie_list; - - bool secure = url.SchemeIsSecure(); - - // Query for the full host, For example: 'a.c.blah.com'. - std::string key(url.host()); - FindRawCookies(key, secure, url.path(), &cookie_list); - - // See if we can search for domain cookies, i.e. if the host has a TLD + 1. - const std::string domain(GetEffectiveDomain(url.scheme(), key)); - if (domain.empty()) - return cookie_list; - - // Use same logic as in FindCookiesForHostAndDomain. - DCHECK_LE(domain.length(), key.length()); - DCHECK_EQ(0, key.compare(key.length() - domain.length(), domain.length(), - domain)); - for (key = "." + key; key.length() > domain.length(); ) { - FindRawCookies(key, secure, url.path(), &cookie_list); - const size_t next_dot = key.find('.', 1); // Skip over leading dot. - key.erase(0, next_dot); - } - return cookie_list; + return InternalGetAllCookiesForURL(url); } void CookieMonster::FindCookiesForHostAndDomain( @@ -1035,6 +1019,39 @@ void CookieMonster::FindRawCookies(const std::string& key, } } +CookieMonster::CookieList CookieMonster::InternalGetAllCookiesForURL( + const GURL& url) { + // Do not return removed cookies. + GarbageCollectExpired(Time::Now(), + CookieMapItPair(cookies_.begin(), cookies_.end()), + NULL); + + CookieList cookie_list; + if (!HasCookieableScheme(url)) + return cookie_list; + + bool secure = url.SchemeIsSecure(); + + // Query for the full host, For example: 'a.c.blah.com'. + std::string key(url.host()); + FindRawCookies(key, secure, url.path(), &cookie_list); + + // See if we can search for domain cookies, i.e. if the host has a TLD + 1. + const std::string domain(GetEffectiveDomain(url.scheme(), key)); + if (domain.empty()) + return cookie_list; + + // Use same logic as in FindCookiesForHostAndDomain. + DCHECK_LE(domain.length(), key.length()); + DCHECK_EQ(0, key.compare(key.length() - domain.length(), domain.length(), + domain)); + for (key = "." + key; key.length() > domain.length(); ) { + FindRawCookies(key, secure, url.path(), &cookie_list); + const size_t next_dot = key.find('.', 1); // Skip over leading dot. + key.erase(0, next_dot); + } + return cookie_list; +} CookieMonster::ParsedCookie::ParsedCookie(const std::string& cookie_line) : is_valid_(false), diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index ab82056..d421d6f 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -118,6 +118,9 @@ class CookieMonster : public CookieStore { // one passed into the function via |delete_after|. int DeleteAllCreatedAfter(const base::Time& delete_begin, bool sync_to_store); + // Delete all cookies that match the given URL. + int DeleteAllForURL(const GURL& url, bool sync_to_store); + // Delete one specific cookie. bool DeleteCookie(const std::string& domain, const CanonicalCookie& cookie, @@ -182,6 +185,10 @@ class CookieMonster : public CookieStore { const std::string& path, CookieList* list); + // Internal helper returning all cookies for a given URL. The caller is + // assumed to hold lock_ and having called InitIfNecessary(). + CookieList InternalGetAllCookiesForURL(const GURL& url); + // Delete any cookies that are equivalent to |ecc| (same path, key, etc). // If |skip_httponly| is true, httponly cookies will not be deleted. The // return value with be true if |skip_httponly| skipped an httponly cookie. |