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

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

Issue 11339032: Account for server vs host clock skew in cookie expiration times. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable test on Android as there's no test server Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | net/cookies/cookie_options.h » ('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 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 const CookieOptions& options) { 1696 const CookieOptions& options) {
1697 lock_.AssertAcquired(); 1697 lock_.AssertAcquired();
1698 1698
1699 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; 1699 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line;
1700 1700
1701 Time creation_time = creation_time_or_null; 1701 Time creation_time = creation_time_or_null;
1702 if (creation_time.is_null()) { 1702 if (creation_time.is_null()) {
1703 creation_time = CurrentTime(); 1703 creation_time = CurrentTime();
1704 last_time_seen_ = creation_time; 1704 last_time_seen_ = creation_time;
1705 } 1705 }
1706 Time server_time;
1707 if (options.has_server_time())
1708 server_time = options.server_time();
1709 else
1710 server_time = creation_time;
1706 1711
1707 // Parse the cookie. 1712 // Parse the cookie.
1708 ParsedCookie pc(cookie_line); 1713 ParsedCookie pc(cookie_line);
1709 1714
1710 if (!pc.IsValid()) { 1715 if (!pc.IsValid()) {
1711 VLOG(kVlogSetCookies) << "WARNING: Couldn't parse cookie"; 1716 VLOG(kVlogSetCookies) << "WARNING: Couldn't parse cookie";
1712 return false; 1717 return false;
1713 } 1718 }
1714 1719
1715 if (options.exclude_httponly() && pc.IsHttpOnly()) { 1720 if (options.exclude_httponly() && pc.IsHttpOnly()) {
1716 VLOG(kVlogSetCookies) << "SetCookie() not setting httponly cookie"; 1721 VLOG(kVlogSetCookies) << "SetCookie() not setting httponly cookie";
1717 return false; 1722 return false;
1718 } 1723 }
1719 1724
1720 std::string cookie_domain; 1725 std::string cookie_domain;
1721 if (!GetCookieDomain(url, pc, &cookie_domain)) { 1726 if (!GetCookieDomain(url, pc, &cookie_domain)) {
1722 return false; 1727 return false;
1723 } 1728 }
1724 1729
1725 std::string cookie_path = CanonicalCookie::CanonPath(url, pc); 1730 std::string cookie_path = CanonicalCookie::CanonPath(url, pc);
1726 std::string mac_key = pc.HasMACKey() ? pc.MACKey() : std::string(); 1731 std::string mac_key = pc.HasMACKey() ? pc.MACKey() : std::string();
1727 std::string mac_algorithm = pc.HasMACAlgorithm() ? 1732 std::string mac_algorithm = pc.HasMACAlgorithm() ?
1728 pc.MACAlgorithm() : std::string(); 1733 pc.MACAlgorithm() : std::string();
1729 1734
1730 scoped_ptr<CanonicalCookie> cc; 1735 scoped_ptr<CanonicalCookie> cc;
1731 Time cookie_expires = CanonicalCookie::CanonExpiration(pc, creation_time); 1736 Time cookie_expires =
1737 CanonicalCookie::CanonExpiration(pc, creation_time, server_time);
1732 1738
1733 cc.reset(new CanonicalCookie(url, pc.Name(), pc.Value(), cookie_domain, 1739 cc.reset(new CanonicalCookie(url, pc.Name(), pc.Value(), cookie_domain,
1734 cookie_path, mac_key, mac_algorithm, 1740 cookie_path, mac_key, mac_algorithm,
1735 creation_time, cookie_expires, 1741 creation_time, cookie_expires,
1736 creation_time, pc.IsSecure(), pc.IsHttpOnly())); 1742 creation_time, pc.IsSecure(), pc.IsHttpOnly()));
1737 1743
1738 if (!cc.get()) { 1744 if (!cc.get()) {
1739 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; 1745 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie";
1740 return false; 1746 return false;
1741 } 1747 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 2149
2144 // The system resolution is not high enough, so we can have multiple 2150 // The system resolution is not high enough, so we can have multiple
2145 // set cookies that result in the same system time. When this happens, we 2151 // set cookies that result in the same system time. When this happens, we
2146 // increment by one Time unit. Let's hope computers don't get too fast. 2152 // increment by one Time unit. Let's hope computers don't get too fast.
2147 Time CookieMonster::CurrentTime() { 2153 Time CookieMonster::CurrentTime() {
2148 return std::max(Time::Now(), 2154 return std::max(Time::Now(),
2149 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); 2155 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
2150 } 2156 }
2151 2157
2152 } // namespace net 2158 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | net/cookies/cookie_options.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698