| 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> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // An interface for storing and retrieving cookies. Implementations need to | 28 // An interface for storing and retrieving cookies. Implementations need to |
| 29 // be thread safe as its methods can be accessed from IO as well as UI threads. | 29 // be thread safe as its methods can be accessed from IO as well as UI threads. |
| 30 class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { | 30 class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> { |
| 31 public: | 31 public: |
| 32 // Callback definitions. | 32 // Callback definitions. |
| 33 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | 33 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; |
| 34 typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback; | 34 typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback; |
| 35 typedef base::Callback<void(bool success)> SetCookiesCallback; | 35 typedef base::Callback<void(bool success)> SetCookiesCallback; |
| 36 typedef base::Callback<void(int num_deleted)> DeleteCallback; | 36 typedef base::Callback<void(int num_deleted)> DeleteCallback; |
| 37 typedef base::Closure CookieChangedCallback; | 37 typedef base::Callback<void(const CanonicalCookie& cookie, bool removed)> |
| 38 typedef base::CallbackList<void(void)> CookieChangedCallbackList; | 38 CookieChangedCallback; |
| 39 typedef base::CallbackList<void(const CanonicalCookie& cookie, bool removed)> |
| 40 CookieChangedCallbackList; |
| 39 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; | 41 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; |
| 40 | 42 |
| 41 // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". | 43 // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". |
| 42 // | 44 // |
| 43 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie | 45 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie |
| 44 // and it would overwrite an existing HTTPONLY cookie. | 46 // and it would overwrite an existing HTTPONLY cookie. |
| 45 // Returns true if the cookie is successfully set. | 47 // Returns true if the cookie is successfully set. |
| 46 virtual void SetCookieWithOptionsAsync( | 48 virtual void SetCookieWithOptionsAsync( |
| 47 const GURL& url, | 49 const GURL& url, |
| 48 const std::string& cookie_line, | 50 const std::string& cookie_line, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 94 |
| 93 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) = 0; | 95 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) = 0; |
| 94 | 96 |
| 95 // Returns the underlying CookieMonster. | 97 // Returns the underlying CookieMonster. |
| 96 virtual CookieMonster* GetCookieMonster() = 0; | 98 virtual CookieMonster* GetCookieMonster() = 0; |
| 97 | 99 |
| 98 // Add a callback to be notified when the set of cookies named |name| that | 100 // Add a callback to be notified when the set of cookies named |name| that |
| 99 // would be sent for a request to |url| changes. The returned handle is | 101 // would be sent for a request to |url| changes. The returned handle is |
| 100 // guaranteed not to hold a hard reference to the CookieStore object. | 102 // guaranteed not to hold a hard reference to the CookieStore object. |
| 101 // | 103 // |
| 104 // |callback| will be called when a cookie is added or removed. |callback| is |
| 105 // passed the respective |cookie| which was added to or removed from the |
| 106 // cookies and a boolean indicating if the cookies was removed or not. |
| 107 // |
| 108 // Note that |callback| is called twice when a cookie is updated: once for |
| 109 // the removal of the existing cookie and once for the adding the new cookie. |
| 110 // |
| 102 // Note that this method consumes memory and CPU per (url, name) pair ever | 111 // Note that this method consumes memory and CPU per (url, name) pair ever |
| 103 // registered that are still consumed even after all subscriptions for that | 112 // registered that are still consumed even after all subscriptions for that |
| 104 // (url, name) pair are removed. If this method ever needs to support an | 113 // (url, name) pair are removed. If this method ever needs to support an |
| 105 // unbounded amount of such pairs, this contract needs to change and | 114 // unbounded amount of such pairs, this contract needs to change and |
| 106 // implementors need to be improved to not behave this way. | 115 // implementors need to be improved to not behave this way. |
| 107 virtual scoped_ptr<CookieChangedSubscription> AddCallbackForCookie( | 116 virtual scoped_ptr<CookieChangedSubscription> AddCallbackForCookie( |
| 108 const GURL& url, | 117 const GURL& url, |
| 109 const std::string& name, | 118 const std::string& name, |
| 110 const CookieChangedCallback& callback) = 0; | 119 const CookieChangedCallback& callback) = 0; |
| 111 | 120 |
| 112 protected: | 121 protected: |
| 113 friend class base::RefCountedThreadSafe<CookieStore>; | 122 friend class base::RefCountedThreadSafe<CookieStore>; |
| 114 CookieStore(); | 123 CookieStore(); |
| 115 virtual ~CookieStore(); | 124 virtual ~CookieStore(); |
| 116 }; | 125 }; |
| 117 | 126 |
| 118 } // namespace net | 127 } // namespace net |
| 119 | 128 |
| 120 #endif // NET_COOKIES_COOKIE_STORE_H_ | 129 #endif // NET_COOKIES_COOKIE_STORE_H_ |
| OLD | NEW |