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

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

Issue 1000103002: Add a method to override all the cookies in CookieMonster (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 9 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
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 size_t idx = url_path.find_last_of('/'); 95 size_t idx = url_path.find_last_of('/');
96 96
97 // The cookie path was invalid or a single '/'. 97 // The cookie path was invalid or a single '/'.
98 if (idx == 0 || idx == std::string::npos) 98 if (idx == 0 || idx == std::string::npos)
99 return std::string("/"); 99 return std::string("/");
100 100
101 // Return up to the rightmost '/'. 101 // Return up to the rightmost '/'.
102 return url_path.substr(0, idx); 102 return url_path.substr(0, idx);
103 } 103 }
104 104
105 // Compares cookies using name, domain and path, so that "equivalent" cookies
106 // (per RFC 2965) are equal to each other.
107 int PartialCookieOrdering(const net::CanonicalCookie& a,
108 const net::CanonicalCookie& b) {
109 int diff = a.Name().compare(b.Name());
110 if (diff != 0)
111 return diff;
112
113 diff = a.Domain().compare(b.Domain());
114 if (diff != 0)
115 return diff;
116
117 return a.Path().compare(b.Path());
118 }
119
105 } // namespace 120 } // namespace
106 121
107 CanonicalCookie::CanonicalCookie() 122 CanonicalCookie::CanonicalCookie()
108 : secure_(false), 123 : secure_(false),
109 httponly_(false) { 124 httponly_(false) {
110 } 125 }
111 126
112 CanonicalCookie::CanonicalCookie(const GURL& url, 127 CanonicalCookie::CanonicalCookie(const GURL& url,
113 const std::string& name, 128 const std::string& name,
114 const std::string& value, 129 const std::string& value,
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 418
404 std::string CanonicalCookie::DebugString() const { 419 std::string CanonicalCookie::DebugString() const {
405 return base::StringPrintf( 420 return base::StringPrintf(
406 "name: %s value: %s domain: %s path: %s creation: %" 421 "name: %s value: %s domain: %s path: %s creation: %"
407 PRId64, 422 PRId64,
408 name_.c_str(), value_.c_str(), 423 name_.c_str(), value_.c_str(),
409 domain_.c_str(), path_.c_str(), 424 domain_.c_str(), path_.c_str(),
410 static_cast<int64>(creation_date_.ToTimeT())); 425 static_cast<int64>(creation_date_.ToTimeT()));
411 } 426 }
412 427
428 bool CanonicalCookie::PartialCompare(const CanonicalCookie& other) const {
429 return PartialCookieOrdering(*this, other) < 0;
430 }
431
432 bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const {
433 // Do the partial comparison first.
434 int diff = PartialCookieOrdering(*this, other);
435 if (diff != 0)
436 return diff < 0;
437
438 DCHECK(IsEquivalent(other));
439
440 // Compare other fields.
441 diff = Value().compare(other.Value());
442 if (diff != 0)
443 return diff < 0;
444
445 if (CreationDate() != other.CreationDate())
446 return CreationDate() < other.CreationDate();
447
448 if (ExpiryDate() != other.ExpiryDate())
449 return ExpiryDate() < other.ExpiryDate();
450
451 if (LastAccessDate() != other.LastAccessDate())
452 return LastAccessDate() < other.LastAccessDate();
453
454 if (IsSecure() != other.IsSecure())
455 return IsSecure();
456
457 if (IsHttpOnly() != other.IsHttpOnly())
458 return IsHttpOnly();
459
460 return Priority() < other.Priority();
461 }
462
413 } // namespace net 463 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698