[email protected] | 8e158367 | 2012-02-11 04:39:41 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
| 5 | // Portions of this code based on Mozilla: |
| 6 | // (netwerk/cookie/src/nsCookieService.cpp) |
| 7 | /* ***** BEGIN LICENSE BLOCK ***** |
| 8 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 9 | * |
| 10 | * The contents of this file are subject to the Mozilla Public License Version |
| 11 | * 1.1 (the "License"); you may not use this file except in compliance with |
| 12 | * the License. You may obtain a copy of the License at |
| 13 | * http://www.mozilla.org/MPL/ |
| 14 | * |
| 15 | * Software distributed under the License is distributed on an "AS IS" basis, |
| 16 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 17 | * for the specific language governing rights and limitations under the |
| 18 | * License. |
| 19 | * |
| 20 | * The Original Code is mozilla.org code. |
| 21 | * |
| 22 | * The Initial Developer of the Original Code is |
| 23 | * Netscape Communications Corporation. |
| 24 | * Portions created by the Initial Developer are Copyright (C) 2003 |
| 25 | * the Initial Developer. All Rights Reserved. |
| 26 | * |
| 27 | * Contributor(s): |
| 28 | * Daniel Witte ([email protected]) |
| 29 | * Michiel van Leeuwen ([email protected]) |
| 30 | * |
| 31 | * Alternatively, the contents of this file may be used under the terms of |
| 32 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 33 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 34 | * in which case the provisions of the GPL or the LGPL are applicable instead |
| 35 | * of those above. If you wish to allow use of your version of this file only |
| 36 | * under the terms of either the GPL or the LGPL, and not to allow others to |
| 37 | * use your version of this file under the terms of the MPL, indicate your |
| 38 | * decision by deleting the provisions above and replace them with the notice |
| 39 | * and other provisions required by the GPL or the LGPL. If you do not delete |
| 40 | * the provisions above, a recipient may use your version of this file under |
| 41 | * the terms of any one of the MPL, the GPL or the LGPL. |
| 42 | * |
| 43 | * ***** END LICENSE BLOCK ***** */ |
| 44 | |
[email protected] | 63ee33bd | 2012-03-15 09:29:58 | [diff] [blame] | 45 | #include "net/cookies/cookie_monster.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 46 | |
| 47 | #include <algorithm> |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 48 | #include <functional> |
[email protected] | 0966648 | 2011-07-12 12:50:40 | [diff] [blame] | 49 | #include <set> |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 50 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 51 | #include "base/bind.h" |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 52 | #include "base/callback.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 53 | #include "base/location.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 54 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 55 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 56 | #include "base/memory/scoped_ptr.h" |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 57 | #include "base/metrics/field_trial.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 58 | #include "base/metrics/histogram.h" |
pkasting | b60049a | 2015-02-07 03:25:25 | [diff] [blame] | 59 | #include "base/profiler/scoped_tracker.h" |
anujk.sharma | afc4517 | 2015-05-15 00:50:34 | [diff] [blame] | 60 | #include "base/single_thread_task_runner.h" |
[email protected] | 4b35521 | 2013-06-11 10:35:19 | [diff] [blame] | 61 | #include "base/strings/string_util.h" |
| 62 | #include "base/strings/stringprintf.h" |
anujk.sharma | afc4517 | 2015-05-15 00:50:34 | [diff] [blame] | 63 | #include "base/thread_task_runner_handle.h" |
[email protected] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 64 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 4b35521 | 2013-06-11 10:35:19 | [diff] [blame] | 65 | #include "net/cookies/canonical_cookie.h" |
[email protected] | 63ee33bd | 2012-03-15 09:29:58 | [diff] [blame] | 66 | #include "net/cookies/cookie_util.h" |
[email protected] | ebfe317 | 2012-07-12 12:21:41 | [diff] [blame] | 67 | #include "net/cookies/parsed_cookie.h" |
mkwst | 8241a12 | 2015-10-20 07:15:10 | [diff] [blame] | 68 | #include "url/origin.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 69 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 70 | using base::Time; |
| 71 | using base::TimeDelta; |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 72 | using base::TimeTicks; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 73 | |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 74 | // In steady state, most cookie requests can be satisfied by the in memory |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 75 | // cookie monster store. If the cookie request cannot be satisfied by the in |
| 76 | // memory store, the relevant cookies must be fetched from the persistent |
| 77 | // store. The task is queued in CookieMonster::tasks_pending_ if it requires |
| 78 | // all cookies to be loaded from the backend, or tasks_pending_for_key_ if it |
| 79 | // only requires all cookies associated with an eTLD+1. |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 80 | // |
| 81 | // On the browser critical paths (e.g. for loading initial web pages in a |
| 82 | // session restore) it may take too long to wait for the full load. If a cookie |
| 83 | // request is for a specific URL, DoCookieTaskForURL is called, which triggers a |
| 84 | // priority load if the key is not loaded yet by calling PersistentCookieStore |
[email protected] | 0184df3 | 2013-05-14 00:53:55 | [diff] [blame] | 85 | // :: LoadCookiesForKey. The request is queued in |
| 86 | // CookieMonster::tasks_pending_for_key_ and executed upon receiving |
| 87 | // notification of key load completion via CookieMonster::OnKeyLoaded(). If |
| 88 | // multiple requests for the same eTLD+1 are received before key load |
| 89 | // completion, only the first request calls |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 90 | // PersistentCookieStore::LoadCookiesForKey, all subsequent requests are queued |
[email protected] | 0184df3 | 2013-05-14 00:53:55 | [diff] [blame] | 91 | // in CookieMonster::tasks_pending_for_key_ and executed upon receiving |
| 92 | // notification of key load completion triggered by the first request for the |
| 93 | // same eTLD+1. |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 94 | |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 95 | static const int kMinutesInTenYears = 10 * 365 * 24 * 60; |
| 96 | |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 97 | namespace { |
| 98 | |
| 99 | const char kFetchWhenNecessaryName[] = "FetchWhenNecessary"; |
| 100 | const char kAlwaysFetchName[] = "AlwaysFetch"; |
| 101 | const char kCookieMonsterFetchStrategyName[] = "CookieMonsterFetchStrategy"; |
| 102 | |
| 103 | } // namespace |
| 104 | |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 105 | namespace net { |
| 106 | |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 107 | // See comments at declaration of these variables in cookie_monster.h |
| 108 | // for details. |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 109 | const size_t CookieMonster::kDomainMaxCookies = 180; |
| 110 | const size_t CookieMonster::kDomainPurgeCookies = 30; |
| 111 | const size_t CookieMonster::kMaxCookies = 3300; |
| 112 | const size_t CookieMonster::kPurgeCookies = 300; |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 113 | |
mkwst | 8773435 | 2016-03-03 17:36:23 | [diff] [blame] | 114 | const size_t CookieMonster::kDomainCookiesQuotaLow = 30; |
| 115 | const size_t CookieMonster::kDomainCookiesQuotaMedium = 50; |
| 116 | const size_t CookieMonster::kDomainCookiesQuotaHigh = |
| 117 | kDomainMaxCookies - kDomainPurgeCookies - kDomainCookiesQuotaLow - |
| 118 | kDomainCookiesQuotaMedium; |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 119 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 120 | const int CookieMonster::kSafeFromGlobalPurgeDays = 30; |
[email protected] | 297a4ed0 | 2010-02-12 08:12:52 | [diff] [blame] | 121 | |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 122 | namespace { |
[email protected] | e32306c5 | 2008-11-06 16:59:05 | [diff] [blame] | 123 | |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 124 | bool ContainsControlCharacter(const std::string& s) { |
| 125 | for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) { |
| 126 | if ((*i >= 0) && (*i <= 31)) |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | return false; |
| 131 | } |
| 132 | |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 133 | typedef std::vector<CanonicalCookie*> CanonicalCookieVector; |
[email protected] | 34a160d | 2011-05-12 22:12:49 | [diff] [blame] | 134 | |
[email protected] | 77e0a46 | 2008-11-01 00:43:35 | [diff] [blame] | 135 | // Default minimum delay after updating a cookie's LastAccessDate before we |
| 136 | // will update it again. |
[email protected] | 297a4ed0 | 2010-02-12 08:12:52 | [diff] [blame] | 137 | const int kDefaultAccessUpdateThresholdSeconds = 60; |
| 138 | |
| 139 | // Comparator to sort cookies from highest creation date to lowest |
| 140 | // creation date. |
| 141 | struct OrderByCreationTimeDesc { |
| 142 | bool operator()(const CookieMonster::CookieMap::iterator& a, |
| 143 | const CookieMonster::CookieMap::iterator& b) const { |
| 144 | return a->second->CreationDate() > b->second->CreationDate(); |
| 145 | } |
| 146 | }; |
| 147 | |
[email protected] | 4d3ce78 | 2010-10-29 18:31:28 | [diff] [blame] | 148 | // Constants for use in VLOG |
| 149 | const int kVlogPerCookieMonster = 1; |
[email protected] | 4d3ce78 | 2010-10-29 18:31:28 | [diff] [blame] | 150 | const int kVlogGarbageCollection = 5; |
| 151 | const int kVlogSetCookies = 7; |
| 152 | const int kVlogGetCookies = 9; |
| 153 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 154 | // Mozilla sorts on the path length (longest first), and then it |
| 155 | // sorts by creation time (oldest first). |
| 156 | // The RFC says the sort order for the domain attribute is undefined. |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 157 | bool CookieSorter(CanonicalCookie* cc1, CanonicalCookie* cc2) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 158 | if (cc1->Path().length() == cc2->Path().length()) |
| 159 | return cc1->CreationDate() < cc2->CreationDate(); |
| 160 | return cc1->Path().length() > cc2->Path().length(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 161 | } |
| 162 | |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 163 | bool LRACookieSorter(const CookieMonster::CookieMap::iterator& it1, |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 164 | const CookieMonster::CookieMap::iterator& it2) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 165 | if (it1->second->LastAccessDate() != it2->second->LastAccessDate()) |
| 166 | return it1->second->LastAccessDate() < it2->second->LastAccessDate(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 167 | |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 168 | // Ensure stability for == last access times by falling back to creation. |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 169 | return it1->second->CreationDate() < it2->second->CreationDate(); |
[email protected] | 297a4ed0 | 2010-02-12 08:12:52 | [diff] [blame] | 170 | } |
| 171 | |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 172 | // Compare cookies using name, domain and path, so that "equivalent" cookies |
| 173 | // (per RFC 2965) are equal to each other. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 174 | bool PartialDiffCookieSorter(const CanonicalCookie& a, |
| 175 | const CanonicalCookie& b) { |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 176 | return a.PartialCompare(b); |
| 177 | } |
| 178 | |
| 179 | // This is a stricter ordering than PartialDiffCookieOrdering, where all fields |
| 180 | // are used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | bool FullDiffCookieSorter(const CanonicalCookie& a, const CanonicalCookie& b) { |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 182 | return a.FullCompare(b); |
| 183 | } |
| 184 | |
[email protected] | 297a4ed0 | 2010-02-12 08:12:52 | [diff] [blame] | 185 | // Our strategy to find duplicates is: |
| 186 | // (1) Build a map from (cookiename, cookiepath) to |
| 187 | // {list of cookies with this signature, sorted by creation time}. |
| 188 | // (2) For each list with more than 1 entry, keep the cookie having the |
| 189 | // most recent creation time, and delete the others. |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 190 | // |
[email protected] | 1655ba34 | 2010-07-14 18:17:42 | [diff] [blame] | 191 | // Two cookies are considered equivalent if they have the same domain, |
| 192 | // name, and path. |
| 193 | struct CookieSignature { |
| 194 | public: |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 195 | CookieSignature(const std::string& name, |
| 196 | const std::string& domain, |
[email protected] | 1655ba34 | 2010-07-14 18:17:42 | [diff] [blame] | 197 | const std::string& path) |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 198 | : name(name), domain(domain), path(path) {} |
[email protected] | 1655ba34 | 2010-07-14 18:17:42 | [diff] [blame] | 199 | |
| 200 | // To be a key for a map this class needs to be assignable, copyable, |
| 201 | // and have an operator<. The default assignment operator |
| 202 | // and copy constructor are exactly what we want. |
| 203 | |
| 204 | bool operator<(const CookieSignature& cs) const { |
| 205 | // Name compare dominates, then domain, then path. |
| 206 | int diff = name.compare(cs.name); |
| 207 | if (diff != 0) |
| 208 | return diff < 0; |
| 209 | |
| 210 | diff = domain.compare(cs.domain); |
| 211 | if (diff != 0) |
| 212 | return diff < 0; |
| 213 | |
| 214 | return path.compare(cs.path) < 0; |
| 215 | } |
| 216 | |
| 217 | std::string name; |
| 218 | std::string domain; |
| 219 | std::string path; |
| 220 | }; |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 221 | |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 222 | // For a CookieItVector iterator range [|it_begin|, |it_end|), |
| 223 | // sorts the first |num_sort| + 1 elements by LastAccessDate(). |
| 224 | // The + 1 element exists so for any interval of length <= |num_sort| starting |
| 225 | // from |cookies_its_begin|, a LastAccessDate() bound can be found. |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 226 | void SortLeastRecentlyAccessed(CookieMonster::CookieItVector::iterator it_begin, |
| 227 | CookieMonster::CookieItVector::iterator it_end, |
| 228 | size_t num_sort) { |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 229 | DCHECK_LT(static_cast<int>(num_sort), it_end - it_begin); |
| 230 | std::partial_sort(it_begin, it_begin + num_sort + 1, it_end, LRACookieSorter); |
| 231 | } |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 232 | |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 233 | // Given a single cookie vector |cookie_its|, pushs all of the secure cookies in |
| 234 | // |cookie_its| into |secure_cookie_its| and all of the non-secure cookies into |
| 235 | // |non_secure_cookie_its|. Both |secure_cookie_its| and |non_secure_cookie_its| |
| 236 | // must be non-NULL. |
| 237 | void SplitCookieVectorIntoSecureAndNonSecure( |
| 238 | const CookieMonster::CookieItVector& cookie_its, |
| 239 | CookieMonster::CookieItVector* secure_cookie_its, |
| 240 | CookieMonster::CookieItVector* non_secure_cookie_its) { |
| 241 | DCHECK(secure_cookie_its && non_secure_cookie_its); |
| 242 | for (const auto& curit : cookie_its) { |
| 243 | if (curit->second->IsSecure()) |
| 244 | secure_cookie_its->push_back(curit); |
| 245 | else |
| 246 | non_secure_cookie_its->push_back(curit); |
| 247 | } |
| 248 | } |
| 249 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 250 | bool LowerBoundAccessDateComparator(const CookieMonster::CookieMap::iterator it, |
| 251 | const Time& access_date) { |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 252 | return it->second->LastAccessDate() < access_date; |
| 253 | } |
| 254 | |
| 255 | // For a CookieItVector iterator range [|it_begin|, |it_end|) |
| 256 | // from a CookieItVector sorted by LastAccessDate(), returns the |
| 257 | // first iterator with access date >= |access_date|, or cookie_its_end if this |
| 258 | // holds for all. |
| 259 | CookieMonster::CookieItVector::iterator LowerBoundAccessDate( |
| 260 | const CookieMonster::CookieItVector::iterator its_begin, |
| 261 | const CookieMonster::CookieItVector::iterator its_end, |
| 262 | const Time& access_date) { |
| 263 | return std::lower_bound(its_begin, its_end, access_date, |
| 264 | LowerBoundAccessDateComparator); |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 267 | // Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the |
| 268 | // mapping also provides a boolean that specifies whether or not an |
| 269 | // OnCookieChanged notification ought to be generated. |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 270 | typedef struct ChangeCausePair_struct { |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 271 | CookieMonsterDelegate::ChangeCause cause; |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 272 | bool notify; |
| 273 | } ChangeCausePair; |
| 274 | ChangeCausePair ChangeCauseMapping[] = { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 275 | // DELETE_COOKIE_EXPLICIT |
| 276 | {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true}, |
| 277 | // DELETE_COOKIE_OVERWRITE |
| 278 | {CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true}, |
| 279 | // DELETE_COOKIE_EXPIRED |
| 280 | {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true}, |
| 281 | // DELETE_COOKIE_EVICTED |
| 282 | {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
| 283 | // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE |
| 284 | {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, |
| 285 | // DELETE_COOKIE_DONT_RECORD |
| 286 | {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}, |
| 287 | // DELETE_COOKIE_EVICTED_DOMAIN |
| 288 | {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
| 289 | // DELETE_COOKIE_EVICTED_GLOBAL |
| 290 | {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
| 291 | // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE |
| 292 | {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
| 293 | // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE |
| 294 | {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
| 295 | // DELETE_COOKIE_EXPIRED_OVERWRITE |
| 296 | {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true}, |
| 297 | // DELETE_COOKIE_CONTROL_CHAR |
| 298 | {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 299 | // DELETE_COOKIE_NON_SECURE |
| 300 | {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 301 | // DELETE_COOKIE_LAST_ENTRY |
| 302 | {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}}; |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 303 | |
ellyjones | 399e35a2 | 2014-10-27 11:09:56 | [diff] [blame] | 304 | void RunAsync(scoped_refptr<base::TaskRunner> proxy, |
msarda | 0aad8f0 | 2014-10-30 09:22:39 | [diff] [blame] | 305 | const CookieStore::CookieChangedCallback& callback, |
| 306 | const CanonicalCookie& cookie, |
| 307 | bool removed) { |
| 308 | proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed)); |
ellyjones | 399e35a2 | 2014-10-27 11:09:56 | [diff] [blame] | 309 | } |
| 310 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 311 | } // namespace |
| 312 | |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 313 | CookieMonster::CookieMonster(PersistentCookieStore* store, |
| 314 | CookieMonsterDelegate* delegate) |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 315 | : CookieMonster(store, delegate, kDefaultAccessUpdateThresholdSeconds) { |
[email protected] | 2d0f89a | 2010-12-06 12:02:23 | [diff] [blame] | 316 | } |
| 317 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 318 | CookieMonster::CookieMonster(PersistentCookieStore* store, |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 319 | CookieMonsterDelegate* delegate, |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 320 | int last_access_threshold_milliseconds) |
| 321 | : initialized_(false), |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 322 | started_fetching_all_cookies_(false), |
| 323 | finished_fetching_all_cookies_(false), |
| 324 | fetch_strategy_(kUnknownFetch), |
mmenke | f49fca0e | 2016-03-08 12:46:24 | [diff] [blame] | 325 | seen_global_task_(false), |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 326 | store_(store), |
| 327 | last_access_threshold_(base::TimeDelta::FromMilliseconds( |
| 328 | last_access_threshold_milliseconds)), |
| 329 | delegate_(delegate), |
[email protected] | 8238866 | 2011-03-10 21:04:06 | [diff] [blame] | 330 | last_statistic_record_time_(base::Time::Now()), |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 331 | persist_session_cookies_(false), |
| 332 | weak_ptr_factory_(this) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 333 | InitializeHistograms(); |
mmenke | 18dd8ba | 2016-02-01 18:42:10 | [diff] [blame] | 334 | cookieable_schemes_.insert( |
| 335 | cookieable_schemes_.begin(), kDefaultCookieableSchemes, |
| 336 | kDefaultCookieableSchemes + kDefaultCookieableSchemesCount); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 337 | } |
| 338 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 339 | // Task classes for queueing the coming request. |
| 340 | |
| 341 | class CookieMonster::CookieMonsterTask |
| 342 | : public base::RefCountedThreadSafe<CookieMonsterTask> { |
| 343 | public: |
| 344 | // Runs the task and invokes the client callback on the thread that |
| 345 | // originally constructed the task. |
| 346 | virtual void Run() = 0; |
| 347 | |
| 348 | protected: |
| 349 | explicit CookieMonsterTask(CookieMonster* cookie_monster); |
| 350 | virtual ~CookieMonsterTask(); |
| 351 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 352 | CookieMonster* cookie_monster() { return cookie_monster_; } |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 353 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 354 | private: |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 355 | friend class base::RefCountedThreadSafe<CookieMonsterTask>; |
| 356 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 357 | CookieMonster* cookie_monster_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 358 | |
| 359 | DISALLOW_COPY_AND_ASSIGN(CookieMonsterTask); |
| 360 | }; |
| 361 | |
| 362 | CookieMonster::CookieMonsterTask::CookieMonsterTask( |
| 363 | CookieMonster* cookie_monster) |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 364 | : cookie_monster_(cookie_monster) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 365 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 366 | CookieMonster::CookieMonsterTask::~CookieMonsterTask() { |
| 367 | } |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 368 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 369 | // Task class for SetCookieWithDetails call. |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 370 | class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 371 | public: |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 372 | SetCookieWithDetailsTask(CookieMonster* cookie_monster, |
| 373 | const GURL& url, |
| 374 | const std::string& name, |
| 375 | const std::string& value, |
| 376 | const std::string& domain, |
| 377 | const std::string& path, |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 378 | base::Time creation_time, |
| 379 | base::Time expiration_time, |
| 380 | base::Time last_access_time, |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 381 | bool secure, |
| 382 | bool http_only, |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 383 | bool same_site, |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 384 | bool enforce_strict_secure, |
[email protected] | ab2d75c8 | 2013-04-19 18:39:04 | [diff] [blame] | 385 | CookiePriority priority, |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 386 | const SetCookiesCallback& callback) |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 387 | : CookieMonsterTask(cookie_monster), |
| 388 | url_(url), |
| 389 | name_(name), |
| 390 | value_(value), |
| 391 | domain_(domain), |
| 392 | path_(path), |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 393 | creation_time_(creation_time), |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 394 | expiration_time_(expiration_time), |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 395 | last_access_time_(last_access_time), |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 396 | secure_(secure), |
| 397 | http_only_(http_only), |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 398 | same_site_(same_site), |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 399 | enforce_strict_secure_(enforce_strict_secure), |
[email protected] | ab2d75c8 | 2013-04-19 18:39:04 | [diff] [blame] | 400 | priority_(priority), |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 401 | callback_(callback) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 402 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 403 | // CookieMonsterTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 404 | void Run() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 405 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 406 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 407 | ~SetCookieWithDetailsTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 408 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 409 | private: |
| 410 | GURL url_; |
| 411 | std::string name_; |
| 412 | std::string value_; |
| 413 | std::string domain_; |
| 414 | std::string path_; |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 415 | base::Time creation_time_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 416 | base::Time expiration_time_; |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 417 | base::Time last_access_time_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 418 | bool secure_; |
| 419 | bool http_only_; |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 420 | bool same_site_; |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 421 | bool enforce_strict_secure_; |
[email protected] | ab2d75c8 | 2013-04-19 18:39:04 | [diff] [blame] | 422 | CookiePriority priority_; |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 423 | SetCookiesCallback callback_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 424 | |
| 425 | DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); |
| 426 | }; |
| 427 | |
| 428 | void CookieMonster::SetCookieWithDetailsTask::Run() { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 429 | bool success = this->cookie_monster()->SetCookieWithDetails( |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 430 | url_, name_, value_, domain_, path_, creation_time_, expiration_time_, |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 431 | last_access_time_, secure_, http_only_, same_site_, |
| 432 | enforce_strict_secure_, priority_); |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 433 | if (!callback_.is_null()) |
| 434 | callback_.Run(success); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | // Task class for GetAllCookies call. |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 438 | class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 439 | public: |
| 440 | GetAllCookiesTask(CookieMonster* cookie_monster, |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 441 | const GetCookieListCallback& callback) |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 442 | : CookieMonsterTask(cookie_monster), callback_(callback) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 443 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 444 | // CookieMonsterTask |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 445 | void Run() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 446 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 447 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 448 | ~GetAllCookiesTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 449 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 450 | private: |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 451 | GetCookieListCallback callback_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 452 | |
| 453 | DISALLOW_COPY_AND_ASSIGN(GetAllCookiesTask); |
| 454 | }; |
| 455 | |
| 456 | void CookieMonster::GetAllCookiesTask::Run() { |
| 457 | if (!callback_.is_null()) { |
| 458 | CookieList cookies = this->cookie_monster()->GetAllCookies(); |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 459 | callback_.Run(cookies); |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 460 | } |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 461 | } |
| 462 | |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 463 | // Task class for GetCookieListWithOptionsAsync call. |
| 464 | class CookieMonster::GetCookieListWithOptionsTask : public CookieMonsterTask { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 465 | public: |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 466 | GetCookieListWithOptionsTask(CookieMonster* cookie_monster, |
| 467 | const GURL& url, |
| 468 | const CookieOptions& options, |
| 469 | const GetCookieListCallback& callback) |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 470 | : CookieMonsterTask(cookie_monster), |
| 471 | url_(url), |
| 472 | options_(options), |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 473 | callback_(callback) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 474 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 475 | // CookieMonsterTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 476 | void Run() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 477 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 478 | protected: |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 479 | ~GetCookieListWithOptionsTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 480 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 481 | private: |
| 482 | GURL url_; |
| 483 | CookieOptions options_; |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 484 | GetCookieListCallback callback_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 485 | |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 486 | DISALLOW_COPY_AND_ASSIGN(GetCookieListWithOptionsTask); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 487 | }; |
| 488 | |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 489 | void CookieMonster::GetCookieListWithOptionsTask::Run() { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 490 | if (!callback_.is_null()) { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 491 | CookieList cookies = |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 492 | this->cookie_monster()->GetCookieListWithOptions(url_, options_); |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 493 | callback_.Run(cookies); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 497 | template <typename Result> |
| 498 | struct CallbackType { |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 499 | typedef base::Callback<void(Result)> Type; |
| 500 | }; |
| 501 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 502 | template <> |
| 503 | struct CallbackType<void> { |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 504 | typedef base::Closure Type; |
| 505 | }; |
| 506 | |
| 507 | // Base task class for Delete*Task. |
| 508 | template <typename Result> |
| 509 | class CookieMonster::DeleteTask : public CookieMonsterTask { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 510 | public: |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 511 | DeleteTask(CookieMonster* cookie_monster, |
| 512 | const typename CallbackType<Result>::Type& callback) |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 513 | : CookieMonsterTask(cookie_monster), callback_(callback) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 514 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 515 | // CookieMonsterTask: |
nick | d3f30d02 | 2015-04-23 10:18:37 | [diff] [blame] | 516 | void Run() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 517 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 518 | protected: |
| 519 | ~DeleteTask() override; |
| 520 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 521 | private: |
| 522 | // Runs the delete task and returns a result. |
| 523 | virtual Result RunDeleteTask() = 0; |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 524 | // Runs the delete task and then returns a callback to be called after |
| 525 | // flushing the persistent store. |
| 526 | // TODO(mmenke): This seems like a pretty ugly and needlessly confusing API. |
| 527 | // Simplify it? |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 528 | base::Closure RunDeleteTaskAndBindCallback(); |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 529 | |
| 530 | typename CallbackType<Result>::Type callback_; |
| 531 | |
| 532 | DISALLOW_COPY_AND_ASSIGN(DeleteTask); |
| 533 | }; |
| 534 | |
| 535 | template <typename Result> |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 536 | CookieMonster::DeleteTask<Result>::~DeleteTask() { |
| 537 | } |
| 538 | |
| 539 | template <typename Result> |
| 540 | base::Closure |
| 541 | CookieMonster::DeleteTask<Result>::RunDeleteTaskAndBindCallback() { |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 542 | Result result = RunDeleteTask(); |
| 543 | if (callback_.is_null()) |
| 544 | return base::Closure(); |
| 545 | return base::Bind(callback_, result); |
| 546 | } |
| 547 | |
| 548 | template <> |
| 549 | base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() { |
| 550 | RunDeleteTask(); |
| 551 | return callback_; |
| 552 | } |
| 553 | |
| 554 | template <typename Result> |
| 555 | void CookieMonster::DeleteTask<Result>::Run() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 556 | base::Closure callback = RunDeleteTaskAndBindCallback(); |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 557 | if (!callback.is_null()) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 558 | callback = base::Bind( |
| 559 | &CookieMonster::RunCallback, |
| 560 | this->cookie_monster()->weak_ptr_factory_.GetWeakPtr(), callback); |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 561 | } |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 562 | this->cookie_monster()->FlushStore(callback); |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 563 | } |
| 564 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 565 | // Task class for DeleteAllCreatedBetween call. |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 566 | class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 567 | public: |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 568 | DeleteAllCreatedBetweenTask(CookieMonster* cookie_monster, |
| 569 | const Time& delete_begin, |
| 570 | const Time& delete_end, |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 571 | const DeleteCallback& callback) |
[email protected] | 151132f | 2013-11-18 21:37:00 | [diff] [blame] | 572 | : DeleteTask<int>(cookie_monster, callback), |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 573 | delete_begin_(delete_begin), |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 574 | delete_end_(delete_end) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 575 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 576 | // DeleteTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 577 | int RunDeleteTask() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 578 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 579 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 580 | ~DeleteAllCreatedBetweenTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 581 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 582 | private: |
| 583 | Time delete_begin_; |
| 584 | Time delete_end_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 585 | |
| 586 | DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenTask); |
| 587 | }; |
| 588 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 589 | int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 590 | return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_, |
| 591 | delete_end_); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 592 | } |
| 593 | |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 594 | // Task class for DeleteAllCreatedBetweenForHost call. |
| 595 | class CookieMonster::DeleteAllCreatedBetweenForHostTask |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 596 | : public DeleteTask<int> { |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 597 | public: |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 598 | DeleteAllCreatedBetweenForHostTask(CookieMonster* cookie_monster, |
| 599 | Time delete_begin, |
| 600 | Time delete_end, |
| 601 | const GURL& url, |
| 602 | const DeleteCallback& callback) |
[email protected] | 151132f | 2013-11-18 21:37:00 | [diff] [blame] | 603 | : DeleteTask<int>(cookie_monster, callback), |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 604 | delete_begin_(delete_begin), |
| 605 | delete_end_(delete_end), |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 606 | url_(url) {} |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 607 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 608 | // DeleteTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 609 | int RunDeleteTask() override; |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 610 | |
| 611 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 612 | ~DeleteAllCreatedBetweenForHostTask() override {} |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 613 | |
| 614 | private: |
| 615 | Time delete_begin_; |
| 616 | Time delete_end_; |
| 617 | GURL url_; |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 618 | |
| 619 | DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); |
| 620 | }; |
| 621 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 622 | int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { |
| 623 | return this->cookie_monster()->DeleteAllCreatedBetweenForHost( |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 624 | delete_begin_, delete_end_, url_); |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 625 | } |
| 626 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 627 | // Task class for DeleteCanonicalCookie call. |
mmenke | 24379d5 | 2016-02-05 23:50:17 | [diff] [blame] | 628 | class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 629 | public: |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 630 | DeleteCanonicalCookieTask(CookieMonster* cookie_monster, |
| 631 | const CanonicalCookie& cookie, |
mmenke | 24379d5 | 2016-02-05 23:50:17 | [diff] [blame] | 632 | const DeleteCallback& callback) |
| 633 | : DeleteTask<int>(cookie_monster, callback), cookie_(cookie) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 634 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 635 | // DeleteTask: |
mmenke | 24379d5 | 2016-02-05 23:50:17 | [diff] [blame] | 636 | int RunDeleteTask() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 637 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 638 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 639 | ~DeleteCanonicalCookieTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 640 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 641 | private: |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 642 | CanonicalCookie cookie_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 643 | |
| 644 | DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); |
| 645 | }; |
| 646 | |
mmenke | 24379d5 | 2016-02-05 23:50:17 | [diff] [blame] | 647 | int CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 648 | return this->cookie_monster()->DeleteCanonicalCookie(cookie_); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // Task class for SetCookieWithOptions call. |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 652 | class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 653 | public: |
| 654 | SetCookieWithOptionsTask(CookieMonster* cookie_monster, |
| 655 | const GURL& url, |
| 656 | const std::string& cookie_line, |
| 657 | const CookieOptions& options, |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 658 | const SetCookiesCallback& callback) |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 659 | : CookieMonsterTask(cookie_monster), |
| 660 | url_(url), |
| 661 | cookie_line_(cookie_line), |
| 662 | options_(options), |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 663 | callback_(callback) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 664 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 665 | // CookieMonsterTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 666 | void Run() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 667 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 668 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 669 | ~SetCookieWithOptionsTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 670 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 671 | private: |
| 672 | GURL url_; |
| 673 | std::string cookie_line_; |
| 674 | CookieOptions options_; |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 675 | SetCookiesCallback callback_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 676 | |
| 677 | DISALLOW_COPY_AND_ASSIGN(SetCookieWithOptionsTask); |
| 678 | }; |
| 679 | |
| 680 | void CookieMonster::SetCookieWithOptionsTask::Run() { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 681 | bool result = this->cookie_monster()->SetCookieWithOptions(url_, cookie_line_, |
| 682 | options_); |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 683 | if (!callback_.is_null()) |
| 684 | callback_.Run(result); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 685 | } |
| 686 | |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 687 | // Task class for SetAllCookies call. |
| 688 | class CookieMonster::SetAllCookiesTask : public CookieMonsterTask { |
| 689 | public: |
| 690 | SetAllCookiesTask(CookieMonster* cookie_monster, |
| 691 | const CookieList& list, |
| 692 | const SetCookiesCallback& callback) |
| 693 | : CookieMonsterTask(cookie_monster), list_(list), callback_(callback) {} |
| 694 | |
| 695 | // CookieMonsterTask: |
| 696 | void Run() override; |
| 697 | |
| 698 | protected: |
| 699 | ~SetAllCookiesTask() override {} |
| 700 | |
| 701 | private: |
| 702 | CookieList list_; |
| 703 | SetCookiesCallback callback_; |
| 704 | |
| 705 | DISALLOW_COPY_AND_ASSIGN(SetAllCookiesTask); |
| 706 | }; |
| 707 | |
| 708 | void CookieMonster::SetAllCookiesTask::Run() { |
| 709 | CookieList positive_diff; |
| 710 | CookieList negative_diff; |
| 711 | CookieList old_cookies = this->cookie_monster()->GetAllCookies(); |
| 712 | this->cookie_monster()->ComputeCookieDiff(&old_cookies, &list_, |
| 713 | &positive_diff, &negative_diff); |
| 714 | |
| 715 | for (CookieList::const_iterator it = negative_diff.begin(); |
| 716 | it != negative_diff.end(); ++it) { |
| 717 | this->cookie_monster()->DeleteCanonicalCookie(*it); |
| 718 | } |
| 719 | |
| 720 | bool result = true; |
| 721 | if (positive_diff.size() > 0) |
| 722 | result = this->cookie_monster()->SetCanonicalCookies(list_); |
| 723 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 724 | if (!callback_.is_null()) |
| 725 | callback_.Run(result); |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 726 | } |
| 727 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 728 | // Task class for GetCookiesWithOptions call. |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 729 | class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 730 | public: |
| 731 | GetCookiesWithOptionsTask(CookieMonster* cookie_monster, |
[email protected] | 0298caf8 | 2011-12-20 23:15:46 | [diff] [blame] | 732 | const GURL& url, |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 733 | const CookieOptions& options, |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 734 | const GetCookiesCallback& callback) |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 735 | : CookieMonsterTask(cookie_monster), |
| 736 | url_(url), |
| 737 | options_(options), |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 738 | callback_(callback) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 739 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 740 | // CookieMonsterTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 741 | void Run() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 742 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 743 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 744 | ~GetCookiesWithOptionsTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 745 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 746 | private: |
| 747 | GURL url_; |
| 748 | CookieOptions options_; |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 749 | GetCookiesCallback callback_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 750 | |
| 751 | DISALLOW_COPY_AND_ASSIGN(GetCookiesWithOptionsTask); |
| 752 | }; |
| 753 | |
| 754 | void CookieMonster::GetCookiesWithOptionsTask::Run() { |
pkasting | a9269aa4 | 2015-04-10 01:42:26 | [diff] [blame] | 755 | // TODO(mkwst): Remove ScopedTracker below once crbug.com/456373 is fixed. |
pkasting | 58e029b | 2015-02-21 05:17:28 | [diff] [blame] | 756 | tracked_objects::ScopedTracker tracking_profile( |
| 757 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 758 | "456373 CookieMonster::GetCookiesWithOptionsTask::Run")); |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 759 | std::string cookie = |
| 760 | this->cookie_monster()->GetCookiesWithOptions(url_, options_); |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 761 | if (!callback_.is_null()) |
| 762 | callback_.Run(cookie); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 763 | } |
| 764 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 765 | // Task class for DeleteCookie call. |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 766 | class CookieMonster::DeleteCookieTask : public DeleteTask<void> { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 767 | public: |
| 768 | DeleteCookieTask(CookieMonster* cookie_monster, |
[email protected] | 0298caf8 | 2011-12-20 23:15:46 | [diff] [blame] | 769 | const GURL& url, |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 770 | const std::string& cookie_name, |
| 771 | const base::Closure& callback) |
[email protected] | 151132f | 2013-11-18 21:37:00 | [diff] [blame] | 772 | : DeleteTask<void>(cookie_monster, callback), |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 773 | url_(url), |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 774 | cookie_name_(cookie_name) {} |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 775 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 776 | // DeleteTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 777 | void RunDeleteTask() override; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 778 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 779 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 780 | ~DeleteCookieTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 781 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 782 | private: |
| 783 | GURL url_; |
| 784 | std::string cookie_name_; |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 785 | |
| 786 | DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); |
| 787 | }; |
| 788 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 789 | void CookieMonster::DeleteCookieTask::RunDeleteTask() { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 790 | this->cookie_monster()->DeleteCookie(url_, cookie_name_); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 791 | } |
| 792 | |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 793 | // Task class for DeleteSessionCookies call. |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 794 | class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> { |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 795 | public: |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 796 | DeleteSessionCookiesTask(CookieMonster* cookie_monster, |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 797 | const DeleteCallback& callback) |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 798 | : DeleteTask<int>(cookie_monster, callback) {} |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 799 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 800 | // DeleteTask: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 801 | int RunDeleteTask() override; |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 802 | |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 803 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 804 | ~DeleteSessionCookiesTask() override {} |
[email protected] | a981330 | 2012-04-28 09:29:28 | [diff] [blame] | 805 | |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 806 | private: |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 807 | DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); |
| 808 | }; |
| 809 | |
[email protected] | 5fa4f9a | 2013-10-03 10:13:16 | [diff] [blame] | 810 | int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { |
| 811 | return this->cookie_monster()->DeleteSessionCookies(); |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 812 | } |
| 813 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 814 | // Asynchronous CookieMonster API |
| 815 | |
| 816 | void CookieMonster::SetCookieWithDetailsAsync( |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 817 | const GURL& url, |
| 818 | const std::string& name, |
| 819 | const std::string& value, |
| 820 | const std::string& domain, |
| 821 | const std::string& path, |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 822 | Time creation_time, |
| 823 | Time expiration_time, |
| 824 | Time last_access_time, |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 825 | bool secure, |
| 826 | bool http_only, |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 827 | bool same_site, |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 828 | bool enforce_strict_secure, |
[email protected] | ab2d75c8 | 2013-04-19 18:39:04 | [diff] [blame] | 829 | CookiePriority priority, |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 830 | const SetCookiesCallback& callback) { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 831 | scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 832 | this, url, name, value, domain, path, creation_time, expiration_time, |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 833 | last_access_time, secure, http_only, same_site, enforce_strict_secure, |
| 834 | priority, callback); |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 835 | DoCookieTaskForURL(task, url); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 836 | } |
| 837 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 838 | void CookieMonster::FlushStore(const base::Closure& callback) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 839 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 606c59c | 2016-03-07 18:20:55 | [diff] [blame] | 840 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 841 | if (initialized_ && store_.get()) |
| 842 | store_->Flush(callback); |
| 843 | else if (!callback.is_null()) |
| 844 | base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 845 | } |
| 846 | |
mmenke | ded79da | 2016-02-06 08:28:51 | [diff] [blame] | 847 | void CookieMonster::SetForceKeepSessionState() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 848 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 606c59c | 2016-03-07 18:20:55 | [diff] [blame] | 849 | |
mmenke | ded79da | 2016-02-06 08:28:51 | [diff] [blame] | 850 | if (store_) |
| 851 | store_->SetForceKeepSessionState(); |
| 852 | } |
| 853 | |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 854 | void CookieMonster::SetAllCookiesAsync(const CookieList& list, |
| 855 | const SetCookiesCallback& callback) { |
| 856 | scoped_refptr<SetAllCookiesTask> task = |
| 857 | new SetAllCookiesTask(this, list, callback); |
| 858 | DoCookieTask(task); |
| 859 | } |
| 860 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 861 | void CookieMonster::SetCookieWithOptionsAsync( |
| 862 | const GURL& url, |
| 863 | const std::string& cookie_line, |
| 864 | const CookieOptions& options, |
| 865 | const SetCookiesCallback& callback) { |
| 866 | scoped_refptr<SetCookieWithOptionsTask> task = |
| 867 | new SetCookieWithOptionsTask(this, url, cookie_line, options, callback); |
| 868 | |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 869 | DoCookieTaskForURL(task, url); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | void CookieMonster::GetCookiesWithOptionsAsync( |
| 873 | const GURL& url, |
| 874 | const CookieOptions& options, |
| 875 | const GetCookiesCallback& callback) { |
| 876 | scoped_refptr<GetCookiesWithOptionsTask> task = |
| 877 | new GetCookiesWithOptionsTask(this, url, options, callback); |
| 878 | |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 879 | DoCookieTaskForURL(task, url); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 880 | } |
| 881 | |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 882 | void CookieMonster::GetCookieListWithOptionsAsync( |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 883 | const GURL& url, |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 884 | const CookieOptions& options, |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 885 | const GetCookieListCallback& callback) { |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 886 | scoped_refptr<GetCookieListWithOptionsTask> task = |
| 887 | new GetCookieListWithOptionsTask(this, url, options, callback); |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 888 | |
| 889 | DoCookieTaskForURL(task, url); |
| 890 | } |
| 891 | |
mmenke | 9fa44f2d | 2016-01-22 23:36:39 | [diff] [blame] | 892 | void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { |
| 893 | scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); |
| 894 | |
| 895 | DoCookieTask(task); |
| 896 | } |
| 897 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 898 | void CookieMonster::DeleteCookieAsync(const GURL& url, |
| 899 | const std::string& cookie_name, |
| 900 | const base::Closure& callback) { |
| 901 | scoped_refptr<DeleteCookieTask> task = |
| 902 | new DeleteCookieTask(this, url, cookie_name, callback); |
| 903 | |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 904 | DoCookieTaskForURL(task, url); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 905 | } |
| 906 | |
mmenke | 24379d5 | 2016-02-05 23:50:17 | [diff] [blame] | 907 | void CookieMonster::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
| 908 | const DeleteCallback& callback) { |
| 909 | scoped_refptr<DeleteCanonicalCookieTask> task = |
| 910 | new DeleteCanonicalCookieTask(this, cookie, callback); |
| 911 | |
| 912 | DoCookieTask(task); |
| 913 | } |
| 914 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 915 | void CookieMonster::DeleteAllCreatedBetweenAsync( |
| 916 | const Time& delete_begin, |
| 917 | const Time& delete_end, |
| 918 | const DeleteCallback& callback) { |
| 919 | scoped_refptr<DeleteAllCreatedBetweenTask> task = |
| 920 | new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback); |
| 921 | |
| 922 | DoCookieTask(task); |
| 923 | } |
| 924 | |
| 925 | void CookieMonster::DeleteAllCreatedBetweenForHostAsync( |
| 926 | const Time delete_begin, |
| 927 | const Time delete_end, |
| 928 | const GURL& url, |
| 929 | const DeleteCallback& callback) { |
| 930 | scoped_refptr<DeleteAllCreatedBetweenForHostTask> task = |
| 931 | new DeleteAllCreatedBetweenForHostTask(this, delete_begin, delete_end, |
| 932 | url, callback); |
| 933 | |
| 934 | DoCookieTaskForURL(task, url); |
| 935 | } |
| 936 | |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 937 | void CookieMonster::DeleteSessionCookiesAsync( |
| 938 | const CookieStore::DeleteCallback& callback) { |
| 939 | scoped_refptr<DeleteSessionCookiesTask> task = |
| 940 | new DeleteSessionCookiesTask(this, callback); |
| 941 | |
| 942 | DoCookieTask(task); |
| 943 | } |
| 944 | |
mmenke | 18dd8ba | 2016-02-01 18:42:10 | [diff] [blame] | 945 | void CookieMonster::SetCookieableSchemes( |
| 946 | const std::vector<std::string>& schemes) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 947 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 948 | |
| 949 | // Calls to this method will have no effect if made after a WebView or |
| 950 | // CookieManager instance has been created. |
mmenke | 18dd8ba | 2016-02-01 18:42:10 | [diff] [blame] | 951 | if (initialized_) |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 952 | return; |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 953 | |
mmenke | 18dd8ba | 2016-02-01 18:42:10 | [diff] [blame] | 954 | cookieable_schemes_ = schemes; |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 955 | } |
| 956 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 957 | // This function must be called before the CookieMonster is used. |
| 958 | void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 959 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 960 | DCHECK(!initialized_); |
| 961 | persist_session_cookies_ = persist_session_cookies; |
| 962 | } |
| 963 | |
| 964 | bool CookieMonster::IsCookieableScheme(const std::string& scheme) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 965 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 966 | |
| 967 | return std::find(cookieable_schemes_.begin(), cookieable_schemes_.end(), |
| 968 | scheme) != cookieable_schemes_.end(); |
| 969 | } |
| 970 | |
mmenke | 18dd8ba | 2016-02-01 18:42:10 | [diff] [blame] | 971 | const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", "https", |
| 972 | "ws", "wss"}; |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 973 | const int CookieMonster::kDefaultCookieableSchemesCount = |
| 974 | arraysize(kDefaultCookieableSchemes); |
| 975 | |
| 976 | scoped_ptr<CookieStore::CookieChangedSubscription> |
| 977 | CookieMonster::AddCallbackForCookie(const GURL& gurl, |
| 978 | const std::string& name, |
| 979 | const CookieChangedCallback& callback) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 980 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 606c59c | 2016-03-07 18:20:55 | [diff] [blame] | 981 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 982 | std::pair<GURL, std::string> key(gurl, name); |
| 983 | if (hook_map_.count(key) == 0) |
| 984 | hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); |
| 985 | return hook_map_[key]->Add( |
| 986 | base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback)); |
| 987 | } |
| 988 | |
nharper | 5babb5e6 | 2016-03-09 18:58:07 | [diff] [blame] | 989 | bool CookieMonster::IsEphemeral() { |
| 990 | return store_.get() == nullptr; |
| 991 | } |
| 992 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 993 | CookieMonster::~CookieMonster() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 994 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 05255cf | 2016-02-03 15:49:31 | [diff] [blame] | 995 | |
mmenke | 606c59c | 2016-03-07 18:20:55 | [diff] [blame] | 996 | // TODO(mmenke): Does it really make sense to run |delegate_| and |
| 997 | // CookieChanged callbacks when the CookieStore is destroyed? |
mmenke | 05255cf | 2016-02-03 15:49:31 | [diff] [blame] | 998 | for (CookieMap::iterator cookie_it = cookies_.begin(); |
| 999 | cookie_it != cookies_.end();) { |
| 1000 | CookieMap::iterator current_cookie_it = cookie_it; |
| 1001 | ++cookie_it; |
| 1002 | InternalDeleteCookie(current_cookie_it, false /* sync_to_store */, |
| 1003 | DELETE_COOKIE_DONT_RECORD); |
| 1004 | } |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1005 | } |
| 1006 | |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 1007 | bool CookieMonster::SetCookieWithDetails(const GURL& url, |
| 1008 | const std::string& name, |
| 1009 | const std::string& value, |
| 1010 | const std::string& domain, |
| 1011 | const std::string& path, |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 1012 | base::Time creation_time, |
| 1013 | base::Time expiration_time, |
| 1014 | base::Time last_access_time, |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 1015 | bool secure, |
[email protected] | ab2d75c8 | 2013-04-19 18:39:04 | [diff] [blame] | 1016 | bool http_only, |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 1017 | bool same_site, |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1018 | bool enforce_strict_secure, |
[email protected] | ab2d75c8 | 2013-04-19 18:39:04 | [diff] [blame] | 1019 | CookiePriority priority) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1020 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 69bb587 | 2010-01-12 20:33:52 | [diff] [blame] | 1021 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1022 | if (!HasCookieableScheme(url)) |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1023 | return false; |
| 1024 | |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1025 | // TODO(mmenke): This class assumes each cookie to have a unique creation |
| 1026 | // time. Allowing the caller to set the creation time violates that |
| 1027 | // assumption. Worth fixing? Worth noting that time changes between browser |
| 1028 | // restarts can cause the same issue. |
| 1029 | base::Time actual_creation_time = creation_time; |
| 1030 | if (creation_time.is_null()) { |
| 1031 | actual_creation_time = CurrentTime(); |
| 1032 | last_time_seen_ = actual_creation_time; |
| 1033 | } |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1034 | |
tfh | 4623ce8 | 2016-01-21 10:37:37 | [diff] [blame] | 1035 | scoped_ptr<CanonicalCookie> cc(CanonicalCookie::Create( |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1036 | url, name, value, domain, path, actual_creation_time, expiration_time, |
| 1037 | secure, http_only, same_site, enforce_strict_secure, priority)); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1038 | |
| 1039 | if (!cc.get()) |
| 1040 | return false; |
| 1041 | |
mmenke | fdd4fc7 | 2016-02-05 20:53:24 | [diff] [blame] | 1042 | if (!last_access_time.is_null()) |
| 1043 | cc->SetLastAccessDate(last_access_time); |
| 1044 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1045 | CookieOptions options; |
| 1046 | options.set_include_httponly(); |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 1047 | options.set_include_same_site(); |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1048 | if (enforce_strict_secure) |
| 1049 | options.set_enforce_strict_secure(); |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1050 | return SetCanonicalCookie(std::move(cc), options); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1051 | } |
| 1052 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1053 | CookieList CookieMonster::GetAllCookies() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1054 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1055 | |
| 1056 | // This function is being called to scrape the cookie list for management UI |
| 1057 | // or similar. We shouldn't show expired cookies in this list since it will |
| 1058 | // just be confusing to users, and this function is called rarely enough (and |
| 1059 | // is already slow enough) that it's OK to take the time to garbage collect |
| 1060 | // the expired cookies now. |
| 1061 | // |
| 1062 | // Note that this does not prune cookies to be below our limits (if we've |
| 1063 | // exceeded them) the way that calling GarbageCollect() would. |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1064 | GarbageCollectExpired( |
| 1065 | Time::Now(), CookieMapItPair(cookies_.begin(), cookies_.end()), NULL); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1066 | |
| 1067 | // Copy the CanonicalCookie pointers from the map so that we can use the same |
| 1068 | // sorter as elsewhere, then copy the result out. |
| 1069 | std::vector<CanonicalCookie*> cookie_ptrs; |
| 1070 | cookie_ptrs.reserve(cookies_.size()); |
| 1071 | for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end(); ++it) |
| 1072 | cookie_ptrs.push_back(it->second); |
| 1073 | std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); |
| 1074 | |
| 1075 | CookieList cookie_list; |
| 1076 | cookie_list.reserve(cookie_ptrs.size()); |
| 1077 | for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); |
| 1078 | it != cookie_ptrs.end(); ++it) |
| 1079 | cookie_list.push_back(**it); |
| 1080 | |
| 1081 | return cookie_list; |
[email protected] | f325f1e1 | 2010-04-30 22:38:55 | [diff] [blame] | 1082 | } |
| 1083 | |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 1084 | CookieList CookieMonster::GetCookieListWithOptions( |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1085 | const GURL& url, |
| 1086 | const CookieOptions& options) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1087 | DCHECK(thread_checker_.CalledOnValidThread()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1088 | |
mkwst | c611e6d | 2016-02-23 15:45:55 | [diff] [blame] | 1089 | CookieList cookies; |
| 1090 | if (!HasCookieableScheme(url)) |
| 1091 | return cookies; |
| 1092 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1093 | std::vector<CanonicalCookie*> cookie_ptrs; |
mkwst | 72b6516 | 2016-02-22 19:58:54 | [diff] [blame] | 1094 | FindCookiesForHostAndDomain(url, options, &cookie_ptrs); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1095 | std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1096 | |
georgesak | c15df672 | 2014-12-02 23:52:12 | [diff] [blame] | 1097 | cookies.reserve(cookie_ptrs.size()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1098 | for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); |
| 1099 | it != cookie_ptrs.end(); it++) |
| 1100 | cookies.push_back(**it); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1101 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1102 | return cookies; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1103 | } |
| 1104 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1105 | int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin, |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1106 | const Time& delete_end) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1107 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | d098033 | 2010-11-16 17:08:53 | [diff] [blame] | 1108 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1109 | int num_deleted = 0; |
| 1110 | for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1111 | CookieMap::iterator curit = it; |
| 1112 | CanonicalCookie* cc = curit->second; |
| 1113 | ++it; |
[email protected] | d098033 | 2010-11-16 17:08:53 | [diff] [blame] | 1114 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1115 | if (cc->CreationDate() >= delete_begin && |
| 1116 | (delete_end.is_null() || cc->CreationDate() < delete_end)) { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1117 | InternalDeleteCookie(curit, true, /*sync_to_store*/ |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1118 | DELETE_COOKIE_EXPLICIT); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1119 | ++num_deleted; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1120 | } |
| 1121 | } |
| 1122 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1123 | return num_deleted; |
| 1124 | } |
| 1125 | |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 1126 | int CookieMonster::DeleteAllCreatedBetweenForHost(const Time delete_begin, |
| 1127 | const Time delete_end, |
| 1128 | const GURL& url) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1129 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1130 | |
| 1131 | if (!HasCookieableScheme(url)) |
| 1132 | return 0; |
| 1133 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1134 | const std::string host(url.host()); |
| 1135 | |
| 1136 | // We store host cookies in the store by their canonical host name; |
| 1137 | // domain cookies are stored with a leading ".". So this is a pretty |
| 1138 | // simple lookup and per-cookie delete. |
| 1139 | int num_deleted = 0; |
| 1140 | for (CookieMapItPair its = cookies_.equal_range(GetKey(host)); |
| 1141 | its.first != its.second;) { |
| 1142 | CookieMap::iterator curit = its.first; |
| 1143 | ++its.first; |
| 1144 | |
| 1145 | const CanonicalCookie* const cc = curit->second; |
| 1146 | |
| 1147 | // Delete only on a match as a host cookie. |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 1148 | if (cc->IsHostCookie() && cc->IsDomainMatch(host) && |
| 1149 | cc->CreationDate() >= delete_begin && |
| 1150 | // The assumption that null |delete_end| is equivalent to |
| 1151 | // Time::Max() is confusing. |
| 1152 | (delete_end.is_null() || cc->CreationDate() < delete_end)) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1153 | num_deleted++; |
| 1154 | |
| 1155 | InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); |
| 1156 | } |
| 1157 | } |
| 1158 | return num_deleted; |
| 1159 | } |
| 1160 | |
[email protected] | d8428d5 | 2013-08-07 06:58:25 | [diff] [blame] | 1161 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1162 | bool CookieMonster::SetCookieWithOptions(const GURL& url, |
| 1163 | const std::string& cookie_line, |
| 1164 | const CookieOptions& options) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1165 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1166 | |
| 1167 | if (!HasCookieableScheme(url)) { |
| 1168 | return false; |
| 1169 | } |
| 1170 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1171 | return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options); |
| 1172 | } |
| 1173 | |
| 1174 | std::string CookieMonster::GetCookiesWithOptions(const GURL& url, |
| 1175 | const CookieOptions& options) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1176 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1177 | |
[email protected] | 34a160d | 2011-05-12 22:12:49 | [diff] [blame] | 1178 | if (!HasCookieableScheme(url)) |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1179 | return std::string(); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1180 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1181 | std::vector<CanonicalCookie*> cookies; |
mkwst | 72b6516 | 2016-02-22 19:58:54 | [diff] [blame] | 1182 | FindCookiesForHostAndDomain(url, options, &cookies); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1183 | std::sort(cookies.begin(), cookies.end(), CookieSorter); |
| 1184 | |
[email protected] | 34a160d | 2011-05-12 22:12:49 | [diff] [blame] | 1185 | std::string cookie_line = BuildCookieLine(cookies); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1186 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1187 | VLOG(kVlogGetCookies) << "GetCookies() result: " << cookie_line; |
| 1188 | |
| 1189 | return cookie_line; |
| 1190 | } |
| 1191 | |
| 1192 | void CookieMonster::DeleteCookie(const GURL& url, |
| 1193 | const std::string& cookie_name) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1194 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1195 | |
| 1196 | if (!HasCookieableScheme(url)) |
| 1197 | return; |
| 1198 | |
| 1199 | CookieOptions options; |
| 1200 | options.set_include_httponly(); |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 1201 | options.set_include_same_site(); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1202 | // Get the cookies for this host and its domain(s). |
| 1203 | std::vector<CanonicalCookie*> cookies; |
mkwst | 72b6516 | 2016-02-22 19:58:54 | [diff] [blame] | 1204 | FindCookiesForHostAndDomain(url, options, &cookies); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1205 | std::set<CanonicalCookie*> matching_cookies; |
| 1206 | |
mmenke | 4379aeb | 2016-03-05 12:22:07 | [diff] [blame] | 1207 | for (const auto& cookie : cookies) { |
| 1208 | if (cookie->Name() != cookie_name) |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1209 | continue; |
mmenke | 4379aeb | 2016-03-05 12:22:07 | [diff] [blame] | 1210 | if (!cookie->IsOnPath(url.path())) |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1211 | continue; |
mmenke | 4379aeb | 2016-03-05 12:22:07 | [diff] [blame] | 1212 | matching_cookies.insert(cookie); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1216 | CookieMap::iterator curit = it; |
| 1217 | ++it; |
| 1218 | if (matching_cookies.find(curit->second) != matching_cookies.end()) { |
| 1219 | InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
mmenke | 24379d5 | 2016-02-05 23:50:17 | [diff] [blame] | 1224 | int CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1225 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 24379d5 | 2016-02-05 23:50:17 | [diff] [blame] | 1226 | |
| 1227 | for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain())); |
| 1228 | its.first != its.second; ++its.first) { |
| 1229 | // The creation date acts as the unique index... |
| 1230 | if (its.first->second->CreationDate() == cookie.CreationDate()) { |
| 1231 | InternalDeleteCookie(its.first, true, DELETE_COOKIE_EXPLICIT); |
| 1232 | return 1; |
| 1233 | } |
| 1234 | } |
| 1235 | return 0; |
| 1236 | } |
| 1237 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 1238 | bool CookieMonster::SetCookieWithCreationTime(const GURL& url, |
| 1239 | const std::string& cookie_line, |
| 1240 | const base::Time& creation_time) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1241 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 1242 | DCHECK(!store_.get()) << "This method is only to be used by unit-tests."; |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 1243 | |
| 1244 | if (!HasCookieableScheme(url)) { |
| 1245 | return false; |
| 1246 | } |
| 1247 | |
| 1248 | MarkCookieStoreAsInitialized(); |
| 1249 | if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) |
| 1250 | FetchAllCookiesIfNecessary(); |
| 1251 | |
| 1252 | return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, |
| 1253 | CookieOptions()); |
| 1254 | } |
| 1255 | |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 1256 | int CookieMonster::DeleteSessionCookies() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1257 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 1258 | |
| 1259 | int num_deleted = 0; |
| 1260 | for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1261 | CookieMap::iterator curit = it; |
| 1262 | CanonicalCookie* cc = curit->second; |
| 1263 | ++it; |
| 1264 | |
| 1265 | if (!cc->IsPersistent()) { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1266 | InternalDeleteCookie(curit, true, /*sync_to_store*/ |
[email protected] | 264807b | 2012-04-25 14:49:37 | [diff] [blame] | 1267 | DELETE_COOKIE_EXPIRED); |
| 1268 | ++num_deleted; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | return num_deleted; |
| 1273 | } |
| 1274 | |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 1275 | void CookieMonster::MarkCookieStoreAsInitialized() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1276 | DCHECK(thread_checker_.CalledOnValidThread()); |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 1277 | initialized_ = true; |
| 1278 | } |
| 1279 | |
| 1280 | void CookieMonster::FetchAllCookiesIfNecessary() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1281 | DCHECK(thread_checker_.CalledOnValidThread()); |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 1282 | if (store_.get() && !started_fetching_all_cookies_) { |
| 1283 | started_fetching_all_cookies_ = true; |
| 1284 | FetchAllCookies(); |
| 1285 | } |
| 1286 | } |
| 1287 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 1288 | void CookieMonster::FetchAllCookies() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1289 | DCHECK(thread_checker_.CalledOnValidThread()); |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 1290 | DCHECK(store_.get()) << "Store must exist to initialize"; |
| 1291 | DCHECK(!finished_fetching_all_cookies_) |
| 1292 | << "All cookies have already been fetched."; |
| 1293 | |
| 1294 | // We bind in the current time so that we can report the wall-clock time for |
| 1295 | // loading cookies. |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1296 | store_->Load(base::Bind(&CookieMonster::OnLoaded, |
| 1297 | weak_ptr_factory_.GetWeakPtr(), TimeTicks::Now())); |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 1298 | } |
| 1299 | |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 1300 | bool CookieMonster::ShouldFetchAllCookiesWhenFetchingAnyCookie() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1301 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 1302 | |
erikchen | 1dd72a7 | 2015-05-06 20:45:05 | [diff] [blame] | 1303 | if (fetch_strategy_ == kUnknownFetch) { |
| 1304 | const std::string group_name = |
| 1305 | base::FieldTrialList::FindFullName(kCookieMonsterFetchStrategyName); |
| 1306 | if (group_name == kFetchWhenNecessaryName) { |
| 1307 | fetch_strategy_ = kFetchWhenNecessary; |
| 1308 | } else if (group_name == kAlwaysFetchName) { |
| 1309 | fetch_strategy_ = kAlwaysFetch; |
| 1310 | } else { |
| 1311 | // The logic in the conditional is redundant, but it makes trials of |
| 1312 | // the Finch experiment more explicit. |
| 1313 | fetch_strategy_ = kAlwaysFetch; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | return fetch_strategy_ == kAlwaysFetch; |
| 1318 | } |
| 1319 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1320 | void CookieMonster::OnLoaded(TimeTicks beginning_time, |
| 1321 | const std::vector<CanonicalCookie*>& cookies) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1322 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1323 | StoreLoadedCookies(cookies); |
[email protected] | c7593fb2 | 2011-11-14 23:54:27 | [diff] [blame] | 1324 | histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1325 | |
| 1326 | // Invoke the task queue of cookie request. |
| 1327 | InvokeQueue(); |
| 1328 | } |
| 1329 | |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1330 | void CookieMonster::OnKeyLoaded(const std::string& key, |
| 1331 | const std::vector<CanonicalCookie*>& cookies) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1332 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 1333 | |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1334 | StoreLoadedCookies(cookies); |
| 1335 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1336 | auto tasks_pending_for_key = tasks_pending_for_key_.find(key); |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1337 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1338 | // TODO(mmenke): Can this be turned into a DCHECK? |
| 1339 | if (tasks_pending_for_key == tasks_pending_for_key_.end()) |
| 1340 | return; |
[email protected] | bab72ec | 2013-10-30 20:50:02 | [diff] [blame] | 1341 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1342 | // Run all tasks for the key. Note that running a task can result in multiple |
| 1343 | // tasks being added to the back of the deque. |
| 1344 | while (!tasks_pending_for_key->second.empty()) { |
| 1345 | scoped_refptr<CookieMonsterTask> task = |
| 1346 | tasks_pending_for_key->second.front(); |
| 1347 | tasks_pending_for_key->second.pop_front(); |
| 1348 | |
| 1349 | task->Run(); |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1350 | } |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1351 | |
| 1352 | tasks_pending_for_key_.erase(tasks_pending_for_key); |
| 1353 | |
| 1354 | // This has to be done last, in case running a task queues a new task for the |
| 1355 | // key, to ensure tasks are run in the correct order. |
| 1356 | keys_loaded_.insert(key); |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1357 | } |
| 1358 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1359 | void CookieMonster::StoreLoadedCookies( |
| 1360 | const std::vector<CanonicalCookie*>& cookies) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1361 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 1362 | |
pkasting | ec2cdb5 | 2015-05-02 01:19:34 | [diff] [blame] | 1363 | // TODO(erikwright): Remove ScopedTracker below once crbug.com/457528 is |
| 1364 | // fixed. |
| 1365 | tracked_objects::ScopedTracker tracking_profile( |
| 1366 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1367 | "457528 CookieMonster::StoreLoadedCookies")); |
| 1368 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1369 | // Even if a key is expired, insert it so it can be garbage collected, |
| 1370 | // removed, and sync'd. |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1371 | CookieItVector cookies_with_control_chars; |
| 1372 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1373 | for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); |
| 1374 | it != cookies.end(); ++it) { |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1375 | int64_t cookie_creation_time = (*it)->CreationDate().ToInternalValue(); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1376 | |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1377 | if (creation_times_.insert(cookie_creation_time).second) { |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1378 | CookieMap::iterator inserted = |
| 1379 | InternalInsertCookie(GetKey((*it)->Domain()), *it, false); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1380 | const Time cookie_access_time((*it)->LastAccessDate()); |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1381 | if (earliest_access_time_.is_null() || |
| 1382 | cookie_access_time < earliest_access_time_) |
| 1383 | earliest_access_time_ = cookie_access_time; |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1384 | |
| 1385 | if (ContainsControlCharacter((*it)->Name()) || |
| 1386 | ContainsControlCharacter((*it)->Value())) { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1387 | cookies_with_control_chars.push_back(inserted); |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1388 | } |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1389 | } else { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1390 | LOG(ERROR) << base::StringPrintf( |
| 1391 | "Found cookies with duplicate creation " |
| 1392 | "times in backing store: " |
| 1393 | "{name='%s', domain='%s', path='%s'}", |
| 1394 | (*it)->Name().c_str(), (*it)->Domain().c_str(), |
| 1395 | (*it)->Path().c_str()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1396 | // We've been given ownership of the cookie and are throwing it |
| 1397 | // away; reclaim the space. |
| 1398 | delete (*it); |
| 1399 | } |
| 1400 | } |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1401 | |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1402 | // Any cookies that contain control characters that we have loaded from the |
| 1403 | // persistent store should be deleted. See http://crbug.com/238041. |
| 1404 | for (CookieItVector::iterator it = cookies_with_control_chars.begin(); |
| 1405 | it != cookies_with_control_chars.end();) { |
| 1406 | CookieItVector::iterator curit = it; |
| 1407 | ++it; |
| 1408 | |
| 1409 | InternalDeleteCookie(*curit, true, DELETE_COOKIE_CONTROL_CHAR); |
| 1410 | } |
| 1411 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1412 | // After importing cookies from the PersistentCookieStore, verify that |
| 1413 | // none of our other constraints are violated. |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1414 | // In particular, the backing store might have given us duplicate cookies. |
[email protected] | 8562034 | 2011-10-17 17:35:04 | [diff] [blame] | 1415 | |
| 1416 | // This method could be called multiple times due to priority loading, thus |
| 1417 | // cookies loaded in previous runs will be validated again, but this is OK |
| 1418 | // since they are expected to be much fewer than total DB. |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1419 | EnsureCookiesMapIsValid(); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1420 | } |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1421 | |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1422 | void CookieMonster::InvokeQueue() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1423 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 1424 | |
mmenke | f49fca0e | 2016-03-08 12:46:24 | [diff] [blame] | 1425 | // Move all per-key tasks into the global queue, if there are any. This is |
| 1426 | // protection about a race where the store learns about all cookies loading |
| 1427 | // before it learned about the cookies for a key loading. |
| 1428 | |
| 1429 | // Needed to prevent any recursively queued tasks from going back into the |
| 1430 | // per-key queues. |
| 1431 | seen_global_task_ = true; |
| 1432 | for (const auto& tasks_for_key : tasks_pending_for_key_) { |
| 1433 | tasks_pending_.insert(tasks_pending_.begin(), tasks_for_key.second.begin(), |
| 1434 | tasks_for_key.second.end()); |
| 1435 | } |
| 1436 | tasks_pending_for_key_.clear(); |
| 1437 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1438 | while (!tasks_pending_.empty()) { |
| 1439 | scoped_refptr<CookieMonsterTask> request_task = tasks_pending_.front(); |
mmenke | f49fca0e | 2016-03-08 12:46:24 | [diff] [blame] | 1440 | tasks_pending_.pop_front(); |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1441 | request_task->Run(); |
| 1442 | } |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1443 | |
mmenke | f49fca0e | 2016-03-08 12:46:24 | [diff] [blame] | 1444 | DCHECK(tasks_pending_for_key_.empty()); |
| 1445 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1446 | finished_fetching_all_cookies_ = true; |
| 1447 | creation_times_.clear(); |
| 1448 | keys_loaded_.clear(); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | void CookieMonster::EnsureCookiesMapIsValid() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1452 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1453 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1454 | // Iterate through all the of the cookies, grouped by host. |
| 1455 | CookieMap::iterator prev_range_end = cookies_.begin(); |
| 1456 | while (prev_range_end != cookies_.end()) { |
| 1457 | CookieMap::iterator cur_range_begin = prev_range_end; |
| 1458 | const std::string key = cur_range_begin->first; // Keep a copy. |
| 1459 | CookieMap::iterator cur_range_end = cookies_.upper_bound(key); |
| 1460 | prev_range_end = cur_range_end; |
| 1461 | |
| 1462 | // Ensure no equivalent cookies for this host. |
ellyjones | cabf5742 | 2015-08-21 18:44:51 | [diff] [blame] | 1463 | TrimDuplicateCookiesForKey(key, cur_range_begin, cur_range_end); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1464 | } |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1465 | } |
| 1466 | |
ellyjones | cabf5742 | 2015-08-21 18:44:51 | [diff] [blame] | 1467 | void CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, |
| 1468 | CookieMap::iterator begin, |
| 1469 | CookieMap::iterator end) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1470 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1471 | |
| 1472 | // Set of cookies ordered by creation time. |
| 1473 | typedef std::set<CookieMap::iterator, OrderByCreationTimeDesc> CookieSet; |
| 1474 | |
| 1475 | // Helper map we populate to find the duplicates. |
| 1476 | typedef std::map<CookieSignature, CookieSet> EquivalenceMap; |
| 1477 | EquivalenceMap equivalent_cookies; |
| 1478 | |
| 1479 | // The number of duplicate cookies that have been found. |
| 1480 | int num_duplicates = 0; |
| 1481 | |
| 1482 | // Iterate through all of the cookies in our range, and insert them into |
| 1483 | // the equivalence map. |
| 1484 | for (CookieMap::iterator it = begin; it != end; ++it) { |
| 1485 | DCHECK_EQ(key, it->first); |
| 1486 | CanonicalCookie* cookie = it->second; |
| 1487 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1488 | CookieSignature signature(cookie->Name(), cookie->Domain(), cookie->Path()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1489 | CookieSet& set = equivalent_cookies[signature]; |
| 1490 | |
| 1491 | // We found a duplicate! |
| 1492 | if (!set.empty()) |
| 1493 | num_duplicates++; |
| 1494 | |
| 1495 | // We save the iterator into |cookies_| rather than the actual cookie |
| 1496 | // pointer, since we may need to delete it later. |
| 1497 | bool insert_success = set.insert(it).second; |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1498 | DCHECK(insert_success) |
| 1499 | << "Duplicate creation times found in duplicate cookie name scan."; |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | // If there were no duplicates, we are done! |
| 1503 | if (num_duplicates == 0) |
ellyjones | cabf5742 | 2015-08-21 18:44:51 | [diff] [blame] | 1504 | return; |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1505 | |
| 1506 | // Make sure we find everything below that we did above. |
| 1507 | int num_duplicates_found = 0; |
| 1508 | |
| 1509 | // Otherwise, delete all the duplicate cookies, both from our in-memory store |
| 1510 | // and from the backing store. |
| 1511 | for (EquivalenceMap::iterator it = equivalent_cookies.begin(); |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1512 | it != equivalent_cookies.end(); ++it) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1513 | const CookieSignature& signature = it->first; |
| 1514 | CookieSet& dupes = it->second; |
| 1515 | |
| 1516 | if (dupes.size() <= 1) |
| 1517 | continue; // This cookiename/path has no duplicates. |
| 1518 | num_duplicates_found += dupes.size() - 1; |
| 1519 | |
| 1520 | // Since |dups| is sorted by creation time (descending), the first cookie |
| 1521 | // is the most recent one, so we will keep it. The rest are duplicates. |
| 1522 | dupes.erase(dupes.begin()); |
| 1523 | |
| 1524 | LOG(ERROR) << base::StringPrintf( |
| 1525 | "Found %d duplicate cookies for host='%s', " |
| 1526 | "with {name='%s', domain='%s', path='%s'}", |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1527 | static_cast<int>(dupes.size()), key.c_str(), signature.name.c_str(), |
| 1528 | signature.domain.c_str(), signature.path.c_str()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1529 | |
| 1530 | // Remove all the cookies identified by |dupes|. It is valid to delete our |
| 1531 | // list of iterators one at a time, since |cookies_| is a multimap (they |
| 1532 | // don't invalidate existing iterators following deletion). |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1533 | for (CookieSet::iterator dupes_it = dupes.begin(); dupes_it != dupes.end(); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1534 | ++dupes_it) { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 1535 | InternalDeleteCookie(*dupes_it, true, |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1536 | DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE); |
| 1537 | } |
| 1538 | } |
| 1539 | DCHECK_EQ(num_duplicates, num_duplicates_found); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1540 | } |
| 1541 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1542 | void CookieMonster::FindCookiesForHostAndDomain( |
| 1543 | const GURL& url, |
| 1544 | const CookieOptions& options, |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1545 | std::vector<CanonicalCookie*>* cookies) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1546 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1547 | |
| 1548 | const Time current_time(CurrentTime()); |
| 1549 | |
| 1550 | // Probe to save statistics relatively frequently. We do it here rather |
| 1551 | // than in the set path as many websites won't set cookies, and we |
| 1552 | // want to collect statistics whenever the browser's being used. |
| 1553 | RecordPeriodicStats(current_time); |
| 1554 | |
[email protected] | 8e158367 | 2012-02-11 04:39:41 | [diff] [blame] | 1555 | // Can just dispatch to FindCookiesForKey |
| 1556 | const std::string key(GetKey(url.host())); |
mkwst | 72b6516 | 2016-02-22 19:58:54 | [diff] [blame] | 1557 | FindCookiesForKey(key, url, options, current_time, cookies); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1558 | } |
| 1559 | |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 1560 | void CookieMonster::FindCookiesForKey(const std::string& key, |
| 1561 | const GURL& url, |
| 1562 | const CookieOptions& options, |
| 1563 | const Time& current, |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 1564 | std::vector<CanonicalCookie*>* cookies) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1565 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1566 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1567 | for (CookieMapItPair its = cookies_.equal_range(key); |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1568 | its.first != its.second;) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1569 | CookieMap::iterator curit = its.first; |
| 1570 | CanonicalCookie* cc = curit->second; |
| 1571 | ++its.first; |
| 1572 | |
| 1573 | // If the cookie is expired, delete it. |
mmenke | 3c79a65 | 2016-02-12 14:39:20 | [diff] [blame] | 1574 | if (cc->IsExpired(current)) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1575 | InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); |
| 1576 | continue; |
| 1577 | } |
| 1578 | |
[email protected] | 65f4e7e | 2012-12-12 21:56:54 | [diff] [blame] | 1579 | // Filter out cookies that should not be included for a request to the |
| 1580 | // given |url|. HTTP only cookies are filtered depending on the passed |
| 1581 | // cookie |options|. |
| 1582 | if (!cc->IncludeForRequestURL(url, options)) |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1583 | continue; |
| 1584 | |
[email protected] | 65f4e7e | 2012-12-12 21:56:54 | [diff] [blame] | 1585 | // Add this cookie to the set of matching cookies. Update the access |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1586 | // time if we've been requested to do so. |
mkwst | 72b6516 | 2016-02-22 19:58:54 | [diff] [blame] | 1587 | if (options.update_access_time()) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1588 | InternalUpdateCookieAccessTime(cc, current); |
| 1589 | } |
| 1590 | cookies->push_back(cc); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, |
| 1595 | const CanonicalCookie& ecc, |
[email protected] | e7c590e5 | 2011-03-30 08:33:55 | [diff] [blame] | 1596 | bool skip_httponly, |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1597 | bool already_expired, |
| 1598 | bool enforce_strict_secure) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1599 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1600 | |
| 1601 | bool found_equivalent_cookie = false; |
| 1602 | bool skipped_httponly = false; |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1603 | bool skipped_secure_cookie = false; |
jww | 31e3263 | 2015-12-16 23:38:34 | [diff] [blame] | 1604 | |
| 1605 | histogram_cookie_delete_equivalent_->Add(COOKIE_DELETE_EQUIVALENT_ATTEMPT); |
| 1606 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1607 | for (CookieMapItPair its = cookies_.equal_range(key); |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1608 | its.first != its.second;) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1609 | CookieMap::iterator curit = its.first; |
| 1610 | CanonicalCookie* cc = curit->second; |
| 1611 | ++its.first; |
| 1612 | |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1613 | // If strict secure cookies is being enforced, then the equivalency |
| 1614 | // requirements are looser. If the cookie is being set from an insecure |
| 1615 | // scheme, then if a cookie already exists with the same name and it is |
| 1616 | // Secure, then the cookie should *not* be updated if they domain-match and |
| 1617 | // ignoring the path attribute. |
| 1618 | // |
| 1619 | // See: https://tools.ietf.org/html/draft-west-leave-secure-cookies-alone |
| 1620 | if (enforce_strict_secure && !ecc.Source().SchemeIsCryptographic() && |
| 1621 | ecc.IsEquivalentForSecureCookieMatching(*cc) && cc->IsSecure()) { |
| 1622 | skipped_secure_cookie = true; |
jww | 31e3263 | 2015-12-16 23:38:34 | [diff] [blame] | 1623 | histogram_cookie_delete_equivalent_->Add( |
| 1624 | COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE); |
| 1625 | // If the cookie is equivalent to the new cookie and wouldn't have been |
| 1626 | // skipped for being HTTP-only, record that it is a skipped secure cookie |
| 1627 | // that would have been deleted otherwise. |
| 1628 | if (ecc.IsEquivalent(*cc)) { |
jww | a9a0d48 | 2015-12-16 18:19:41 | [diff] [blame] | 1629 | found_equivalent_cookie = true; |
jww | 31e3263 | 2015-12-16 23:38:34 | [diff] [blame] | 1630 | |
| 1631 | if (!skip_httponly || !cc->IsHttpOnly()) { |
| 1632 | histogram_cookie_delete_equivalent_->Add( |
| 1633 | COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED); |
| 1634 | } |
| 1635 | } |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1636 | } else if (ecc.IsEquivalent(*cc)) { |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1637 | // We should never have more than one equivalent cookie, since they should |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1638 | // overwrite each other, unless secure cookies require secure scheme is |
| 1639 | // being enforced. In that case, cookies with different paths might exist |
| 1640 | // and be considered equivalent. |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1641 | CHECK(!found_equivalent_cookie) |
| 1642 | << "Duplicate equivalent cookies found, cookie store is corrupted."; |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1643 | if (skip_httponly && cc->IsHttpOnly()) { |
| 1644 | skipped_httponly = true; |
| 1645 | } else { |
jww | 31e3263 | 2015-12-16 23:38:34 | [diff] [blame] | 1646 | histogram_cookie_delete_equivalent_->Add( |
| 1647 | COOKIE_DELETE_EQUIVALENT_FOUND); |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1648 | InternalDeleteCookie(curit, true, already_expired |
| 1649 | ? DELETE_COOKIE_EXPIRED_OVERWRITE |
| 1650 | : DELETE_COOKIE_OVERWRITE); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1651 | } |
| 1652 | found_equivalent_cookie = true; |
| 1653 | } |
| 1654 | } |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1655 | return skipped_httponly || skipped_secure_cookie; |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1656 | } |
| 1657 | |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1658 | CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( |
| 1659 | const std::string& key, |
| 1660 | CanonicalCookie* cc, |
| 1661 | bool sync_to_store) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1662 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 1663 | |
pkasting | a9269aa4 | 2015-04-10 01:42:26 | [diff] [blame] | 1664 | // TODO(mkwst): Remove ScopedTracker below once crbug.com/456373 is fixed. |
pkasting | 58e029b | 2015-02-21 05:17:28 | [diff] [blame] | 1665 | tracked_objects::ScopedTracker tracking_profile( |
| 1666 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1667 | "456373 CookieMonster::InternalInsertCookie")); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1668 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1669 | if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
| 1670 | sync_to_store) |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1671 | store_->AddCookie(*cc); |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1672 | CookieMap::iterator inserted = |
| 1673 | cookies_.insert(CookieMap::value_type(key, cc)); |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 1674 | if (delegate_.get()) { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1675 | delegate_->OnCookieChanged(*cc, false, |
| 1676 | CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 1677 | } |
mkwst | c1aa4cc | 2015-04-03 19:57:45 | [diff] [blame] | 1678 | |
| 1679 | // See InitializeHistograms() for details. |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 1680 | int32_t type_sample = cc->IsSameSite() ? 1 << COOKIE_TYPE_SAME_SITE : 0; |
| 1681 | type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; |
| 1682 | type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; |
| 1683 | histogram_cookie_type_->Add(type_sample); |
estark | 7feb65c2b | 2015-08-21 23:38:20 | [diff] [blame] | 1684 | |
| 1685 | // Histogram the type of scheme used on URLs that set cookies. This |
| 1686 | // intentionally includes cookies that are set or overwritten by |
| 1687 | // http:// URLs, but not cookies that are cleared by http:// URLs, to |
| 1688 | // understand if the former behavior can be deprecated for Secure |
| 1689 | // cookies. |
| 1690 | if (!cc->Source().is_empty()) { |
| 1691 | CookieSource cookie_source_sample; |
| 1692 | if (cc->Source().SchemeIsCryptographic()) { |
| 1693 | cookie_source_sample = |
| 1694 | cc->IsSecure() ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME |
| 1695 | : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; |
| 1696 | } else { |
| 1697 | cookie_source_sample = |
| 1698 | cc->IsSecure() |
| 1699 | ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME |
| 1700 | : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; |
| 1701 | } |
| 1702 | histogram_cookie_source_scheme_->Add(cookie_source_sample); |
| 1703 | } |
mkwst | c1aa4cc | 2015-04-03 19:57:45 | [diff] [blame] | 1704 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1705 | RunCookieChangedCallbacks(*cc, false); |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1706 | |
| 1707 | return inserted; |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 1708 | } |
| 1709 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 1710 | bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
| 1711 | const GURL& url, |
| 1712 | const std::string& cookie_line, |
| 1713 | const Time& creation_time_or_null, |
| 1714 | const CookieOptions& options) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1715 | DCHECK(thread_checker_.CalledOnValidThread()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1716 | |
[email protected] | 4d3ce78 | 2010-10-29 18:31:28 | [diff] [blame] | 1717 | VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1718 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 1719 | Time creation_time = creation_time_or_null; |
| 1720 | if (creation_time.is_null()) { |
| 1721 | creation_time = CurrentTime(); |
| 1722 | last_time_seen_ = creation_time; |
| 1723 | } |
| 1724 | |
[email protected] | abbd13b | 2012-11-15 17:54:20 | [diff] [blame] | 1725 | scoped_ptr<CanonicalCookie> cc( |
| 1726 | CanonicalCookie::Create(url, cookie_line, creation_time, options)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1727 | |
| 1728 | if (!cc.get()) { |
[email protected] | 4d3ce78 | 2010-10-29 18:31:28 | [diff] [blame] | 1729 | VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1730 | return false; |
| 1731 | } |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1732 | return SetCanonicalCookie(std::move(cc), options); |
[email protected] | f325f1e1 | 2010-04-30 22:38:55 | [diff] [blame] | 1733 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1734 | |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1735 | bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie> cc, |
[email protected] | f325f1e1 | 2010-04-30 22:38:55 | [diff] [blame] | 1736 | const CookieOptions& options) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1737 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 1738 | |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1739 | Time creation_time = cc->CreationDate(); |
| 1740 | const std::string key(GetKey(cc->Domain())); |
| 1741 | bool already_expired = cc->IsExpired(creation_time); |
ellyjones | 399e35a2 | 2014-10-27 11:09:56 | [diff] [blame] | 1742 | |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1743 | if (DeleteAnyEquivalentCookie(key, *cc, options.exclude_httponly(), |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1744 | already_expired, |
| 1745 | options.enforce_strict_secure())) { |
| 1746 | std::string error; |
| 1747 | if (options.enforce_strict_secure()) { |
| 1748 | error = |
| 1749 | "SetCookie() not clobbering httponly cookie or secure cookie for " |
| 1750 | "insecure scheme"; |
| 1751 | } else { |
| 1752 | error = "SetCookie() not clobbering httponly cookie"; |
| 1753 | } |
| 1754 | |
| 1755 | VLOG(kVlogSetCookies) << error; |
[email protected] | 3a96c74 | 2008-11-19 19:46:27 | [diff] [blame] | 1756 | return false; |
| 1757 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1758 | |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1759 | VLOG(kVlogSetCookies) << "SetCookie() key: " << key |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1760 | << " cc: " << cc->DebugString(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1761 | |
| 1762 | // Realize that we might be setting an expired cookie, and the only point |
| 1763 | // was to delete the cookie which we've already done. |
mmenke | 3c79a65 | 2016-02-12 14:39:20 | [diff] [blame] | 1764 | if (!already_expired) { |
[email protected] | 374f58b | 2010-07-20 15:29:26 | [diff] [blame] | 1765 | // See InitializeHistograms() for details. |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1766 | if (cc->IsPersistent()) { |
[email protected] | 8475bee | 2011-03-17 18:40:24 | [diff] [blame] | 1767 | histogram_expiration_duration_minutes_->Add( |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1768 | (cc->ExpiryDate() - creation_time).InMinutes()); |
[email protected] | 8475bee | 2011-03-17 18:40:24 | [diff] [blame] | 1769 | } |
| 1770 | |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1771 | InternalInsertCookie(key, cc.release(), true); |
[email protected] | 348dd66 | 2013-03-13 20:25:07 | [diff] [blame] | 1772 | } else { |
| 1773 | VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 1774 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1775 | |
| 1776 | // We assume that hopefully setting a cookie will be less common than |
| 1777 | // querying a cookie. Since setting a cookie can put us over our limits, |
| 1778 | // make sure that we garbage collect... We can also make the assumption that |
| 1779 | // if a cookie was set, in the common case it will be used soon after, |
| 1780 | // and we will purge the expired cookies in GetCookies(). |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1781 | GarbageCollect(creation_time, key, options.enforce_strict_secure()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1782 | |
| 1783 | return true; |
| 1784 | } |
| 1785 | |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 1786 | bool CookieMonster::SetCanonicalCookies(const CookieList& list) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1787 | DCHECK(thread_checker_.CalledOnValidThread()); |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 1788 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1789 | CookieOptions options; |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 1790 | options.set_include_httponly(); |
| 1791 | |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1792 | for (const auto& cookie : list) { |
| 1793 | if (!SetCanonicalCookie(make_scoped_ptr(new CanonicalCookie(cookie)), |
| 1794 | options)) { |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 1795 | return false; |
mmenke | ea4cd40 | 2016-02-02 04:03:10 | [diff] [blame] | 1796 | } |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | return true; |
| 1800 | } |
| 1801 | |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 1802 | void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, |
| 1803 | const Time& current) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1804 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | bb890572 | 2010-05-21 17:29:04 | [diff] [blame] | 1805 | |
[email protected] | 77e0a46 | 2008-11-01 00:43:35 | [diff] [blame] | 1806 | // Based off the Mozilla code. When a cookie has been accessed recently, |
| 1807 | // don't bother updating its access time again. This reduces the number of |
| 1808 | // updates we do during pageload, which in turn reduces the chance our storage |
| 1809 | // backend will hit its batch thresholds and be forced to update. |
[email protected] | 77e0a46 | 2008-11-01 00:43:35 | [diff] [blame] | 1810 | if ((current - cc->LastAccessDate()) < last_access_threshold_) |
| 1811 | return; |
| 1812 | |
| 1813 | cc->SetLastAccessDate(current); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1814 | if ((cc->IsPersistent() || persist_session_cookies_) && store_.get()) |
[email protected] | 77e0a46 | 2008-11-01 00:43:35 | [diff] [blame] | 1815 | store_->UpdateCookieAccessTime(*cc); |
| 1816 | } |
| 1817 | |
[email protected] | 6210ce5 | 2013-09-20 03:33:14 | [diff] [blame] | 1818 | // InternalDeleteCookies must not invalidate iterators other than the one being |
| 1819 | // deleted. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1820 | void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 1821 | bool sync_to_store, |
| 1822 | DeletionCause deletion_cause) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1823 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | bb890572 | 2010-05-21 17:29:04 | [diff] [blame] | 1824 | |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 1825 | // Ideally, this would be asserted up where we define ChangeCauseMapping, |
| 1826 | // but DeletionCause's visibility (or lack thereof) forces us to make |
| 1827 | // this check here. |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1828 | static_assert(arraysize(ChangeCauseMapping) == DELETE_COOKIE_LAST_ENTRY + 1, |
| 1829 | "ChangeCauseMapping size should match DeletionCause size"); |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 1830 | |
[email protected] | 374f58b | 2010-07-20 15:29:26 | [diff] [blame] | 1831 | // See InitializeHistograms() for details. |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 1832 | if (deletion_cause != DELETE_COOKIE_DONT_RECORD) |
| 1833 | histogram_cookie_deletion_cause_->Add(deletion_cause); |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 1834 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1835 | CanonicalCookie* cc = it->second; |
xiyuan | 8dbb8989 | 2015-04-13 17:04:30 | [diff] [blame] | 1836 | VLOG(kVlogSetCookies) << "InternalDeleteCookie()" |
| 1837 | << ", cause:" << deletion_cause |
| 1838 | << ", cc: " << cc->DebugString(); |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 1839 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1840 | if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && |
| 1841 | sync_to_store) |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1842 | store_->DeleteCookie(*cc); |
[email protected] | 8bb846f | 2011-03-23 12:08:18 | [diff] [blame] | 1843 | if (delegate_.get()) { |
| 1844 | ChangeCausePair mapping = ChangeCauseMapping[deletion_cause]; |
| 1845 | |
| 1846 | if (mapping.notify) |
| 1847 | delegate_->OnCookieChanged(*cc, true, mapping.cause); |
| 1848 | } |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1849 | RunCookieChangedCallbacks(*cc, true); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1850 | cookies_.erase(it); |
| 1851 | delete cc; |
| 1852 | } |
| 1853 | |
[email protected] | 8807b32 | 2010-10-01 17:10:14 | [diff] [blame] | 1854 | // Domain expiry behavior is unchanged by key/expiry scheme (the |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1855 | // meaning of the key is different, but that's not visible to this routine). |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1856 | size_t CookieMonster::GarbageCollect(const Time& current, |
| 1857 | const std::string& key, |
| 1858 | bool enforce_strict_secure) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 1859 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | bb890572 | 2010-05-21 17:29:04 | [diff] [blame] | 1860 | |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1861 | size_t num_deleted = 0; |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1862 | Time safe_date(Time::Now() - TimeDelta::FromDays(kSafeFromGlobalPurgeDays)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1863 | |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1864 | // Collect garbage for this key, minding cookie priorities. |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 1865 | if (cookies_.count(key) > kDomainMaxCookies) { |
[email protected] | 4d3ce78 | 2010-10-29 18:31:28 | [diff] [blame] | 1866 | VLOG(kVlogGarbageCollection) << "GarbageCollect() key: " << key; |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 1867 | |
mkwst | 8773435 | 2016-03-03 17:36:23 | [diff] [blame] | 1868 | CookieItVector* cookie_its; |
jww | 601411a | 2015-11-20 19:46:57 | [diff] [blame] | 1869 | |
mkwst | 8773435 | 2016-03-03 17:36:23 | [diff] [blame] | 1870 | CookieItVector non_expired_cookie_its; |
| 1871 | cookie_its = &non_expired_cookie_its; |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1872 | num_deleted += |
mkwst | 8773435 | 2016-03-03 17:36:23 | [diff] [blame] | 1873 | GarbageCollectExpired(current, cookies_.equal_range(key), cookie_its); |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1874 | |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1875 | // TODO(mkwst): Soften this. |
mkwst | 8773435 | 2016-03-03 17:36:23 | [diff] [blame] | 1876 | CookieItVector secure_cookie_its; |
| 1877 | if (enforce_strict_secure && cookie_its->size() > kDomainMaxCookies) { |
| 1878 | VLOG(kVlogGarbageCollection) << "Garbage collecting non-Secure cookies."; |
| 1879 | num_deleted += |
| 1880 | GarbageCollectNonSecure(non_expired_cookie_its, &secure_cookie_its); |
| 1881 | cookie_its = &secure_cookie_its; |
| 1882 | } |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1883 | |
mkwst | 8773435 | 2016-03-03 17:36:23 | [diff] [blame] | 1884 | if (cookie_its->size() > kDomainMaxCookies) { |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1885 | VLOG(kVlogGarbageCollection) << "Deep Garbage Collect domain."; |
| 1886 | size_t purge_goal = |
mkwst | 8773435 | 2016-03-03 17:36:23 | [diff] [blame] | 1887 | cookie_its->size() - (kDomainMaxCookies - kDomainPurgeCookies); |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1888 | DCHECK(purge_goal > kDomainPurgeCookies); |
| 1889 | |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1890 | // Sort the cookies by access date, from least-recent to most-recent. |
| 1891 | std::sort(cookie_its->begin(), cookie_its->end(), LRACookieSorter); |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1892 | |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1893 | // Remove all but the kDomainCookiesQuotaLow most-recently accessed |
| 1894 | // cookies with low-priority. Then, if cookies still need to be removed, |
| 1895 | // bump the quota and remove low- and medium-priority. Then, if cookies |
| 1896 | // _still_ need to be removed, bump the quota and remove cookies with |
| 1897 | // any priority. |
| 1898 | const size_t kQuotas[3] = {kDomainCookiesQuotaLow, |
| 1899 | kDomainCookiesQuotaMedium, |
| 1900 | kDomainCookiesQuotaHigh}; |
| 1901 | size_t quota = 0; |
| 1902 | for (size_t i = 0; i < arraysize(kQuotas) && purge_goal > 0; i++) { |
| 1903 | quota += kQuotas[i]; |
mkwst | aa07ee8 | 2016-03-11 15:32:14 | [diff] [blame^] | 1904 | size_t just_deleted = PurgeLeastRecentMatches( |
| 1905 | cookie_its, static_cast<CookiePriority>(i), quota, purge_goal); |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1906 | DCHECK_LE(just_deleted, purge_goal); |
| 1907 | purge_goal -= just_deleted; |
| 1908 | num_deleted += just_deleted; |
mkwst | 162d271 | 2016-02-18 18:21:29 | [diff] [blame] | 1909 | } |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1910 | |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1911 | DCHECK_EQ(0U, purge_goal); |
[email protected] | 8807b32 | 2010-10-01 17:10:14 | [diff] [blame] | 1912 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1913 | } |
| 1914 | |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1915 | // Collect garbage for everything. With firefox style we want to preserve |
| 1916 | // cookies accessed in kSafeFromGlobalPurgeDays, otherwise evict. |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 1917 | if (cookies_.size() > kMaxCookies && earliest_access_time_ < safe_date) { |
[email protected] | 4d3ce78 | 2010-10-29 18:31:28 | [diff] [blame] | 1918 | VLOG(kVlogGarbageCollection) << "GarbageCollect() everything"; |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1919 | CookieItVector cookie_its; |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1920 | |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 1921 | num_deleted += GarbageCollectExpired( |
| 1922 | current, CookieMapItPair(cookies_.begin(), cookies_.end()), |
| 1923 | &cookie_its); |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1924 | |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 1925 | if (cookie_its.size() > kMaxCookies) { |
| 1926 | VLOG(kVlogGarbageCollection) << "Deep Garbage Collect everything."; |
| 1927 | size_t purge_goal = cookie_its.size() - (kMaxCookies - kPurgeCookies); |
| 1928 | DCHECK(purge_goal > kPurgeCookies); |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1929 | |
| 1930 | if (enforce_strict_secure) { |
| 1931 | CookieItVector secure_cookie_its; |
| 1932 | CookieItVector non_secure_cookie_its; |
| 1933 | SplitCookieVectorIntoSecureAndNonSecure(cookie_its, &secure_cookie_its, |
| 1934 | &non_secure_cookie_its); |
| 1935 | size_t non_secure_purge_goal = |
| 1936 | std::min<size_t>(purge_goal, non_secure_cookie_its.size() - 1); |
| 1937 | |
| 1938 | size_t just_deleted = GarbageCollectLeastRecentlyAccessed( |
| 1939 | current, safe_date, non_secure_purge_goal, non_secure_cookie_its); |
| 1940 | num_deleted += just_deleted; |
| 1941 | |
| 1942 | if (just_deleted < purge_goal) { |
| 1943 | size_t secure_purge_goal = std::min<size_t>( |
| 1944 | purge_goal - just_deleted, secure_cookie_its.size() - 1); |
| 1945 | num_deleted += GarbageCollectLeastRecentlyAccessed( |
| 1946 | current, safe_date, secure_purge_goal, secure_cookie_its); |
| 1947 | } |
| 1948 | } else { |
| 1949 | num_deleted += GarbageCollectLeastRecentlyAccessed( |
| 1950 | current, safe_date, purge_goal, cookie_its); |
| 1951 | } |
[email protected] | 8807b32 | 2010-10-01 17:10:14 | [diff] [blame] | 1952 | } |
[email protected] | c890ed19 | 2008-10-30 23:45:53 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | return num_deleted; |
| 1956 | } |
| 1957 | |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1958 | size_t CookieMonster::PurgeLeastRecentMatches(CookieItVector* cookies, |
| 1959 | CookiePriority priority, |
| 1960 | size_t to_protect, |
mkwst | aa07ee8 | 2016-03-11 15:32:14 | [diff] [blame^] | 1961 | size_t purge_goal) { |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1962 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 1963 | |
| 1964 | // Find the first protected cookie by walking down from the end of the list |
| 1965 | // cookie list (most-recently accessed) until |to_protect| cookies that match |
| 1966 | // |priority| are found. |
| 1967 | size_t protection_boundary = cookies->size(); |
| 1968 | while (to_protect > 0 && protection_boundary > 0) { |
| 1969 | protection_boundary--; |
| 1970 | if (cookies->at(protection_boundary)->second->Priority() <= priority) |
| 1971 | to_protect--; |
| 1972 | } |
| 1973 | |
| 1974 | // Now, walk up from the beginning of the list (least-recently accessed) until |
| 1975 | // |purge_goal| cookies are removed, or the iterator hits |
| 1976 | // |protection_boundary|. |
| 1977 | size_t removed = 0; |
| 1978 | size_t current = 0; |
| 1979 | while (removed < purge_goal && current < protection_boundary) { |
| 1980 | if (cookies->at(current)->second->Priority() <= priority) { |
mkwst | aa07ee8 | 2016-03-11 15:32:14 | [diff] [blame^] | 1981 | InternalDeleteCookie(cookies->at(current), true, |
| 1982 | DELETE_COOKIE_EVICTED_DOMAIN); |
mkwst | e079ac41 | 2016-03-11 09:04:06 | [diff] [blame] | 1983 | cookies->erase(cookies->begin() + current); |
| 1984 | removed++; |
| 1985 | |
| 1986 | // The call to 'erase' above shifts the contents of the vector, but |
| 1987 | // doesn't shift |protection_boundary|. Decrement that here to ensure that |
| 1988 | // the correct set of cookies is protected. |
| 1989 | protection_boundary--; |
| 1990 | } else { |
| 1991 | current++; |
| 1992 | } |
| 1993 | } |
| 1994 | return removed; |
| 1995 | } |
| 1996 | |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 1997 | size_t CookieMonster::GarbageCollectExpired(const Time& current, |
| 1998 | const CookieMapItPair& itpair, |
| 1999 | CookieItVector* cookie_its) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2000 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | bb890572 | 2010-05-21 17:29:04 | [diff] [blame] | 2001 | |
[email protected] | c890ed19 | 2008-10-30 23:45:53 | [diff] [blame] | 2002 | int num_deleted = 0; |
| 2003 | for (CookieMap::iterator it = itpair.first, end = itpair.second; it != end;) { |
| 2004 | CookieMap::iterator curit = it; |
| 2005 | ++it; |
| 2006 | |
| 2007 | if (curit->second->IsExpired(current)) { |
[email protected] | 2f3f359 | 2010-07-07 20:11:51 | [diff] [blame] | 2008 | InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPIRED); |
[email protected] | c890ed19 | 2008-10-30 23:45:53 | [diff] [blame] | 2009 | ++num_deleted; |
| 2010 | } else if (cookie_its) { |
| 2011 | cookie_its->push_back(curit); |
| 2012 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | return num_deleted; |
| 2016 | } |
| 2017 | |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 2018 | size_t CookieMonster::GarbageCollectNonSecure( |
| 2019 | const CookieItVector& valid_cookies, |
| 2020 | CookieItVector* cookie_its) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2021 | DCHECK(thread_checker_.CalledOnValidThread()); |
jww | 82d99c1 | 2015-11-25 18:39:53 | [diff] [blame] | 2022 | |
| 2023 | size_t num_deleted = 0; |
| 2024 | for (const auto& curr_cookie_it : valid_cookies) { |
| 2025 | if (!curr_cookie_it->second->IsSecure()) { |
| 2026 | InternalDeleteCookie(curr_cookie_it, true, DELETE_COOKIE_NON_SECURE); |
| 2027 | ++num_deleted; |
| 2028 | } else if (cookie_its) { |
| 2029 | cookie_its->push_back(curr_cookie_it); |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | return num_deleted; |
| 2034 | } |
| 2035 | |
| 2036 | size_t CookieMonster::GarbageCollectDeleteRange( |
| 2037 | const Time& current, |
| 2038 | DeletionCause cause, |
| 2039 | CookieItVector::iterator it_begin, |
| 2040 | CookieItVector::iterator it_end) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2041 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2042 | |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 2043 | for (CookieItVector::iterator it = it_begin; it != it_end; it++) { |
| 2044 | histogram_evicted_last_access_minutes_->Add( |
| 2045 | (current - (*it)->second->LastAccessDate()).InMinutes()); |
| 2046 | InternalDeleteCookie((*it), true, cause); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 2047 | } |
[email protected] | 8ad5d46 | 2013-05-02 08:45:26 | [diff] [blame] | 2048 | return it_end - it_begin; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 2049 | } |
| 2050 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 2051 | size_t CookieMonster::GarbageCollectLeastRecentlyAccessed( |
| 2052 | const base::Time& current, |
| 2053 | const base::Time& safe_date, |
| 2054 | size_t purge_goal, |
| 2055 | CookieItVector cookie_its) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2056 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2057 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 2058 | // Sorts up to *and including* |cookie_its[purge_goal]|, so |
| 2059 | // |earliest_access_time| will be properly assigned even if |
| 2060 | // |global_purge_it| == |cookie_its.begin() + purge_goal|. |
| 2061 | SortLeastRecentlyAccessed(cookie_its.begin(), cookie_its.end(), purge_goal); |
| 2062 | // Find boundary to cookies older than safe_date. |
| 2063 | CookieItVector::iterator global_purge_it = LowerBoundAccessDate( |
| 2064 | cookie_its.begin(), cookie_its.begin() + purge_goal, safe_date); |
| 2065 | // Only delete the old cookies, and if strict secure is enabled, delete |
| 2066 | // non-secure ones first. |
| 2067 | size_t num_deleted = |
| 2068 | GarbageCollectDeleteRange(current, DELETE_COOKIE_EVICTED_GLOBAL, |
| 2069 | cookie_its.begin(), global_purge_it); |
| 2070 | // Set access day to the oldest cookie that wasn't deleted. |
| 2071 | earliest_access_time_ = (*global_purge_it)->second->LastAccessDate(); |
| 2072 | return num_deleted; |
| 2073 | } |
| 2074 | |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 2075 | // A wrapper around registry_controlled_domains::GetDomainAndRegistry |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2076 | // to make clear we're creating a key for our local map. Here and |
| 2077 | // in FindCookiesForHostAndDomain() are the only two places where |
| 2078 | // we need to conditionalize based on key type. |
| 2079 | // |
| 2080 | // Note that this key algorithm explicitly ignores the scheme. This is |
| 2081 | // because when we're entering cookies into the map from the backing store, |
| 2082 | // we in general won't have the scheme at that point. |
| 2083 | // In practical terms, this means that file cookies will be stored |
| 2084 | // in the map either by an empty string or by UNC name (and will be |
| 2085 | // limited by kMaxCookiesPerHost), and extension cookies will be stored |
| 2086 | // based on the single extension id, as the extension id won't have the |
| 2087 | // form of a DNS host and hence GetKey() will return it unchanged. |
| 2088 | // |
| 2089 | // Arguably the right thing to do here is to make the key |
| 2090 | // algorithm dependent on the scheme, and make sure that the scheme is |
| 2091 | // available everywhere the key must be obtained (specfically at backing |
| 2092 | // store load time). This would require either changing the backing store |
| 2093 | // database schema to include the scheme (far more trouble than it's worth), or |
| 2094 | // separating out file cookies into their own CookieMonster instance and |
| 2095 | // thus restricting each scheme to a single cookie monster (which might |
| 2096 | // be worth it, but is still too much trouble to solve what is currently a |
| 2097 | // non-problem). |
| 2098 | std::string CookieMonster::GetKey(const std::string& domain) const { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2099 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2100 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2101 | std::string effective_domain( |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 2102 | registry_controlled_domains::GetDomainAndRegistry( |
[email protected] | aabe179 | 2014-01-30 21:37:46 | [diff] [blame] | 2103 | domain, registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2104 | if (effective_domain.empty()) |
| 2105 | effective_domain = domain; |
| 2106 | |
| 2107 | if (!effective_domain.empty() && effective_domain[0] == '.') |
| 2108 | return effective_domain.substr(1); |
| 2109 | return effective_domain; |
| 2110 | } |
| 2111 | |
| 2112 | bool CookieMonster::HasCookieableScheme(const GURL& url) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2113 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2114 | |
| 2115 | // Make sure the request is on a cookie-able url scheme. |
| 2116 | for (size_t i = 0; i < cookieable_schemes_.size(); ++i) { |
| 2117 | // We matched a scheme. |
| 2118 | if (url.SchemeIs(cookieable_schemes_[i].c_str())) { |
| 2119 | // We've matched a supported scheme. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 2120 | return true; |
| 2121 | } |
| 2122 | } |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2123 | |
| 2124 | // The scheme didn't match any in our whitelist. |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 2125 | VLOG(kVlogPerCookieMonster) |
| 2126 | << "WARNING: Unsupported cookie scheme: " << url.scheme(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 2127 | return false; |
| 2128 | } |
| 2129 | |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 2130 | // Test to see if stats should be recorded, and record them if so. |
| 2131 | // The goal here is to get sampling for the average browser-hour of |
| 2132 | // activity. We won't take samples when the web isn't being surfed, |
| 2133 | // and when the web is being surfed, we'll take samples about every |
| 2134 | // kRecordStatisticsIntervalSeconds. |
| 2135 | // last_statistic_record_time_ is initialized to Now() rather than null |
| 2136 | // in the constructor so that we won't take statistics right after |
| 2137 | // startup, to avoid bias from browsers that are started but not used. |
| 2138 | void CookieMonster::RecordPeriodicStats(const base::Time& current_time) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2139 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2140 | |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 2141 | const base::TimeDelta kRecordStatisticsIntervalTime( |
| 2142 | base::TimeDelta::FromSeconds(kRecordStatisticsIntervalSeconds)); |
| 2143 | |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 2144 | // If we've taken statistics recently, return. |
| 2145 | if (current_time - last_statistic_record_time_ <= |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 2146 | kRecordStatisticsIntervalTime) { |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 2147 | return; |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 2148 | } |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 2149 | |
| 2150 | // See InitializeHistograms() for details. |
| 2151 | histogram_count_->Add(cookies_.size()); |
| 2152 | |
| 2153 | // More detailed statistics on cookie counts at different granularities. |
[email protected] | 7a964a7 | 2010-09-07 19:33:26 | [diff] [blame] | 2154 | last_statistic_record_time_ = current_time; |
[email protected] | c4058fb | 2010-06-22 17:25:26 | [diff] [blame] | 2155 | } |
| 2156 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2157 | // Initialize all histogram counter variables used in this class. |
| 2158 | // |
| 2159 | // Normal histogram usage involves using the macros defined in |
| 2160 | // histogram.h, which automatically takes care of declaring these |
| 2161 | // variables (as statics), initializing them, and accumulating into |
| 2162 | // them, all from a single entry point. Unfortunately, that solution |
| 2163 | // doesn't work for the CookieMonster, as it's vulnerable to races between |
| 2164 | // separate threads executing the same functions and hence initializing the |
| 2165 | // same static variables. There isn't a race danger in the histogram |
| 2166 | // accumulation calls; they are written to be resilient to simultaneous |
| 2167 | // calls from multiple threads. |
| 2168 | // |
| 2169 | // The solution taken here is to have per-CookieMonster instance |
| 2170 | // variables that are constructed during CookieMonster construction. |
| 2171 | // Note that these variables refer to the same underlying histogram, |
| 2172 | // so we still race (but safely) with other CookieMonster instances |
| 2173 | // for accumulation. |
| 2174 | // |
| 2175 | // To do this we've expanded out the individual histogram macros calls, |
| 2176 | // with declarations of the variables in the class decl, initialization here |
| 2177 | // (done from the class constructor) and direct calls to the accumulation |
| 2178 | // methods where needed. The specific histogram macro calls on which the |
| 2179 | // initialization is based are included in comments below. |
| 2180 | void CookieMonster::InitializeHistograms() { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2181 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2182 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2183 | // From UMA_HISTOGRAM_CUSTOM_COUNTS |
| 2184 | histogram_expiration_duration_minutes_ = base::Histogram::FactoryGet( |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 2185 | "Cookie.ExpirationDurationMinutes", 1, kMinutesInTenYears, 50, |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2186 | base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2187 | histogram_evicted_last_access_minutes_ = base::Histogram::FactoryGet( |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 2188 | "Cookie.EvictedLastAccessMinutes", 1, kMinutesInTenYears, 50, |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2189 | base::Histogram::kUmaTargetedHistogramFlag); |
| 2190 | histogram_count_ = base::Histogram::FactoryGet( |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 2191 | "Cookie.Count", 1, 4000, 50, base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2192 | |
| 2193 | // From UMA_HISTOGRAM_ENUMERATION |
| 2194 | histogram_cookie_deletion_cause_ = base::LinearHistogram::FactoryGet( |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 2195 | "Cookie.DeletionCause", 1, DELETE_COOKIE_LAST_ENTRY - 1, |
| 2196 | DELETE_COOKIE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag); |
mkwst | c1aa4cc | 2015-04-03 19:57:45 | [diff] [blame] | 2197 | histogram_cookie_type_ = base::LinearHistogram::FactoryGet( |
mkwst | 87378d9 | 2015-04-10 21:22:11 | [diff] [blame] | 2198 | "Cookie.Type", 1, (1 << COOKIE_TYPE_LAST_ENTRY) - 1, |
| 2199 | 1 << COOKIE_TYPE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag); |
estark | 7feb65c2b | 2015-08-21 23:38:20 | [diff] [blame] | 2200 | histogram_cookie_source_scheme_ = base::LinearHistogram::FactoryGet( |
| 2201 | "Cookie.CookieSourceScheme", 1, COOKIE_SOURCE_LAST_ENTRY - 1, |
| 2202 | COOKIE_SOURCE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag); |
jww | 31e3263 | 2015-12-16 23:38:34 | [diff] [blame] | 2203 | histogram_cookie_delete_equivalent_ = base::LinearHistogram::FactoryGet( |
| 2204 | "Cookie.CookieDeleteEquivalent", 1, |
| 2205 | COOKIE_DELETE_EQUIVALENT_LAST_ENTRY - 1, |
| 2206 | COOKIE_DELETE_EQUIVALENT_LAST_ENTRY, |
| 2207 | base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2208 | |
| 2209 | // From UMA_HISTOGRAM_{CUSTOM_,}TIMES |
[email protected] | c7593fb2 | 2011-11-14 23:54:27 | [diff] [blame] | 2210 | histogram_time_blocked_on_load_ = base::Histogram::FactoryTimeGet( |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 2211 | "Cookie.TimeBlockedOnLoad", base::TimeDelta::FromMilliseconds(1), |
| 2212 | base::TimeDelta::FromMinutes(1), 50, |
| 2213 | base::Histogram::kUmaTargetedHistogramFlag); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2214 | } |
| 2215 | |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2216 | // The system resolution is not high enough, so we can have multiple |
| 2217 | // set cookies that result in the same system time. When this happens, we |
| 2218 | // increment by one Time unit. Let's hope computers don't get too fast. |
| 2219 | Time CookieMonster::CurrentTime() { |
mkwst | be84af31 | 2015-02-20 08:52:45 | [diff] [blame] | 2220 | return std::max(Time::Now(), Time::FromInternalValue( |
| 2221 | last_time_seen_.ToInternalValue() + 1)); |
[email protected] | f48b943 | 2011-01-11 07:25:40 | [diff] [blame] | 2222 | } |
| 2223 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 2224 | void CookieMonster::DoCookieTask( |
| 2225 | const scoped_refptr<CookieMonsterTask>& task_item) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2226 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2227 | |
| 2228 | MarkCookieStoreAsInitialized(); |
| 2229 | FetchAllCookiesIfNecessary(); |
mmenke | f49fca0e | 2016-03-08 12:46:24 | [diff] [blame] | 2230 | seen_global_task_ = true; |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2231 | |
| 2232 | if (!finished_fetching_all_cookies_ && store_.get()) { |
mmenke | f49fca0e | 2016-03-08 12:46:24 | [diff] [blame] | 2233 | tasks_pending_.push_back(task_item); |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2234 | return; |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | task_item->Run(); |
| 2238 | } |
| 2239 | |
| 2240 | void CookieMonster::DoCookieTaskForURL( |
| 2241 | const scoped_refptr<CookieMonsterTask>& task_item, |
| 2242 | const GURL& url) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2243 | MarkCookieStoreAsInitialized(); |
| 2244 | if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) |
| 2245 | FetchAllCookiesIfNecessary(); |
| 2246 | |
| 2247 | // If cookies for the requested domain key (eTLD+1) have been loaded from DB |
| 2248 | // then run the task, otherwise load from DB. |
| 2249 | if (!finished_fetching_all_cookies_ && store_.get()) { |
mmenke | f49fca0e | 2016-03-08 12:46:24 | [diff] [blame] | 2250 | // If a global task has been previously seen, queue the task as a global |
| 2251 | // task. Note that the CookieMonster may be in the middle of executing |
| 2252 | // the global queue, |tasks_pending_| may be empty, which is why another |
| 2253 | // bool is needed. |
| 2254 | if (seen_global_task_) { |
| 2255 | tasks_pending_.push_back(task_item); |
| 2256 | return; |
| 2257 | } |
| 2258 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2259 | // Checks if the domain key has been loaded. |
| 2260 | std::string key(cookie_util::GetEffectiveDomain(url.scheme(), url.host())); |
| 2261 | if (keys_loaded_.find(key) == keys_loaded_.end()) { |
| 2262 | std::map<std::string, |
| 2263 | std::deque<scoped_refptr<CookieMonsterTask>>>::iterator it = |
| 2264 | tasks_pending_for_key_.find(key); |
| 2265 | if (it == tasks_pending_for_key_.end()) { |
| 2266 | store_->LoadCookiesForKey( |
| 2267 | key, base::Bind(&CookieMonster::OnKeyLoaded, |
| 2268 | weak_ptr_factory_.GetWeakPtr(), key)); |
| 2269 | it = tasks_pending_for_key_ |
| 2270 | .insert(std::make_pair( |
| 2271 | key, std::deque<scoped_refptr<CookieMonsterTask>>())) |
| 2272 | .first; |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 2273 | } |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2274 | it->second.push_back(task_item); |
| 2275 | return; |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 2276 | } |
| 2277 | } |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2278 | |
mmenke | 74bcbd5 | 2016-01-21 17:17:56 | [diff] [blame] | 2279 | task_item->Run(); |
| 2280 | } |
| 2281 | |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 2282 | void CookieMonster::ComputeCookieDiff(CookieList* old_cookies, |
| 2283 | CookieList* new_cookies, |
| 2284 | CookieList* cookies_to_add, |
| 2285 | CookieList* cookies_to_delete) { |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2286 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2287 | |
droger | d5d1278c | 2015-03-17 19:21:51 | [diff] [blame] | 2288 | DCHECK(old_cookies); |
| 2289 | DCHECK(new_cookies); |
| 2290 | DCHECK(cookies_to_add); |
| 2291 | DCHECK(cookies_to_delete); |
| 2292 | DCHECK(cookies_to_add->empty()); |
| 2293 | DCHECK(cookies_to_delete->empty()); |
| 2294 | |
| 2295 | // Sort both lists. |
| 2296 | // A set ordered by FullDiffCookieSorter is also ordered by |
| 2297 | // PartialDiffCookieSorter. |
| 2298 | std::sort(old_cookies->begin(), old_cookies->end(), FullDiffCookieSorter); |
| 2299 | std::sort(new_cookies->begin(), new_cookies->end(), FullDiffCookieSorter); |
| 2300 | |
| 2301 | // Select any old cookie for deletion if no new cookie has the same name, |
| 2302 | // domain, and path. |
| 2303 | std::set_difference( |
| 2304 | old_cookies->begin(), old_cookies->end(), new_cookies->begin(), |
| 2305 | new_cookies->end(), |
| 2306 | std::inserter(*cookies_to_delete, cookies_to_delete->begin()), |
| 2307 | PartialDiffCookieSorter); |
| 2308 | |
| 2309 | // Select any new cookie for addition (or update) if no old cookie is exactly |
| 2310 | // equivalent. |
| 2311 | std::set_difference(new_cookies->begin(), new_cookies->end(), |
| 2312 | old_cookies->begin(), old_cookies->end(), |
| 2313 | std::inserter(*cookies_to_add, cookies_to_add->begin()), |
| 2314 | FullDiffCookieSorter); |
| 2315 | } |
| 2316 | |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2317 | void CookieMonster::RunCallback(const base::Closure& callback) { |
| 2318 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2319 | callback.Run(); |
| 2320 | } |
| 2321 | |
| 2322 | void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, |
| 2323 | bool removed) { |
| 2324 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 2325 | |
ellyjones | 399e35a2 | 2014-10-27 11:09:56 | [diff] [blame] | 2326 | CookieOptions opts; |
| 2327 | opts.set_include_httponly(); |
mkwst | 4654941 | 2016-02-01 10:05:37 | [diff] [blame] | 2328 | opts.set_include_same_site(); |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2329 | // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they |
ellyjones | 399e35a2 | 2014-10-27 11:09:56 | [diff] [blame] | 2330 | // are guaranteed to not take long - they just post a RunAsync task back to |
mmenke | be0910d | 2016-03-01 19:09:09 | [diff] [blame] | 2331 | // the appropriate thread's message loop and return. |
| 2332 | // TODO(mmenke): Consider running these synchronously? |
ellyjones | 399e35a2 | 2014-10-27 11:09:56 | [diff] [blame] | 2333 | for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
| 2334 | it != hook_map_.end(); ++it) { |
| 2335 | std::pair<GURL, std::string> key = it->first; |
| 2336 | if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2337 | cookie.Name() == key.second) { |
msarda | 0aad8f0 | 2014-10-30 09:22:39 | [diff] [blame] | 2338 | it->second->Notify(cookie, removed); |
ellyjones | 399e35a2 | 2014-10-27 11:09:56 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | } |
| 2342 | |
[email protected] | 6372531 | 2012-07-19 08:24:16 | [diff] [blame] | 2343 | } // namespace net |