| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Brought to you by number 42. | 5 // Provides a temporary redirection while clients are updated to use the new |
| 6 // path. |
| 6 | 7 |
| 7 #ifndef NET_BASE_COOKIE_STORE_H_ | 8 #ifndef NET_BASE_COOKIE_STORE_H_ |
| 8 #define NET_BASE_COOKIE_STORE_H_ | 9 #define NET_BASE_COOKIE_STORE_H_ |
| 9 #pragma once | 10 #pragma once |
| 10 | 11 |
| 11 #include <string> | 12 #include "net/cookies/cookie_store.h" |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/callback.h" | |
| 16 #include "base/memory/ref_counted.h" | |
| 17 #include "base/time.h" | |
| 18 #include "net/base/cookie_options.h" | |
| 19 #include "net/base/net_export.h" | |
| 20 | |
| 21 class GURL; | |
| 22 | |
| 23 namespace net { | |
| 24 | |
| 25 class CookieMonster; | |
| 26 | |
| 27 // An interface for storing and retrieving cookies. Implementations need to | |
| 28 // be thread safe as its methods can be accessed from IO as well as UI threads. | |
| 29 class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { | |
| 30 public: | |
| 31 // This struct contains additional consumer-specific information that might | |
| 32 // be stored with cookies; currently just MAC information, see: | |
| 33 // http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac | |
| 34 struct NET_EXPORT CookieInfo { | |
| 35 CookieInfo(); | |
| 36 ~CookieInfo(); | |
| 37 | |
| 38 // The name of the cookie. | |
| 39 std::string name; | |
| 40 // TODO(abarth): Add value if any clients need it. | |
| 41 | |
| 42 // The time at which the cookie was created. | |
| 43 base::Time creation_date; | |
| 44 | |
| 45 // The value of the MAC-Key and MAC-Algorithm attributes, if present. | |
| 46 std::string mac_key; | |
| 47 std::string mac_algorithm; | |
| 48 }; | |
| 49 | |
| 50 // Callback definitions. | |
| 51 typedef base::Callback <void( | |
| 52 const std::string& cookie_line, | |
| 53 const std::vector<CookieInfo>& cookie_infos)> GetCookieInfoCallback; | |
| 54 typedef base::Callback<void(const std::string& cookie)> | |
| 55 GetCookiesCallback; | |
| 56 typedef base::Callback<void(bool success)> SetCookiesCallback; | |
| 57 typedef base::Callback<void(int num_deleted)> DeleteCallback; | |
| 58 | |
| 59 | |
| 60 // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". | |
| 61 // | |
| 62 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie | |
| 63 // and it would overwrite an existing HTTPONLY cookie. | |
| 64 // Returns true if the cookie is successfully set. | |
| 65 virtual void SetCookieWithOptionsAsync( | |
| 66 const GURL& url, | |
| 67 const std::string& cookie_line, | |
| 68 const CookieOptions& options, | |
| 69 const SetCookiesCallback& callback) = 0; | |
| 70 | |
| 71 // TODO(???): what if the total size of all the cookies >4k, can we have a | |
| 72 // header that big or do we need multiple Cookie: headers? | |
| 73 // Note: Some sites, such as Facebook, occasionally use Cookie headers >4k. | |
| 74 // | |
| 75 // Simple interface, gets a cookie string "a=b; c=d" for the given URL. | |
| 76 // Use options to access httponly cookies. | |
| 77 virtual void GetCookiesWithOptionsAsync( | |
| 78 const GURL& url, const CookieOptions& options, | |
| 79 const GetCookiesCallback& callback) = 0; | |
| 80 | |
| 81 // This function is similar to GetCookiesWithOptions same functionality as | |
| 82 // GetCookiesWithOptions except that it additionally provides detailed | |
| 83 // information about the cookie contained in the cookie line. See |struct | |
| 84 // CookieInfo| above for details. | |
| 85 virtual void GetCookiesWithInfoAsync( | |
| 86 const GURL& url, | |
| 87 const CookieOptions& options, | |
| 88 const GetCookieInfoCallback& callback) = 0; | |
| 89 | |
| 90 // Deletes the passed in cookie for the specified URL. | |
| 91 virtual void DeleteCookieAsync(const GURL& url, | |
| 92 const std::string& cookie_name, | |
| 93 const base::Closure& callback) = 0; | |
| 94 | |
| 95 // Deletes all of the cookies that have a creation_date greater than or equal | |
| 96 // to |delete_begin| and less than |delete_end| | |
| 97 // Returns the number of cookies that have been deleted. | |
| 98 virtual void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, | |
| 99 const base::Time& delete_end, | |
| 100 const DeleteCallback& callback) = 0; | |
| 101 | |
| 102 // Returns the underlying CookieMonster. | |
| 103 virtual CookieMonster* GetCookieMonster() = 0; | |
| 104 | |
| 105 protected: | |
| 106 friend class base::RefCountedThreadSafe<CookieStore>; | |
| 107 CookieStore(); | |
| 108 virtual ~CookieStore(); | |
| 109 }; | |
| 110 | |
| 111 } // namespace net | |
| 112 | 13 |
| 113 #endif // NET_BASE_COOKIE_STORE_H_ | 14 #endif // NET_BASE_COOKIE_STORE_H_ |
| OLD | NEW |