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

Side by Side Diff: net/cookies/canonical_cookie.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.h ('k') | net/cookies/cookie_monster.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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 name_(pc.Name()), 132 name_(pc.Name()),
133 value_(pc.Value()), 133 value_(pc.Value()),
134 path_(CanonPath(url, pc)), 134 path_(CanonPath(url, pc)),
135 mac_key_(pc.MACKey()), 135 mac_key_(pc.MACKey()),
136 mac_algorithm_(pc.MACAlgorithm()), 136 mac_algorithm_(pc.MACAlgorithm()),
137 creation_date_(Time::Now()), 137 creation_date_(Time::Now()),
138 last_access_date_(Time()), 138 last_access_date_(Time()),
139 secure_(pc.IsSecure()), 139 secure_(pc.IsSecure()),
140 httponly_(pc.IsHttpOnly()) { 140 httponly_(pc.IsHttpOnly()) {
141 if (pc.HasExpires()) 141 if (pc.HasExpires())
142 expiry_date_ = CanonExpiration(pc, creation_date_); 142 expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_);
143 143
144 // Do the best we can with the domain. 144 // Do the best we can with the domain.
145 std::string cookie_domain; 145 std::string cookie_domain;
146 std::string domain_string; 146 std::string domain_string;
147 if (pc.HasDomain()) { 147 if (pc.HasDomain()) {
148 domain_string = pc.Domain(); 148 domain_string = pc.Domain();
149 } 149 }
150 bool result 150 bool result
151 = cookie_util::GetCookieDomainWithString(url, domain_string, 151 = cookie_util::GetCookieDomainWithString(url, domain_string,
152 &cookie_domain); 152 &cookie_domain);
(...skipping 21 matching lines...) Expand all
174 std::string CanonicalCookie::CanonPath(const GURL& url, 174 std::string CanonicalCookie::CanonPath(const GURL& url,
175 const ParsedCookie& pc) { 175 const ParsedCookie& pc) {
176 std::string path_string; 176 std::string path_string;
177 if (pc.HasPath()) 177 if (pc.HasPath())
178 path_string = pc.Path(); 178 path_string = pc.Path();
179 return CanonPathWithString(url, path_string); 179 return CanonPathWithString(url, path_string);
180 } 180 }
181 181
182 // static 182 // static
183 Time CanonicalCookie::CanonExpiration(const ParsedCookie& pc, 183 Time CanonicalCookie::CanonExpiration(const ParsedCookie& pc,
184 const Time& current) { 184 const Time& current,
185 const Time& server_time) {
185 // First, try the Max-Age attribute. 186 // First, try the Max-Age attribute.
186 uint64 max_age = 0; 187 uint64 max_age = 0;
187 if (pc.HasMaxAge() && 188 if (pc.HasMaxAge() &&
188 #ifdef COMPILER_MSVC 189 #ifdef COMPILER_MSVC
189 sscanf_s( 190 sscanf_s(
190 #else 191 #else
191 sscanf( 192 sscanf(
192 #endif 193 #endif
193 pc.MaxAge().c_str(), " %" PRIu64, &max_age) == 1) { 194 pc.MaxAge().c_str(), " %" PRIu64, &max_age) == 1) {
194 return current + TimeDelta::FromSeconds(max_age); 195 return current + TimeDelta::FromSeconds(max_age);
195 } 196 }
196 197
197 // Try the Expires attribute. 198 // Try the Expires attribute.
198 if (pc.HasExpires()) 199 if (pc.HasExpires()) {
199 return cookie_util::ParseCookieTime(pc.Expires()); 200 // Adjust for clock skew between server and host.
201 return current + (cookie_util::ParseCookieTime(pc.Expires()) - server_time);
202 }
200 203
201 // Invalid or no expiration, persistent cookie. 204 // Invalid or no expiration, persistent cookie.
202 return Time(); 205 return Time();
203 } 206 }
204 207
205 CanonicalCookie* CanonicalCookie::Create(const GURL& url, 208 CanonicalCookie* CanonicalCookie::Create(const GURL& url,
206 const ParsedCookie& pc) { 209 const ParsedCookie& pc) {
207 if (!pc.IsValid()) { 210 if (!pc.IsValid()) {
208 return NULL; 211 return NULL;
209 } 212 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 std::string CanonicalCookie::DebugString() const { 353 std::string CanonicalCookie::DebugString() const {
351 return base::StringPrintf( 354 return base::StringPrintf(
352 "name: %s value: %s domain: %s path: %s creation: %" 355 "name: %s value: %s domain: %s path: %s creation: %"
353 PRId64, 356 PRId64,
354 name_.c_str(), value_.c_str(), 357 name_.c_str(), value_.c_str(),
355 domain_.c_str(), path_.c_str(), 358 domain_.c_str(), path_.c_str(),
356 static_cast<int64>(creation_date_.ToTimeT())); 359 static_cast<int64>(creation_date_.ToTimeT()));
357 } 360 }
358 361
359 } // namespace net 362 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.h ('k') | net/cookies/cookie_monster.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698