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

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

Issue 2867693004: Snapshot of all changes to get jumbo in blink and content.
Patch Set: Rebased again Created 3 years, 5 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/BUILD.gn ('k') | net/disk_cache/simple/simple_index_file.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) 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 struct OrderByCreationTimeDesc { 168 struct OrderByCreationTimeDesc {
169 bool operator()(const CookieMonster::CookieMap::iterator& a, 169 bool operator()(const CookieMonster::CookieMap::iterator& a,
170 const CookieMonster::CookieMap::iterator& b) const { 170 const CookieMonster::CookieMap::iterator& b) const {
171 return a->second->CreationDate() > b->second->CreationDate(); 171 return a->second->CreationDate() > b->second->CreationDate();
172 } 172 }
173 }; 173 };
174 174
175 // Constants for use in VLOG 175 // Constants for use in VLOG
176 const int kVlogPerCookieMonster = 1; 176 const int kVlogPerCookieMonster = 1;
177 const int kVlogGarbageCollection = 5; 177 const int kVlogGarbageCollection = 5;
178 const int kVlogSetCookies = 7; 178 const int kVlogSetCookies2 = 7;
179 const int kVlogGetCookies = 9; 179 const int kVlogGetCookies = 9;
180 180
181 // Mozilla sorts on the path length (longest first), and then it 181 // Mozilla sorts on the path length (longest first), and then it
182 // sorts by creation time (oldest first). 182 // sorts by creation time (oldest first).
183 // The RFC says the sort order for the domain attribute is undefined. 183 // The RFC says the sort order for the domain attribute is undefined.
184 bool CookieSorter(CanonicalCookie* cc1, CanonicalCookie* cc2) { 184 bool CookieSorter(CanonicalCookie* cc1, CanonicalCookie* cc2) {
185 if (cc1->Path().length() == cc2->Path().length()) 185 if (cc1->Path().length() == cc2->Path().length())
186 return cc1->CreationDate() < cc2->CreationDate(); 186 return cc1->CreationDate() < cc2->CreationDate();
187 return cc1->Path().length() > cc2->Path().length(); 187 return cc1->Path().length() > cc2->Path().length();
188 } 188 }
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 } 1360 }
1361 1361
1362 void CookieMonster::SetCookieWithCreationTimeAndOptions( 1362 void CookieMonster::SetCookieWithCreationTimeAndOptions(
1363 const GURL& url, 1363 const GURL& url,
1364 const std::string& cookie_line, 1364 const std::string& cookie_line,
1365 const Time& creation_time_or_null, 1365 const Time& creation_time_or_null,
1366 const CookieOptions& options, 1366 const CookieOptions& options,
1367 SetCookiesCallback callback) { 1367 SetCookiesCallback callback) {
1368 DCHECK(thread_checker_.CalledOnValidThread()); 1368 DCHECK(thread_checker_.CalledOnValidThread());
1369 1369
1370 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; 1370 VLOG(kVlogSetCookies2) << "SetCookie() line: " << cookie_line;
1371 1371
1372 Time creation_time = creation_time_or_null; 1372 Time creation_time = creation_time_or_null;
1373 if (creation_time.is_null()) { 1373 if (creation_time.is_null()) {
1374 creation_time = CurrentTime(); 1374 creation_time = CurrentTime();
1375 last_time_seen_ = creation_time; 1375 last_time_seen_ = creation_time;
1376 } 1376 }
1377 1377
1378 std::unique_ptr<CanonicalCookie> cc( 1378 std::unique_ptr<CanonicalCookie> cc(
1379 CanonicalCookie::Create(url, cookie_line, creation_time, options)); 1379 CanonicalCookie::Create(url, cookie_line, creation_time, options));
1380 1380
1381 if (!cc.get()) { 1381 if (!cc.get()) {
1382 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; 1382 VLOG(kVlogSetCookies2) << "WARNING: Failed to allocate CanonicalCookie";
1383 MaybeRunCookieCallback(std::move(callback), false); 1383 MaybeRunCookieCallback(std::move(callback), false);
1384 return; 1384 return;
1385 } 1385 }
1386 SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(), 1386 SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(),
1387 !options.exclude_httponly(), std::move(callback)); 1387 !options.exclude_httponly(), std::move(callback));
1388 } 1388 }
1389 1389
1390 void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc, 1390 void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
1391 bool secure_source, 1391 bool secure_source,
1392 bool modify_http_only, 1392 bool modify_http_only,
(...skipping 19 matching lines...) Expand all
1412 } 1412 }
1413 bool already_expired = cc->IsExpired(creation_date); 1413 bool already_expired = cc->IsExpired(creation_date);
1414 1414
1415 if (DeleteAnyEquivalentCookie(key, *cc, secure_source, !modify_http_only, 1415 if (DeleteAnyEquivalentCookie(key, *cc, secure_source, !modify_http_only,
1416 already_expired)) { 1416 already_expired)) {
1417 std::string error; 1417 std::string error;
1418 error = 1418 error =
1419 "SetCookie() not clobbering httponly cookie or secure cookie for " 1419 "SetCookie() not clobbering httponly cookie or secure cookie for "
1420 "insecure scheme"; 1420 "insecure scheme";
1421 1421
1422 VLOG(kVlogSetCookies) << error; 1422 VLOG(kVlogSetCookies2) << error;
1423 MaybeRunCookieCallback(std::move(callback), false); 1423 MaybeRunCookieCallback(std::move(callback), false);
1424 return; 1424 return;
1425 } 1425 }
1426 1426
1427 VLOG(kVlogSetCookies) << "SetCookie() key: " << key 1427 VLOG(kVlogSetCookies2) << "SetCookie() key: " << key
1428 << " cc: " << cc->DebugString(); 1428 << " cc: " << cc->DebugString();
1429 1429
1430 // Realize that we might be setting an expired cookie, and the only point 1430 // Realize that we might be setting an expired cookie, and the only point
1431 // was to delete the cookie which we've already done. 1431 // was to delete the cookie which we've already done.
1432 if (!already_expired) { 1432 if (!already_expired) {
1433 // See InitializeHistograms() for details. 1433 // See InitializeHistograms() for details.
1434 if (cc->IsPersistent()) { 1434 if (cc->IsPersistent()) {
1435 histogram_expiration_duration_minutes_->Add( 1435 histogram_expiration_duration_minutes_->Add(
1436 (cc->ExpiryDate() - creation_date).InMinutes()); 1436 (cc->ExpiryDate() - creation_date).InMinutes());
1437 } 1437 }
1438 1438
1439 // Histogram the type of scheme used on URLs that set cookies. This 1439 // Histogram the type of scheme used on URLs that set cookies. This
1440 // intentionally includes cookies that are set or overwritten by 1440 // intentionally includes cookies that are set or overwritten by
1441 // http:// URLs, but not cookies that are cleared by http:// URLs, to 1441 // http:// URLs, but not cookies that are cleared by http:// URLs, to
1442 // understand if the former behavior can be deprecated for Secure 1442 // understand if the former behavior can be deprecated for Secure
1443 // cookies. 1443 // cookies.
1444 CookieSource cookie_source_sample = 1444 CookieSource cookie_source_sample =
1445 (secure_source 1445 (secure_source
1446 ? (cc->IsSecure() 1446 ? (cc->IsSecure()
1447 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME 1447 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME
1448 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME) 1448 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME)
1449 : (cc->IsSecure() 1449 : (cc->IsSecure()
1450 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME 1450 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME
1451 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME)); 1451 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME));
1452 histogram_cookie_source_scheme_->Add(cookie_source_sample); 1452 histogram_cookie_source_scheme_->Add(cookie_source_sample);
1453 1453
1454 InternalInsertCookie(key, std::move(cc), true); 1454 InternalInsertCookie(key, std::move(cc), true);
1455 } else { 1455 } else {
1456 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; 1456 VLOG(kVlogSetCookies2) << "SetCookie() not storing already expired cookie.";
1457 } 1457 }
1458 1458
1459 // We assume that hopefully setting a cookie will be less common than 1459 // We assume that hopefully setting a cookie will be less common than
1460 // querying a cookie. Since setting a cookie can put us over our limits, 1460 // querying a cookie. Since setting a cookie can put us over our limits,
1461 // make sure that we garbage collect... We can also make the assumption that 1461 // make sure that we garbage collect... We can also make the assumption that
1462 // if a cookie was set, in the common case it will be used soon after, 1462 // if a cookie was set, in the common case it will be used soon after,
1463 // and we will purge the expired cookies in GetCookies(). 1463 // and we will purge the expired cookies in GetCookies().
1464 GarbageCollect(creation_date, key); 1464 GarbageCollect(creation_date, key);
1465 1465
1466 MaybeRunCookieCallback(std::move(callback), true); 1466 MaybeRunCookieCallback(std::move(callback), true);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 DeletionCause deletion_cause) { 1522 DeletionCause deletion_cause) {
1523 DCHECK(thread_checker_.CalledOnValidThread()); 1523 DCHECK(thread_checker_.CalledOnValidThread());
1524 1524
1525 // Ideally, this would be asserted up where we define kChangeCauseMapping, 1525 // Ideally, this would be asserted up where we define kChangeCauseMapping,
1526 // but DeletionCause's visibility (or lack thereof) forces us to make 1526 // but DeletionCause's visibility (or lack thereof) forces us to make
1527 // this check here. 1527 // this check here.
1528 static_assert(arraysize(kChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, 1528 static_assert(arraysize(kChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1,
1529 "kChangeCauseMapping size should match DeletionCause size"); 1529 "kChangeCauseMapping size should match DeletionCause size");
1530 1530
1531 CanonicalCookie* cc = it->second.get(); 1531 CanonicalCookie* cc = it->second.get();
1532 VLOG(kVlogSetCookies) << "InternalDeleteCookie()" 1532 VLOG(kVlogSetCookies2) << "InternalDeleteCookie()"
1533 << ", cause:" << deletion_cause 1533 << ", cause:" << deletion_cause
1534 << ", cc: " << cc->DebugString(); 1534 << ", cc: " << cc->DebugString();
1535 1535
1536 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && 1536 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() &&
1537 sync_to_store) 1537 sync_to_store)
1538 store_->DeleteCookie(*cc); 1538 store_->DeleteCookie(*cc);
1539 ChangeCausePair mapping = kChangeCauseMapping[deletion_cause]; 1539 ChangeCausePair mapping = kChangeCauseMapping[deletion_cause];
1540 if (delegate_.get() && mapping.notify) 1540 if (delegate_.get() && mapping.notify)
1541 delegate_->OnCookieChanged(*cc, true, mapping.cause); 1541 delegate_->OnCookieChanged(*cc, true, mapping.cause);
1542 RunCookieChangedCallbacks(*cc, mapping.cause); 1542 RunCookieChangedCallbacks(*cc, mapping.cause);
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
2029 it != hook_map_.end(); ++it) { 2029 it != hook_map_.end(); ++it) {
2030 std::pair<GURL, std::string> key = it->first; 2030 std::pair<GURL, std::string> key = it->first;
2031 if (cookie.IncludeForRequestURL(key.first, opts) && 2031 if (cookie.IncludeForRequestURL(key.first, opts) &&
2032 cookie.Name() == key.second) { 2032 cookie.Name() == key.second) {
2033 it->second->Notify(cookie, cause); 2033 it->second->Notify(cookie, cause);
2034 } 2034 }
2035 } 2035 }
2036 } 2036 }
2037 2037
2038 } // namespace net 2038 } // namespace net
OLDNEW
« no previous file with comments | « net/BUILD.gn ('k') | net/disk_cache/simple/simple_index_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698