Index: net/base/cookie_monster.cc |
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc |
index 03061c6851041bf6b9e2a6ab707a52b57f076fde..9c4fba3cc162a54f292b610cb73f5e2319a9c925 100644 |
--- a/net/base/cookie_monster.cc |
+++ b/net/base/cookie_monster.cc |
@@ -320,6 +320,8 @@ ChangeCausePair ChangeCauseMapping[] = { |
{ CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, |
// DELETE_COOKIE_EXPIRED_OVERWRITE |
{ CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, |
+ // DELETE_COOKIE_OLD_SESSION_COOKIE |
+ { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }, |
// DELETE_COOKIE_LAST_ENTRY |
{ CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false } |
}; |
@@ -370,7 +372,9 @@ CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) |
TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), |
delegate_(delegate), |
last_statistic_record_time_(Time::Now()), |
- keep_expired_cookies_(false) { |
+ keep_expired_cookies_(false), |
+ keep_old_session_cookies_(false), |
+ sync_session_cookies_(false) { |
InitializeHistograms(); |
SetDefaultCookieableSchemes(); |
} |
@@ -386,7 +390,9 @@ CookieMonster::CookieMonster(PersistentCookieStore* store, |
last_access_threshold_milliseconds)), |
delegate_(delegate), |
last_statistic_record_time_(base::Time::Now()), |
- keep_expired_cookies_(false) { |
+ keep_expired_cookies_(false), |
+ keep_old_session_cookies_(false), |
+ sync_session_cookies_(false) { |
InitializeHistograms(); |
SetDefaultCookieableSchemes(); |
} |
@@ -1399,6 +1405,34 @@ CookieMonster* CookieMonster::GetCookieMonster() { |
return this; |
} |
+void CookieMonster::SetSyncSessionCookies(bool sync_session_cookies) { |
+ sync_session_cookies_ = sync_session_cookies; |
+} |
+ |
+void CookieMonster::SaveSessionCookies() { |
+ if (store_) { |
+ store_->SetClearSessionStateOnExit(false); |
+ store_->SetClearLocalStateOnExit(false); |
+ } |
+} |
+ |
+void CookieMonster::RestoreOldSessionCookies() { |
+ keep_old_session_cookies_ = true; |
+ for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end(); ++it) { |
+ it->second->SetIsOldSessionCookie(false); |
jochen (gone - plz use gerrit)
2011/11/25 14:45:14
this should notify the delegate about the cookie b
marja
2011/11/28 15:22:01
Done. (And made it so that StoreLoadedCookies won'
|
+ } |
+} |
+ |
+void CookieMonster::DiscardOldSessionCookies() { |
+ for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
+ CookieMap::iterator curit = it; |
+ ++it; |
+ if (curit->second->IsOldSessionCookie()) { |
+ InternalDeleteCookie(curit, true, DELETE_COOKIE_OLD_SESSION_COOKIE); |
jochen (gone - plz use gerrit)
2011/11/25 14:45:14
we need to make sure that this doesn't call the co
marja
2011/11/28 15:22:01
Should already work since the notifications are se
|
+ } |
+ } |
+} |
+ |
CookieMonster::~CookieMonster() { |
DeleteAll(false); |
} |
@@ -1468,6 +1502,11 @@ void CookieMonster::StoreLoadedCookies( |
for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); |
it != cookies.end(); ++it) { |
+ // Mark restored session cookies as old session cookies, so they can be |
+ // discarded if needed. |
+ if (!keep_old_session_cookies_ && !(*it)->IsPersistent()) |
+ (*it)->SetIsOldSessionCookie(true); |
+ |
int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue(); |
if (creation_times_.insert(cookie_creation_time).second) { |
@@ -1713,6 +1752,13 @@ void CookieMonster::FindCookiesForKey( |
continue; |
} |
+ // If the cookie is an old session cookie, and we are not supposed to keep |
+ // them, delete it. |
+ if (!keep_old_session_cookies_ && cc->IsOldSessionCookie()) { |
+ InternalDeleteCookie(curit, true, DELETE_COOKIE_OLD_SESSION_COOKIE); |
jochen (gone - plz use gerrit)
2011/11/25 14:45:14
again, this shouldn't notify
marja
2011/11/28 15:22:01
Same here.
|
+ continue; |
+ } |
+ |
// Filter out HttpOnly cookies, per options. |
if (options.exclude_httponly() && cc->IsHttpOnly()) |
continue; |
@@ -1774,7 +1820,7 @@ void CookieMonster::InternalInsertCookie(const std::string& key, |
bool sync_to_store) { |
lock_.AssertAcquired(); |
- if (cc->IsPersistent() && store_ && sync_to_store) |
+ if ((cc->IsPersistent() || sync_session_cookies_) && store_ && sync_to_store) |
store_->AddCookie(*cc); |
cookies_.insert(CookieMap::value_type(key, cc)); |
if (delegate_.get()) { |
@@ -1853,6 +1899,18 @@ bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, |
VLOG(kVlogSetCookies) << "SetCookie() key: " << key << " cc: " |
<< (*cc)->DebugString(); |
+ if (!keep_old_session_cookies_ && sync_session_cookies_) { |
+ // Delete all old session cookies for that key. |
+ CookieMapItPair its = cookies_.equal_range(key); |
+ while (its.first != its.second) { |
+ CookieMap::iterator curit = its.first; |
+ ++its.first; |
+ if (curit->second->IsOldSessionCookie()) { |
+ InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); |
+ } |
+ } |
+ } |
+ |
// Realize that we might be setting an expired cookie, and the only point |
// was to delete the cookie which we've already done. |
if (!already_expired || keep_expired_cookies_) { |
@@ -1891,7 +1949,7 @@ void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, |
(current - cc->LastAccessDate()).InMinutes()); |
cc->SetLastAccessDate(current); |
- if (cc->IsPersistent() && store_) |
+ if ((cc->IsPersistent() || sync_session_cookies_) && store_) |
store_->UpdateCookieAccessTime(*cc); |
} |
@@ -1913,7 +1971,7 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, |
CanonicalCookie* cc = it->second; |
VLOG(kVlogSetCookies) << "InternalDeleteCookie() cc: " << cc->DebugString(); |
- if (cc->IsPersistent() && store_ && sync_to_store) |
+ if ((cc->IsPersistent() || sync_session_cookies_) && store_ && sync_to_store) |
store_->DeleteCookie(*cc); |
if (delegate_.get()) { |
ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; |
@@ -2519,7 +2577,8 @@ CookieMonster::CanonicalCookie::CanonicalCookie() |
: secure_(false), |
httponly_(false), |
has_expires_(false), |
- is_persistent_(false) { |
+ is_persistent_(false), |
+ is_old_session_cookie_(false) { |
SetSessionCookieExpiryTime(); |
} |
@@ -2543,7 +2602,8 @@ CookieMonster::CanonicalCookie::CanonicalCookie( |
secure_(secure), |
httponly_(httponly), |
has_expires_(has_expires), |
- is_persistent_(is_persistent) { |
+ is_persistent_(is_persistent), |
+ is_old_session_cookie_(false) { |
if (!has_expires_) { |
DCHECK(!is_persistent_); |
SetSessionCookieExpiryTime(); |
@@ -2563,7 +2623,8 @@ CookieMonster::CanonicalCookie::CanonicalCookie(const GURL& url, |
secure_(pc.IsSecure()), |
httponly_(pc.IsHttpOnly()), |
has_expires_(pc.HasExpires()), |
- is_persistent_(pc.HasExpires()) { |
+ is_persistent_(pc.HasExpires()), |
+ is_old_session_cookie_(false) { |
if (has_expires_) |
expiry_date_ = CanonExpiration(pc, creation_date_); |
else |