1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Brought to you by number 42.
7 #ifndef NET_COOKIES_COOKIE_STORE_H_
8 #define NET_COOKIES_COOKIE_STORE_H_
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/time/time.h"
17 #include "net/base/net_export.h"
18 #include "net/cookies/cookie_options.h"
26 // An interface for storing and retrieving cookies. Implementations need to
27 // be thread safe as its methods can be accessed from IO as well as UI threads.
28 class NET_EXPORT CookieStore
: public base::RefCountedThreadSafe
<CookieStore
> {
30 // Callback definitions.
31 typedef base::Callback
<void(const std::string
& cookie
)>
33 typedef base::Callback
<void(bool success
)> SetCookiesCallback
;
34 typedef base::Callback
<void(int num_deleted
)> DeleteCallback
;
37 // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com".
39 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie
40 // and it would overwrite an existing HTTPONLY cookie.
41 // Returns true if the cookie is successfully set.
42 virtual void SetCookieWithOptionsAsync(
44 const std::string
& cookie_line
,
45 const CookieOptions
& options
,
46 const SetCookiesCallback
& callback
) = 0;
48 // TODO(???): what if the total size of all the cookies >4k, can we have a
49 // header that big or do we need multiple Cookie: headers?
50 // Note: Some sites, such as Facebook, occasionally use Cookie headers >4k.
52 // Simple interface, gets a cookie string "a=b; c=d" for the given URL.
53 // Use options to access httponly cookies.
54 virtual void GetCookiesWithOptionsAsync(
56 const CookieOptions
& options
,
57 const GetCookiesCallback
& callback
) = 0;
59 // Deletes the passed in cookie for the specified URL.
60 virtual void DeleteCookieAsync(const GURL
& url
,
61 const std::string
& cookie_name
,
62 const base::Closure
& callback
) = 0;
64 // Deletes all of the cookies that have a creation_date greater than or equal
65 // to |delete_begin| and less than |delete_end|
66 // Returns the number of cookies that have been deleted.
67 virtual void DeleteAllCreatedBetweenAsync(const base::Time
& delete_begin
,
68 const base::Time
& delete_end
,
69 const DeleteCallback
& callback
) = 0;
71 virtual void DeleteSessionCookiesAsync(const DeleteCallback
&) = 0;
73 // Returns the underlying CookieMonster.
74 virtual CookieMonster
* GetCookieMonster() = 0;
77 friend class base::RefCountedThreadSafe
<CookieStore
>;
79 virtual ~CookieStore();
84 #endif // NET_COOKIES_COOKIE_STORE_H_