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

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

Issue 10831117: Remove ENABLE_PERSISTENT_SESSION_COOKIES (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 8 years, 4 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/canonical_cookie.h ('k') | net/cookies/cookie_monster_unittest.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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "net/cookies/cookie_util.h" 53 #include "net/cookies/cookie_util.h"
54 #include "net/cookies/parsed_cookie.h" 54 #include "net/cookies/parsed_cookie.h"
55 55
56 using base::Time; 56 using base::Time;
57 using base::TimeDelta; 57 using base::TimeDelta;
58 58
59 namespace net { 59 namespace net {
60 60
61 namespace { 61 namespace {
62 62
63 #if defined(ENABLE_PERSISTENT_SESSION_COOKIES)
64 const int kPersistentSessionCookieExpiryInDays = 14;
65 #endif
66
67 // Determine the cookie domain to use for setting the specified cookie. 63 // Determine the cookie domain to use for setting the specified cookie.
68 bool GetCookieDomain(const GURL& url, 64 bool GetCookieDomain(const GURL& url,
69 const ParsedCookie& pc, 65 const ParsedCookie& pc,
70 std::string* result) { 66 std::string* result) {
71 std::string domain_string; 67 std::string domain_string;
72 if (pc.HasDomain()) 68 if (pc.HasDomain())
73 domain_string = pc.Domain(); 69 domain_string = pc.Domain();
74 return cookie_util::GetCookieDomainWithString(url, domain_string, result); 70 return cookie_util::GetCookieDomainWithString(url, domain_string, result);
75 } 71 }
76 72
(...skipping 25 matching lines...) Expand all
102 98
103 // Return up to the rightmost '/'. 99 // Return up to the rightmost '/'.
104 return url_path.substr(0, idx); 100 return url_path.substr(0, idx);
105 } 101 }
106 102
107 } // namespace 103 } // namespace
108 104
109 CanonicalCookie::CanonicalCookie() 105 CanonicalCookie::CanonicalCookie()
110 : secure_(false), 106 : secure_(false),
111 httponly_(false) { 107 httponly_(false) {
112 SetSessionCookieExpiryTime();
113 } 108 }
114 109
115 CanonicalCookie::CanonicalCookie( 110 CanonicalCookie::CanonicalCookie(
116 const GURL& url, const std::string& name, const std::string& value, 111 const GURL& url, const std::string& name, const std::string& value,
117 const std::string& domain, const std::string& path, 112 const std::string& domain, const std::string& path,
118 const std::string& mac_key, const std::string& mac_algorithm, 113 const std::string& mac_key, const std::string& mac_algorithm,
119 const base::Time& creation, const base::Time& expiration, 114 const base::Time& creation, const base::Time& expiration,
120 const base::Time& last_access, bool secure, bool httponly) 115 const base::Time& last_access, bool secure, bool httponly)
121 : source_(GetCookieSourceFromURL(url)), 116 : source_(GetCookieSourceFromURL(url)),
122 name_(name), 117 name_(name),
123 value_(value), 118 value_(value),
124 domain_(domain), 119 domain_(domain),
125 path_(path), 120 path_(path),
126 mac_key_(mac_key), 121 mac_key_(mac_key),
127 mac_algorithm_(mac_algorithm), 122 mac_algorithm_(mac_algorithm),
128 creation_date_(creation), 123 creation_date_(creation),
129 expiry_date_(expiration), 124 expiry_date_(expiration),
130 last_access_date_(last_access), 125 last_access_date_(last_access),
131 secure_(secure), 126 secure_(secure),
132 httponly_(httponly) { 127 httponly_(httponly) {
133 if (expiration.is_null())
134 SetSessionCookieExpiryTime();
135 } 128 }
136 129
137 CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc) 130 CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc)
138 : source_(GetCookieSourceFromURL(url)), 131 : source_(GetCookieSourceFromURL(url)),
139 name_(pc.Name()), 132 name_(pc.Name()),
140 value_(pc.Value()), 133 value_(pc.Value()),
141 path_(CanonPath(url, pc)), 134 path_(CanonPath(url, pc)),
142 mac_key_(pc.MACKey()), 135 mac_key_(pc.MACKey()),
143 mac_algorithm_(pc.MACAlgorithm()), 136 mac_algorithm_(pc.MACAlgorithm()),
144 creation_date_(Time::Now()), 137 creation_date_(Time::Now()),
145 last_access_date_(Time()), 138 last_access_date_(Time()),
146 secure_(pc.IsSecure()), 139 secure_(pc.IsSecure()),
147 httponly_(pc.IsHttpOnly()) { 140 httponly_(pc.IsHttpOnly()) {
148 if (pc.HasExpires()) 141 if (pc.HasExpires())
149 expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_); 142 expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_);
150 else
151 SetSessionCookieExpiryTime();
152 143
153 // Do the best we can with the domain. 144 // Do the best we can with the domain.
154 std::string cookie_domain; 145 std::string cookie_domain;
155 std::string domain_string; 146 std::string domain_string;
156 if (pc.HasDomain()) { 147 if (pc.HasDomain()) {
157 domain_string = pc.Domain(); 148 domain_string = pc.Domain();
158 } 149 }
159 bool result 150 bool result
160 = cookie_util::GetCookieDomainWithString(url, domain_string, 151 = cookie_util::GetCookieDomainWithString(url, domain_string,
161 &cookie_domain); 152 &cookie_domain);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // Try the Expires attribute. 198 // Try the Expires attribute.
208 if (pc.HasExpires()) { 199 if (pc.HasExpires()) {
209 // Adjust for clock skew between server and host. 200 // Adjust for clock skew between server and host.
210 return current + (cookie_util::ParseCookieTime(pc.Expires()) - server_time); 201 return current + (cookie_util::ParseCookieTime(pc.Expires()) - server_time);
211 } 202 }
212 203
213 // Invalid or no expiration, persistent cookie. 204 // Invalid or no expiration, persistent cookie.
214 return Time(); 205 return Time();
215 } 206 }
216 207
217 void CanonicalCookie::SetSessionCookieExpiryTime() {
218 #if defined(ENABLE_PERSISTENT_SESSION_COOKIES)
219 // Mobile apps can sometimes be shut down without any warning, so the session
220 // cookie has to be persistent and given a default expiration time.
221 expiry_date_ = base::Time::Now() +
222 base::TimeDelta::FromDays(kPersistentSessionCookieExpiryInDays);
223 #endif
224 }
225
226 CanonicalCookie* CanonicalCookie::Create(const GURL& url, 208 CanonicalCookie* CanonicalCookie::Create(const GURL& url,
227 const ParsedCookie& pc) { 209 const ParsedCookie& pc) {
228 if (!pc.IsValid()) { 210 if (!pc.IsValid()) {
229 return NULL; 211 return NULL;
230 } 212 }
231 213
232 std::string domain_string; 214 std::string domain_string;
233 if (!GetCookieDomain(url, pc, &domain_string)) { 215 if (!GetCookieDomain(url, pc, &domain_string)) {
234 return NULL; 216 return NULL;
235 } 217 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 std::string CanonicalCookie::DebugString() const { 353 std::string CanonicalCookie::DebugString() const {
372 return base::StringPrintf( 354 return base::StringPrintf(
373 "name: %s value: %s domain: %s path: %s creation: %" 355 "name: %s value: %s domain: %s path: %s creation: %"
374 PRId64, 356 PRId64,
375 name_.c_str(), value_.c_str(), 357 name_.c_str(), value_.c_str(),
376 domain_.c_str(), path_.c_str(), 358 domain_.c_str(), path_.c_str(),
377 static_cast<int64>(creation_date_.ToTimeT())); 359 static_cast<int64>(creation_date_.ToTimeT()));
378 } 360 }
379 361
380 } // namespace net 362 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.h ('k') | net/cookies/cookie_monster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698