blob: 219b5b060182c15884d5fa1ce2e1e988ae70886b [file] [log] [blame]
[email protected]63ee33bd2012-03-15 09:29:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Brought to you by the letter D and the number 2.
6
7#ifndef NET_COOKIES_COOKIE_MONSTER_H_
8#define NET_COOKIES_COOKIE_MONSTER_H_
[email protected]63ee33bd2012-03-15 09:29:589
Avi Drissman13fc8932015-12-20 04:40:4610#include <stddef.h>
11#include <stdint.h>
12
[email protected]63ee33bd2012-03-15 09:29:5813#include <deque>
14#include <map>
danakja9850e12016-04-18 22:28:0815#include <memory>
[email protected]63ee33bd2012-03-15 09:29:5816#include <queue>
17#include <set>
18#include <string>
19#include <utility>
20#include <vector>
21
[email protected]63ee33bd2012-03-15 09:29:5822#include "base/callback_forward.h"
23#include "base/gtest_prod_util.h"
Avi Drissman13fc8932015-12-20 04:40:4624#include "base/macros.h"
[email protected]63ee33bd2012-03-15 09:29:5825#include "base/memory/ref_counted.h"
mmenkebe0910d2016-03-01 19:09:0926#include "base/memory/weak_ptr.h"
27#include "base/threading/thread_checker.h"
[email protected]9da992db2013-06-28 05:40:4728#include "base/time/time.h"
[email protected]565c3f42012-08-14 14:22:5829#include "net/base/net_export.h"
[email protected]8da4b1812012-07-25 13:54:3830#include "net/cookies/canonical_cookie.h"
[email protected]ab2d75c82013-04-19 18:39:0431#include "net/cookies/cookie_constants.h"
[email protected]63ee33bd2012-03-15 09:29:5832#include "net/cookies/cookie_store.h"
ellyjones399e35a22014-10-27 11:09:5633#include "url/gurl.h"
[email protected]63ee33bd2012-03-15 09:29:5834
35namespace base {
[email protected]de415552013-01-23 04:12:1736class HistogramBase;
[email protected]63ee33bd2012-03-15 09:29:5837} // namespace base
38
39namespace net {
40
nharper2b0ad9a2017-05-22 18:33:4541class ChannelIDService;
[email protected]7c4b66b2014-01-04 12:28:1342class CookieMonsterDelegate;
[email protected]63ee33bd2012-03-15 09:29:5843
44// The cookie monster is the system for storing and retrieving cookies. It has
45// an in-memory list of all cookies, and synchronizes non-session cookies to an
46// optional permanent storage that implements the PersistentCookieStore
47// interface.
48//
mmenke96f3bab2016-01-22 17:34:0249// Tasks may be deferred if all affected cookies are not yet loaded from the
50// backing store. Otherwise, callbacks may be invoked immediately.
[email protected]63ee33bd2012-03-15 09:29:5851//
52// A cookie task is either pending loading of the entire cookie store, or
avie7cd11a2016-10-11 02:00:3553// loading of cookies for a specific domain key(eTLD+1). In the former case, the
[email protected]0184df32013-05-14 00:53:5554// cookie task will be queued in tasks_pending_ while PersistentCookieStore
55// chain loads the cookie store on DB thread. In the latter case, the cookie
56// task will be queued in tasks_pending_for_key_ while PermanentCookieStore
57// loads cookies for the specified domain key(eTLD+1) on DB thread.
[email protected]63ee33bd2012-03-15 09:29:5858//
[email protected]63ee33bd2012-03-15 09:29:5859// TODO(deanm) Implement CookieMonster, the cookie database.
60// - Verify that our domain enforcement and non-dotted handling is correct
61class NET_EXPORT CookieMonster : public CookieStore {
62 public:
[email protected]63ee33bd2012-03-15 09:29:5863 class PersistentCookieStore;
64
65 // Terminology:
66 // * The 'top level domain' (TLD) of an internet domain name is
67 // the terminal "." free substring (e.g. "com" for google.com
68 // or world.std.com).
69 // * The 'effective top level domain' (eTLD) is the longest
70 // "." initiated terminal substring of an internet domain name
71 // that is controlled by a general domain registrar.
72 // (e.g. "co.uk" for news.bbc.co.uk).
73 // * The 'effective top level domain plus one' (eTLD+1) is the
74 // shortest "." delimited terminal substring of an internet
75 // domain name that is not controlled by a general domain
76 // registrar (e.g. "bbc.co.uk" for news.bbc.co.uk, or
77 // "google.com" for news.google.com). The general assumption
78 // is that all hosts and domains under an eTLD+1 share some
79 // administrative control.
80
81 // CookieMap is the central data structure of the CookieMonster. It
82 // is a map whose values are pointers to CanonicalCookie data
83 // structures (the data structures are owned by the CookieMonster
84 // and must be destroyed when removed from the map). The key is based on the
85 // effective domain of the cookies. If the domain of the cookie has an
86 // eTLD+1, that is the key for the map. If the domain of the cookie does not
87 // have an eTLD+1, the key of the map is the host the cookie applies to (it is
88 // not legal to have domain cookies without an eTLD+1). This rule
89 // excludes cookies for, e.g, ".com", ".co.uk", or ".internalnetwork".
90 // This behavior is the same as the behavior in Firefox v 3.6.10.
91
92 // NOTE(deanm):
93 // I benchmarked hash_multimap vs multimap. We're going to be query-heavy
94 // so it would seem like hashing would help. However they were very
95 // close, with multimap being a tiny bit faster. I think this is because
96 // our map is at max around 1000 entries, and the additional complexity
97 // for the hashing might not overcome the O(log(1000)) for querying
98 // a multimap. Also, multimap is standard, another reason to use it.
99 // TODO(rdsmith): This benchmark should be re-done now that we're allowing
avie7cd11a2016-10-11 02:00:35100 // substantially more entries in the map.
101 using CookieMap =
102 std::multimap<std::string, std::unique_ptr<CanonicalCookie>>;
103 using CookieMapItPair = std::pair<CookieMap::iterator, CookieMap::iterator>;
104 using CookieItVector = std::vector<CookieMap::iterator>;
[email protected]8ad5d462013-05-02 08:45:26105
106 // Cookie garbage collection thresholds. Based off of the Mozilla defaults.
107 // When the number of cookies gets to k{Domain,}MaxCookies
108 // purge down to k{Domain,}MaxCookies - k{Domain,}PurgeCookies.
109 // It might seem scary to have a high purge value, but really it's not.
110 // You just make sure that you increase the max to cover the increase
111 // in purge, and we would have been purging the same number of cookies.
112 // We're just going through the garbage collection process less often.
113 // Note that the DOMAIN values are per eTLD+1; see comment for the
114 // CookieMap typedef. So, e.g., the maximum number of cookies allowed for
115 // google.com and all of its subdomains will be 150-180.
116 //
117 // Any cookies accessed more recently than kSafeFromGlobalPurgeDays will not
118 // be evicted by global garbage collection, even if we have more than
119 // kMaxCookies. This does not affect domain garbage collection.
120 static const size_t kDomainMaxCookies;
121 static const size_t kDomainPurgeCookies;
122 static const size_t kMaxCookies;
123 static const size_t kPurgeCookies;
124
125 // Quota for cookies with {low, medium, high} priorities within a domain.
mkwst87734352016-03-03 17:36:23126 static const size_t kDomainCookiesQuotaLow;
127 static const size_t kDomainCookiesQuotaMedium;
128 static const size_t kDomainCookiesQuotaHigh;
[email protected]63ee33bd2012-03-15 09:29:58129
130 // The store passed in should not have had Init() called on it yet. This
131 // class will take care of initializing it. The backing store is NOT owned by
132 // this class, but it must remain valid for the duration of the cookie
133 // monster's existence. If |store| is NULL, then no backing store will be
134 // updated. If |delegate| is non-NULL, it will be notified on
135 // creation/deletion of cookies.
[email protected]7c4b66b2014-01-04 12:28:13136 CookieMonster(PersistentCookieStore* store, CookieMonsterDelegate* delegate);
[email protected]63ee33bd2012-03-15 09:29:58137
nharper2b0ad9a2017-05-22 18:33:45138 // Like above, but includes a non-owning pointer |channel_id_service| for the
139 // corresponding ChannelIDService used with this CookieStore. The
140 // |channel_id_service| must outlive the CookieMonster.
141 CookieMonster(PersistentCookieStore* store,
142 CookieMonsterDelegate* delegate,
143 ChannelIDService* channel_id_service);
144
[email protected]63ee33bd2012-03-15 09:29:58145 // Only used during unit testing.
146 CookieMonster(PersistentCookieStore* store,
[email protected]7c4b66b2014-01-04 12:28:13147 CookieMonsterDelegate* delegate,
shessf0bc1182016-05-19 04:35:58148 base::TimeDelta last_access_threshold);
[email protected]63ee33bd2012-03-15 09:29:58149
mmenke606c59c2016-03-07 18:20:55150 ~CookieMonster() override;
151
drogerd5d1278c2015-03-17 19:21:51152 // Replaces all the cookies by |list|. This method does not flush the backend.
mmenke009cf62e2016-07-18 19:33:31153 // This method does not support setting secure cookies, which need source
154 // URLs.
155 // TODO(mmenke): This method is only used on iOS. Consider removing it.
drogerd5d1278c2015-03-17 19:21:51156 void SetAllCookiesAsync(const CookieList& list,
157 const SetCookiesCallback& callback);
158
[email protected]63ee33bd2012-03-15 09:29:58159 // CookieStore implementation.
dchengb03027d2014-10-21 12:00:20160 void SetCookieWithOptionsAsync(const GURL& url,
161 const std::string& cookie_line,
162 const CookieOptions& options,
163 const SetCookiesCallback& callback) override;
mmenkeea4cd402016-02-02 04:03:10164 void SetCookieWithDetailsAsync(const GURL& url,
165 const std::string& name,
166 const std::string& value,
167 const std::string& domain,
168 const std::string& path,
mmenkefdd4fc72016-02-05 20:53:24169 base::Time creation_time,
170 base::Time expiration_time,
171 base::Time last_access_time,
mmenkeea4cd402016-02-02 04:03:10172 bool secure,
173 bool http_only,
mkwste1a29582016-03-15 10:07:52174 CookieSameSite same_site,
mmenkeea4cd402016-02-02 04:03:10175 CookiePriority priority,
176 const SetCookiesCallback& callback) override;
dchengb03027d2014-10-21 12:00:20177 void GetCookiesWithOptionsAsync(const GURL& url,
178 const CookieOptions& options,
179 const GetCookiesCallback& callback) override;
mkwstc611e6d2016-02-23 15:45:55180 void GetCookieListWithOptionsAsync(
181 const GURL& url,
182 const CookieOptions& options,
183 const GetCookieListCallback& callback) override;
mmenke9fa44f2d2016-01-22 23:36:39184 void GetAllCookiesAsync(const GetCookieListCallback& callback) override;
dchengb03027d2014-10-21 12:00:20185 void DeleteCookieAsync(const GURL& url,
186 const std::string& cookie_name,
187 const base::Closure& callback) override;
mmenke24379d52016-02-05 23:50:17188 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
189 const DeleteCallback& callback) override;
dchengb03027d2014-10-21 12:00:20190 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin,
191 const base::Time& delete_end,
192 const DeleteCallback& callback) override;
dmurphfaea244c2016-04-09 00:42:30193 void DeleteAllCreatedBetweenWithPredicateAsync(
194 const base::Time& delete_begin,
195 const base::Time& delete_end,
196 const base::Callback<bool(const CanonicalCookie&)>& predicate,
mostynbba063d6032014-10-09 11:01:13197 const DeleteCallback& callback) override;
dchengb03027d2014-10-21 12:00:20198 void DeleteSessionCookiesAsync(const DeleteCallback&) override;
mmenke96f3bab2016-01-22 17:34:02199 void FlushStore(const base::Closure& callback) override;
mmenkeded79da2016-02-06 08:28:51200 void SetForceKeepSessionState() override;
[email protected]264807b2012-04-25 14:49:37201
mmenke74bcbd52016-01-21 17:17:56202 // Resets the list of cookieable schemes to the supplied schemes. Does
203 // nothing if called after first use of the instance (i.e. after the
204 // instance initialization process).
mmenke18dd8ba2016-02-01 18:42:10205 void SetCookieableSchemes(const std::vector<std::string>& schemes);
mmenke74bcbd52016-01-21 17:17:56206
[email protected]63ee33bd2012-03-15 09:29:58207 // Enables writing session cookies into the cookie database. If this this
208 // method is called, it must be called before first use of the instance
209 // (i.e. as part of the instance initialization process).
210 void SetPersistSessionCookies(bool persist_session_cookies);
211
[email protected]97a3b6e2012-06-12 01:53:56212 // Determines if the scheme of the URL is a scheme that cookies will be
213 // stored for.
214 bool IsCookieableScheme(const std::string& scheme);
215
[email protected]63ee33bd2012-03-15 09:29:58216 // The default list of schemes the cookie monster can handle.
[email protected]5edff3c52014-06-23 20:27:48217 static const char* const kDefaultCookieableSchemes[];
[email protected]63ee33bd2012-03-15 09:29:58218 static const int kDefaultCookieableSchemesCount;
219
danakja9850e12016-04-18 22:28:08220 std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie(
ellyjones399e35a22014-10-27 11:09:56221 const GURL& url,
222 const std::string& name,
223 const CookieChangedCallback& callback) override;
224
nharper5babb5e62016-03-09 18:58:07225 bool IsEphemeral() override;
226
[email protected]63ee33bd2012-03-15 09:29:58227 private:
nharper2b0ad9a2017-05-22 18:33:45228 CookieMonster(PersistentCookieStore* store,
229 CookieMonsterDelegate* delegate,
230 ChannelIDService* channel_id_service,
231 base::TimeDelta last_access_threshold);
232
[email protected]63ee33bd2012-03-15 09:29:58233 // For queueing the cookie monster calls.
234 class CookieMonsterTask;
mkwstbe84af312015-02-20 08:52:45235 template <typename Result>
236 class DeleteTask;
[email protected]63ee33bd2012-03-15 09:29:58237 class DeleteAllCreatedBetweenTask;
dmurphfaea244c2016-04-09 00:42:30238 class DeleteAllCreatedBetweenWithPredicateTask;
[email protected]63ee33bd2012-03-15 09:29:58239 class DeleteCookieTask;
240 class DeleteCanonicalCookieTask;
mkwst72b65162016-02-22 19:58:54241 class GetCookieListForURLWithOptionsTask;
[email protected]63ee33bd2012-03-15 09:29:58242 class GetAllCookiesTask;
243 class GetCookiesWithOptionsTask;
mkwstc611e6d2016-02-23 15:45:55244 class GetCookieListWithOptionsTask;
drogerd5d1278c2015-03-17 19:21:51245 class SetAllCookiesTask;
[email protected]63ee33bd2012-03-15 09:29:58246 class SetCookieWithDetailsTask;
247 class SetCookieWithOptionsTask;
[email protected]264807b2012-04-25 14:49:37248 class DeleteSessionCookiesTask;
[email protected]63ee33bd2012-03-15 09:29:58249
250 // Testing support.
251 // For SetCookieWithCreationTime.
252 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest,
253 TestCookieDeleteAllCreatedBetweenTimestamps);
dmurphfaea244c2016-04-09 00:42:30254 FRIEND_TEST_ALL_PREFIXES(
255 CookieMonsterTest,
256 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate);
[email protected]63ee33bd2012-03-15 09:29:58257
avie7cd11a2016-10-11 02:00:35258 // For garbage collection constants.
[email protected]63ee33bd2012-03-15 09:29:58259 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection);
[email protected]63ee33bd2012-03-15 09:29:58260 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers);
mmenkef4721d992017-06-07 17:13:59261 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest,
262 GarbageCollectWithSecureCookiesOnly);
[email protected]63ee33bd2012-03-15 09:29:58263 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes);
264
265 // For validation of key values.
266 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestDomainTree);
267 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestImport);
268 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey);
269 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey);
270
271 // For FindCookiesForKey.
272 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies);
273
drogerd5d1278c2015-03-17 19:21:51274 // For ComputeCookieDiff.
275 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ComputeCookieDiff);
276
estark7feb65c2b2015-08-21 23:38:20277 // For CookieSource histogram enum.
278 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, CookieSourceHistogram);
279
jww31e32632015-12-16 23:38:34280 // For kSafeFromGlobalPurgeDays in CookieStore.
jwwa26e439d2017-01-27 18:17:27281 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, EvictSecureCookies);
jww82d99c12015-11-25 18:39:53282
jww31e32632015-12-16 23:38:34283 // For CookieDeleteEquivalent histogram enum.
284 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest,
285 CookieDeleteEquivalentHistogramTest);
jww31e32632015-12-16 23:38:34286
[email protected]63ee33bd2012-03-15 09:29:58287 // Internal reasons for deletion, used to populate informative histograms
288 // and to provide a public cause for onCookieChange notifications.
289 //
290 // If you add or remove causes from this list, please be sure to also update
nharper352933e2016-09-30 18:24:57291 // the CookieStore::ChangeCause mapping inside ChangeCauseMapping.
[email protected]7c4b66b2014-01-04 12:28:13292 // Moreover, these are used as array indexes, so avoid reordering to keep the
[email protected]63ee33bd2012-03-15 09:29:58293 // histogram buckets consistent. New items (if necessary) should be added
nharper68903362017-01-20 04:07:14294 // at the end of the list, before DELETE_COOKIE_LAST_ENTRY and the temporary
295 // values added for debugging.
[email protected]63ee33bd2012-03-15 09:29:58296 enum DeletionCause {
nharper68903362017-01-20 04:07:14297 // DELETE_COOKIE_EXPLICIT is temporarily unused (except for logging to the
298 // histogram) - see values 13-16 below.
[email protected]63ee33bd2012-03-15 09:29:58299 DELETE_COOKIE_EXPLICIT = 0,
mkwstaa07ee82016-03-11 15:32:14300 DELETE_COOKIE_OVERWRITE = 1,
301 DELETE_COOKIE_EXPIRED = 2,
302 DELETE_COOKIE_EVICTED = 3,
303 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE = 4,
304 DELETE_COOKIE_DONT_RECORD = 5, // For final cleanup after flush to store.
[email protected]63ee33bd2012-03-15 09:29:58305
mkwstaa07ee82016-03-11 15:32:14306 // Cookies evicted during domain-level garbage collection.
307 DELETE_COOKIE_EVICTED_DOMAIN = 6,
[email protected]63ee33bd2012-03-15 09:29:58308
mkwstaa07ee82016-03-11 15:32:14309 // Cookies evicted during global garbage collection (which takes place after
310 // domain-level garbage collection fails to bring the cookie store under
311 // the overall quota.
312 DELETE_COOKIE_EVICTED_GLOBAL = 7,
313
314 // #8 was DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE
315 // #9 was DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE
[email protected]63ee33bd2012-03-15 09:29:58316
317 // A common idiom is to remove a cookie by overwriting it with an
318 // already-expired expiration date. This captures that case.
mkwstaa07ee82016-03-11 15:32:14319 DELETE_COOKIE_EXPIRED_OVERWRITE = 10,
[email protected]63ee33bd2012-03-15 09:29:58320
[email protected]6210ce52013-09-20 03:33:14321 // Cookies are not allowed to contain control characters in the name or
322 // value. However, we used to allow them, so we are now evicting any such
323 // cookies as we load them. See http://crbug.com/238041.
mkwstaa07ee82016-03-11 15:32:14324 DELETE_COOKIE_CONTROL_CHAR = 11,
[email protected]6210ce52013-09-20 03:33:14325
jww82d99c12015-11-25 18:39:53326 // When strict secure cookies is enabled, non-secure cookies are evicted
327 // right after expired cookies.
mkwstaa07ee82016-03-11 15:32:14328 DELETE_COOKIE_NON_SECURE = 12,
jww82d99c12015-11-25 18:39:53329
nharper68903362017-01-20 04:07:14330 // The following values are temporary and being used to track down a bug.
331 // They should be treated the same as DELETE_COOKIE_EXPLICIT, and are logged
332 // to the histogram as DELETE_COOKIE_EXPLICIT.
333 DELETE_COOKIE_CREATED_BETWEEN = 13,
334 DELETE_COOKIE_CREATED_BETWEEN_WITH_PREDICATE = 14,
335 DELETE_COOKIE_SINGLE = 15,
336 DELETE_COOKIE_CANONICAL = 16,
337
338 // Do not add new values between DELETE_COOKIE_CREATED_BETWEEN and
339 // DELETE_COOKIE_LAST_ENTRY, as the above values are temporary. Instead, new
340 // values should go before DELETE_COOKIE_CREATED_BETWEEN.
341 DELETE_COOKIE_LAST_ENTRY = 17
[email protected]63ee33bd2012-03-15 09:29:58342 };
343
mkwstc1aa4cc2015-04-03 19:57:45344 // This enum is used to generate a histogramed bitmask measureing the types
345 // of stored cookies. Please do not reorder the list when adding new entries.
346 // New items MUST be added at the end of the list, just before
347 // COOKIE_TYPE_LAST_ENTRY;
348 enum CookieType {
mkwst46549412016-02-01 10:05:37349 COOKIE_TYPE_SAME_SITE = 0,
mkwstc1aa4cc2015-04-03 19:57:45350 COOKIE_TYPE_HTTPONLY,
351 COOKIE_TYPE_SECURE,
352 COOKIE_TYPE_LAST_ENTRY
353 };
354
estark7feb65c2b2015-08-21 23:38:20355 // Used to populate a histogram containing information about the
356 // sources of Secure and non-Secure cookies: that is, whether such
357 // cookies are set by origins with cryptographic or non-cryptographic
358 // schemes. Please do not reorder the list when adding new
359 // entries. New items MUST be added at the end of the list, just
360 // before COOKIE_SOURCE_LAST_ENTRY.
361 //
362 // COOKIE_SOURCE_(NON)SECURE_COOKIE_(NON)CRYPTOGRAPHIC_SCHEME means
363 // that a cookie was set or overwritten from a URL with the given type
364 // of scheme. This enum should not be used when cookies are *cleared*,
365 // because its purpose is to understand if Chrome can deprecate the
366 // ability of HTTP urls to set/overwrite Secure cookies.
367 enum CookieSource {
368 COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME = 0,
369 COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME,
370 COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME,
371 COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME,
372 COOKIE_SOURCE_LAST_ENTRY
373 };
374
jww31e32632015-12-16 23:38:34375 // Used to populate a histogram for cookie setting in the "delete equivalent"
376 // step. Measures total attempts to delete an equivalent cookie as well as if
377 // a cookie is found to delete, if a cookie is skipped because it is secure,
378 // and if it is skipped for being secure but would have been deleted
379 // otherwise. The last two are only possible if strict secure cookies is
380 // turned on and if an insecure origin attempts to a set a cookie where a
381 // cookie with the same name and secure attribute already exists.
382 //
383 // Enum for UMA. Do no reorder or remove entries. New entries must be place
384 // directly before COOKIE_DELETE_EQUIVALENT_LAST_ENTRY and histograms.xml must
385 // be updated accordingly.
386 enum CookieDeleteEquivalent {
387 COOKIE_DELETE_EQUIVALENT_ATTEMPT = 0,
388 COOKIE_DELETE_EQUIVALENT_FOUND,
389 COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE,
390 COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED,
391 COOKIE_DELETE_EQUIVALENT_LAST_ENTRY
392 };
393
erikchen1dd72a72015-05-06 20:45:05394 // The strategy for fetching cookies. Controlled by Finch experiment.
395 enum FetchStrategy {
396 // Fetches all cookies only when they're needed.
397 kFetchWhenNecessary = 0,
398 // Fetches all cookies as soon as any cookie is needed.
399 // This is the default behavior.
400 kAlwaysFetch,
401 // The fetch strategy is not yet determined.
402 kUnknownFetch,
403 };
404
[email protected]63ee33bd2012-03-15 09:29:58405 // The number of days since last access that cookies will not be subject
406 // to global garbage collection.
407 static const int kSafeFromGlobalPurgeDays;
408
409 // Record statistics every kRecordStatisticsIntervalSeconds of uptime.
410 static const int kRecordStatisticsIntervalSeconds = 10 * 60;
411
[email protected]63ee33bd2012-03-15 09:29:58412 // The following are synchronous calls to which the asynchronous methods
413 // delegate either immediately (if the store is loaded) or through a deferred
414 // task (if the store is not yet loaded).
415 bool SetCookieWithDetails(const GURL& url,
416 const std::string& name,
417 const std::string& value,
418 const std::string& domain,
419 const std::string& path,
mmenkefdd4fc72016-02-05 20:53:24420 base::Time creation_time,
421 base::Time expiration_time,
422 base::Time last_access_time,
[email protected]ab2d75c82013-04-19 18:39:04423 bool secure,
424 bool http_only,
mkwste1a29582016-03-15 10:07:52425 CookieSameSite same_site,
[email protected]ab2d75c82013-04-19 18:39:04426 CookiePriority priority);
[email protected]63ee33bd2012-03-15 09:29:58427
428 CookieList GetAllCookies();
429
mkwstc611e6d2016-02-23 15:45:55430 CookieList GetCookieListWithOptions(const GURL& url,
431 const CookieOptions& options);
[email protected]63ee33bd2012-03-15 09:29:58432
[email protected]63ee33bd2012-03-15 09:29:58433 int DeleteAllCreatedBetween(const base::Time& delete_begin,
434 const base::Time& delete_end);
435
dmurphfaea244c2016-04-09 00:42:30436 // Predicate will be called with the calling thread.
437 int DeleteAllCreatedBetweenWithPredicate(
438 const base::Time& delete_begin,
439 const base::Time& delete_end,
440 const base::Callback<bool(const CanonicalCookie&)>& predicate);
[email protected]63ee33bd2012-03-15 09:29:58441
[email protected]63ee33bd2012-03-15 09:29:58442 bool SetCookieWithOptions(const GURL& url,
443 const std::string& cookie_line,
444 const CookieOptions& options);
445
446 std::string GetCookiesWithOptions(const GURL& url,
447 const CookieOptions& options);
448
[email protected]63ee33bd2012-03-15 09:29:58449 void DeleteCookie(const GURL& url, const std::string& cookie_name);
450
mmenke24379d52016-02-05 23:50:17451 int DeleteCanonicalCookie(const CanonicalCookie& cookie);
452
[email protected]63ee33bd2012-03-15 09:29:58453 bool SetCookieWithCreationTime(const GURL& url,
454 const std::string& cookie_line,
455 const base::Time& creation_time);
456
[email protected]264807b2012-04-25 14:49:37457 int DeleteSessionCookies();
458
erikchen1dd72a72015-05-06 20:45:05459 // The first access to the cookie store initializes it. This method should be
460 // called before any access to the cookie store.
461 void MarkCookieStoreAsInitialized();
[email protected]63ee33bd2012-03-15 09:29:58462
erikchen1dd72a72015-05-06 20:45:05463 // Fetches all cookies if the backing store exists and they're not already
464 // being fetched.
erikchen1dd72a72015-05-06 20:45:05465 void FetchAllCookiesIfNecessary();
466
467 // Fetches all cookies from the backing store.
erikchen1dd72a72015-05-06 20:45:05468 void FetchAllCookies();
469
470 // Whether all cookies should be fetched as soon as any is requested.
471 bool ShouldFetchAllCookiesWhenFetchingAnyCookie();
[email protected]63ee33bd2012-03-15 09:29:58472
473 // Stores cookies loaded from the backing store and invokes any deferred
474 // calls. |beginning_time| should be the moment PersistentCookieStore::Load
475 // was invoked and is used for reporting histogram_time_blocked_on_load_.
476 // See PersistentCookieStore::Load for details on the contents of cookies.
477 void OnLoaded(base::TimeTicks beginning_time,
avie7cd11a2016-10-11 02:00:35478 std::vector<std::unique_ptr<CanonicalCookie>> cookies);
[email protected]63ee33bd2012-03-15 09:29:58479
480 // Stores cookies loaded from the backing store and invokes the deferred
481 // task(s) pending loading of cookies associated with the domain key
482 // (eTLD+1). Called when all cookies for the domain key(eTLD+1) have been
483 // loaded from DB. See PersistentCookieStore::Load for details on the contents
484 // of cookies.
mkwstbe84af312015-02-20 08:52:45485 void OnKeyLoaded(const std::string& key,
avie7cd11a2016-10-11 02:00:35486 std::vector<std::unique_ptr<CanonicalCookie>> cookies);
[email protected]63ee33bd2012-03-15 09:29:58487
488 // Stores the loaded cookies.
avie7cd11a2016-10-11 02:00:35489 void StoreLoadedCookies(
490 std::vector<std::unique_ptr<CanonicalCookie>> cookies);
[email protected]63ee33bd2012-03-15 09:29:58491
492 // Invokes deferred calls.
493 void InvokeQueue();
494
495 // Checks that |cookies_| matches our invariants, and tries to repair any
496 // inconsistencies. (In other words, it does not have duplicate cookies).
497 void EnsureCookiesMapIsValid();
498
499 // Checks for any duplicate cookies for CookieMap key |key| which lie between
500 // |begin| and |end|. If any are found, all but the most recent are deleted.
ellyjonescabf57422015-08-21 18:44:51501 void TrimDuplicateCookiesForKey(const std::string& key,
502 CookieMap::iterator begin,
503 CookieMap::iterator end);
[email protected]63ee33bd2012-03-15 09:29:58504
505 void SetDefaultCookieableSchemes();
506
507 void FindCookiesForHostAndDomain(const GURL& url,
508 const CookieOptions& options,
[email protected]63ee33bd2012-03-15 09:29:58509 std::vector<CanonicalCookie*>* cookies);
510
511 void FindCookiesForKey(const std::string& key,
512 const GURL& url,
513 const CookieOptions& options,
514 const base::Time& current,
[email protected]63ee33bd2012-03-15 09:29:58515 std::vector<CanonicalCookie*>* cookies);
516
517 // Delete any cookies that are equivalent to |ecc| (same path, domain, etc).
mmenke009cf62e2016-07-18 19:33:31518 // |source_url| is the URL that is attempting to set the cookie.
[email protected]63ee33bd2012-03-15 09:29:58519 // If |skip_httponly| is true, httponly cookies will not be deleted. The
jww601411a2015-11-20 19:46:57520 // return value will be true if |skip_httponly| skipped an httponly cookie or
jwwa26e439d2017-01-27 18:17:27521 // the cookie to delete was Secure and the scheme of |ecc| is insecure. |key|
522 // is the key to find the cookie in cookies_; see the comment before the
523 // CookieMap typedef for details.
[email protected]63ee33bd2012-03-15 09:29:58524 // NOTE: There should never be more than a single matching equivalent cookie.
525 bool DeleteAnyEquivalentCookie(const std::string& key,
526 const CanonicalCookie& ecc,
mmenke009cf62e2016-07-18 19:33:31527 const GURL& source_url,
[email protected]63ee33bd2012-03-15 09:29:58528 bool skip_httponly,
jwwa26e439d2017-01-27 18:17:27529 bool already_expired);
[email protected]63ee33bd2012-03-15 09:29:58530
avie7cd11a2016-10-11 02:00:35531 // Inserts |cc| into cookies_. Returns an iterator that points to the inserted
[email protected]6210ce52013-09-20 03:33:14532 // cookie in cookies_. Guarantee: all iterators to cookies_ remain valid.
533 CookieMap::iterator InternalInsertCookie(const std::string& key,
avie7cd11a2016-10-11 02:00:35534 std::unique_ptr<CanonicalCookie> cc,
mmenke009cf62e2016-07-18 19:33:31535 const GURL& source_url,
[email protected]6210ce52013-09-20 03:33:14536 bool sync_to_store);
[email protected]63ee33bd2012-03-15 09:29:58537
538 // Helper function that sets cookies with more control.
539 // Not exposed as we don't want callers to have the ability
540 // to specify (potentially duplicate) creation times.
541 bool SetCookieWithCreationTimeAndOptions(const GURL& url,
542 const std::string& cookie_line,
543 const base::Time& creation_time,
544 const CookieOptions& options);
545
546 // Helper function that sets a canonical cookie, deleting equivalents and
547 // performing garbage collection.
mmenke009cf62e2016-07-18 19:33:31548 // |source_url| is the URL that's attempting to set the cookie.
danakja9850e12016-04-18 22:28:08549 bool SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
mmenke009cf62e2016-07-18 19:33:31550 const GURL& source_url,
[email protected]63ee33bd2012-03-15 09:29:58551 const CookieOptions& options);
552
drogerd5d1278c2015-03-17 19:21:51553 // Helper function calling SetCanonicalCookie() for all cookies in |list|.
554 bool SetCanonicalCookies(const CookieList& list);
555
[email protected]63ee33bd2012-03-15 09:29:58556 void InternalUpdateCookieAccessTime(CanonicalCookie* cc,
557 const base::Time& current_time);
558
559 // |deletion_cause| argument is used for collecting statistics and choosing
nharper352933e2016-09-30 18:24:57560 // the correct CookieStore::ChangeCause for OnCookieChanged
[email protected]7c4b66b2014-01-04 12:28:13561 // notifications. Guarantee: All iterators to cookies_ except to the
avie7cd11a2016-10-11 02:00:35562 // deleted entry remain valid.
mkwstbe84af312015-02-20 08:52:45563 void InternalDeleteCookie(CookieMap::iterator it,
564 bool sync_to_store,
[email protected]63ee33bd2012-03-15 09:29:58565 DeletionCause deletion_cause);
566
567 // If the number of cookies for CookieMap key |key|, or globally, are
568 // over the preset maximums above, garbage collect, first for the host and
569 // then globally. See comments above garbage collection threshold
570 // constants for details.
571 //
572 // Returns the number of cookies deleted (useful for debugging).
jwwa26e439d2017-01-27 18:17:27573 size_t GarbageCollect(const base::Time& current, const std::string& key);
[email protected]63ee33bd2012-03-15 09:29:58574
mkwste079ac412016-03-11 09:04:06575 // Helper for GarbageCollect(). Deletes up to |purge_goal| cookies with a
576 // priority less than or equal to |priority| from |cookies|, while ensuring
577 // that at least the |to_protect| most-recent cookies are retained.
jwwc00ac712016-05-05 22:21:44578 // |protected_secure_cookies| specifies whether or not secure cookies should
579 // be protected from deletion.
mkwste079ac412016-03-11 09:04:06580 //
581 // |cookies| must be sorted from least-recent to most-recent.
582 //
mkwste079ac412016-03-11 09:04:06583 // Returns the number of cookies deleted.
584 size_t PurgeLeastRecentMatches(CookieItVector* cookies,
585 CookiePriority priority,
586 size_t to_protect,
jwwc00ac712016-05-05 22:21:44587 size_t purge_goal,
588 bool protect_secure_cookies);
mkwste079ac412016-03-11 09:04:06589
jww82d99c12015-11-25 18:39:53590 // Helper for GarbageCollect(); can be called directly as well. Deletes all
591 // expired cookies in |itpair|. If |cookie_its| is non-NULL, all the
592 // non-expired cookies from |itpair| are appended to |cookie_its|.
[email protected]63ee33bd2012-03-15 09:29:58593 //
594 // Returns the number of cookies deleted.
jww82d99c12015-11-25 18:39:53595 size_t GarbageCollectExpired(const base::Time& current,
596 const CookieMapItPair& itpair,
597 CookieItVector* cookie_its);
598
[email protected]8ad5d462013-05-02 08:45:26599 // Helper for GarbageCollect(). Deletes all cookies in the range specified by
600 // [|it_begin|, |it_end|). Returns the number of cookies deleted.
jww82d99c12015-11-25 18:39:53601 size_t GarbageCollectDeleteRange(const base::Time& current,
602 DeletionCause cause,
603 CookieItVector::iterator cookie_its_begin,
604 CookieItVector::iterator cookie_its_end);
605
606 // Helper for GarbageCollect(). Deletes cookies in |cookie_its| from least to
607 // most recently used, but only before |safe_date|. Also will stop deleting
608 // when the number of remaining cookies hits |purge_goal|.
mmenkef4721d992017-06-07 17:13:59609 //
610 // Sets |earliest_time| to be the earliest last access time of a cookie that
611 // was not deleted, or base::Time() if no such cookie exists.
jww82d99c12015-11-25 18:39:53612 size_t GarbageCollectLeastRecentlyAccessed(const base::Time& current,
613 const base::Time& safe_date,
614 size_t purge_goal,
mmenkef4721d992017-06-07 17:13:59615 CookieItVector cookie_its,
616 base::Time* earliest_time);
[email protected]63ee33bd2012-03-15 09:29:58617
davidben879199c2015-03-06 00:55:04618 // Find the key (for lookup in cookies_) based on the given domain.
619 // See comment on keys before the CookieMap typedef.
620 std::string GetKey(const std::string& domain) const;
621
[email protected]63ee33bd2012-03-15 09:29:58622 bool HasCookieableScheme(const GURL& url);
623
624 // Statistics support
625
626 // This function should be called repeatedly, and will record
627 // statistics if a sufficient time period has passed.
628 void RecordPeriodicStats(const base::Time& current_time);
629
630 // Initialize the above variables; should only be called from
631 // the constructor.
632 void InitializeHistograms();
633
634 // The resolution of our time isn't enough, so we do something
635 // ugly and increment when we've seen the same time twice.
636 base::Time CurrentTime();
637
638 // Runs the task if, or defers the task until, the full cookie database is
639 // loaded.
640 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item);
641
642 // Runs the task if, or defers the task until, the cookies for the given URL
643 // are loaded.
644 void DoCookieTaskForURL(const scoped_refptr<CookieMonsterTask>& task_item,
mkwstbe84af312015-02-20 08:52:45645 const GURL& url);
[email protected]63ee33bd2012-03-15 09:29:58646
drogerd5d1278c2015-03-17 19:21:51647 // Computes the difference between |old_cookies| and |new_cookies|, and writes
648 // the result in |cookies_to_add| and |cookies_to_delete|.
649 // This function has the side effect of changing the order of |old_cookies|
650 // and |new_cookies|. |cookies_to_add| and |cookies_to_delete| must be empty,
651 // and none of the arguments can be null.
652 void ComputeCookieDiff(CookieList* old_cookies,
653 CookieList* new_cookies,
654 CookieList* cookies_to_add,
655 CookieList* cookies_to_delete);
656
mmenkebe0910d2016-03-01 19:09:09657 // Runs the given callback. Used to avoid running callbacks after the store
658 // has been destroyed.
659 void RunCallback(const base::Closure& callback);
660
msarda0aad8f02014-10-30 09:22:39661 // Run all cookie changed callbacks that are monitoring |cookie|.
662 // |removed| is true if the cookie was deleted.
nharper352933e2016-09-30 18:24:57663 void RunCookieChangedCallbacks(const CanonicalCookie& cookie,
664 CookieStore::ChangeCause cause);
msarda0aad8f02014-10-30 09:22:39665
[email protected]63ee33bd2012-03-15 09:29:58666 // Histogram variables; see CookieMonster::InitializeHistograms() in
667 // cookie_monster.cc for details.
[email protected]de415552013-01-23 04:12:17668 base::HistogramBase* histogram_expiration_duration_minutes_;
[email protected]de415552013-01-23 04:12:17669 base::HistogramBase* histogram_evicted_last_access_minutes_;
670 base::HistogramBase* histogram_count_;
[email protected]de415552013-01-23 04:12:17671 base::HistogramBase* histogram_cookie_deletion_cause_;
mkwstc1aa4cc2015-04-03 19:57:45672 base::HistogramBase* histogram_cookie_type_;
estark7feb65c2b2015-08-21 23:38:20673 base::HistogramBase* histogram_cookie_source_scheme_;
jww31e32632015-12-16 23:38:34674 base::HistogramBase* histogram_cookie_delete_equivalent_;
[email protected]de415552013-01-23 04:12:17675 base::HistogramBase* histogram_time_blocked_on_load_;
[email protected]63ee33bd2012-03-15 09:29:58676
677 CookieMap cookies_;
678
erikchen1dd72a72015-05-06 20:45:05679 // Indicates whether the cookie store has been initialized.
[email protected]63ee33bd2012-03-15 09:29:58680 bool initialized_;
681
erikchen1dd72a72015-05-06 20:45:05682 // Indicates whether the cookie store has started fetching all cookies.
683 bool started_fetching_all_cookies_;
684 // Indicates whether the cookie store has finished fetching all cookies.
685 bool finished_fetching_all_cookies_;
686 // The strategy to use for fetching cookies.
687 FetchStrategy fetch_strategy_;
[email protected]63ee33bd2012-03-15 09:29:58688
689 // List of domain keys that have been loaded from the DB.
690 std::set<std::string> keys_loaded_;
691
692 // Map of domain keys to their associated task queues. These tasks are blocked
693 // until all cookies for the associated domain key eTLD+1 are loaded from the
694 // backend store.
mkwstbe84af312015-02-20 08:52:45695 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask>>>
[email protected]0184df32013-05-14 00:53:55696 tasks_pending_for_key_;
[email protected]63ee33bd2012-03-15 09:29:58697
698 // Queues tasks that are blocked until all cookies are loaded from the backend
699 // store.
mmenkef49fca0e2016-03-08 12:46:24700 std::deque<scoped_refptr<CookieMonsterTask>> tasks_pending_;
701
702 // Once a global cookie task has been seen, all per-key tasks must be put in
703 // |tasks_pending_| instead of |tasks_pending_for_key_| to ensure a reasonable
704 // view of the cookie store. This more to ensure fancy cookie export/import
705 // code has a consistent view of the CookieStore, rather than out of concern
706 // for typical use.
707 bool seen_global_task_;
[email protected]63ee33bd2012-03-15 09:29:58708
709 scoped_refptr<PersistentCookieStore> store_;
710
711 base::Time last_time_seen_;
712
713 // Minimum delay after updating a cookie's LastAccessDate before we will
714 // update it again.
715 const base::TimeDelta last_access_threshold_;
716
717 // Approximate date of access time of least recently accessed cookie
718 // in |cookies_|. Note that this is not guaranteed to be accurate, only a)
719 // to be before or equal to the actual time, and b) to be accurate
mmenkef4721d992017-06-07 17:13:59720 // immediately after a garbage collection that scans through all the cookies
721 // (When garbage collection does not scan through all cookies, it may not be
722 // updated). This value is used to determine whether global garbage collection
723 // might find cookies to purge. Note: The default Time() constructor will
724 // create a value that compares earlier than any other time value, which is
725 // wanted. Thus this value is not initialized.
[email protected]63ee33bd2012-03-15 09:29:58726 base::Time earliest_access_time_;
727
728 // During loading, holds the set of all loaded cookie creation times. Used to
729 // avoid ever letting cookies with duplicate creation times into the store;
730 // that way we don't have to worry about what sections of code are safe
731 // to call while it's in that state.
Avi Drissman13fc8932015-12-20 04:40:46732 std::set<int64_t> creation_times_;
[email protected]63ee33bd2012-03-15 09:29:58733
734 std::vector<std::string> cookieable_schemes_;
735
[email protected]7c4b66b2014-01-04 12:28:13736 scoped_refptr<CookieMonsterDelegate> delegate_;
nharper2b0ad9a2017-05-22 18:33:45737 ChannelIDService* channel_id_service_;
[email protected]63ee33bd2012-03-15 09:29:58738
[email protected]63ee33bd2012-03-15 09:29:58739 base::Time last_statistic_record_time_;
740
[email protected]63ee33bd2012-03-15 09:29:58741 bool persist_session_cookies_;
742
avie7cd11a2016-10-11 02:00:35743 using CookieChangedHookMap =
744 std::map<std::pair<GURL, std::string>,
745 std::unique_ptr<CookieChangedCallbackList>>;
ellyjones399e35a22014-10-27 11:09:56746 CookieChangedHookMap hook_map_;
747
mmenkebe0910d2016-03-01 19:09:09748 base::ThreadChecker thread_checker_;
749
750 base::WeakPtrFactory<CookieMonster> weak_ptr_factory_;
751
[email protected]63ee33bd2012-03-15 09:29:58752 DISALLOW_COPY_AND_ASSIGN(CookieMonster);
753};
754
[email protected]7c4b66b2014-01-04 12:28:13755class NET_EXPORT CookieMonsterDelegate
756 : public base::RefCountedThreadSafe<CookieMonsterDelegate> {
[email protected]63ee33bd2012-03-15 09:29:58757 public:
[email protected]63ee33bd2012-03-15 09:29:58758 // Will be called when a cookie is added or removed. The function is passed
759 // the respective |cookie| which was added to or removed from the cookies.
760 // If |removed| is true, the cookie was deleted, and |cause| will be set
[email protected]a2c92a1c2012-04-03 12:32:14761 // to the reason for its removal. If |removed| is false, the cookie was
nharper352933e2016-09-30 18:24:57762 // added, and |cause| will be set to ChangeCause::EXPLICIT.
[email protected]63ee33bd2012-03-15 09:29:58763 //
764 // As a special case, note that updating a cookie's properties is implemented
765 // as a two step process: the cookie to be updated is first removed entirely,
nharper352933e2016-09-30 18:24:57766 // generating a notification with cause ChangeCause::OVERWRITE. Afterwards,
[email protected]63ee33bd2012-03-15 09:29:58767 // a new cookie is written with the updated values, generating a notification
nharper352933e2016-09-30 18:24:57768 // with cause ChangeCause::EXPLICIT.
[email protected]5b9bc352012-07-18 13:13:34769 virtual void OnCookieChanged(const CanonicalCookie& cookie,
[email protected]63ee33bd2012-03-15 09:29:58770 bool removed,
nharper352933e2016-09-30 18:24:57771 CookieStore::ChangeCause cause) = 0;
772
[email protected]63ee33bd2012-03-15 09:29:58773 protected:
[email protected]7c4b66b2014-01-04 12:28:13774 friend class base::RefCountedThreadSafe<CookieMonsterDelegate>;
775 virtual ~CookieMonsterDelegate() {}
[email protected]63ee33bd2012-03-15 09:29:58776};
777
[email protected]63ee33bd2012-03-15 09:29:58778typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore>
779 RefcountedPersistentCookieStore;
780
[email protected]c1b6e102013-04-10 20:54:49781class NET_EXPORT CookieMonster::PersistentCookieStore
[email protected]63ee33bd2012-03-15 09:29:58782 : public RefcountedPersistentCookieStore {
783 public:
avie7cd11a2016-10-11 02:00:35784 typedef base::Callback<void(std::vector<std::unique_ptr<CanonicalCookie>>)>
[email protected]5b9bc352012-07-18 13:13:34785 LoadedCallback;
[email protected]63ee33bd2012-03-15 09:29:58786
erikchen1dd72a72015-05-06 20:45:05787 // TODO(erikchen): Depending on the results of the cookie monster Finch
788 // experiment, update the name and description of this method. The behavior
789 // of this method doesn't change, but it has different semantics for the two
790 // different logic paths. See http://crbug.com/473483.
[email protected]63ee33bd2012-03-15 09:29:58791 // Initializes the store and retrieves the existing cookies. This will be
792 // called only once at startup. The callback will return all the cookies
793 // that are not yet returned to CookieMonster by previous priority loads.
mmenkebe0910d2016-03-01 19:09:09794 //
795 // |loaded_callback| may not be NULL.
[email protected]63ee33bd2012-03-15 09:29:58796 virtual void Load(const LoadedCallback& loaded_callback) = 0;
797
798 // Does a priority load of all cookies for the domain key (eTLD+1). The
799 // callback will return all the cookies that are not yet returned by previous
800 // loads, which includes cookies for the requested domain key if they are not
801 // already returned, plus all cookies that are chain-loaded and not yet
802 // returned to CookieMonster.
mmenkebe0910d2016-03-01 19:09:09803 //
804 // |loaded_callback| may not be NULL.
[email protected]63ee33bd2012-03-15 09:29:58805 virtual void LoadCookiesForKey(const std::string& key,
[email protected]dedec0b2013-02-28 04:50:10806 const LoadedCallback& loaded_callback) = 0;
[email protected]63ee33bd2012-03-15 09:29:58807
808 virtual void AddCookie(const CanonicalCookie& cc) = 0;
809 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0;
810 virtual void DeleteCookie(const CanonicalCookie& cc) = 0;
811
[email protected]bf510ed2012-06-05 08:31:43812 // Instructs the store to not discard session only cookies on shutdown.
813 virtual void SetForceKeepSessionState() = 0;
[email protected]63ee33bd2012-03-15 09:29:58814
mmenkebe0910d2016-03-01 19:09:09815 // Flushes the store and posts |callback| when complete. |callback| may be
816 // NULL.
[email protected]63ee33bd2012-03-15 09:29:58817 virtual void Flush(const base::Closure& callback) = 0;
818
819 protected:
820 PersistentCookieStore() {}
[email protected]a9813302012-04-28 09:29:28821 virtual ~PersistentCookieStore() {}
[email protected]63ee33bd2012-03-15 09:29:58822
823 private:
[email protected]a9813302012-04-28 09:29:28824 friend class base::RefCountedThreadSafe<PersistentCookieStore>;
[email protected]63ee33bd2012-03-15 09:29:58825 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
826};
827
[email protected]63ee33bd2012-03-15 09:29:58828} // namespace net
829
830#endif // NET_COOKIES_COOKIE_MONSTER_H_