Home | History | Annotate | Download | only in base
      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 #include "net/base/net_export.h"
     19 
     20 class GURL;
     21 
     22 namespace net {
     23 
     24 class CookieMonster;
     25 
     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> {
     29  public:
     30   // Sets a single cookie.  Expects a cookie line, like "a=1; domain=b.com".
     31   virtual bool SetCookieWithOptions(const GURL& url,
     32                                     const std::string& cookie_line,
     33                                     const CookieOptions& options) = 0;
     34 
     35   // TODO what if the total size of all the cookies >4k, can we have a header
     36   // that big or do we need multiple Cookie: headers?
     37   // Simple interface, gets a cookie string "a=b; c=d" for the given URL.
     38   // Use options to access httponly cookies.
     39   virtual std::string GetCookiesWithOptions(const GURL& url,
     40                                             const CookieOptions& options) = 0;
     41 
     42   // Deletes the passed in cookie for the specified URL.
     43   virtual void DeleteCookie(const GURL& url,
     44                             const std::string& cookie_name) = 0;
     45 
     46   // Returns the underlying CookieMonster.
     47   virtual CookieMonster* GetCookieMonster() = 0;
     48 
     49 
     50   // --------------------------------------------------------------------------
     51   // Helpers to make the above interface simpler for some cases.
     52 
     53   // Sets a cookie for the given URL using default options.
     54   bool SetCookie(const GURL& url, const std::string& cookie_line);
     55 
     56   // Gets cookies for the given URL using default options.
     57   std::string GetCookies(const GURL& url);
     58 
     59   // Sets a vector of response cookie values for the same URL.
     60   void SetCookiesWithOptions(const GURL& url,
     61                              const std::vector<std::string>& cookie_lines,
     62                              const CookieOptions& options);
     63   void SetCookies(const GURL& url,
     64                   const std::vector<std::string>& cookie_lines);
     65 
     66  protected:
     67   friend class base::RefCountedThreadSafe<CookieStore>;
     68   CookieStore();
     69   virtual ~CookieStore();
     70 };
     71 
     72 }  // namespace net
     73 
     74 #endif  // NET_BASE_COOKIE_STORE_H_
     75