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. 4 5 // Brought to you by number 42. 6 7 #ifndef NET_COOKIES_COOKIE_STORE_H_ 8 #define NET_COOKIES_COOKIE_STORE_H_ 9 10 #include <string> 11 #include <vector> 12 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" 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 // Callback definitions. 31 typedef base::Callback<void(const std::string& cookie)> 32 GetCookiesCallback; 33 typedef base::Callback<void(bool success)> SetCookiesCallback; 34 typedef base::Callback<void(int num_deleted)> DeleteCallback; 35 36 37 // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". 38 // 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( 43 const GURL& url, 44 const std::string& cookie_line, 45 const CookieOptions& options, 46 const SetCookiesCallback& callback) = 0; 47 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. 51 // 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( 55 const GURL& url, 56 const CookieOptions& options, 57 const GetCookiesCallback& callback) = 0; 58 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; 63 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; 70 71 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) = 0; 72 73 // Returns the underlying CookieMonster. 74 virtual CookieMonster* GetCookieMonster() = 0; 75 76 protected: 77 friend class base::RefCountedThreadSafe<CookieStore>; 78 CookieStore(); 79 virtual ~CookieStore(); 80 }; 81 82 } // namespace net 83 84 #endif // NET_COOKIES_COOKIE_STORE_H_ 85