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

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: Code review. 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
« no previous file with comments | « net/base/cookie_monster.h ('k') | net/base/cookie_monster_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 363
364 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) 364 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate)
365 : initialized_(false), 365 : initialized_(false),
366 loaded_(false), 366 loaded_(false),
367 expiry_and_key_scheme_(expiry_and_key_default_), 367 expiry_and_key_scheme_(expiry_and_key_default_),
368 store_(store), 368 store_(store),
369 last_access_threshold_( 369 last_access_threshold_(
370 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), 370 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
371 delegate_(delegate), 371 delegate_(delegate),
372 last_statistic_record_time_(Time::Now()), 372 last_statistic_record_time_(Time::Now()),
373 keep_expired_cookies_(false) { 373 keep_expired_cookies_(false),
374 persist_session_cookies_(false) {
374 InitializeHistograms(); 375 InitializeHistograms();
375 SetDefaultCookieableSchemes(); 376 SetDefaultCookieableSchemes();
376 } 377 }
377 378
378 CookieMonster::CookieMonster(PersistentCookieStore* store, 379 CookieMonster::CookieMonster(PersistentCookieStore* store,
379 Delegate* delegate, 380 Delegate* delegate,
380 int last_access_threshold_milliseconds) 381 int last_access_threshold_milliseconds)
381 : initialized_(false), 382 : initialized_(false),
382 loaded_(false), 383 loaded_(false),
383 expiry_and_key_scheme_(expiry_and_key_default_), 384 expiry_and_key_scheme_(expiry_and_key_default_),
384 store_(store), 385 store_(store),
385 last_access_threshold_(base::TimeDelta::FromMilliseconds( 386 last_access_threshold_(base::TimeDelta::FromMilliseconds(
386 last_access_threshold_milliseconds)), 387 last_access_threshold_milliseconds)),
387 delegate_(delegate), 388 delegate_(delegate),
388 last_statistic_record_time_(base::Time::Now()), 389 last_statistic_record_time_(base::Time::Now()),
389 keep_expired_cookies_(false) { 390 keep_expired_cookies_(false),
391 persist_session_cookies_(false) {
390 InitializeHistograms(); 392 InitializeHistograms();
391 SetDefaultCookieableSchemes(); 393 SetDefaultCookieableSchemes();
392 } 394 }
393 395
394 // Parse a cookie expiration time. We try to be lenient, but we need to 396 // 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: 397 // 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 398 // - The month name must be present and prefix the first 3 letters of the
397 // full month name (jan for January, jun for June). 399 // full month name (jan for January, jun for June).
398 // - If the year is <= 2 digits, it must occur after the day of month. 400 // - 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. 401 // - 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()) { 1394 if (matching_cookies.find(curit->second) != matching_cookies.end()) {
1393 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); 1395 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT);
1394 } 1396 }
1395 } 1397 }
1396 } 1398 }
1397 1399
1398 CookieMonster* CookieMonster::GetCookieMonster() { 1400 CookieMonster* CookieMonster::GetCookieMonster() {
1399 return this; 1401 return this;
1400 } 1402 }
1401 1403
1404 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) {
1405 // This function must be called before the CookieMonster is used.
1406 DCHECK(!initialized_);
1407 persist_session_cookies_ = persist_session_cookies;
1408 }
1409
1410 void CookieMonster::SaveSessionCookies() {
1411 if (store_) {
1412 store_->SetClearLocalStateOnExit(false);
1413 }
1414 }
1415
1402 CookieMonster::~CookieMonster() { 1416 CookieMonster::~CookieMonster() {
1403 DeleteAll(false); 1417 DeleteAll(false);
1404 } 1418 }
1405 1419
1406 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, 1420 bool CookieMonster::SetCookieWithCreationTime(const GURL& url,
1407 const std::string& cookie_line, 1421 const std::string& cookie_line,
1408 const base::Time& creation_time) { 1422 const base::Time& creation_time) {
1409 DCHECK(!store_) << "This method is only to be used by unit-tests."; 1423 DCHECK(!store_) << "This method is only to be used by unit-tests.";
1410 base::AutoLock autolock(lock_); 1424 base::AutoLock autolock(lock_);
1411 1425
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 } 1781 }
1768 } 1782 }
1769 return skipped_httponly; 1783 return skipped_httponly;
1770 } 1784 }
1771 1785
1772 void CookieMonster::InternalInsertCookie(const std::string& key, 1786 void CookieMonster::InternalInsertCookie(const std::string& key,
1773 CanonicalCookie* cc, 1787 CanonicalCookie* cc,
1774 bool sync_to_store) { 1788 bool sync_to_store) {
1775 lock_.AssertAcquired(); 1789 lock_.AssertAcquired();
1776 1790
1777 if (cc->IsPersistent() && store_ && sync_to_store) 1791 if ((cc->IsPersistent() || persist_session_cookies_) &&
1792 store_ && sync_to_store)
1778 store_->AddCookie(*cc); 1793 store_->AddCookie(*cc);
1779 cookies_.insert(CookieMap::value_type(key, cc)); 1794 cookies_.insert(CookieMap::value_type(key, cc));
1780 if (delegate_.get()) { 1795 if (delegate_.get()) {
1781 delegate_->OnCookieChanged( 1796 delegate_->OnCookieChanged(
1782 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT); 1797 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT);
1783 } 1798 }
1784 } 1799 }
1785 1800
1786 bool CookieMonster::SetCookieWithCreationTimeAndOptions( 1801 bool CookieMonster::SetCookieWithCreationTimeAndOptions(
1787 const GURL& url, 1802 const GURL& url,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 // updates we do during pageload, which in turn reduces the chance our storage 1899 // 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. 1900 // backend will hit its batch thresholds and be forced to update.
1886 if ((current - cc->LastAccessDate()) < last_access_threshold_) 1901 if ((current - cc->LastAccessDate()) < last_access_threshold_)
1887 return; 1902 return;
1888 1903
1889 // See InitializeHistograms() for details. 1904 // See InitializeHistograms() for details.
1890 histogram_between_access_interval_minutes_->Add( 1905 histogram_between_access_interval_minutes_->Add(
1891 (current - cc->LastAccessDate()).InMinutes()); 1906 (current - cc->LastAccessDate()).InMinutes());
1892 1907
1893 cc->SetLastAccessDate(current); 1908 cc->SetLastAccessDate(current);
1894 if (cc->IsPersistent() && store_) 1909 if ((cc->IsPersistent() || persist_session_cookies_) && store_)
1895 store_->UpdateCookieAccessTime(*cc); 1910 store_->UpdateCookieAccessTime(*cc);
1896 } 1911 }
1897 1912
1898 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, 1913 void CookieMonster::InternalDeleteCookie(CookieMap::iterator it,
1899 bool sync_to_store, 1914 bool sync_to_store,
1900 DeletionCause deletion_cause) { 1915 DeletionCause deletion_cause) {
1901 lock_.AssertAcquired(); 1916 lock_.AssertAcquired();
1902 1917
1903 // Ideally, this would be asserted up where we define ChangeCauseMapping, 1918 // Ideally, this would be asserted up where we define ChangeCauseMapping,
1904 // but DeletionCause's visibility (or lack thereof) forces us to make 1919 // but DeletionCause's visibility (or lack thereof) forces us to make
1905 // this check here. 1920 // this check here.
1906 COMPILE_ASSERT(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, 1921 COMPILE_ASSERT(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1,
1907 ChangeCauseMapping_size_not_eq_DeletionCause_enum_size); 1922 ChangeCauseMapping_size_not_eq_DeletionCause_enum_size);
1908 1923
1909 // See InitializeHistograms() for details. 1924 // See InitializeHistograms() for details.
1910 if (deletion_cause != DELETE_COOKIE_DONT_RECORD) 1925 if (deletion_cause != DELETE_COOKIE_DONT_RECORD)
1911 histogram_cookie_deletion_cause_->Add(deletion_cause); 1926 histogram_cookie_deletion_cause_->Add(deletion_cause);
1912 1927
1913 CanonicalCookie* cc = it->second; 1928 CanonicalCookie* cc = it->second;
1914 VLOG(kVlogSetCookies) << "InternalDeleteCookie() cc: " << cc->DebugString(); 1929 VLOG(kVlogSetCookies) << "InternalDeleteCookie() cc: " << cc->DebugString();
1915 1930
1916 if (cc->IsPersistent() && store_ && sync_to_store) 1931 if ((cc->IsPersistent() || persist_session_cookies_)
1932 && store_ && sync_to_store)
1917 store_->DeleteCookie(*cc); 1933 store_->DeleteCookie(*cc);
1918 if (delegate_.get()) { 1934 if (delegate_.get()) {
1919 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; 1935 ChangeCausePair mapping = ChangeCauseMapping[deletion_cause];
1920 1936
1921 if (mapping.notify) 1937 if (mapping.notify)
1922 delegate_->OnCookieChanged(*cc, true, mapping.cause); 1938 delegate_->OnCookieChanged(*cc, true, mapping.cause);
1923 } 1939 }
1924 cookies_.erase(it); 1940 cookies_.erase(it);
1925 delete cc; 1941 delete cc;
1926 } 1942 }
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 std::string CookieMonster::CanonicalCookie::DebugString() const { 2778 std::string CookieMonster::CanonicalCookie::DebugString() const {
2763 return base::StringPrintf( 2779 return base::StringPrintf(
2764 "name: %s value: %s domain: %s path: %s creation: %" 2780 "name: %s value: %s domain: %s path: %s creation: %"
2765 PRId64, 2781 PRId64,
2766 name_.c_str(), value_.c_str(), 2782 name_.c_str(), value_.c_str(),
2767 domain_.c_str(), path_.c_str(), 2783 domain_.c_str(), path_.c_str(),
2768 static_cast<int64>(creation_date_.ToTimeT())); 2784 static_cast<int64>(creation_date_.ToTimeT()));
2769 } 2785 }
2770 2786
2771 } // namespace 2787 } // namespace
OLDNEW
« no previous file with comments | « net/base/cookie_monster.h ('k') | net/base/cookie_monster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698