| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 struct OrderByCreationTimeDesc { | 167 struct OrderByCreationTimeDesc { |
| 168 bool operator()(const CookieMonster::CookieMap::iterator& a, | 168 bool operator()(const CookieMonster::CookieMap::iterator& a, |
| 169 const CookieMonster::CookieMap::iterator& b) const { | 169 const CookieMonster::CookieMap::iterator& b) const { |
| 170 return a->second->CreationDate() > b->second->CreationDate(); | 170 return a->second->CreationDate() > b->second->CreationDate(); |
| 171 } | 171 } |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 // Constants for use in VLOG | 174 // Constants for use in VLOG |
| 175 const int kVlogPerCookieMonster = 1; | 175 const int kVlogPerCookieMonster = 1; |
| 176 const int kVlogGarbageCollection = 5; | 176 const int kVlogGarbageCollection = 5; |
| 177 const int kVlogSetCookies = 7; | 177 const int kVlogSetCookies2 = 7; |
| 178 const int kVlogGetCookies = 9; | 178 const int kVlogGetCookies = 9; |
| 179 | 179 |
| 180 // Mozilla sorts on the path length (longest first), and then it | 180 // Mozilla sorts on the path length (longest first), and then it |
| 181 // sorts by creation time (oldest first). | 181 // sorts by creation time (oldest first). |
| 182 // The RFC says the sort order for the domain attribute is undefined. | 182 // The RFC says the sort order for the domain attribute is undefined. |
| 183 bool CookieSorter(CanonicalCookie* cc1, CanonicalCookie* cc2) { | 183 bool CookieSorter(CanonicalCookie* cc1, CanonicalCookie* cc2) { |
| 184 if (cc1->Path().length() == cc2->Path().length()) | 184 if (cc1->Path().length() == cc2->Path().length()) |
| 185 return cc1->CreationDate() < cc2->CreationDate(); | 185 return cc1->CreationDate() < cc2->CreationDate(); |
| 186 return cc1->Path().length() > cc2->Path().length(); | 186 return cc1->Path().length() > cc2->Path().length(); |
| 187 } | 187 } |
| (...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 } | 1367 } |
| 1368 | 1368 |
| 1369 void CookieMonster::SetCookieWithCreationTimeAndOptions( | 1369 void CookieMonster::SetCookieWithCreationTimeAndOptions( |
| 1370 const GURL& url, | 1370 const GURL& url, |
| 1371 const std::string& cookie_line, | 1371 const std::string& cookie_line, |
| 1372 const Time& creation_time_or_null, | 1372 const Time& creation_time_or_null, |
| 1373 const CookieOptions& options, | 1373 const CookieOptions& options, |
| 1374 SetCookiesCallback callback) { | 1374 SetCookiesCallback callback) { |
| 1375 DCHECK(thread_checker_.CalledOnValidThread()); | 1375 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1376 | 1376 |
| 1377 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; | 1377 VLOG(kVlogSetCookies2) << "SetCookie() line: " << cookie_line; |
| 1378 | 1378 |
| 1379 Time creation_time = creation_time_or_null; | 1379 Time creation_time = creation_time_or_null; |
| 1380 if (creation_time.is_null()) { | 1380 if (creation_time.is_null()) { |
| 1381 creation_time = CurrentTime(); | 1381 creation_time = CurrentTime(); |
| 1382 last_time_seen_ = creation_time; | 1382 last_time_seen_ = creation_time; |
| 1383 } | 1383 } |
| 1384 | 1384 |
| 1385 std::unique_ptr<CanonicalCookie> cc( | 1385 std::unique_ptr<CanonicalCookie> cc( |
| 1386 CanonicalCookie::Create(url, cookie_line, creation_time, options)); | 1386 CanonicalCookie::Create(url, cookie_line, creation_time, options)); |
| 1387 | 1387 |
| 1388 if (!cc.get()) { | 1388 if (!cc.get()) { |
| 1389 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; | 1389 VLOG(kVlogSetCookies2) << "WARNING: Failed to allocate CanonicalCookie"; |
| 1390 MaybeRunCookieCallback(std::move(callback), false); | 1390 MaybeRunCookieCallback(std::move(callback), false); |
| 1391 return; | 1391 return; |
| 1392 } | 1392 } |
| 1393 SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(), | 1393 SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(), |
| 1394 !options.exclude_httponly(), std::move(callback)); | 1394 !options.exclude_httponly(), std::move(callback)); |
| 1395 } | 1395 } |
| 1396 | 1396 |
| 1397 void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc, | 1397 void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc, |
| 1398 bool secure_source, | 1398 bool secure_source, |
| 1399 bool modify_http_only, | 1399 bool modify_http_only, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1420 } | 1420 } |
| 1421 bool already_expired = cc->IsExpired(creation_date); | 1421 bool already_expired = cc->IsExpired(creation_date); |
| 1422 | 1422 |
| 1423 if (DeleteAnyEquivalentCookie(key, *cc, secure_source, !modify_http_only, | 1423 if (DeleteAnyEquivalentCookie(key, *cc, secure_source, !modify_http_only, |
| 1424 already_expired)) { | 1424 already_expired)) { |
| 1425 std::string error; | 1425 std::string error; |
| 1426 error = | 1426 error = |
| 1427 "SetCookie() not clobbering httponly cookie or secure cookie for " | 1427 "SetCookie() not clobbering httponly cookie or secure cookie for " |
| 1428 "insecure scheme"; | 1428 "insecure scheme"; |
| 1429 | 1429 |
| 1430 VLOG(kVlogSetCookies) << error; | 1430 VLOG(kVlogSetCookies2) << error; |
| 1431 MaybeRunCookieCallback(std::move(callback), false); | 1431 MaybeRunCookieCallback(std::move(callback), false); |
| 1432 return; | 1432 return; |
| 1433 } | 1433 } |
| 1434 | 1434 |
| 1435 VLOG(kVlogSetCookies) << "SetCookie() key: " << key | 1435 VLOG(kVlogSetCookies2) << "SetCookie() key: " << key |
| 1436 << " cc: " << cc->DebugString(); | 1436 << " cc: " << cc->DebugString(); |
| 1437 | 1437 |
| 1438 // Realize that we might be setting an expired cookie, and the only point | 1438 // Realize that we might be setting an expired cookie, and the only point |
| 1439 // was to delete the cookie which we've already done. | 1439 // was to delete the cookie which we've already done. |
| 1440 if (!already_expired) { | 1440 if (!already_expired) { |
| 1441 // See InitializeHistograms() for details. | 1441 // See InitializeHistograms() for details. |
| 1442 if (cc->IsPersistent()) { | 1442 if (cc->IsPersistent()) { |
| 1443 histogram_expiration_duration_minutes_->Add( | 1443 histogram_expiration_duration_minutes_->Add( |
| 1444 (cc->ExpiryDate() - creation_date).InMinutes()); | 1444 (cc->ExpiryDate() - creation_date).InMinutes()); |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 // Histogram the type of scheme used on URLs that set cookies. This | 1447 // Histogram the type of scheme used on URLs that set cookies. This |
| 1448 // intentionally includes cookies that are set or overwritten by | 1448 // intentionally includes cookies that are set or overwritten by |
| 1449 // http:// URLs, but not cookies that are cleared by http:// URLs, to | 1449 // http:// URLs, but not cookies that are cleared by http:// URLs, to |
| 1450 // understand if the former behavior can be deprecated for Secure | 1450 // understand if the former behavior can be deprecated for Secure |
| 1451 // cookies. | 1451 // cookies. |
| 1452 CookieSource cookie_source_sample = | 1452 CookieSource cookie_source_sample = |
| 1453 (secure_source | 1453 (secure_source |
| 1454 ? (cc->IsSecure() | 1454 ? (cc->IsSecure() |
| 1455 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME | 1455 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME |
| 1456 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME) | 1456 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME) |
| 1457 : (cc->IsSecure() | 1457 : (cc->IsSecure() |
| 1458 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME | 1458 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME |
| 1459 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME)); | 1459 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME)); |
| 1460 histogram_cookie_source_scheme_->Add(cookie_source_sample); | 1460 histogram_cookie_source_scheme_->Add(cookie_source_sample); |
| 1461 | 1461 |
| 1462 InternalInsertCookie(key, std::move(cc), true); | 1462 InternalInsertCookie(key, std::move(cc), true); |
| 1463 } else { | 1463 } else { |
| 1464 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; | 1464 VLOG(kVlogSetCookies2) << "SetCookie() not storing already expired cookie."; |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 // We assume that hopefully setting a cookie will be less common than | 1467 // We assume that hopefully setting a cookie will be less common than |
| 1468 // querying a cookie. Since setting a cookie can put us over our limits, | 1468 // querying a cookie. Since setting a cookie can put us over our limits, |
| 1469 // make sure that we garbage collect... We can also make the assumption that | 1469 // make sure that we garbage collect... We can also make the assumption that |
| 1470 // if a cookie was set, in the common case it will be used soon after, | 1470 // if a cookie was set, in the common case it will be used soon after, |
| 1471 // and we will purge the expired cookies in GetCookies(). | 1471 // and we will purge the expired cookies in GetCookies(). |
| 1472 GarbageCollect(creation_date, key); | 1472 GarbageCollect(creation_date, key); |
| 1473 | 1473 |
| 1474 MaybeRunCookieCallback(std::move(callback), true); | 1474 MaybeRunCookieCallback(std::move(callback), true); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 DeletionCause deletion_cause) { | 1530 DeletionCause deletion_cause) { |
| 1531 DCHECK(thread_checker_.CalledOnValidThread()); | 1531 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1532 | 1532 |
| 1533 // Ideally, this would be asserted up where we define kChangeCauseMapping, | 1533 // Ideally, this would be asserted up where we define kChangeCauseMapping, |
| 1534 // but DeletionCause's visibility (or lack thereof) forces us to make | 1534 // but DeletionCause's visibility (or lack thereof) forces us to make |
| 1535 // this check here. | 1535 // this check here. |
| 1536 static_assert(arraysize(kChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, | 1536 static_assert(arraysize(kChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, |
| 1537 "kChangeCauseMapping size should match DeletionCause size"); | 1537 "kChangeCauseMapping size should match DeletionCause size"); |
| 1538 | 1538 |
| 1539 CanonicalCookie* cc = it->second.get(); | 1539 CanonicalCookie* cc = it->second.get(); |
| 1540 VLOG(kVlogSetCookies) << "InternalDeleteCookie()" | 1540 VLOG(kVlogSetCookies2) << "InternalDeleteCookie()" |
| 1541 << ", cause:" << deletion_cause | 1541 << ", cause:" << deletion_cause |
| 1542 << ", cc: " << cc->DebugString(); | 1542 << ", cc: " << cc->DebugString(); |
| 1543 | 1543 |
| 1544 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && | 1544 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
| 1545 sync_to_store) | 1545 sync_to_store) |
| 1546 store_->DeleteCookie(*cc); | 1546 store_->DeleteCookie(*cc); |
| 1547 ChangeCausePair mapping = kChangeCauseMapping[deletion_cause]; | 1547 ChangeCausePair mapping = kChangeCauseMapping[deletion_cause]; |
| 1548 RunCookieChangedCallbacks(*cc, mapping.notify, mapping.cause); | 1548 RunCookieChangedCallbacks(*cc, mapping.notify, mapping.cause); |
| 1549 cookies_.erase(it); | 1549 cookies_.erase(it); |
| 1550 } | 1550 } |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2040 cookie.Name() == key.second) { | 2040 cookie.Name() == key.second) { |
| 2041 it->second->Notify(cookie, cause); | 2041 it->second->Notify(cookie, cause); |
| 2042 } | 2042 } |
| 2043 } | 2043 } |
| 2044 | 2044 |
| 2045 if (notify_global_hooks) | 2045 if (notify_global_hooks) |
| 2046 global_hook_map_->Notify(cookie, cause); | 2046 global_hook_map_->Notify(cookie, cause); |
| 2047 } | 2047 } |
| 2048 | 2048 |
| 2049 } // namespace net | 2049 } // namespace net |
| OLD | NEW |