15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Brought to you by the letter D and the number 2.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_COOKIES_COOKIE_MONSTER_H_
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_COOKIES_COOKIE_MONSTER_H_
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <deque>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <queue>
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set>
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utility>
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback_forward.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/synchronization/lock.h"
24eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/canonical_cookie.h"
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/cookies/cookie_constants.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/cookie_store.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Histogram;
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class HistogramBase;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TimeTicks;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace base
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CookieMonsterDelegate;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ParsedCookie;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The cookie monster is the system for storing and retrieving cookies. It has
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// an in-memory list of all cookies, and synchronizes non-session cookies to an
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// optional permanent storage that implements the PersistentCookieStore
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class IS thread-safe. Normally, it is only used on the I/O thread, but
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is also accessed directly through Automation for UI testing.
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All cookie tasks are handled asynchronously. Tasks may be deferred if
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// all affected cookies are not yet loaded from the backing store. Otherwise,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the callback may be invoked immediately (prior to return of the asynchronous
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// function).
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A cookie task is either pending loading of the entire cookie store, or
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// loading of cookies for a specfic domain key(eTLD+1). In the former case, the
58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// cookie task will be queued in tasks_pending_ while PersistentCookieStore
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// chain loads the cookie store on DB thread. In the latter case, the cookie
60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// task will be queued in tasks_pending_for_key_ while PermanentCookieStore
61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// loads cookies for the specified domain key(eTLD+1) on DB thread.
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Callbacks are guaranteed to be invoked on the calling thread.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(deanm) Implement CookieMonster, the cookie database.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  - Verify that our domain enforcement and non-dotted handling is correct
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT CookieMonster : public CookieStore {
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class PersistentCookieStore;
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef CookieMonsterDelegate Delegate;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Terminology:
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    * The 'top level domain' (TLD) of an internet domain name is
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      the terminal "." free substring (e.g. "com" for google.com
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      or world.std.com).
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    * The 'effective top level domain' (eTLD) is the longest
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      "." initiated terminal substring of an internet domain name
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      that is controlled by a general domain registrar.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      (e.g. "co.uk" for news.bbc.co.uk).
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    * The 'effective top level domain plus one' (eTLD+1) is the
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      shortest "." delimited terminal substring of an internet
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      domain name that is not controlled by a general domain
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      registrar (e.g. "bbc.co.uk" for news.bbc.co.uk, or
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      "google.com" for news.google.com).  The general assumption
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      is that all hosts and domains under an eTLD+1 share some
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      administrative control.
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CookieMap is the central data structure of the CookieMonster.  It
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is a map whose values are pointers to CanonicalCookie data
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // structures (the data structures are owned by the CookieMonster
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and must be destroyed when removed from the map).  The key is based on the
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // effective domain of the cookies.  If the domain of the cookie has an
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // eTLD+1, that is the key for the map.  If the domain of the cookie does not
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // have an eTLD+1, the key of the map is the host the cookie applies to (it is
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not legal to have domain cookies without an eTLD+1).  This rule
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // excludes cookies for, e.g, ".com", ".co.uk", or ".internalnetwork".
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This behavior is the same as the behavior in Firefox v 3.6.10.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE(deanm):
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // I benchmarked hash_multimap vs multimap.  We're going to be query-heavy
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // so it would seem like hashing would help.  However they were very
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // close, with multimap being a tiny bit faster.  I think this is because
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // our map is at max around 1000 entries, and the additional complexity
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for the hashing might not overcome the O(log(1000)) for querying
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a multimap.  Also, multimap is standard, another reason to use it.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(rdsmith): This benchmark should be re-done now that we're allowing
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // subtantially more entries in the map.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef std::multimap<std::string, CanonicalCookie*> CookieMap;
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef std::pair<CookieMap::iterator, CookieMap::iterator> CookieMapItPair;
110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  typedef std::vector<CookieMap::iterator> CookieItVector;
111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Cookie garbage collection thresholds.  Based off of the Mozilla defaults.
113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // When the number of cookies gets to k{Domain,}MaxCookies
114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // purge down to k{Domain,}MaxCookies - k{Domain,}PurgeCookies.
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // It might seem scary to have a high purge value, but really it's not.
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // You just make sure that you increase the max to cover the increase
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // in purge, and we would have been purging the same number of cookies.
118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // We're just going through the garbage collection process less often.
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Note that the DOMAIN values are per eTLD+1; see comment for the
120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // CookieMap typedef.  So, e.g., the maximum number of cookies allowed for
121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // google.com and all of its subdomains will be 150-180.
122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //
123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Any cookies accessed more recently than kSafeFromGlobalPurgeDays will not
124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // be evicted by global garbage collection, even if we have more than
125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // kMaxCookies.  This does not affect domain garbage collection.
126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const size_t kDomainMaxCookies;
127c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const size_t kDomainPurgeCookies;
128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const size_t kMaxCookies;
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const size_t kPurgeCookies;
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Quota for cookies with {low, medium, high} priorities within a domain.
132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const size_t kDomainCookiesQuotaLow;
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const size_t kDomainCookiesQuotaMedium;
134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static const size_t kDomainCookiesQuotaHigh;
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The store passed in should not have had Init() called on it yet. This
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // class will take care of initializing it. The backing store is NOT owned by
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // this class, but it must remain valid for the duration of the cookie
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // monster's existence. If |store| is NULL, then no backing store will be
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // updated. If |delegate| is non-NULL, it will be notified on
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // creation/deletion of cookies.
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CookieMonster(PersistentCookieStore* store, CookieMonsterDelegate* delegate);
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Only used during unit testing.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieMonster(PersistentCookieStore* store,
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                CookieMonsterDelegate* delegate,
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                int last_access_threshold_milliseconds);
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Helper function that adds all cookies from |list| into this instance,
1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // overwriting any equivalent cookies.
1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool ImportCookies(const CookieList& list);
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback;
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(bool success)> DeleteCookieCallback;
155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  typedef base::Callback<void(bool cookies_exist)> HasCookiesForETLDP1Callback;
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets a cookie given explicit user-provided cookie attributes. The cookie
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // name, value, domain, etc. are each provided as separate strings. This
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // function expects each attribute to be well-formed. It will check for
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // disallowed characters (e.g. the ';' character is disallowed within the
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookie value attribute) and will return false without setting the cookie
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if such characters are found.
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetCookieWithDetailsAsync(const GURL& url,
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const std::string& name,
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const std::string& value,
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const std::string& domain,
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const std::string& path,
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const base::Time& expiration_time,
169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                 bool secure,
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                 bool http_only,
171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                 CookiePriority priority,
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const SetCookiesCallback& callback);
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns all the cookies, for use in management UI, etc. This does not mark
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the cookies as having been accessed.
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The returned cookies are ordered by longest path, then by earliest
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // creation date.
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetAllCookiesAsync(const GetCookieListCallback& callback);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns all the cookies, for use in management UI, etc. Filters results
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // using given url scheme, host / domain and path and options. This does not
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // mark the cookies as having been accessed.
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The returned cookies are ordered by longest path, then earliest
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // creation date.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetAllCookiesForURLWithOptionsAsync(
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CookieOptions& options,
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GetCookieListCallback& callback);
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes all of the cookies.
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteAllAsync(const DeleteCallback& callback);
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes all cookies that match the host of the given URL
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // regardless of path.  This includes all http_only and secure cookies,
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // but does not include any domain cookies that may apply to this host.
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the number of cookies deleted.
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteAllForHostAsync(const GURL& url,
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const DeleteCallback& callback);
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes one specific cookie.
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const DeleteCookieCallback& callback);
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Checks whether for a given ETLD+1, there currently exist any cookies.
206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void HasCookiesForETLDP1Async(const std::string& etldp1,
207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                const HasCookiesForETLDP1Callback& callback);
208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Resets the list of cookieable schemes to the supplied schemes.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If this this method is called, it must be called before first use of
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the instance (i.e. as part of the instance initialization process).
212116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void SetCookieableSchemes(const char* const schemes[], size_t num_schemes);
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // without 'file' being included.
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // There are some unknowns about how to correctly handle file:// cookies,
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // and our implementation for this is not robust enough. This allows you
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to enable support, but it should only be used for testing. Bug 1157243.
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetEnableFileScheme(bool accept);
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Instructs the cookie monster to not delete expired cookies. This is used
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in cases where the cookie monster is used as a data structure to keep
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // arbitrary cookies.
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetKeepExpiredCookies();
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Protects session cookies from deletion on shutdown.
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetForceKeepSessionState();
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Flush the backing store (if any) to disk and post the given callback when
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // done.
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE.
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // It may be posted to the current thread, or it may run on the thread that
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // actually does the flushing. Your Task should generally post a notification
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the thread you actually want to be notified on.
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FlushStore(const base::Closure& callback);
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CookieStore implementation.
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the cookies specified by |cookie_list| returned from |url|
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // with options |options| in effect.
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetCookieWithOptionsAsync(
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& cookie_line,
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CookieOptions& options,
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const SetCookiesCallback& callback) OVERRIDE;
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets all cookies that apply to |url| given |options|.
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The returned cookies are ordered by longest path, then earliest
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // creation date.
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GetCookiesWithOptionsAsync(
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CookieOptions& options,
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GetCookiesCallback& callback) OVERRIDE;
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
256effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP
257effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // only cookies.
258effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual void GetAllCookiesForURLAsync(
259effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      const GURL& url,
260effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      const GetCookieListCallback& callback) OVERRIDE;
261effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes all cookies with that might apply to |url| that has |cookie_name|.
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DeleteCookieAsync(
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url, const std::string& cookie_name,
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const base::Closure& callback) OVERRIDE;
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes all of the cookies that have a creation_date greater than or equal
2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to |delete_begin| and less than |delete_end|.
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the number of cookies that have been deleted.
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DeleteAllCreatedBetweenAsync(
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const base::Time& delete_begin,
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const base::Time& delete_end,
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const DeleteCallback& callback) OVERRIDE;
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Deletes all of the cookies that match the host of the given URL
2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // regardless of path and that have a creation_date greater than or
2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // equal to |delete_begin| and less then |delete_end|. This includes
2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // all http_only and secure cookies, but does not include any domain
2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // cookies that may apply to this host.
2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns the number of cookies deleted.
2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DeleteAllCreatedBetweenForHostAsync(
2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::Time delete_begin,
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::Time delete_end,
2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GURL& url,
2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const DeleteCallback& callback) OVERRIDE;
2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE;
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual CookieMonster* GetCookieMonster() OVERRIDE;
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Enables writing session cookies into the cookie database. If this this
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // method is called, it must be called before first use of the instance
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (i.e. as part of the instance initialization process).
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetPersistSessionCookies(bool persist_session_cookies);
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Debugging method to perform various validation checks on the map.
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Currently just checking that there are no null CanonicalCookie pointers
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in the map.
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Argument |arg| is to allow retaining of arbitrary data if the CHECKs
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in the function trip.  TODO(rdsmith):Remove hack.
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ValidateMap(int arg);
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Determines if the scheme of the URL is a scheme that cookies will be
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // stored for.
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsCookieableScheme(const std::string& scheme);
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The default list of schemes the cookie monster can handle.
308116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static const char* const kDefaultCookieableSchemes[];
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kDefaultCookieableSchemesCount;
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Copies all keys for the given |key| to another cookie monster |other|.
312cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Both |other| and |this| must be loaded for this operation to succeed.
313cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Furthermore, there may not be any cookies stored in |other| for |key|.
314cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns false if any of these conditions is not met.
315cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  bool CopyCookiesForKeyToOtherCookieMonster(std::string key,
316cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                             CookieMonster* other);
317cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
318cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Find the key (for lookup in cookies_) based on the given domain.
319cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // See comment on keys before the CookieMap typedef.
320cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  std::string GetKey(const std::string& domain) const;
321cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
322cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  bool loaded();
323cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For queueing the cookie monster calls.
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class CookieMonsterTask;
3274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  template <typename Result> class DeleteTask;
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DeleteAllCreatedBetweenTask;
3293240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  class DeleteAllCreatedBetweenForHostTask;
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DeleteAllForHostTask;
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DeleteAllTask;
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DeleteCookieTask;
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DeleteCanonicalCookieTask;
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class GetAllCookiesForURLWithOptionsTask;
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class GetAllCookiesTask;
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class GetCookiesWithOptionsTask;
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class SetCookieWithDetailsTask;
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class SetCookieWithOptionsTask;
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DeleteSessionCookiesTask;
340c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  class HasCookiesForETLDP1Task;
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Testing support.
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For SetCookieWithCreationTime.
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest,
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           TestCookieDeleteAllCreatedBetweenTimestamps);
3463240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  // For SetCookieWithCreationTime.
3473240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  FRIEND_TEST_ALL_PREFIXES(MultiThreadedCookieMonsterTest,
3483240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch                           ThreadCheckDeleteAllCreatedBetweenForHost);
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For gargage collection constants.
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection);
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection);
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers);
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes);
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For validation of key values.
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestDomainTree);
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestImport);
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey);
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey);
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For FindCookiesForKey.
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies);
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Internal reasons for deletion, used to populate informative histograms
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and to provide a public cause for onCookieChange notifications.
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If you add or remove causes from this list, please be sure to also update
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping.
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Moreover, these are used as array indexes, so avoid reordering to keep the
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // histogram buckets consistent. New items (if necessary) should be added
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY.
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum DeletionCause {
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EXPLICIT = 0,
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_OVERWRITE,
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EXPIRED,
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EVICTED,
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE,
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_DONT_RECORD,  // e.g. For final cleanup after flush to store.
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EVICTED_DOMAIN,
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EVICTED_GLOBAL,
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Cookies evicted during domain level garbage collection that
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // were accessed longer ago than kSafeFromGlobalPurgeDays
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE,
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Cookies evicted during domain level garbage collection that
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // were accessed more recently than kSafeFromGlobalPurgeDays
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // (and thus would have been preserved by global garbage collection).
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE,
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // A common idiom is to remove a cookie by overwriting it with an
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // already-expired expiration date. This captures that case.
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_EXPIRED_OVERWRITE,
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
39668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // Cookies are not allowed to contain control characters in the name or
39768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // value. However, we used to allow them, so we are now evicting any such
39868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    // cookies as we load them. See http://crbug.com/238041.
39968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    DELETE_COOKIE_CONTROL_CHAR,
40068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DELETE_COOKIE_LAST_ENTRY
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The number of days since last access that cookies will not be subject
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to global garbage collection.
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kSafeFromGlobalPurgeDays;
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Record statistics every kRecordStatisticsIntervalSeconds of uptime.
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kRecordStatisticsIntervalSeconds = 10 * 60;
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~CookieMonster();
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The following are synchronous calls to which the asynchronous methods
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // delegate either immediately (if the store is loaded) or through a deferred
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // task (if the store is not yet loaded).
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCookieWithDetails(const GURL& url,
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const std::string& name,
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const std::string& value,
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const std::string& domain,
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const std::string& path,
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const base::Time& expiration_time,
422c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            bool secure,
423c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            bool http_only,
424c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                            CookiePriority priority);
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieList GetAllCookies();
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieList GetAllCookiesForURLWithOptions(const GURL& url,
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            const CookieOptions& options);
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieList GetAllCookiesForURL(const GURL& url);
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DeleteAll(bool sync_to_store);
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DeleteAllCreatedBetween(const base::Time& delete_begin,
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              const base::Time& delete_end);
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DeleteAllForHost(const GURL& url);
4393240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  int DeleteAllCreatedBetweenForHost(const base::Time delete_begin,
4403240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch                                     const base::Time delete_end,
4413240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch                                     const GURL& url);
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool DeleteCanonicalCookie(const CanonicalCookie& cookie);
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCookieWithOptions(const GURL& url,
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const std::string& cookie_line,
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const CookieOptions& options);
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string GetCookiesWithOptions(const GURL& url,
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const CookieOptions& options);
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteCookie(const GURL& url, const std::string& cookie_name);
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCookieWithCreationTime(const GURL& url,
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const std::string& cookie_line,
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const base::Time& creation_time);
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DeleteSessionCookies();
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
460c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool HasCookiesForETLDP1(const std::string& etldp1);
461c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by all non-static functions to ensure that the cookies store has
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // been initialized. This is not done during creating so it doesn't block
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the window showing.
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note: this method should always be called with lock_ held.
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InitIfNecessary() {
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!initialized_) {
468868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      if (store_.get()) {
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        InitStore();
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      } else {
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        loaded_ = true;
472cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        ReportLoaded();
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      initialized_ = true;
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the backing store and reads existing cookies from it.
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Should only be called by InitIfNecessary().
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InitStore();
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
482cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Reports to the delegate that the cookie monster was loaded.
483cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void ReportLoaded();
484cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores cookies loaded from the backing store and invokes any deferred
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // calls. |beginning_time| should be the moment PersistentCookieStore::Load
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // was invoked and is used for reporting histogram_time_blocked_on_load_.
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // See PersistentCookieStore::Load for details on the contents of cookies.
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnLoaded(base::TimeTicks beginning_time,
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                const std::vector<CanonicalCookie*>& cookies);
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores cookies loaded from the backing store and invokes the deferred
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // task(s) pending loading of cookies associated with the domain key
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (eTLD+1). Called when all cookies for the domain key(eTLD+1) have been
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // loaded from DB. See PersistentCookieStore::Load for details on the contents
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of cookies.
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnKeyLoaded(
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& key,
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::vector<CanonicalCookie*>& cookies);
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores the loaded cookies.
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies);
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Invokes deferred calls.
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InvokeQueue();
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Checks that |cookies_| matches our invariants, and tries to repair any
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // inconsistencies. (In other words, it does not have duplicate cookies).
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void EnsureCookiesMapIsValid();
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Checks for any duplicate cookies for CookieMap key |key| which lie between
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |begin| and |end|. If any are found, all but the most recent are deleted.
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the number of duplicate cookies that were deleted.
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int TrimDuplicateCookiesForKey(const std::string& key,
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 CookieMap::iterator begin,
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 CookieMap::iterator end);
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetDefaultCookieableSchemes();
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FindCookiesForHostAndDomain(const GURL& url,
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const CookieOptions& options,
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   bool update_access_time,
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   std::vector<CanonicalCookie*>* cookies);
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FindCookiesForKey(const std::string& key,
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const GURL& url,
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const CookieOptions& options,
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const base::Time& current,
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         bool update_access_time,
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         std::vector<CanonicalCookie*>* cookies);
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete any cookies that are equivalent to |ecc| (same path, domain, etc).
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |skip_httponly| is true, httponly cookies will not be deleted.  The
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return value with be true if |skip_httponly| skipped an httponly cookie.
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |key| is the key to find the cookie in cookies_; see the comment before
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the CookieMap typedef for details.
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE: There should never be more than a single matching equivalent cookie.
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool DeleteAnyEquivalentCookie(const std::string& key,
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const CanonicalCookie& ecc,
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 bool skip_httponly,
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 bool already_expired);
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
54368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Takes ownership of *cc. Returns an iterator that points to the inserted
54468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // cookie in cookies_. Guarantee: all iterators to cookies_ remain valid.
54568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  CookieMap::iterator InternalInsertCookie(const std::string& key,
54668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                                           CanonicalCookie* cc,
54768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                                           bool sync_to_store);
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper function that sets cookies with more control.
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Not exposed as we don't want callers to have the ability
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to specify (potentially duplicate) creation times.
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCookieWithCreationTimeAndOptions(const GURL& url,
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const std::string& cookie_line,
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const base::Time& creation_time,
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const CookieOptions& options);
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper function that sets a canonical cookie, deleting equivalents and
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // performing garbage collection.
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          const base::Time& creation_time,
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          const CookieOptions& options);
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InternalUpdateCookieAccessTime(CanonicalCookie* cc,
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      const base::Time& current_time);
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |deletion_cause| argument is used for collecting statistics and choosing
5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged
5685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // notifications.  Guarantee: All iterators to cookies_ except to the
5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // deleted entry remain vaild.
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store,
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            DeletionCause deletion_cause);
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If the number of cookies for CookieMap key |key|, or globally, are
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // over the preset maximums above, garbage collect, first for the host and
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // then globally.  See comments above garbage collection threshold
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // constants for details.
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the number of cookies deleted (useful for debugging).
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int GarbageCollect(const base::Time& current, const std::string& key);
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper for GarbageCollect(); can be called directly as well.  Deletes
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // all expired cookies in |itpair|.  If |cookie_its| is non-NULL, it is
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // populated with all the non-expired cookies from |itpair|.
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the number of cookies deleted.
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int GarbageCollectExpired(const base::Time& current,
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const CookieMapItPair& itpair,
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            std::vector<CookieMap::iterator>* cookie_its);
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
590c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Helper for GarbageCollect(). Deletes all cookies in the range specified by
591c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // [|it_begin|, |it_end|). Returns the number of cookies deleted.
592c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int GarbageCollectDeleteRange(const base::Time& current,
593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                DeletionCause cause,
594c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                CookieItVector::iterator cookie_its_begin,
595c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                CookieItVector::iterator cookie_its_end);
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasCookieableScheme(const GURL& url);
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Statistics support
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This function should be called repeatedly, and will record
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // statistics if a sufficient time period has passed.
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RecordPeriodicStats(const base::Time& current_time);
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initialize the above variables; should only be called from
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the constructor.
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InitializeHistograms();
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The resolution of our time isn't enough, so we do something
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ugly and increment when we've seen the same time twice.
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Time CurrentTime();
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Runs the task if, or defers the task until, the full cookie database is
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // loaded.
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item);
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Runs the task if, or defers the task until, the cookies for the given URL
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // are loaded.
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DoCookieTaskForURL(const scoped_refptr<CookieMonsterTask>& task_item,
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const GURL& url);
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Histogram variables; see CookieMonster::InitializeHistograms() in
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookie_monster.cc for details.
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_expiration_duration_minutes_;
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_between_access_interval_minutes_;
6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_evicted_last_access_minutes_;
6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_count_;
6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_domain_count_;
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_etldp1_count_;
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_domain_per_etldp1_count_;
6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_number_duplicate_db_cookies_;
6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_cookie_deletion_cause_;
6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_time_get_;
6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_time_mac_;
6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::HistogramBase* histogram_time_blocked_on_load_;
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieMap cookies_;
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates whether the cookie store has been initialized. This happens
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // lazily in InitStoreIfNecessary().
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool initialized_;
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates whether loading from the backend store is completed and
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // calls may be immediately processed.
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool loaded_;
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // List of domain keys that have been loaded from the DB.
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::set<std::string> keys_loaded_;
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Map of domain keys to their associated task queues. These tasks are blocked
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // until all cookies for the associated domain key eTLD+1 are loaded from the
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // backend store.
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > >
654a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      tasks_pending_for_key_;
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Queues tasks that are blocked until all cookies are loaded from the backend
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // store.
658a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::queue<scoped_refptr<CookieMonsterTask> > tasks_pending_;
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<PersistentCookieStore> store_;
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Time last_time_seen_;
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Minimum delay after updating a cookie's LastAccessDate before we will
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // update it again.
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::TimeDelta last_access_threshold_;
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Approximate date of access time of least recently accessed cookie
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in |cookies_|.  Note that this is not guaranteed to be accurate, only a)
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to be before or equal to the actual time, and b) to be accurate
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // immediately after a garbage collection that scans through all the cookies.
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This value is used to determine whether global garbage collection might
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // find cookies to purge.
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note: The default Time() constructor will create a value that compares
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // earlier than any other time value, which is wanted.  Thus this
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // value is not initialized.
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Time earliest_access_time_;
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // During loading, holds the set of all loaded cookie creation times. Used to
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // avoid ever letting cookies with duplicate creation times into the store;
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that way we don't have to worry about what sections of code are safe
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to call while it's in that state.
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::set<int64> creation_times_;
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<std::string> cookieable_schemes_;
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_refptr<CookieMonsterDelegate> delegate_;
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Lock for thread-safety
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Lock lock_;
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Time last_statistic_record_time_;
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool keep_expired_cookies_;
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool persist_session_cookies_;
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Static setting for whether or not file scheme cookies are allows when
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a new CookieMonster is created, or the accepted schemes on a CookieMonster
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // instance are reset back to defaults.
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool default_enable_file_scheme_;
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(CookieMonster);
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT CookieMonsterDelegate
7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : public base::RefCountedThreadSafe<CookieMonsterDelegate> {
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The publicly relevant reasons a cookie might be changed.
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ChangeCause {
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The cookie was changed directly by a consumer's action.
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CHANGE_COOKIE_EXPLICIT,
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The cookie was automatically removed due to an insert operation that
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // overwrote it.
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CHANGE_COOKIE_OVERWRITE,
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The cookie was automatically removed as it expired.
7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CHANGE_COOKIE_EXPIRED,
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The cookie was automatically evicted during garbage collection.
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CHANGE_COOKIE_EVICTED,
7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The cookie was overwritten with an already-expired expiration date.
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CHANGE_COOKIE_EXPIRED_OVERWRITE
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Will be called when a cookie is added or removed. The function is passed
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the respective |cookie| which was added to or removed from the cookies.
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |removed| is true, the cookie was deleted, and |cause| will be set
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the reason for its removal. If |removed| is false, the cookie was
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // added, and |cause| will be set to CHANGE_COOKIE_EXPLICIT.
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // As a special case, note that updating a cookie's properties is implemented
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // as a two step process: the cookie to be updated is first removed entirely,
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // generating a notification with cause CHANGE_COOKIE_OVERWRITE.  Afterwards,
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a new cookie is written with the updated values, generating a notification
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // with cause CHANGE_COOKIE_EXPLICIT.
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnCookieChanged(const CanonicalCookie& cookie,
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               bool removed,
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               ChangeCause cause) = 0;
737cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Indicates that the cookie store has fully loaded.
738cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnLoaded() = 0;
739cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  friend class base::RefCountedThreadSafe<CookieMonsterDelegate>;
7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~CookieMonsterDelegate() {}
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore>
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RefcountedPersistentCookieStore;
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
748c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class NET_EXPORT CookieMonster::PersistentCookieStore
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public RefcountedPersistentCookieStore {
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(const std::vector<CanonicalCookie*>&)>
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      LoadedCallback;
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the store and retrieves the existing cookies. This will be
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called only once at startup. The callback will return all the cookies
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that are not yet returned to CookieMonster by previous priority loads.
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Load(const LoadedCallback& loaded_callback) = 0;
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Does a priority load of all cookies for the domain key (eTLD+1). The
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // callback will return all the cookies that are not yet returned by previous
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // loads, which includes cookies for the requested domain key if they are not
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // already returned, plus all cookies that are chain-loaded and not yet
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returned to CookieMonster.
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void LoadCookiesForKey(const std::string& key,
7652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                 const LoadedCallback& loaded_callback) = 0;
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AddCookie(const CanonicalCookie& cc) = 0;
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0;
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DeleteCookie(const CanonicalCookie& cc) = 0;
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Instructs the store to not discard session only cookies on shutdown.
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetForceKeepSessionState() = 0;
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Flushes the store and posts |callback| when complete.
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Flush(const base::Closure& callback) = 0;
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PersistentCookieStore() {}
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~PersistentCookieStore() {}
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class base::RefCountedThreadSafe<PersistentCookieStore>;
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_COOKIES_COOKIE_MONSTER_H_
789