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

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

Issue 2974363002: Simplify CookieMonster::SetAllCookies{,Async}() implementation. (Closed)
Patch Set: Sync'd to p485987 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/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 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 // if a cookie was set, in the common case it will be used soon after, 1481 // if a cookie was set, in the common case it will be used soon after,
1482 // and we will purge the expired cookies in GetCookies(). 1482 // and we will purge the expired cookies in GetCookies().
1483 GarbageCollect(creation_date, key); 1483 GarbageCollect(creation_date, key);
1484 1484
1485 ConditionalCookieCallback(std::move(callback), true); 1485 ConditionalCookieCallback(std::move(callback), true);
1486 } 1486 }
1487 1487
1488 void CookieMonster::SetAllCookies(CookieList list, 1488 void CookieMonster::SetAllCookies(CookieList list,
1489 SetCookiesCallback callback) { 1489 SetCookiesCallback callback) {
1490 DCHECK(thread_checker_.CalledOnValidThread()); 1490 DCHECK(thread_checker_.CalledOnValidThread());
1491 CookieList positive_diff;
1492 CookieList negative_diff;
1493 1491
1494 CookieList old_cookies; 1492 // Nuke the existing store.
1495 old_cookies.reserve(cookies_.size()); 1493 for (auto prev_it = cookies_.begin(), next_it = prev_it;
1496 for (const auto& cookie : cookies_) 1494 next_it != cookies_.end(); prev_it = next_it) {
mmenke 2017/07/12 18:56:35 I think this can just be: while (!cookies_.empty(
Randy Smith (Not in Mondays) 2017/07/12 20:07:08 You're right, that's quite a bit nicer. Done.
1497 old_cookies.push_back(*cookie.second.get()); 1495 ++next_it;
1498 1496 // TODO(rdsmith): The CANONICAL is a lie.
1499 ComputeCookieDiff(&old_cookies, &list, &positive_diff, &negative_diff); 1497 InternalDeleteCookie(prev_it, true, DELETE_COOKIE_CANONICAL);
mmenke 2017/07/12 18:56:35 Is ComputeCookieDiff still used? I'd check it mys
Randy Smith (Not in Mondays) 2017/07/12 20:07:08 Used by test code in order to test it, which I thi
1500
1501 for (const auto& cookie_to_delete : negative_diff) {
1502 for (CookieMapItPair its =
1503 cookies_.equal_range(GetKey(cookie_to_delete.Domain()));
1504 its.first != its.second; ++its.first) {
1505 // The creation date acts as the unique index...
1506 if (its.first->second->CreationDate() ==
1507 cookie_to_delete.CreationDate()) {
1508 // TODO(rdsmith): DELETE_COOKIE_CANONICAL is incorrect and should
1509 // be changed.
1510 InternalDeleteCookie(its.first, true, DELETE_COOKIE_CANONICAL);
1511 break;
1512 }
1513 }
1514 } 1498 }
1515 1499
1516 if (positive_diff.size() == 0) { 1500 // Set all passed in cookies.
1517 ConditionalCookieCallback(std::move(callback), true);
1518 return;
1519 }
1520
1521 for (const auto& cookie : list) { 1501 for (const auto& cookie : list) {
1522 const std::string key(GetKey(cookie.Domain())); 1502 const std::string key(GetKey(cookie.Domain()));
1523 Time creation_time = cookie.CreationDate(); 1503 Time creation_time = cookie.CreationDate();
1524 bool already_expired = cookie.IsExpired(creation_time); 1504 if (cookie.IsExpired(creation_time))
1525
1526 bool result =
1527 DeleteAnyEquivalentCookie(key, cookie, true, false, already_expired);
1528 DCHECK(!result);
1529
1530 if (already_expired)
1531 continue; 1505 continue;
1532 1506
1533 if (cookie.IsPersistent()) { 1507 if (cookie.IsPersistent()) {
1534 histogram_expiration_duration_minutes_->Add( 1508 histogram_expiration_duration_minutes_->Add(
1535 (cookie.ExpiryDate() - creation_time).InMinutes()); 1509 (cookie.ExpiryDate() - creation_time).InMinutes());
1536 } 1510 }
1537 1511
1538 InternalInsertCookie(key, base::MakeUnique<CanonicalCookie>(cookie), true); 1512 InternalInsertCookie(key, base::MakeUnique<CanonicalCookie>(cookie), true);
1539 GarbageCollect(creation_time, key); 1513 GarbageCollect(creation_time, key);
1540 } 1514 }
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 it != hook_map_.end(); ++it) { 2086 it != hook_map_.end(); ++it) {
2113 std::pair<GURL, std::string> key = it->first; 2087 std::pair<GURL, std::string> key = it->first;
2114 if (cookie.IncludeForRequestURL(key.first, opts) && 2088 if (cookie.IncludeForRequestURL(key.first, opts) &&
2115 cookie.Name() == key.second) { 2089 cookie.Name() == key.second) {
2116 it->second->Notify(cookie, cause); 2090 it->second->Notify(cookie, cause);
2117 } 2091 }
2118 } 2092 }
2119 } 2093 }
2120 2094
2121 } // namespace net 2095 } // 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