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

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

Issue 2882063002: Add a SetCanonicalCookie method for CookieMonster. (Closed)
Patch Set: Fix AW cookie store wrapper. Created 3 years, 6 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/canonical_cookie_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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return nullptr; 219 return nullptr;
220 } 220 }
221 221
222 std::string cookie_path = CanonPathWithString( 222 std::string cookie_path = CanonPathWithString(
223 url, parsed_cookie.HasPath() ? parsed_cookie.Path() : std::string()); 223 url, parsed_cookie.HasPath() ? parsed_cookie.Path() : std::string());
224 224
225 Time server_time(creation_time); 225 Time server_time(creation_time);
226 if (options.has_server_time()) 226 if (options.has_server_time())
227 server_time = options.server_time(); 227 server_time = options.server_time();
228 228
229 DCHECK(!creation_time.is_null());
229 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie, 230 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie,
230 creation_time, 231 creation_time,
231 server_time); 232 server_time);
232 233
233 CookiePrefix prefix = GetCookiePrefix(parsed_cookie.Name()); 234 CookiePrefix prefix = GetCookiePrefix(parsed_cookie.Name());
234 bool is_cookie_valid = IsCookiePrefixValid(prefix, url, parsed_cookie); 235 bool is_cookie_valid = IsCookiePrefixValid(prefix, url, parsed_cookie);
235 RecordCookiePrefixMetrics(prefix, is_cookie_valid); 236 RecordCookiePrefixMetrics(prefix, is_cookie_valid);
236 if (!is_cookie_valid) { 237 if (!is_cookie_valid) {
237 VLOG(kVlogSetCookies) 238 VLOG(kVlogSetCookies)
238 << "Create() failed because the cookie violated prefix rules."; 239 << "Create() failed because the cookie violated prefix rules.";
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return false; 438 return false;
438 439
439 if (GetCookiePrefix(name_) == COOKIE_PREFIX_HOST && 440 if (GetCookiePrefix(name_) == COOKIE_PREFIX_HOST &&
440 (path_ != "/" || domain_.empty() || domain_[0] == '.')) { 441 (path_ != "/" || domain_.empty() || domain_[0] == '.')) {
441 return false; 442 return false;
442 } 443 }
443 444
444 return true; 445 return true;
445 } 446 }
446 447
448 void CanonicalCookie::SetCreationDate(base::Time new_creation_date) {
449 DCHECK(CreationDate().is_null());
450 creation_date_ = new_creation_date;
451 }
452
447 // static 453 // static
448 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix( 454 CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix(
449 const std::string& name) { 455 const std::string& name) {
450 const char kSecurePrefix[] = "__Secure-"; 456 const char kSecurePrefix[] = "__Secure-";
451 const char kHostPrefix[] = "__Host-"; 457 const char kHostPrefix[] = "__Host-";
452 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE)) 458 if (base::StartsWith(name, kSecurePrefix, base::CompareCase::SENSITIVE))
453 return CanonicalCookie::COOKIE_PREFIX_SECURE; 459 return CanonicalCookie::COOKIE_PREFIX_SECURE;
454 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE)) 460 if (base::StartsWith(name, kHostPrefix, base::CompareCase::SENSITIVE))
455 return CanonicalCookie::COOKIE_PREFIX_HOST; 461 return CanonicalCookie::COOKIE_PREFIX_HOST;
456 return CanonicalCookie::COOKIE_PREFIX_NONE; 462 return CanonicalCookie::COOKIE_PREFIX_NONE;
(...skipping 30 matching lines...) Expand all
487 return true; 493 return true;
488 } 494 }
489 495
490 std::string CanonicalCookie::DomainWithoutDot() const { 496 std::string CanonicalCookie::DomainWithoutDot() const {
491 if (domain_.empty() || domain_[0] != '.') 497 if (domain_.empty() || domain_[0] != '.')
492 return domain_; 498 return domain_;
493 return domain_.substr(1); 499 return domain_.substr(1);
494 } 500 }
495 501
496 } // namespace net 502 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.h ('k') | net/cookies/canonical_cookie_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698