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

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

Issue 2903213004: Refactor transmission of security of source and http_only mods in cookie_monster.cc. (Closed)
Patch Set: Add garbage collection to SetAllCookies() path. Created 3 years, 6 months 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
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 this->cookie_monster()->ComputeCookieDiff(&old_cookies, &list_, 758 this->cookie_monster()->ComputeCookieDiff(&old_cookies, &list_,
759 &positive_diff, &negative_diff); 759 &positive_diff, &negative_diff);
760 760
761 for (CookieList::const_iterator it = negative_diff.begin(); 761 for (CookieList::const_iterator it = negative_diff.begin();
762 it != negative_diff.end(); ++it) { 762 it != negative_diff.end(); ++it) {
763 this->cookie_monster()->DeleteCanonicalCookie(*it); 763 this->cookie_monster()->DeleteCanonicalCookie(*it);
764 } 764 }
765 765
766 bool result = true; 766 bool result = true;
767 if (positive_diff.size() > 0) 767 if (positive_diff.size() > 0)
768 result = this->cookie_monster()->SetCanonicalCookies(list_); 768 result = this->cookie_monster()->SetAllCookies(list_);
769 769
770 if (!callback_.is_null()) 770 if (!callback_.is_null())
771 callback_.Run(result); 771 callback_.Run(result);
772 } 772 }
773 773
774 // Task class for GetCookiesWithOptions call. 774 // Task class for GetCookiesWithOptions call.
775 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { 775 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask {
776 public: 776 public:
777 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, 777 GetCookiesWithOptionsTask(CookieMonster* cookie_monster,
778 const GURL& url, 778 const GURL& url,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 } 1078 }
1079 1079
1080 // Validate consistency of passed arguments. 1080 // Validate consistency of passed arguments.
1081 if (ParsedCookie::ParseTokenString(name) != name || 1081 if (ParsedCookie::ParseTokenString(name) != name ||
1082 ParsedCookie::ParseValueString(value) != value || 1082 ParsedCookie::ParseValueString(value) != value ||
1083 ParsedCookie::ParseValueString(domain) != domain || 1083 ParsedCookie::ParseValueString(domain) != domain ||
1084 ParsedCookie::ParseValueString(path) != path) { 1084 ParsedCookie::ParseValueString(path) != path) {
1085 return false; 1085 return false;
1086 } 1086 }
1087 1087
1088 // Validate passed arguments against URL.
1089 if (secure && !url.SchemeIsCryptographic())
1090 return false;
1091
1092 std::string cookie_domain; 1088 std::string cookie_domain;
1093 if (!cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain)) 1089 if (!cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain))
1094 return false; 1090 return false;
1095 1091
1096 std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path); 1092 std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path);
1097 if (!path.empty() && cookie_path != path) 1093 if (!path.empty() && cookie_path != path)
1098 return false; 1094 return false;
1099 1095
1100 // Canonicalize path again to make sure it escapes characters as needed. 1096 // Canonicalize path again to make sure it escapes characters as needed.
1101 url::Component path_component(0, cookie_path.length()); 1097 url::Component path_component(0, cookie_path.length());
1102 url::RawCanonOutputT<char> canon_path; 1098 url::RawCanonOutputT<char> canon_path;
1103 url::Component canon_path_component; 1099 url::Component canon_path_component;
1104 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, 1100 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path,
1105 &canon_path_component); 1101 &canon_path_component);
1106 cookie_path = std::string(canon_path.data() + canon_path_component.begin, 1102 cookie_path = std::string(canon_path.data() + canon_path_component.begin,
1107 canon_path_component.len); 1103 canon_path_component.len);
1108 1104
1109 std::unique_ptr<CanonicalCookie> cc(base::MakeUnique<CanonicalCookie>( 1105 std::unique_ptr<CanonicalCookie> cc(base::MakeUnique<CanonicalCookie>(
1110 name, value, cookie_domain, cookie_path, actual_creation_time, 1106 name, value, cookie_domain, cookie_path, actual_creation_time,
1111 expiration_time, last_access_time, secure, http_only, same_site, 1107 expiration_time, last_access_time, secure, http_only, same_site,
1112 priority)); 1108 priority));
1113 1109
1114 CookieOptions options; 1110 return SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(), true);
1115 options.set_include_httponly();
1116 options.set_same_site_cookie_mode(
1117 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
1118 return SetCanonicalCookie(std::move(cc), url, options);
1119 } 1111 }
1120 1112
1121 CookieList CookieMonster::GetAllCookies() { 1113 CookieList CookieMonster::GetAllCookies() {
1122 DCHECK(thread_checker_.CalledOnValidThread()); 1114 DCHECK(thread_checker_.CalledOnValidThread());
1123 1115
1124 // This function is being called to scrape the cookie list for management UI 1116 // This function is being called to scrape the cookie list for management UI
1125 // or similar. We shouldn't show expired cookies in this list since it will 1117 // or similar. We shouldn't show expired cookies in this list since it will
1126 // just be confusing to users, and this function is called rarely enough (and 1118 // just be confusing to users, and this function is called rarely enough (and
1127 // is already slow enough) that it's OK to take the time to garbage collect 1119 // is already slow enough) that it's OK to take the time to garbage collect
1128 // the expired cookies now. 1120 // the expired cookies now.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 // Even if a key is expired, insert it so it can be garbage collected, 1419 // Even if a key is expired, insert it so it can be garbage collected,
1428 // removed, and sync'd. 1420 // removed, and sync'd.
1429 CookieItVector cookies_with_control_chars; 1421 CookieItVector cookies_with_control_chars;
1430 1422
1431 for (auto& cookie : cookies) { 1423 for (auto& cookie : cookies) {
1432 int64_t cookie_creation_time = cookie->CreationDate().ToInternalValue(); 1424 int64_t cookie_creation_time = cookie->CreationDate().ToInternalValue();
1433 1425
1434 if (creation_times_.insert(cookie_creation_time).second) { 1426 if (creation_times_.insert(cookie_creation_time).second) {
1435 CanonicalCookie* cookie_ptr = cookie.get(); 1427 CanonicalCookie* cookie_ptr = cookie.get();
1436 CookieMap::iterator inserted = InternalInsertCookie( 1428 CookieMap::iterator inserted = InternalInsertCookie(
1437 GetKey(cookie_ptr->Domain()), std::move(cookie), GURL(), false); 1429 GetKey(cookie_ptr->Domain()), std::move(cookie), false);
1438 const Time cookie_access_time(cookie_ptr->LastAccessDate()); 1430 const Time cookie_access_time(cookie_ptr->LastAccessDate());
1439 if (earliest_access_time_.is_null() || 1431 if (earliest_access_time_.is_null() ||
1440 cookie_access_time < earliest_access_time_) 1432 cookie_access_time < earliest_access_time_)
1441 earliest_access_time_ = cookie_access_time; 1433 earliest_access_time_ = cookie_access_time;
1442 1434
1443 if (ContainsControlCharacter(cookie_ptr->Name()) || 1435 if (ContainsControlCharacter(cookie_ptr->Name()) ||
1444 ContainsControlCharacter(cookie_ptr->Value())) { 1436 ContainsControlCharacter(cookie_ptr->Value())) {
1445 cookies_with_control_chars.push_back(inserted); 1437 cookies_with_control_chars.push_back(inserted);
1446 } 1438 }
1447 } else { 1439 } else {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 // time if we've been requested to do so. 1633 // time if we've been requested to do so.
1642 if (options.update_access_time()) { 1634 if (options.update_access_time()) {
1643 InternalUpdateCookieAccessTime(cc, current); 1635 InternalUpdateCookieAccessTime(cc, current);
1644 } 1636 }
1645 cookies->push_back(cc); 1637 cookies->push_back(cc);
1646 } 1638 }
1647 } 1639 }
1648 1640
1649 bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, 1641 bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key,
1650 const CanonicalCookie& ecc, 1642 const CanonicalCookie& ecc,
1651 const GURL& source_url, 1643 bool source_secure,
1652 bool skip_httponly, 1644 bool skip_httponly,
1653 bool already_expired) { 1645 bool already_expired) {
1654 DCHECK(thread_checker_.CalledOnValidThread()); 1646 DCHECK(thread_checker_.CalledOnValidThread());
1655 1647
1656 bool found_equivalent_cookie = false; 1648 bool found_equivalent_cookie = false;
1657 bool skipped_httponly = false; 1649 bool skipped_httponly = false;
1658 bool skipped_secure_cookie = false; 1650 bool skipped_secure_cookie = false;
1659 1651
1660 histogram_cookie_delete_equivalent_->Add(COOKIE_DELETE_EQUIVALENT_ATTEMPT); 1652 histogram_cookie_delete_equivalent_->Add(COOKIE_DELETE_EQUIVALENT_ATTEMPT);
1661 1653
1662 for (CookieMapItPair its = cookies_.equal_range(key); 1654 for (CookieMapItPair its = cookies_.equal_range(key);
1663 its.first != its.second;) { 1655 its.first != its.second;) {
1664 CookieMap::iterator curit = its.first; 1656 CookieMap::iterator curit = its.first;
1665 CanonicalCookie* cc = curit->second.get(); 1657 CanonicalCookie* cc = curit->second.get();
1666 ++its.first; 1658 ++its.first;
1667 1659
1668 // If the cookie is being set from an insecure scheme, then if a cookie 1660 // If the cookie is being set from an insecure scheme, then if a cookie
1669 // already exists with the same name and it is Secure, then the cookie 1661 // already exists with the same name and it is Secure, then the cookie
1670 // should *not* be updated if they domain-match and ignoring the path 1662 // should *not* be updated if they domain-match and ignoring the path
1671 // attribute. 1663 // attribute.
1672 // 1664 //
1673 // See: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-alone 1665 // See: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-alone
1674 if (cc->IsSecure() && !source_url.SchemeIsCryptographic() && 1666 if (cc->IsSecure() && !source_secure &&
1675 ecc.IsEquivalentForSecureCookieMatching(*cc)) { 1667 ecc.IsEquivalentForSecureCookieMatching(*cc)) {
1676 skipped_secure_cookie = true; 1668 skipped_secure_cookie = true;
1677 histogram_cookie_delete_equivalent_->Add( 1669 histogram_cookie_delete_equivalent_->Add(
1678 COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE); 1670 COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE);
1679 // If the cookie is equivalent to the new cookie and wouldn't have been 1671 // If the cookie is equivalent to the new cookie and wouldn't have been
1680 // skipped for being HTTP-only, record that it is a skipped secure cookie 1672 // skipped for being HTTP-only, record that it is a skipped secure cookie
1681 // that would have been deleted otherwise. 1673 // that would have been deleted otherwise.
1682 if (ecc.IsEquivalent(*cc)) { 1674 if (ecc.IsEquivalent(*cc)) {
1683 found_equivalent_cookie = true; 1675 found_equivalent_cookie = true;
1684 1676
(...skipping 20 matching lines...) Expand all
1705 } 1697 }
1706 found_equivalent_cookie = true; 1698 found_equivalent_cookie = true;
1707 } 1699 }
1708 } 1700 }
1709 return skipped_httponly || skipped_secure_cookie; 1701 return skipped_httponly || skipped_secure_cookie;
1710 } 1702 }
1711 1703
1712 CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( 1704 CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie(
1713 const std::string& key, 1705 const std::string& key,
1714 std::unique_ptr<CanonicalCookie> cc, 1706 std::unique_ptr<CanonicalCookie> cc,
1715 const GURL& source_url,
1716 bool sync_to_store) { 1707 bool sync_to_store) {
1717 DCHECK(thread_checker_.CalledOnValidThread()); 1708 DCHECK(thread_checker_.CalledOnValidThread());
1718 CanonicalCookie* cc_ptr = cc.get(); 1709 CanonicalCookie* cc_ptr = cc.get();
1719 1710
1720 if ((cc_ptr->IsPersistent() || persist_session_cookies_) && store_.get() && 1711 if ((cc_ptr->IsPersistent() || persist_session_cookies_) && store_.get() &&
1721 sync_to_store) 1712 sync_to_store)
1722 store_->AddCookie(*cc_ptr); 1713 store_->AddCookie(*cc_ptr);
1723 CookieMap::iterator inserted = 1714 CookieMap::iterator inserted =
1724 cookies_.insert(CookieMap::value_type(key, std::move(cc))); 1715 cookies_.insert(CookieMap::value_type(key, std::move(cc)));
1725 if (delegate_.get()) { 1716 if (delegate_.get()) {
1726 delegate_->OnCookieChanged(*cc_ptr, false, 1717 delegate_->OnCookieChanged(*cc_ptr, false,
1727 CookieStore::ChangeCause::INSERTED); 1718 CookieStore::ChangeCause::INSERTED);
1728 } 1719 }
1729 1720
1730 // See InitializeHistograms() for details. 1721 // See InitializeHistograms() for details.
1731 int32_t type_sample = cc_ptr->SameSite() != CookieSameSite::NO_RESTRICTION 1722 int32_t type_sample = cc_ptr->SameSite() != CookieSameSite::NO_RESTRICTION
1732 ? 1 << COOKIE_TYPE_SAME_SITE 1723 ? 1 << COOKIE_TYPE_SAME_SITE
1733 : 0; 1724 : 0;
1734 type_sample |= cc_ptr->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; 1725 type_sample |= cc_ptr->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0;
1735 type_sample |= cc_ptr->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; 1726 type_sample |= cc_ptr->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0;
1736 histogram_cookie_type_->Add(type_sample); 1727 histogram_cookie_type_->Add(type_sample);
1737 1728
1738 // Histogram the type of scheme used on URLs that set cookies. This
1739 // intentionally includes cookies that are set or overwritten by
1740 // http:// URLs, but not cookies that are cleared by http:// URLs, to
1741 // understand if the former behavior can be deprecated for Secure
1742 // cookies.
1743 if (!source_url.is_empty()) {
1744 CookieSource cookie_source_sample;
1745 if (source_url.SchemeIsCryptographic()) {
1746 cookie_source_sample =
1747 cc_ptr->IsSecure()
1748 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME
1749 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME;
1750 } else {
1751 cookie_source_sample =
1752 cc_ptr->IsSecure()
1753 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME
1754 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME;
1755 }
1756 histogram_cookie_source_scheme_->Add(cookie_source_sample);
1757 }
1758
1759 RunCookieChangedCallbacks(*cc_ptr, CookieStore::ChangeCause::INSERTED); 1729 RunCookieChangedCallbacks(*cc_ptr, CookieStore::ChangeCause::INSERTED);
1760 1730
1761 return inserted; 1731 return inserted;
1762 } 1732 }
1763 1733
1764 bool CookieMonster::SetCookieWithCreationTimeAndOptions( 1734 bool CookieMonster::SetCookieWithCreationTimeAndOptions(
1765 const GURL& url, 1735 const GURL& url,
1766 const std::string& cookie_line, 1736 const std::string& cookie_line,
1767 const Time& creation_time_or_null, 1737 const Time& creation_time_or_null,
1768 const CookieOptions& options) { 1738 const CookieOptions& options) {
1769 DCHECK(thread_checker_.CalledOnValidThread()); 1739 DCHECK(thread_checker_.CalledOnValidThread());
1770 1740
1771 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; 1741 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line;
1772 1742
1773 Time creation_time = creation_time_or_null; 1743 Time creation_time = creation_time_or_null;
1774 if (creation_time.is_null()) { 1744 if (creation_time.is_null()) {
1775 creation_time = CurrentTime(); 1745 creation_time = CurrentTime();
1776 last_time_seen_ = creation_time; 1746 last_time_seen_ = creation_time;
1777 } 1747 }
1778 1748
1779 std::unique_ptr<CanonicalCookie> cc( 1749 std::unique_ptr<CanonicalCookie> cc(
1780 CanonicalCookie::Create(url, cookie_line, creation_time, options)); 1750 CanonicalCookie::Create(url, cookie_line, creation_time, options));
1781 1751
1782 if (!cc.get()) { 1752 if (!cc.get()) {
1783 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; 1753 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie";
1784 return false; 1754 return false;
1785 } 1755 }
1786 return SetCanonicalCookie(std::move(cc), url, options); 1756 return SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(),
1757 !options.exclude_httponly());
1787 } 1758 }
1788 1759
1789 bool CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc, 1760 bool CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
1790 const GURL& source_url, 1761 bool secure_source,
1791 const CookieOptions& options) { 1762 bool modify_http_only) {
1792 DCHECK(thread_checker_.CalledOnValidThread()); 1763 DCHECK(thread_checker_.CalledOnValidThread());
1793 1764
1765 if (cc->IsSecure() && !secure_source)
1766 return false;
1767
1794 Time creation_time = cc->CreationDate(); 1768 Time creation_time = cc->CreationDate();
1795 const std::string key(GetKey(cc->Domain())); 1769 const std::string key(GetKey(cc->Domain()));
1796 bool already_expired = cc->IsExpired(creation_time); 1770 bool already_expired = cc->IsExpired(creation_time);
1797 1771
1798 if (DeleteAnyEquivalentCookie(key, *cc, source_url, 1772 if (DeleteAnyEquivalentCookie(key, *cc, secure_source, !modify_http_only,
1799 options.exclude_httponly(), already_expired)) { 1773 already_expired)) {
1800 std::string error; 1774 std::string error;
1801 error = 1775 error =
1802 "SetCookie() not clobbering httponly cookie or secure cookie for " 1776 "SetCookie() not clobbering httponly cookie or secure cookie for "
1803 "insecure scheme"; 1777 "insecure scheme";
1804 1778
1805 VLOG(kVlogSetCookies) << error; 1779 VLOG(kVlogSetCookies) << error;
1806 return false; 1780 return false;
1807 } 1781 }
1808 1782
1809 VLOG(kVlogSetCookies) << "SetCookie() key: " << key 1783 VLOG(kVlogSetCookies) << "SetCookie() key: " << key
1810 << " cc: " << cc->DebugString(); 1784 << " cc: " << cc->DebugString();
1811 1785
1812 // Realize that we might be setting an expired cookie, and the only point 1786 // Realize that we might be setting an expired cookie, and the only point
1813 // was to delete the cookie which we've already done. 1787 // was to delete the cookie which we've already done.
1814 if (!already_expired) { 1788 if (!already_expired) {
1815 // See InitializeHistograms() for details. 1789 // See InitializeHistograms() for details.
1816 if (cc->IsPersistent()) { 1790 if (cc->IsPersistent()) {
1817 histogram_expiration_duration_minutes_->Add( 1791 histogram_expiration_duration_minutes_->Add(
1818 (cc->ExpiryDate() - creation_time).InMinutes()); 1792 (cc->ExpiryDate() - creation_time).InMinutes());
1819 } 1793 }
1820 1794
1821 InternalInsertCookie(key, std::move(cc), source_url, true); 1795 // Histogram the type of scheme used on URLs that set cookies. This
1796 // intentionally includes cookies that are set or overwritten by
1797 // http:// URLs, but not cookies that are cleared by http:// URLs, to
1798 // understand if the former behavior can be deprecated for Secure
1799 // cookies.
1800 CookieSource cookie_source_sample =
1801 (secure_source
1802 ? (cc->IsSecure()
1803 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME
1804 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME)
1805 : (cc->IsSecure()
1806 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME
1807 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME));
1808 histogram_cookie_source_scheme_->Add(cookie_source_sample);
1809
1810 InternalInsertCookie(key, std::move(cc), true);
1822 } else { 1811 } else {
1823 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; 1812 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie.";
1824 } 1813 }
1825 1814
1826 // We assume that hopefully setting a cookie will be less common than 1815 // We assume that hopefully setting a cookie will be less common than
1827 // querying a cookie. Since setting a cookie can put us over our limits, 1816 // querying a cookie. Since setting a cookie can put us over our limits,
1828 // make sure that we garbage collect... We can also make the assumption that 1817 // make sure that we garbage collect... We can also make the assumption that
1829 // if a cookie was set, in the common case it will be used soon after, 1818 // if a cookie was set, in the common case it will be used soon after,
1830 // and we will purge the expired cookies in GetCookies(). 1819 // and we will purge the expired cookies in GetCookies().
1831 GarbageCollect(creation_time, key); 1820 GarbageCollect(creation_time, key);
1832 1821
1833 return true; 1822 return true;
1834 } 1823 }
1835 1824
1836 bool CookieMonster::SetCanonicalCookies(const CookieList& list) { 1825 bool CookieMonster::SetAllCookies(const CookieList& list) {
1837 DCHECK(thread_checker_.CalledOnValidThread()); 1826 DCHECK(thread_checker_.CalledOnValidThread());
1827 for (const auto& cookie : list) {
1828 const std::string key(GetKey(cookie.Domain()));
1829 Time creation_time = cookie.CreationDate();
1830 bool already_expired = cookie.IsExpired(creation_time);
1838 1831
1839 CookieOptions options; 1832 bool result =
1840 options.set_include_httponly(); 1833 DeleteAnyEquivalentCookie(key, cookie, true, false, already_expired);
1834 DCHECK(!result);
1841 1835
1842 for (const auto& cookie : list) { 1836 if (already_expired)
1843 // Use an empty GURL. This method does not support setting secure cookies. 1837 continue;
1844 if (!SetCanonicalCookie(base::MakeUnique<CanonicalCookie>(cookie), GURL(), 1838
1845 options)) { 1839 if (cookie.IsPersistent()) {
1846 return false; 1840 histogram_expiration_duration_minutes_->Add(
1841 (cookie.ExpiryDate() - creation_time).InMinutes());
1847 } 1842 }
1843
1844 InternalInsertCookie(key, base::MakeUnique<CanonicalCookie>(cookie), true);
1845 GarbageCollect(creation_time, key);
1848 } 1846 }
1849 1847
1848 // TODO(rdsmith): If this function always returns the same value, it
1849 // shouldn't have a return value. But it should also be deleted (see
1850 // https://codereview.chromium.org/2882063002/#msg64), which would
1851 // solve the return value problem.
1850 return true; 1852 return true;
1851 } 1853 }
1852 1854
1853 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, 1855 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc,
1854 const Time& current) { 1856 const Time& current) {
1855 DCHECK(thread_checker_.CalledOnValidThread()); 1857 DCHECK(thread_checker_.CalledOnValidThread());
1856 1858
1857 // Based off the Mozilla code. When a cookie has been accessed recently, 1859 // Based off the Mozilla code. When a cookie has been accessed recently,
1858 // don't bother updating its access time again. This reduces the number of 1860 // don't bother updating its access time again. This reduces the number of
1859 // updates we do during pageload, which in turn reduces the chance our storage 1861 // updates we do during pageload, which in turn reduces the chance our storage
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 it != hook_map_.end(); ++it) { 2443 it != hook_map_.end(); ++it) {
2442 std::pair<GURL, std::string> key = it->first; 2444 std::pair<GURL, std::string> key = it->first;
2443 if (cookie.IncludeForRequestURL(key.first, opts) && 2445 if (cookie.IncludeForRequestURL(key.first, opts) &&
2444 cookie.Name() == key.second) { 2446 cookie.Name() == key.second) {
2445 it->second->Notify(cookie, cause); 2447 it->second->Notify(cookie, cause);
2446 } 2448 }
2447 } 2449 }
2448 } 2450 }
2449 2451
2450 } // namespace net 2452 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698