Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: net/cookies/cookie_store.h

Issue 2349823003: Pass a RemovalCause to CookieChangedCallback (Closed)
Patch Set: Merge enums Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ChangeCause {
38 // The cookie was inserted.
39 CHANGE_COOKIE_INSERTED,
mmenke 2016/09/26 18:29:26 Can we make this an enum class (And maybe get rid
nharper 2016/09/26 21:09:10 Done.
40 // The cookie was changed directly by a consumer's action.
41 CHANGE_COOKIE_EXPLICIT,
42 // The cookie was deleted, but no more details are known.
43 CHANGE_COOKIE_UNKNOWN_DELETION,
44 // The cookie was automatically removed due to an insert operation that
45 // overwrote it.
46 CHANGE_COOKIE_OVERWRITE,
47 // The cookie was automatically removed as it expired.
48 CHANGE_COOKIE_EXPIRED,
49 // The cookie was automatically evicted during garbage collection.
50 CHANGE_COOKIE_EVICTED,
51 // The cookie was overwritten with an already-expired expiration date.
52 CHANGE_COOKIE_EXPIRED_OVERWRITE
53 };
54
55 static bool ChangeCauseIsDeletion(ChangeCause cause);
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)>
Mike West 2016/09/26 07:55:37 Can you add some tests for this change? It looks l
nharper 2016/09/26 21:09:10 I've updated cookie_monster_unittest.cc to check t
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // passed the respective |cookie| which was added to or removed from the 212 // passed the respective |cookie| which was added to or removed from the
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.
mmenke 2016/09/26 18:29:26 Maybe add a warning that the callback must not syn
nharper 2016/09/26 21:09:10 Done.
201 virtual std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie( 223 virtual std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie(
202 const GURL& url, 224 const GURL& url,
203 const std::string& name, 225 const std::string& name,
204 const CookieChangedCallback& callback) = 0; 226 const CookieChangedCallback& callback) = 0;
205 227
206 // Returns true if this cookie store is ephemeral, and false if it is backed 228 // Returns true if this cookie store is ephemeral, and false if it is backed
207 // by some sort of persistence layer. 229 // by some sort of persistence layer.
208 // TODO(nharper): Remove this method once crbug.com/548423 has been closed. 230 // TODO(nharper): Remove this method once crbug.com/548423 has been closed.
209 virtual bool IsEphemeral() = 0; 231 virtual bool IsEphemeral() = 0;
210 void SetChannelIDServiceID(int id); 232 void SetChannelIDServiceID(int id);
211 int GetChannelIDServiceID(); 233 int GetChannelIDServiceID();
212 234
213 protected: 235 protected:
214 CookieStore(); 236 CookieStore();
215 int channel_id_service_id_; 237 int channel_id_service_id_;
216 }; 238 };
217 239
218 } // namespace net 240 } // namespace net
219 241
220 #endif // NET_COOKIES_COOKIE_STORE_H_ 242 #endif // NET_COOKIES_COOKIE_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698