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

Side by Side Diff: ios/net/cookies/cookie_store_ios.h

Issue 2937963003: Shift cookie system callbacks to OnceCallback to impedance match mojo. (Closed)
Patch Set: Finish Merge Created 3 years, 6 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ 5 #ifndef IOS_NET_COOKIES_COOKIE_STORE_IOS_H_
6 #define IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ 6 #define IOS_NET_COOKIES_COOKIE_STORE_IOS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // |NSHTTPCookieStorage sharedHTTPCookieStorage|. 68 // |NSHTTPCookieStorage sharedHTTPCookieStorage|.
69 static void NotifySystemCookiesChanged(); 69 static void NotifySystemCookiesChanged();
70 70
71 // Only one cookie store may enable metrics. 71 // Only one cookie store may enable metrics.
72 void SetMetricsEnabled(); 72 void SetMetricsEnabled();
73 73
74 // Inherited CookieStore methods. 74 // Inherited CookieStore methods.
75 void SetCookieWithOptionsAsync(const GURL& url, 75 void SetCookieWithOptionsAsync(const GURL& url,
76 const std::string& cookie_line, 76 const std::string& cookie_line,
77 const net::CookieOptions& options, 77 const net::CookieOptions& options,
78 const SetCookiesCallback& callback) override; 78 SetCookiesCallback callback) override;
79 void SetCookieWithDetailsAsync(const GURL& url, 79 void SetCookieWithDetailsAsync(const GURL& url,
80 const std::string& name, 80 const std::string& name,
81 const std::string& value, 81 const std::string& value,
82 const std::string& domain, 82 const std::string& domain,
83 const std::string& path, 83 const std::string& path,
84 base::Time creation_time, 84 base::Time creation_time,
85 base::Time expiration_time, 85 base::Time expiration_time,
86 base::Time last_access_time, 86 base::Time last_access_time,
87 bool secure, 87 bool secure,
88 bool http_only, 88 bool http_only,
89 CookieSameSite same_site, 89 CookieSameSite same_site,
90 CookiePriority priority, 90 CookiePriority priority,
91 const SetCookiesCallback& callback) override; 91 SetCookiesCallback callback) override;
92 void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie, 92 void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie,
93 bool secure_source, 93 bool secure_source,
94 bool modify_http_only, 94 bool modify_http_only,
95 const SetCookiesCallback& callback) override; 95 SetCookiesCallback callback) override;
96 void GetCookiesWithOptionsAsync(const GURL& url, 96 void GetCookiesWithOptionsAsync(const GURL& url,
97 const net::CookieOptions& options, 97 const net::CookieOptions& options,
98 const GetCookiesCallback& callback) override; 98 GetCookiesCallback callback) override;
99 void GetCookieListWithOptionsAsync( 99 void GetCookieListWithOptionsAsync(const GURL& url,
100 const GURL& url, 100 const net::CookieOptions& options,
101 const net::CookieOptions& options, 101 GetCookieListCallback callback) override;
102 const GetCookieListCallback& callback) override; 102 void GetAllCookiesAsync(GetCookieListCallback callback) override;
103 void GetAllCookiesAsync(const GetCookieListCallback& callback) override;
104 void DeleteCookieAsync(const GURL& url, 103 void DeleteCookieAsync(const GURL& url,
105 const std::string& cookie_name, 104 const std::string& cookie_name,
106 const base::Closure& callback) override; 105 base::OnceClosure callback) override;
107 void DeleteCanonicalCookieAsync( 106 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
108 const CanonicalCookie& cookie, 107 DeleteCallback callback) override;
109 const DeleteCallback& callback) override;
110 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, 108 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin,
111 const base::Time& delete_end, 109 const base::Time& delete_end,
112 const DeleteCallback& callback) override; 110 DeleteCallback callback) override;
113 void DeleteAllCreatedBetweenWithPredicateAsync( 111 void DeleteAllCreatedBetweenWithPredicateAsync(
114 const base::Time& delete_begin, 112 const base::Time& delete_begin,
115 const base::Time& delete_end, 113 const base::Time& delete_end,
116 const CookiePredicate& predicate, 114 const CookiePredicate& predicate,
117 const DeleteCallback& callback) override; 115 DeleteCallback callback) override;
118 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override; 116 void DeleteSessionCookiesAsync(DeleteCallback callback) override;
119 void FlushStore(const base::Closure& callback) override; 117 void FlushStore(base::OnceClosure callback) override;
120 118
121 std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie( 119 std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie(
122 const GURL& url, 120 const GURL& url,
123 const std::string& name, 121 const std::string& name,
124 const CookieChangedCallback& callback) override; 122 const CookieChangedCallback& callback) override;
125 123
126 bool IsEphemeral() override; 124 bool IsEphemeral() override;
127 125
128 protected: 126 protected:
129 CookieStoreIOS(net::CookieMonster::PersistentCookieStore* persistent_store, 127 CookieStoreIOS(net::CookieMonster::PersistentCookieStore* persistent_store,
130 NSHTTPCookieStorage* system_store); 128 NSHTTPCookieStorage* system_store);
131 129
132 // These three functions are used for wrapping user-supplied callbacks given 130 // These three functions are used for wrapping user-supplied callbacks given
133 // to CookieStoreIOS mutator methods. Given a callback, they return a new 131 // to CookieStoreIOS mutator methods. Given a callback, they return a new
134 // callback that invokes UpdateCachesFromCookieMonster() to schedule an 132 // callback that invokes UpdateCachesFromCookieMonster() to schedule an
135 // asynchronous synchronization of the cookie cache and then calls the 133 // asynchronous synchronization of the cookie cache and then calls the
136 // original callback. 134 // original callback.
137 SetCookiesCallback WrapSetCallback(const SetCookiesCallback& callback); 135 SetCookiesCallback WrapSetCallback(SetCookiesCallback callback);
138 DeleteCallback WrapDeleteCallback(const DeleteCallback& callback); 136 DeleteCallback WrapDeleteCallback(DeleteCallback callback);
139 base::Closure WrapClosure(const base::Closure& callback); 137 base::OnceClosure WrapClosure(base::OnceClosure callback);
140 138
141 bool metrics_enabled() { return metrics_enabled_; } 139 bool metrics_enabled() { return metrics_enabled_; }
142 140
143 net::CookieMonster* cookie_monster() { return cookie_monster_.get(); } 141 net::CookieMonster* cookie_monster() { return cookie_monster_.get(); }
144 142
145 const base::ThreadChecker& thread_checker() { return thread_checker_; } 143 const base::ThreadChecker& thread_checker() { return thread_checker_; }
146 144
147 private: 145 private:
148 // Cookie filter for DeleteCookiesWithFilter(). 146 // Cookie filter for DeleteCookiesWithFilter().
149 // Takes a cookie and a creation time and returns true the cookie must be 147 // Takes a cookie and a creation time and returns true the cookie must be
150 // deleted. 148 // deleted.
151 typedef base::Callback<bool(NSHTTPCookie*, base::Time)> CookieFilterFunction; 149 typedef base::Callback<bool(NSHTTPCookie*, base::Time)> CookieFilterFunction;
152 150
153 // Clears the system cookie store. 151 // Clears the system cookie store.
154 void ClearSystemStore(); 152 void ClearSystemStore();
155 // Returns true if the system cookie store policy is 153 // Returns true if the system cookie store policy is
156 // |NSHTTPCookieAcceptPolicyAlways|. 154 // |NSHTTPCookieAcceptPolicyAlways|.
157 bool SystemCookiesAllowed(); 155 bool SystemCookiesAllowed();
158 // Copies the cookies to the backing CookieMonster. 156 // Copies the cookies to the backing CookieMonster.
159 virtual void WriteToCookieMonster(NSArray* system_cookies); 157 virtual void WriteToCookieMonster(NSArray* system_cookies);
160 158
161 // Inherited CookieNotificationObserver methods. 159 // Inherited CookieNotificationObserver methods.
162 void OnSystemCookiesChanged() override; 160 void OnSystemCookiesChanged() override;
163 161
164 void DeleteCookiesWithFilter(const CookieFilterFunction& filter, 162 void DeleteCookiesWithFilter(const CookieFilterFunction& filter,
165 const DeleteCallback& callback); 163 DeleteCallback callback);
166 164
167 std::unique_ptr<net::CookieMonster> cookie_monster_; 165 std::unique_ptr<net::CookieMonster> cookie_monster_;
168 base::scoped_nsobject<NSHTTPCookieStorage> system_store_; 166 base::scoped_nsobject<NSHTTPCookieStorage> system_store_;
169 std::unique_ptr<CookieCreationTimeManager> creation_time_manager_; 167 std::unique_ptr<CookieCreationTimeManager> creation_time_manager_;
170 bool metrics_enabled_; 168 bool metrics_enabled_;
171 base::CancelableClosure flush_closure_; 169 base::CancelableClosure flush_closure_;
172 170
173 base::ThreadChecker thread_checker_; 171 base::ThreadChecker thread_checker_;
174 172
175 // Cookie notification methods. 173 // Cookie notification methods.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 216
219 // Fetches new values for all (url, name) pairs that have hooks registered, 217 // Fetches new values for all (url, name) pairs that have hooks registered,
220 // asynchronously invoking callbacks if necessary. 218 // asynchronously invoking callbacks if necessary.
221 void UpdateCachesFromCookieMonster(); 219 void UpdateCachesFromCookieMonster();
222 220
223 // Called after cookies are cleared from NSHTTPCookieStorage so that cookies 221 // Called after cookies are cleared from NSHTTPCookieStorage so that cookies
224 // can be cleared from .binarycookies file. |callback| is called after all the 222 // can be cleared from .binarycookies file. |callback| is called after all the
225 // cookies are deleted (with the total number of cookies deleted). 223 // cookies are deleted (with the total number of cookies deleted).
226 // |num_deleted| contains the number of cookies deleted from 224 // |num_deleted| contains the number of cookies deleted from
227 // NSHTTPCookieStorage. 225 // NSHTTPCookieStorage.
228 void DidClearNSHTTPCookieStorageCookies(const DeleteCallback& callback, 226 void DidClearNSHTTPCookieStorageCookies(DeleteCallback callback,
229 int num_deleted); 227 int num_deleted);
230 // Called after cookies are cleared from .binarycookies files. |callback| is 228 // Called after cookies are cleared from .binarycookies files. |callback| is
231 // called after all the cookies are deleted with the total number of cookies 229 // called after all the cookies are deleted with the total number of cookies
232 // deleted. 230 // deleted.
233 // |num_deleted_from_nshttp_cookie_storage| contains the number of cookies 231 // |num_deleted_from_nshttp_cookie_storage| contains the number of cookies
234 // deleted from NSHTTPCookieStorage. 232 // deleted from NSHTTPCookieStorage.
235 void DidClearBinaryCookiesFileCookies( 233 void DidClearBinaryCookiesFileCookies(
236 const DeleteCallback& callback, 234 DeleteCallback callback,
237 int num_deleted_from_nshttp_cookie_storage); 235 int num_deleted_from_nshttp_cookie_storage);
238 236
239 // Callback-wrapping: 237 // Callback-wrapping:
240 // When this CookieStoreIOS object is synchronized with the system store, 238 // When this CookieStoreIOS object is synchronized with the system store,
241 // OnSystemCookiesChanged is responsible for updating the cookie cache (and 239 // OnSystemCookiesChanged is responsible for updating the cookie cache (and
242 // hence running callbacks). 240 // hence running callbacks).
243 // 241 //
244 // When this CookieStoreIOS object is not synchronized, the various mutator 242 // When this CookieStoreIOS object is not synchronized, the various mutator
245 // methods (SetCookieWithOptionsAsync &c) instead store their state in a 243 // methods (SetCookieWithOptionsAsync &c) instead store their state in a
246 // CookieMonster object to be written back when the system store synchronizes. 244 // CookieMonster object to be written back when the system store synchronizes.
247 // To deliver notifications in a timely manner, the mutators have to ensure 245 // To deliver notifications in a timely manner, the mutators have to ensure
248 // that hooks get run, but only after the changes have been written back to 246 // that hooks get run, but only after the changes have been written back to
249 // CookieMonster. To do this, the mutators wrap the user-supplied callback in 247 // CookieMonster. To do this, the mutators wrap the user-supplied callback in
250 // a callback which schedules an asynchronous task to synchronize the cache 248 // a callback which schedules an asynchronous task to synchronize the cache
251 // and run callbacks, then calls through to the user-specified callback. 249 // and run callbacks, then calls through to the user-specified callback.
252 // 250 //
253 // These three UpdateCachesAfter functions are responsible for scheduling an 251 // These three UpdateCachesAfter functions are responsible for scheduling an
254 // asynchronous cache update (using UpdateCachesFromCookieMonster()) and 252 // asynchronous cache update (using UpdateCachesFromCookieMonster()) and
255 // calling the provided callback. 253 // calling the provided callback.
256 254
257 void UpdateCachesAfterSet(const SetCookiesCallback& callback, bool success); 255 void UpdateCachesAfterSet(SetCookiesCallback callback, bool success);
258 void UpdateCachesAfterDelete(const DeleteCallback& callback, int num_deleted); 256 void UpdateCachesAfterDelete(DeleteCallback callback, int num_deleted);
259 void UpdateCachesAfterClosure(const base::Closure& callback); 257 void UpdateCachesAfterClosure(base::OnceClosure callback);
260 258
261 // Takes an NSArray of NSHTTPCookies as returns a net::CookieList. 259 // Takes an NSArray of NSHTTPCookies as returns a net::CookieList.
262 // The returned cookies are ordered by longest path, then earliest 260 // The returned cookies are ordered by longest path, then earliest
263 // creation date. 261 // creation date.
264 net::CookieList CanonicalCookieListFromSystemCookies(NSArray* cookies); 262 net::CookieList CanonicalCookieListFromSystemCookies(NSArray* cookies);
265 263
266 // Cached values of system cookies. Only cookies which have an observer added 264 // Cached values of system cookies. Only cookies which have an observer added
267 // with AddCallbackForCookie are kept in this cache. 265 // with AddCallbackForCookie are kept in this cache.
268 std::unique_ptr<CookieCache> cookie_cache_; 266 std::unique_ptr<CookieCache> cookie_cache_;
269 267
270 // Callbacks for cookie changes installed by AddCallbackForCookie. 268 // Callbacks for cookie changes installed by AddCallbackForCookie.
271 std::map<std::pair<GURL, std::string>, 269 std::map<std::pair<GURL, std::string>,
272 std::unique_ptr<CookieChangedCallbackList>> 270 std::unique_ptr<CookieChangedCallbackList>>
273 hook_map_; 271 hook_map_;
274 272
275 base::WeakPtrFactory<CookieStoreIOS> weak_factory_; 273 base::WeakPtrFactory<CookieStoreIOS> weak_factory_;
276 274
277 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS); 275 DISALLOW_COPY_AND_ASSIGN(CookieStoreIOS);
278 }; 276 };
279 277
280 } // namespace net 278 } // namespace net
281 279
282 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_ 280 #endif // IOS_NET_COOKIES_COOKIE_STORE_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698