• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 number 42.
6 
7 #ifndef NET_BASE_COOKIE_STORE_H_
8 #define NET_BASE_COOKIE_STORE_H_
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 
14 #include "base/basictypes.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/time.h"
17 #include "net/base/cookie_options.h"
18 
19 class GURL;
20 
21 namespace net {
22 
23 class CookieMonster;
24 
25 // An interface for storing and retrieving cookies. Implementations need to
26 // be thread safe as its methods can be accessed from IO as well as UI threads.
27 class CookieStore : public base::RefCountedThreadSafe<CookieStore> {
28  public:
29   // Sets a single cookie.  Expects a cookie line, like "a=1; domain=b.com".
30   virtual bool SetCookieWithOptions(const GURL& url,
31                                     const std::string& cookie_line,
32                                     const CookieOptions& options) = 0;
33 
34   // TODO what if the total size of all the cookies >4k, can we have a header
35   // that big or do we need multiple Cookie: headers?
36   // Simple interface, gets a cookie string "a=b; c=d" for the given URL.
37   // Use options to access httponly cookies.
38   virtual std::string GetCookiesWithOptions(const GURL& url,
39                                             const CookieOptions& options) = 0;
40 
41   // Deletes the passed in cookie for the specified URL.
42   virtual void DeleteCookie(const GURL& url,
43                             const std::string& cookie_name) = 0;
44 
45   // Returns the underlying CookieMonster.
46   virtual CookieMonster* GetCookieMonster() = 0;
47 
48 
49   // --------------------------------------------------------------------------
50   // Helpers to make the above interface simpler for some cases.
51 
52   // Sets a cookie for the given URL using default options.
53   bool SetCookie(const GURL& url, const std::string& cookie_line);
54 
55   // Gets cookies for the given URL using default options.
56   std::string GetCookies(const GURL& url);
57 
58   // Sets a vector of response cookie values for the same URL.
59   void SetCookiesWithOptions(const GURL& url,
60                              const std::vector<std::string>& cookie_lines,
61                              const CookieOptions& options);
62   void SetCookies(const GURL& url,
63                   const std::vector<std::string>& cookie_lines);
64 
65  protected:
66   friend class base::RefCountedThreadSafe<CookieStore>;
67   CookieStore();
68   virtual ~CookieStore();
69 };
70 
71 }  // namespace net
72 
73 #endif  // NET_BASE_COOKIE_STORE_H_
74