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 <memory> | 10 #include <memory> |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 // An interface for storing and retrieving cookies. Implementations are not | 27 // An interface for storing and retrieving cookies. Implementations are not |
28 // thread safe, as with most other net classes. All methods must be invoked on | 28 // thread safe, as with most other net classes. All methods must be invoked on |
29 // the network thread, and all callbacks will be calle there. | 29 // the network thread, and all callbacks will be calle there. |
30 // | 30 // |
31 // All async functions may either invoke the callback asynchronously, or they | 31 // All async functions may either invoke the callback asynchronously, or they |
32 // may be invoked immediately (prior to return of the asynchronous function). | 32 // may be invoked immediately (prior to return of the asynchronous function). |
33 // Destroying the CookieStore will cancel pending async callbacks. | 33 // Destroying the CookieStore will cancel pending async callbacks. |
34 class NET_EXPORT CookieStore { | 34 class NET_EXPORT CookieStore { |
35 public: | 35 public: |
36 // The publicly relevant reasons a cookie might be changed. | |
37 enum class ChangeCause { | |
38 // The cookie was inserted. | |
39 INSERTED, | |
40 // The cookie was changed directly by a consumer's action. | |
41 EXPLICIT, | |
42 // The cookie was deleted, but no more details are known. | |
43 UNKNOWN_DELETION, | |
44 // The cookie was automatically removed due to an insert operation that | |
45 // overwrote it. | |
46 OVERWRITE, | |
47 // The cookie was automatically removed as it expired. | |
48 EXPIRED, | |
49 // The cookie was automatically evicted during garbage collection. | |
50 EVICTED, | |
51 // The cookie was overwritten with an already-expired expiration date. | |
52 EXPIRED_OVERWRITE | |
53 }; | |
54 | |
55 static bool ChangeCauseIsDeletion(ChangeCause cause); | |
mmenke
2016/09/27 18:09:21
Need to document this.
nharper
2016/09/27 21:50:53
Done.
| |
56 | |
36 // Callback definitions. | 57 // Callback definitions. |
37 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | 58 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; |
38 typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback; | 59 typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback; |
39 typedef base::Callback<void(bool success)> SetCookiesCallback; | 60 typedef base::Callback<void(bool success)> SetCookiesCallback; |
40 typedef base::Callback<void(int num_deleted)> DeleteCallback; | 61 typedef base::Callback<void(int num_deleted)> DeleteCallback; |
41 typedef base::Callback<void(const CanonicalCookie& cookie, bool removed)> | 62 typedef base::Callback<void(const CanonicalCookie& cookie, ChangeCause cause)> |
42 CookieChangedCallback; | 63 CookieChangedCallback; |
43 typedef base::CallbackList<void(const CanonicalCookie& cookie, bool removed)> | 64 typedef base::CallbackList<void(const CanonicalCookie& cookie, |
65 ChangeCause cause)> | |
44 CookieChangedCallbackList; | 66 CookieChangedCallbackList; |
45 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; | 67 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; |
46 typedef base::Callback<bool(const CanonicalCookie& cookie)> CookiePredicate; | 68 typedef base::Callback<bool(const CanonicalCookie& cookie)> CookiePredicate; |
47 | 69 |
48 virtual ~CookieStore(); | 70 virtual ~CookieStore(); |
49 | 71 |
50 // Returns the cookie line (e.g. "cookie1=value1; cookie2=value2") represented | 72 // Returns the cookie line (e.g. "cookie1=value1; cookie2=value2") represented |
51 // by |cookies|. The string is built in the same order as the given list. | 73 // by |cookies|. The string is built in the same order as the given list. |
52 // | 74 // |
53 // TODO(mkwst): We really should standardize on either | 75 // TODO(mkwst): We really should standardize on either |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 // cookies and a boolean indicating if the cookies was removed or not. | 213 // cookies and a boolean indicating if the cookies was removed or not. |
192 // | 214 // |
193 // Note that |callback| is called twice when a cookie is updated: once for | 215 // Note that |callback| is called twice when a cookie is updated: once for |
194 // the removal of the existing cookie and once for the adding the new cookie. | 216 // the removal of the existing cookie and once for the adding the new cookie. |
195 // | 217 // |
196 // Note that this method consumes memory and CPU per (url, name) pair ever | 218 // Note that this method consumes memory and CPU per (url, name) pair ever |
197 // registered that are still consumed even after all subscriptions for that | 219 // registered that are still consumed even after all subscriptions for that |
198 // (url, name) pair are removed. If this method ever needs to support an | 220 // (url, name) pair are removed. If this method ever needs to support an |
199 // unbounded amount of such pairs, this contract needs to change and | 221 // unbounded amount of such pairs, this contract needs to change and |
200 // implementors need to be improved to not behave this way. | 222 // implementors need to be improved to not behave this way. |
223 // | |
224 // The callback must not synchronously modify another cookie. | |
201 virtual std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie( | 225 virtual std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie( |
202 const GURL& url, | 226 const GURL& url, |
203 const std::string& name, | 227 const std::string& name, |
204 const CookieChangedCallback& callback) = 0; | 228 const CookieChangedCallback& callback) = 0; |
205 | 229 |
206 // Returns true if this cookie store is ephemeral, and false if it is backed | 230 // Returns true if this cookie store is ephemeral, and false if it is backed |
207 // by some sort of persistence layer. | 231 // by some sort of persistence layer. |
208 // TODO(nharper): Remove this method once crbug.com/548423 has been closed. | 232 // TODO(nharper): Remove this method once crbug.com/548423 has been closed. |
209 virtual bool IsEphemeral() = 0; | 233 virtual bool IsEphemeral() = 0; |
210 void SetChannelIDServiceID(int id); | 234 void SetChannelIDServiceID(int id); |
211 int GetChannelIDServiceID(); | 235 int GetChannelIDServiceID(); |
212 | 236 |
213 protected: | 237 protected: |
214 CookieStore(); | 238 CookieStore(); |
215 int channel_id_service_id_; | 239 int channel_id_service_id_; |
216 }; | 240 }; |
217 | 241 |
218 } // namespace net | 242 } // namespace net |
219 | 243 |
220 #endif // NET_COOKIES_COOKIE_STORE_H_ | 244 #endif // NET_COOKIES_COOKIE_STORE_H_ |
OLD | NEW |