OLD | NEW |
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 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 | 1126 |
1127 return num_deleted; | 1127 return num_deleted; |
1128 } | 1128 } |
1129 | 1129 |
1130 int CookieMonster::DeleteAllForHost(const GURL& url) { | 1130 int CookieMonster::DeleteAllForHost(const GURL& url) { |
1131 base::AutoLock autolock(lock_); | 1131 base::AutoLock autolock(lock_); |
1132 | 1132 |
1133 if (!HasCookieableScheme(url)) | 1133 if (!HasCookieableScheme(url)) |
1134 return 0; | 1134 return 0; |
1135 | 1135 |
1136 const std::string scheme(url.scheme()); | |
1137 const std::string host(url.host()); | 1136 const std::string host(url.host()); |
1138 | 1137 |
1139 // We store host cookies in the store by their canonical host name; | 1138 // We store host cookies in the store by their canonical host name; |
1140 // domain cookies are stored with a leading ".". So this is a pretty | 1139 // domain cookies are stored with a leading ".". So this is a pretty |
1141 // simple lookup and per-cookie delete. | 1140 // simple lookup and per-cookie delete. |
1142 int num_deleted = 0; | 1141 int num_deleted = 0; |
1143 for (CookieMapItPair its = cookies_.equal_range(GetKey(host)); | 1142 for (CookieMapItPair its = cookies_.equal_range(GetKey(host)); |
1144 its.first != its.second;) { | 1143 its.first != its.second;) { |
1145 CookieMap::iterator curit = its.first; | 1144 CookieMap::iterator curit = its.first; |
1146 ++its.first; | 1145 ++its.first; |
1147 | 1146 |
1148 const CanonicalCookie* const cc = curit->second; | 1147 const CanonicalCookie* const cc = curit->second; |
1149 | 1148 |
1150 // Delete only on a match as a host cookie. | 1149 // Delete only on a match as a host cookie. |
1151 if (cc->IsHostCookie() && cc->IsDomainMatch(scheme, host)) { | 1150 if (cc->IsHostCookie() && cc->IsDomainMatch(host)) { |
1152 num_deleted++; | 1151 num_deleted++; |
1153 | 1152 |
1154 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); | 1153 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); |
1155 } | 1154 } |
1156 } | 1155 } |
1157 return num_deleted; | 1156 return num_deleted; |
1158 } | 1157 } |
1159 | 1158 |
1160 bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { | 1159 bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { |
1161 base::AutoLock autolock(lock_); | 1160 base::AutoLock autolock(lock_); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 | 1595 |
1597 void CookieMonster::FindCookiesForKey( | 1596 void CookieMonster::FindCookiesForKey( |
1598 const std::string& key, | 1597 const std::string& key, |
1599 const GURL& url, | 1598 const GURL& url, |
1600 const CookieOptions& options, | 1599 const CookieOptions& options, |
1601 const Time& current, | 1600 const Time& current, |
1602 bool update_access_time, | 1601 bool update_access_time, |
1603 std::vector<CanonicalCookie*>* cookies) { | 1602 std::vector<CanonicalCookie*>* cookies) { |
1604 lock_.AssertAcquired(); | 1603 lock_.AssertAcquired(); |
1605 | 1604 |
1606 const std::string scheme(url.scheme()); | |
1607 const std::string host(url.host()); | 1605 const std::string host(url.host()); |
1608 bool secure = url.SchemeIsSecure(); | 1606 bool secure = url.SchemeIsSecure(); |
1609 | 1607 |
1610 for (CookieMapItPair its = cookies_.equal_range(key); | 1608 for (CookieMapItPair its = cookies_.equal_range(key); |
1611 its.first != its.second; ) { | 1609 its.first != its.second; ) { |
1612 CookieMap::iterator curit = its.first; | 1610 CookieMap::iterator curit = its.first; |
1613 CanonicalCookie* cc = curit->second; | 1611 CanonicalCookie* cc = curit->second; |
1614 ++its.first; | 1612 ++its.first; |
1615 | 1613 |
1616 // If the cookie is expired, delete it. | 1614 // If the cookie is expired, delete it. |
1617 if (cc->IsExpired(current) && !keep_expired_cookies_) { | 1615 if (cc->IsExpired(current) && !keep_expired_cookies_) { |
1618 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); | 1616 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); |
1619 continue; | 1617 continue; |
1620 } | 1618 } |
1621 | 1619 |
1622 // Filter out HttpOnly cookies, per options. | 1620 // Filter out HttpOnly cookies, per options. |
1623 if (options.exclude_httponly() && cc->IsHttpOnly()) | 1621 if (options.exclude_httponly() && cc->IsHttpOnly()) |
1624 continue; | 1622 continue; |
1625 | 1623 |
1626 // Filter out secure cookies unless we're https. | 1624 // Filter out secure cookies unless we're https. |
1627 if (!secure && cc->IsSecure()) | 1625 if (!secure && cc->IsSecure()) |
1628 continue; | 1626 continue; |
1629 | 1627 |
1630 // Filter out cookies that don't apply to this domain. | 1628 // Filter out cookies that don't apply to this domain. |
1631 if (!cc->IsDomainMatch(scheme, host)) | 1629 if (!cc->IsDomainMatch(host)) |
1632 continue; | 1630 continue; |
1633 | 1631 |
1634 if (!cc->IsOnPath(url.path())) | 1632 if (!cc->IsOnPath(url.path())) |
1635 continue; | 1633 continue; |
1636 | 1634 |
1637 // Add this cookie to the set of matching cookies. Update the access | 1635 // Add this cookie to the set of matching cookies. Update the access |
1638 // time if we've been requested to do so. | 1636 // time if we've been requested to do so. |
1639 if (update_access_time) { | 1637 if (update_access_time) { |
1640 InternalUpdateCookieAccessTime(cc, current); | 1638 InternalUpdateCookieAccessTime(cc, current); |
1641 } | 1639 } |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 | 2113 |
2116 // The system resolution is not high enough, so we can have multiple | 2114 // The system resolution is not high enough, so we can have multiple |
2117 // set cookies that result in the same system time. When this happens, we | 2115 // set cookies that result in the same system time. When this happens, we |
2118 // increment by one Time unit. Let's hope computers don't get too fast. | 2116 // increment by one Time unit. Let's hope computers don't get too fast. |
2119 Time CookieMonster::CurrentTime() { | 2117 Time CookieMonster::CurrentTime() { |
2120 return std::max(Time::Now(), | 2118 return std::max(Time::Now(), |
2121 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2119 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
2122 } | 2120 } |
2123 | 2121 |
2124 } // namespace net | 2122 } // namespace net |
OLD | NEW |