| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Brought to you by number 42. |
| 6 | 6 |
| 7 #ifndef NET_COOKIES_COOKIE_STORE_H_ | 7 #ifndef NET_COOKIES_COOKIE_STORE_H_ |
| 8 #define NET_COOKIES_COOKIE_STORE_H_ | 8 #define NET_COOKIES_COOKIE_STORE_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_list.h" | 14 #include "base/callback_list.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 18 #include "net/cookies/canonical_cookie.h" | 18 #include "net/cookies/canonical_cookie.h" |
| 19 #include "net/cookies/cookie_options.h" | 19 #include "net/cookies/cookie_options.h" |
| 20 | 20 |
| 21 class GURL; | 21 class GURL; |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 | 24 |
| 25 class CookieMonster; | 25 class CookieMonster; |
| 26 | 26 |
| 27 // An interface for storing and retrieving cookies. Implementations need to | 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. | 28 // be thread safe as its methods can be accessed from IO as well as UI threads. |
| 29 // |
| 30 // All async functions may either invoke the callback asynchronously on the same |
| 31 // thread, or they may be invoked immediately (prior to return of the |
| 32 // asynchronous function). |
| 29 class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { | 33 class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { |
| 30 public: | 34 public: |
| 31 // Callback definitions. | 35 // Callback definitions. |
| 32 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | 36 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; |
| 33 typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback; | 37 typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback; |
| 34 typedef base::Callback<void(bool success)> SetCookiesCallback; | 38 typedef base::Callback<void(bool success)> SetCookiesCallback; |
| 35 typedef base::Callback<void(int num_deleted)> DeleteCallback; | 39 typedef base::Callback<void(int num_deleted)> DeleteCallback; |
| 36 typedef base::Callback<void(const CanonicalCookie& cookie, bool removed)> | 40 typedef base::Callback<void(const CanonicalCookie& cookie, bool removed)> |
| 37 CookieChangedCallback; | 41 CookieChangedCallback; |
| 38 typedef base::CallbackList<void(const CanonicalCookie& cookie, bool removed)> | 42 typedef base::CallbackList<void(const CanonicalCookie& cookie, bool removed)> |
| 39 CookieChangedCallbackList; | 43 CookieChangedCallbackList; |
| 40 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; | 44 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; |
| 41 | 45 |
| 42 // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". | 46 // Sets the cookies specified by |cookie_list| returned from |url| |
| 47 // with options |options| in effect. Expects a cookie line, like |
| 48 // "a=1; domain=b.com". |
| 43 // | 49 // |
| 44 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie | 50 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie |
| 45 // and it would overwrite an existing HTTPONLY cookie. | 51 // and it would overwrite an existing HTTPONLY cookie. |
| 46 // Returns true if the cookie is successfully set. | 52 // Returns true if the cookie is successfully set. |
| 47 virtual void SetCookieWithOptionsAsync( | 53 virtual void SetCookieWithOptionsAsync( |
| 48 const GURL& url, | 54 const GURL& url, |
| 49 const std::string& cookie_line, | 55 const std::string& cookie_line, |
| 50 const CookieOptions& options, | 56 const CookieOptions& options, |
| 51 const SetCookiesCallback& callback) = 0; | 57 const SetCookiesCallback& callback) = 0; |
| 52 | 58 |
| 53 // TODO(???): what if the total size of all the cookies >4k, can we have a | 59 // TODO(???): what if the total size of all the cookies >4k, can we have a |
| 54 // header that big or do we need multiple Cookie: headers? | 60 // header that big or do we need multiple Cookie: headers? |
| 55 // Note: Some sites, such as Facebook, occasionally use Cookie headers >4k. | 61 // Note: Some sites, such as Facebook, occasionally use Cookie headers >4k. |
| 56 // | 62 // |
| 57 // Simple interface, gets a cookie string "a=b; c=d" for the given URL. | 63 // Simple interface, gets a cookie string "a=b; c=d" for the given URL. |
| 58 // Use options to access httponly cookies. | 64 // Gets all cookies that apply to |url| given |options|. Use options to |
| 65 // access httponly cookies. |
| 66 // |
| 67 // The returned cookies are ordered by longest path, then earliest |
| 68 // creation date. |
| 59 virtual void GetCookiesWithOptionsAsync( | 69 virtual void GetCookiesWithOptionsAsync( |
| 60 const GURL& url, | 70 const GURL& url, |
| 61 const CookieOptions& options, | 71 const CookieOptions& options, |
| 62 const GetCookiesCallback& callback) = 0; | 72 const GetCookiesCallback& callback) = 0; |
| 63 | 73 |
| 64 // Returns all matching cookies without marking them as accessed, | 74 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP |
| 65 // including HTTP only cookies. | 75 // only cookies. |
| 66 virtual void GetAllCookiesForURLAsync( | 76 virtual void GetAllCookiesForURLAsync( |
| 67 const GURL& url, | 77 const GURL& url, |
| 68 const GetCookieListCallback& callback) = 0; | 78 const GetCookieListCallback& callback) = 0; |
| 69 | 79 |
| 70 // Deletes the passed in cookie for the specified URL. | 80 // Deletes all cookies that might apply to |url| that have |cookie_name|. |
| 71 virtual void DeleteCookieAsync(const GURL& url, | 81 virtual void DeleteCookieAsync(const GURL& url, |
| 72 const std::string& cookie_name, | 82 const std::string& cookie_name, |
| 73 const base::Closure& callback) = 0; | 83 const base::Closure& callback) = 0; |
| 74 | 84 |
| 75 // Deletes all of the cookies that have a creation_date greater than or equal | 85 // Deletes all of the cookies that have a creation_date greater than or equal |
| 76 // to |delete_begin| and less than |delete_end| | 86 // to |delete_begin| and less than |delete_end| |
| 77 // Returns the number of cookies that have been deleted. | 87 // Returns the number of cookies that have been deleted. |
| 78 virtual void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, | 88 virtual void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, |
| 79 const base::Time& delete_end, | 89 const base::Time& delete_end, |
| 80 const DeleteCallback& callback) = 0; | 90 const DeleteCallback& callback) = 0; |
| 81 | 91 |
| 82 // Deletes all of the cookies that match the host of the given URL | 92 // Deletes all of the cookies that match the host of the given URL |
| 83 // regardless of path and that have a creation_date greater than or | 93 // regardless of path and that have a creation_date greater than or |
| 84 // equal to |delete_begin| and less then |delete_end|. This includes | 94 // equal to |delete_begin| and less then |delete_end|. This includes |
| 85 // all http_only and secure cookies, but does not include any domain | 95 // all http_only and secure cookies, but does not include any domain |
| 86 // cookies that may apply to this host. | 96 // cookies that may apply to this host. |
| 87 // Returns the number of cookies deleted. | 97 // Returns the number of cookies deleted. |
| 88 virtual void DeleteAllCreatedBetweenForHostAsync( | 98 virtual void DeleteAllCreatedBetweenForHostAsync( |
| 89 const base::Time delete_begin, | 99 const base::Time delete_begin, |
| 90 const base::Time delete_end, | 100 const base::Time delete_end, |
| 91 const GURL& url, | 101 const GURL& url, |
| 92 const DeleteCallback& callback) = 0; | 102 const DeleteCallback& callback) = 0; |
| 93 | 103 |
| 94 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) = 0; | 104 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) = 0; |
| 95 | 105 |
| 106 // Flush the backing store (if any) to disk and post the given callback when |
| 107 // done. |
| 108 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. |
| 109 // It may be posted to the current thread, or it may run on the thread that |
| 110 // actually does the flushing. Your Task should generally post a notification |
| 111 // to the thread you actually want to be notified on. |
| 112 // TODO(mmenke): Once this class is no longer thread-safe, this will always |
| 113 // be invoked on the CookieStore's thread, and this comment can be removed. |
| 114 // https://crbug.com/46185 |
| 115 virtual void FlushStore(const base::Closure& callback) = 0; |
| 116 |
| 96 // Returns the underlying CookieMonster. | 117 // Returns the underlying CookieMonster. |
| 97 virtual CookieMonster* GetCookieMonster() = 0; | 118 virtual CookieMonster* GetCookieMonster() = 0; |
| 98 | 119 |
| 99 // Add a callback to be notified when the set of cookies named |name| that | 120 // Add a callback to be notified when the set of cookies named |name| that |
| 100 // would be sent for a request to |url| changes. The returned handle is | 121 // would be sent for a request to |url| changes. The returned handle is |
| 101 // guaranteed not to hold a hard reference to the CookieStore object. | 122 // guaranteed not to hold a hard reference to the CookieStore object. |
| 102 // | 123 // |
| 103 // |callback| will be called when a cookie is added or removed. |callback| is | 124 // |callback| will be called when a cookie is added or removed. |callback| is |
| 104 // passed the respective |cookie| which was added to or removed from the | 125 // passed the respective |cookie| which was added to or removed from the |
| 105 // cookies and a boolean indicating if the cookies was removed or not. | 126 // cookies and a boolean indicating if the cookies was removed or not. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 | 140 |
| 120 protected: | 141 protected: |
| 121 friend class base::RefCountedThreadSafe<CookieStore>; | 142 friend class base::RefCountedThreadSafe<CookieStore>; |
| 122 CookieStore(); | 143 CookieStore(); |
| 123 virtual ~CookieStore(); | 144 virtual ~CookieStore(); |
| 124 }; | 145 }; |
| 125 | 146 |
| 126 } // namespace net | 147 } // namespace net |
| 127 | 148 |
| 128 #endif // NET_COOKIES_COOKIE_STORE_H_ | 149 #endif // NET_COOKIES_COOKIE_STORE_H_ |
| OLD | NEW |