Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: net/base/cookie_monster.cc

Issue 8533013: SessionRestore: Store session cookies and restore them if chrome crashes or auto-restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Portions of this code based on Mozilla: 5 // Portions of this code based on Mozilla:
6 // (netwerk/cookie/src/nsCookieService.cpp) 6 // (netwerk/cookie/src/nsCookieService.cpp)
7 /* ***** BEGIN LICENSE BLOCK ***** 7 /* ***** BEGIN LICENSE BLOCK *****
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
9 * 9 *
10 * The contents of this file are subject to the Mozilla Public License Version 10 * The contents of this file are subject to the Mozilla Public License Version
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // DELETE_COOKIE_EVICTED_DOMAIN 313 // DELETE_COOKIE_EVICTED_DOMAIN
314 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 314 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
315 // DELETE_COOKIE_EVICTED_GLOBAL 315 // DELETE_COOKIE_EVICTED_GLOBAL
316 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 316 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
317 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE 317 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE
318 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 318 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
319 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE 319 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE
320 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 320 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
321 // DELETE_COOKIE_EXPIRED_OVERWRITE 321 // DELETE_COOKIE_EXPIRED_OVERWRITE
322 { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, 322 { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true },
323 // DELETE_COOKIE_OLD_SESSION_COOKIE
324 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false },
323 // DELETE_COOKIE_LAST_ENTRY 325 // DELETE_COOKIE_LAST_ENTRY
324 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false } 326 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }
325 }; 327 };
326 328
327 std::string BuildCookieLine(const CanonicalCookieVector& cookies) { 329 std::string BuildCookieLine(const CanonicalCookieVector& cookies) {
328 std::string cookie_line; 330 std::string cookie_line;
329 for (CanonicalCookieVector::const_iterator it = cookies.begin(); 331 for (CanonicalCookieVector::const_iterator it = cookies.begin();
330 it != cookies.end(); ++it) { 332 it != cookies.end(); ++it) {
331 if (it != cookies.begin()) 333 if (it != cookies.begin())
332 cookie_line += "; "; 334 cookie_line += "; ";
(...skipping 30 matching lines...) Expand all
363 365
364 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) 366 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate)
365 : initialized_(false), 367 : initialized_(false),
366 loaded_(false), 368 loaded_(false),
367 expiry_and_key_scheme_(expiry_and_key_default_), 369 expiry_and_key_scheme_(expiry_and_key_default_),
368 store_(store), 370 store_(store),
369 last_access_threshold_( 371 last_access_threshold_(
370 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), 372 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
371 delegate_(delegate), 373 delegate_(delegate),
372 last_statistic_record_time_(Time::Now()), 374 last_statistic_record_time_(Time::Now()),
373 keep_expired_cookies_(false) { 375 keep_expired_cookies_(false),
376 persist_session_cookies_(false),
377 old_session_cookie_behavior_(SESSION_COOKIES_UNDECIDED) {
374 InitializeHistograms(); 378 InitializeHistograms();
375 SetDefaultCookieableSchemes(); 379 SetDefaultCookieableSchemes();
376 } 380 }
377 381
378 CookieMonster::CookieMonster(PersistentCookieStore* store, 382 CookieMonster::CookieMonster(PersistentCookieStore* store,
379 Delegate* delegate, 383 Delegate* delegate,
380 int last_access_threshold_milliseconds) 384 int last_access_threshold_milliseconds)
381 : initialized_(false), 385 : initialized_(false),
382 loaded_(false), 386 loaded_(false),
383 expiry_and_key_scheme_(expiry_and_key_default_), 387 expiry_and_key_scheme_(expiry_and_key_default_),
384 store_(store), 388 store_(store),
385 last_access_threshold_(base::TimeDelta::FromMilliseconds( 389 last_access_threshold_(base::TimeDelta::FromMilliseconds(
386 last_access_threshold_milliseconds)), 390 last_access_threshold_milliseconds)),
387 delegate_(delegate), 391 delegate_(delegate),
388 last_statistic_record_time_(base::Time::Now()), 392 last_statistic_record_time_(base::Time::Now()),
389 keep_expired_cookies_(false) { 393 keep_expired_cookies_(false),
394 persist_session_cookies_(false),
395 old_session_cookie_behavior_(SESSION_COOKIES_UNDECIDED) {
390 InitializeHistograms(); 396 InitializeHistograms();
391 SetDefaultCookieableSchemes(); 397 SetDefaultCookieableSchemes();
392 } 398 }
393 399
394 // Parse a cookie expiration time. We try to be lenient, but we need to 400 // Parse a cookie expiration time. We try to be lenient, but we need to
395 // assume some order to distinguish the fields. The basic rules: 401 // assume some order to distinguish the fields. The basic rules:
396 // - The month name must be present and prefix the first 3 letters of the 402 // - The month name must be present and prefix the first 3 letters of the
397 // full month name (jan for January, jun for June). 403 // full month name (jan for January, jun for June).
398 // - If the year is <= 2 digits, it must occur after the day of month. 404 // - If the year is <= 2 digits, it must occur after the day of month.
399 // - The time must be of the format hh:mm:ss. 405 // - The time must be of the format hh:mm:ss.
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 if (matching_cookies.find(curit->second) != matching_cookies.end()) { 1398 if (matching_cookies.find(curit->second) != matching_cookies.end()) {
1393 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); 1399 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT);
1394 } 1400 }
1395 } 1401 }
1396 } 1402 }
1397 1403
1398 CookieMonster* CookieMonster::GetCookieMonster() { 1404 CookieMonster* CookieMonster::GetCookieMonster() {
1399 return this; 1405 return this;
1400 } 1406 }
1401 1407
1408 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) {
1409 persist_session_cookies_ = persist_session_cookies;
1410 }
1411
1412 void CookieMonster::SaveSessionCookies() {
1413 if (store_) {
1414 store_->SetClearLocalStateOnExit(false);
erikwright (departed) 2011/11/28 16:18:16 ...
erikwright (departed) 2011/11/28 16:31:44 Never mind, I've answered my own question.
1415 }
1416 }
1417
1418 void CookieMonster::RestoreOldSessionCookies() {
1419 old_session_cookie_behavior_ = SESSION_COOKIES_MERGE;
1420 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end(); ++it) {
1421 it->second->SetIsOldSessionCookie(false);
1422 if (delegate_) {
1423 delegate_->OnCookieChanged(
1424 *it->second, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT);
erikwright (departed) 2011/11/28 16:18:16 ...
erikwright (departed) 2011/11/28 16:31:44 I don't know what I was planning to comment on her
1425 }
1426 }
1427 }
1428
1429 void CookieMonster::DiscardOldSessionCookies() {
1430 old_session_cookie_behavior_ = SESSION_COOKIES_DELETE;
1431 // It is ok to call DeleteSessionCookies even if |store_| hasn't initialized
1432 // yet.
1433 if (store_)
1434 store_->DeleteSessionCookies();
erikwright (departed) 2011/11/28 16:18:16 Won't this also delete any new session cookies set
erikwright (departed) 2011/11/28 16:31:44 I suppose one solution is to pass a timestamp (i.e
marja 2011/11/29 12:56:01 Yep, it was buggy. The change of approach (always
1435 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
1436 CookieMap::iterator curit = it;
1437 ++it;
1438 if (curit->second->IsOldSessionCookie()) {
1439 // Don't sync this to store. Session cookies will be deleted from the
1440 // store separately.
1441 InternalDeleteCookie(curit, false, DELETE_COOKIE_OLD_SESSION_COOKIE);
1442 }
1443 }
1444 }
1445
1402 CookieMonster::~CookieMonster() { 1446 CookieMonster::~CookieMonster() {
1403 DeleteAll(false); 1447 DeleteAll(false);
1404 } 1448 }
1405 1449
1406 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, 1450 bool CookieMonster::SetCookieWithCreationTime(const GURL& url,
1407 const std::string& cookie_line, 1451 const std::string& cookie_line,
1408 const base::Time& creation_time) { 1452 const base::Time& creation_time) {
1409 DCHECK(!store_) << "This method is only to be used by unit-tests."; 1453 DCHECK(!store_) << "This method is only to be used by unit-tests.";
1410 base::AutoLock autolock(lock_); 1454 base::AutoLock autolock(lock_);
1411 1455
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 1505
1462 void CookieMonster::StoreLoadedCookies( 1506 void CookieMonster::StoreLoadedCookies(
1463 const std::vector<CanonicalCookie*>& cookies) { 1507 const std::vector<CanonicalCookie*>& cookies) {
1464 // Initialize the store and sync in any saved persistent cookies. We don't 1508 // Initialize the store and sync in any saved persistent cookies. We don't
1465 // care if it's expired, insert it so it can be garbage collected, removed, 1509 // care if it's expired, insert it so it can be garbage collected, removed,
1466 // and sync'd. 1510 // and sync'd.
1467 base::AutoLock autolock(lock_); 1511 base::AutoLock autolock(lock_);
1468 1512
1469 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); 1513 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin();
1470 it != cookies.end(); ++it) { 1514 it != cookies.end(); ++it) {
1515 bool notify = true;
1516 if (!(*it)->IsPersistent()) {
1517 if (old_session_cookie_behavior_ == SESSION_COOKIES_DELETE) {
1518 // Ignore this cookie; old session cookies are getting deleted from the
1519 // database.
1520 continue;
1521 } else if (old_session_cookie_behavior_ == SESSION_COOKIES_UNDECIDED) {
1522 // Mark restored session cookies as old session cookies, so they can be
1523 // discarded if needed.
1524 (*it)->SetIsOldSessionCookie(true);
1525 notify = false;
1526 }
1527 // else, |old_session_cookie_behavior_| is |SESSION_COOKIES_MERGE|, and we
1528 // treat the old session cookie as a normal cookie.
1529 }
1530
1471 int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue(); 1531 int64 cookie_creation_time = (*it)->CreationDate().ToInternalValue();
1472 1532
1473 if (creation_times_.insert(cookie_creation_time).second) { 1533 if (creation_times_.insert(cookie_creation_time).second) {
1474 InternalInsertCookie(GetKey((*it)->Domain()), *it, false); 1534 InternalInsertCookie(GetKey((*it)->Domain()), *it, false, notify);
1475 const Time cookie_access_time((*it)->LastAccessDate()); 1535 const Time cookie_access_time((*it)->LastAccessDate());
1476 if (earliest_access_time_.is_null() || 1536 if (earliest_access_time_.is_null() ||
1477 cookie_access_time < earliest_access_time_) 1537 cookie_access_time < earliest_access_time_)
1478 earliest_access_time_ = cookie_access_time; 1538 earliest_access_time_ = cookie_access_time;
1479 } else { 1539 } else {
1480 LOG(ERROR) << base::StringPrintf("Found cookies with duplicate creation " 1540 LOG(ERROR) << base::StringPrintf("Found cookies with duplicate creation "
1481 "times in backing store: " 1541 "times in backing store: "
1482 "{name='%s', domain='%s', path='%s'}", 1542 "{name='%s', domain='%s', path='%s'}",
1483 (*it)->Name().c_str(), 1543 (*it)->Name().c_str(),
1484 (*it)->Domain().c_str(), 1544 (*it)->Domain().c_str(),
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 CookieMap::iterator curit = its.first; 1766 CookieMap::iterator curit = its.first;
1707 CanonicalCookie* cc = curit->second; 1767 CanonicalCookie* cc = curit->second;
1708 ++its.first; 1768 ++its.first;
1709 1769
1710 // If the cookie is expired, delete it. 1770 // If the cookie is expired, delete it.
1711 if (cc->IsExpired(current) && !keep_expired_cookies_) { 1771 if (cc->IsExpired(current) && !keep_expired_cookies_) {
1712 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); 1772 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED);
1713 continue; 1773 continue;
1714 } 1774 }
1715 1775
1776 if (cc->IsOldSessionCookie()) {
1777 // The cookie is an old session cookie, and we're supposed to ignore
1778 // it. If |old_session_cookie_behavior_| is something else, |cookies_|
1779 // contains no cookies marked as session cookies.
erikwright (departed) 2011/11/28 16:18:16 'as _old_ session cookies'
marja 2011/11/29 12:56:01 (Obsolete)
1780 DCHECK(old_session_cookie_behavior_ == SESSION_COOKIES_UNDECIDED);
1781 continue;
erikwright (departed) 2011/11/28 16:18:16 I think we should also be deleting this cookie (fr
marja 2011/11/29 12:56:01 (Obsolete)
1782 }
1783
1716 // Filter out HttpOnly cookies, per options. 1784 // Filter out HttpOnly cookies, per options.
1717 if (options.exclude_httponly() && cc->IsHttpOnly()) 1785 if (options.exclude_httponly() && cc->IsHttpOnly())
1718 continue; 1786 continue;
1719 1787
1720 // Filter out secure cookies unless we're https. 1788 // Filter out secure cookies unless we're https.
1721 if (!secure && cc->IsSecure()) 1789 if (!secure && cc->IsSecure())
1722 continue; 1790 continue;
1723 1791
1724 // Filter out cookies that don't apply to this domain. 1792 // Filter out cookies that don't apply to this domain.
1725 if (expiry_and_key_scheme_ == EKS_KEEP_RECENT_AND_PURGE_ETLDP1 1793 if (expiry_and_key_scheme_ == EKS_KEEP_RECENT_AND_PURGE_ETLDP1
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 DELETE_COOKIE_EXPIRED_OVERWRITE : DELETE_COOKIE_OVERWRITE); 1832 DELETE_COOKIE_EXPIRED_OVERWRITE : DELETE_COOKIE_OVERWRITE);
1765 } 1833 }
1766 found_equivalent_cookie = true; 1834 found_equivalent_cookie = true;
1767 } 1835 }
1768 } 1836 }
1769 return skipped_httponly; 1837 return skipped_httponly;
1770 } 1838 }
1771 1839
1772 void CookieMonster::InternalInsertCookie(const std::string& key, 1840 void CookieMonster::InternalInsertCookie(const std::string& key,
1773 CanonicalCookie* cc, 1841 CanonicalCookie* cc,
1774 bool sync_to_store) { 1842 bool sync_to_store,
1843 bool notify) {
1775 lock_.AssertAcquired(); 1844 lock_.AssertAcquired();
1776 1845
1777 if (cc->IsPersistent() && store_ && sync_to_store) 1846 if ((cc->IsPersistent() || persist_session_cookies_) &&
1847 store_ && sync_to_store)
1778 store_->AddCookie(*cc); 1848 store_->AddCookie(*cc);
1779 cookies_.insert(CookieMap::value_type(key, cc)); 1849 cookies_.insert(CookieMap::value_type(key, cc));
1780 if (delegate_.get()) { 1850 if (notify && delegate_.get()) {
1781 delegate_->OnCookieChanged( 1851 delegate_->OnCookieChanged(
1782 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT); 1852 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT);
1783 } 1853 }
1784 } 1854 }
1785 1855
1786 bool CookieMonster::SetCookieWithCreationTimeAndOptions( 1856 bool CookieMonster::SetCookieWithCreationTimeAndOptions(
1787 const GURL& url, 1857 const GURL& url,
1788 const std::string& cookie_line, 1858 const std::string& cookie_line,
1789 const Time& creation_time_or_null, 1859 const Time& creation_time_or_null,
1790 const CookieOptions& options) { 1860 const CookieOptions& options) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 bool already_expired = (*cc)->IsExpired(creation_time); 1916 bool already_expired = (*cc)->IsExpired(creation_time);
1847 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(), 1917 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(),
1848 already_expired)) { 1918 already_expired)) {
1849 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie"; 1919 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie";
1850 return false; 1920 return false;
1851 } 1921 }
1852 1922
1853 VLOG(kVlogSetCookies) << "SetCookie() key: " << key << " cc: " 1923 VLOG(kVlogSetCookies) << "SetCookie() key: " << key << " cc: "
1854 << (*cc)->DebugString(); 1924 << (*cc)->DebugString();
1855 1925
1926 if (persist_session_cookies_ &&
1927 old_session_cookie_behavior_ == SESSION_COOKIES_UNDECIDED) {
1928 // We're setting a cookie, and there are session cookies for which we
jochen (gone - plz use gerrit) 2011/11/28 15:47:19 I think we should also delete all session cookies
erikwright (departed) 2011/11/28 16:18:16 Also, this should occur before the DeleteAnyEquiva
marja 2011/11/29 12:56:01 (Obsolete.)
1929 // haven't yet decided whether to merge them or not. Delete all old session
1930 // cookies for the same key. If |old_session_cookie_behavior_| is something
1931 // else than |SESSION_COOKIES_UNDECIDED|, |cookies_| contains no cookies
1932 // marked as session cookies.
erikwright (departed) 2011/11/28 16:18:16 'as _old_ session cookies'
marja 2011/11/29 12:56:01 (Obsolete.)
1933 CookieMapItPair its = cookies_.equal_range(key);
1934 while (its.first != its.second) {
1935 CookieMap::iterator curit = its.first;
1936 ++its.first;
1937 if (curit->second->IsOldSessionCookie()) {
1938 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT);
1939 }
1940 }
1941 }
1942
1856 // Realize that we might be setting an expired cookie, and the only point 1943 // Realize that we might be setting an expired cookie, and the only point
1857 // was to delete the cookie which we've already done. 1944 // was to delete the cookie which we've already done.
1858 if (!already_expired || keep_expired_cookies_) { 1945 if (!already_expired || keep_expired_cookies_) {
1859 // See InitializeHistograms() for details. 1946 // See InitializeHistograms() for details.
1860 if ((*cc)->DoesExpire()) { 1947 if ((*cc)->DoesExpire()) {
1861 histogram_expiration_duration_minutes_->Add( 1948 histogram_expiration_duration_minutes_->Add(
1862 ((*cc)->ExpiryDate() - creation_time).InMinutes()); 1949 ((*cc)->ExpiryDate() - creation_time).InMinutes());
1863 } 1950 }
1864 1951
1865 InternalInsertCookie(key, cc->release(), true); 1952 InternalInsertCookie(key, cc->release(), true, true);
1866 } 1953 }
1867 1954
1868 // We assume that hopefully setting a cookie will be less common than 1955 // We assume that hopefully setting a cookie will be less common than
1869 // querying a cookie. Since setting a cookie can put us over our limits, 1956 // querying a cookie. Since setting a cookie can put us over our limits,
1870 // make sure that we garbage collect... We can also make the assumption that 1957 // make sure that we garbage collect... We can also make the assumption that
1871 // if a cookie was set, in the common case it will be used soon after, 1958 // if a cookie was set, in the common case it will be used soon after,
1872 // and we will purge the expired cookies in GetCookies(). 1959 // and we will purge the expired cookies in GetCookies().
1873 GarbageCollect(creation_time, key); 1960 GarbageCollect(creation_time, key);
1874 1961
1875 return true; 1962 return true;
1876 } 1963 }
1877 1964
1878 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, 1965 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc,
1879 const Time& current) { 1966 const Time& current) {
1880 lock_.AssertAcquired(); 1967 lock_.AssertAcquired();
1881 1968
1882 // Based off the Mozilla code. When a cookie has been accessed recently, 1969 // Based off the Mozilla code. When a cookie has been accessed recently,
1883 // don't bother updating its access time again. This reduces the number of 1970 // don't bother updating its access time again. This reduces the number of
1884 // updates we do during pageload, which in turn reduces the chance our storage 1971 // updates we do during pageload, which in turn reduces the chance our storage
1885 // backend will hit its batch thresholds and be forced to update. 1972 // backend will hit its batch thresholds and be forced to update.
1886 if ((current - cc->LastAccessDate()) < last_access_threshold_) 1973 if ((current - cc->LastAccessDate()) < last_access_threshold_)
1887 return; 1974 return;
1888 1975
1889 // See InitializeHistograms() for details. 1976 // See InitializeHistograms() for details.
1890 histogram_between_access_interval_minutes_->Add( 1977 histogram_between_access_interval_minutes_->Add(
1891 (current - cc->LastAccessDate()).InMinutes()); 1978 (current - cc->LastAccessDate()).InMinutes());
1892 1979
1893 cc->SetLastAccessDate(current); 1980 cc->SetLastAccessDate(current);
1894 if (cc->IsPersistent() && store_) 1981 if ((cc->IsPersistent() || persist_session_cookies_) && store_)
1895 store_->UpdateCookieAccessTime(*cc); 1982 store_->UpdateCookieAccessTime(*cc);
1896 } 1983 }
1897 1984
1898 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, 1985 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it,
1899 bool sync_to_store, 1986 bool sync_to_store,
1900 DeletionCause deletion_cause) { 1987 DeletionCause deletion_cause) {
1901 lock_.AssertAcquired(); 1988 lock_.AssertAcquired();
1902 1989
1903 // Ideally, this would be asserted up where we define ChangeCauseMapping, 1990 // Ideally, this would be asserted up where we define ChangeCauseMapping,
1904 // but DeletionCause's visibility (or lack thereof) forces us to make 1991 // but DeletionCause's visibility (or lack thereof) forces us to make
1905 // this check here. 1992 // this check here.
1906 COMPILE_ASSERT(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, 1993 COMPILE_ASSERT(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1,
1907 ChangeCauseMapping_size_not_eq_DeletionCause_enum_size); 1994 ChangeCauseMapping_size_not_eq_DeletionCause_enum_size);
1908 1995
1909 // See InitializeHistograms() for details. 1996 // See InitializeHistograms() for details.
1910 if (deletion_cause != DELETE_COOKIE_DONT_RECORD) 1997 if (deletion_cause != DELETE_COOKIE_DONT_RECORD)
1911 histogram_cookie_deletion_cause_->Add(deletion_cause); 1998 histogram_cookie_deletion_cause_->Add(deletion_cause);
1912 1999
1913 CanonicalCookie* cc = it->second; 2000 CanonicalCookie* cc = it->second;
1914 VLOG(kVlogSetCookies) << "InternalDeleteCookie() cc: " << cc->DebugString(); 2001 VLOG(kVlogSetCookies) << "InternalDeleteCookie() cc: " << cc->DebugString();
1915 2002
1916 if (cc->IsPersistent() && store_ && sync_to_store) 2003 if ((cc->IsPersistent() || persist_session_cookies_)
2004 && store_ && sync_to_store)
1917 store_->DeleteCookie(*cc); 2005 store_->DeleteCookie(*cc);
1918 if (delegate_.get()) { 2006 if (delegate_.get()) {
1919 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; 2007 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause];
1920 2008
1921 if (mapping.notify) 2009 if (mapping.notify)
1922 delegate_->OnCookieChanged(*cc, true, mapping.cause); 2010 delegate_->OnCookieChanged(*cc, true, mapping.cause);
1923 } 2011 }
1924 cookies_.erase(it); 2012 cookies_.erase(it);
1925 delete cc; 2013 delete cc;
1926 } 2014 }
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 } else { 2600 } else {
2513 /* some attribute we don't know or don't care about. */ 2601 /* some attribute we don't know or don't care about. */
2514 } 2602 }
2515 } 2603 }
2516 } 2604 }
2517 2605
2518 CookieMonster::CanonicalCookie::CanonicalCookie() 2606 CookieMonster::CanonicalCookie::CanonicalCookie()
2519 : secure_(false), 2607 : secure_(false),
2520 httponly_(false), 2608 httponly_(false),
2521 has_expires_(false), 2609 has_expires_(false),
2522 is_persistent_(false) { 2610 is_persistent_(false),
2611 is_old_session_cookie_(false) {
2523 SetSessionCookieExpiryTime(); 2612 SetSessionCookieExpiryTime();
2524 } 2613 }
2525 2614
2526 CookieMonster::CanonicalCookie::CanonicalCookie( 2615 CookieMonster::CanonicalCookie::CanonicalCookie(
2527 const GURL& url, const std::string& name, const std::string& value, 2616 const GURL& url, const std::string& name, const std::string& value,
2528 const std::string& domain, const std::string& path, 2617 const std::string& domain, const std::string& path,
2529 const std::string& mac_key, const std::string& mac_algorithm, 2618 const std::string& mac_key, const std::string& mac_algorithm,
2530 const base::Time& creation, const base::Time& expiration, 2619 const base::Time& creation, const base::Time& expiration,
2531 const base::Time& last_access, bool secure, bool httponly, bool has_expires, 2620 const base::Time& last_access, bool secure, bool httponly, bool has_expires,
2532 bool is_persistent) 2621 bool is_persistent)
2533 : source_(GetCookieSourceFromURL(url)), 2622 : source_(GetCookieSourceFromURL(url)),
2534 name_(name), 2623 name_(name),
2535 value_(value), 2624 value_(value),
2536 domain_(domain), 2625 domain_(domain),
2537 path_(path), 2626 path_(path),
2538 mac_key_(mac_key), 2627 mac_key_(mac_key),
2539 mac_algorithm_(mac_algorithm), 2628 mac_algorithm_(mac_algorithm),
2540 creation_date_(creation), 2629 creation_date_(creation),
2541 expiry_date_(expiration), 2630 expiry_date_(expiration),
2542 last_access_date_(last_access), 2631 last_access_date_(last_access),
2543 secure_(secure), 2632 secure_(secure),
2544 httponly_(httponly), 2633 httponly_(httponly),
2545 has_expires_(has_expires), 2634 has_expires_(has_expires),
2546 is_persistent_(is_persistent) { 2635 is_persistent_(is_persistent),
2636 is_old_session_cookie_(false) {
2547 if (!has_expires_) { 2637 if (!has_expires_) {
2548 DCHECK(!is_persistent_); 2638 DCHECK(!is_persistent_);
2549 SetSessionCookieExpiryTime(); 2639 SetSessionCookieExpiryTime();
2550 } 2640 }
2551 } 2641 }
2552 2642
2553 CookieMonster::CanonicalCookie::CanonicalCookie(const GURL& url, 2643 CookieMonster::CanonicalCookie::CanonicalCookie(const GURL& url,
2554 const ParsedCookie& pc) 2644 const ParsedCookie& pc)
2555 : source_(GetCookieSourceFromURL(url)), 2645 : source_(GetCookieSourceFromURL(url)),
2556 name_(pc.Name()), 2646 name_(pc.Name()),
2557 value_(pc.Value()), 2647 value_(pc.Value()),
2558 path_(CanonPath(url, pc)), 2648 path_(CanonPath(url, pc)),
2559 mac_key_(pc.MACKey()), 2649 mac_key_(pc.MACKey()),
2560 mac_algorithm_(pc.MACAlgorithm()), 2650 mac_algorithm_(pc.MACAlgorithm()),
2561 creation_date_(Time::Now()), 2651 creation_date_(Time::Now()),
2562 last_access_date_(Time()), 2652 last_access_date_(Time()),
2563 secure_(pc.IsSecure()), 2653 secure_(pc.IsSecure()),
2564 httponly_(pc.IsHttpOnly()), 2654 httponly_(pc.IsHttpOnly()),
2565 has_expires_(pc.HasExpires()), 2655 has_expires_(pc.HasExpires()),
2566 is_persistent_(pc.HasExpires()) { 2656 is_persistent_(pc.HasExpires()),
2657 is_old_session_cookie_(false) {
2567 if (has_expires_) 2658 if (has_expires_)
2568 expiry_date_ = CanonExpiration(pc, creation_date_); 2659 expiry_date_ = CanonExpiration(pc, creation_date_);
2569 else 2660 else
2570 SetSessionCookieExpiryTime(); 2661 SetSessionCookieExpiryTime();
2571 2662
2572 // Do the best we can with the domain. 2663 // Do the best we can with the domain.
2573 std::string cookie_domain; 2664 std::string cookie_domain;
2574 std::string domain_string; 2665 std::string domain_string;
2575 if (pc.HasDomain()) { 2666 if (pc.HasDomain()) {
2576 domain_string = pc.Domain(); 2667 domain_string = pc.Domain();
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 std::string CookieMonster::CanonicalCookie::DebugString() const { 2853 std::string CookieMonster::CanonicalCookie::DebugString() const {
2763 return base::StringPrintf( 2854 return base::StringPrintf(
2764 "name: %s value: %s domain: %s path: %s creation: %" 2855 "name: %s value: %s domain: %s path: %s creation: %"
2765 PRId64, 2856 PRId64,
2766 name_.c_str(), value_.c_str(), 2857 name_.c_str(), value_.c_str(),
2767 domain_.c_str(), path_.c_str(), 2858 domain_.c_str(), path_.c_str(),
2768 static_cast<int64>(creation_date_.ToTimeT())); 2859 static_cast<int64>(creation_date_.ToTimeT()));
2769 } 2860 }
2770 2861
2771 } // namespace 2862 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698