OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 the letter D and the number 2. | 5 // Brought to you by the letter D and the number 2. |
6 | 6 |
7 #ifndef NET_BASE_COOKIE_MONSTER_H_ | 7 #ifndef NET_BASE_COOKIE_MONSTER_H_ |
8 #define NET_BASE_COOKIE_MONSTER_H_ | 8 #define NET_BASE_COOKIE_MONSTER_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <map> | 11 #include <map> |
| 12 #include <queue> |
12 #include <string> | 13 #include <string> |
13 #include <utility> | 14 #include <utility> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
17 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
21 #include "base/task.h" | 22 #include "base/task.h" |
22 #include "base/time.h" | 23 #include "base/time.h" |
23 #include "net/base/cookie_store.h" | 24 #include "net/base/cookie_store.h" |
24 #include "net/base/net_export.h" | 25 #include "net/base/net_export.h" |
25 | 26 |
26 class GURL; | 27 class GURL; |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class Histogram; | 30 class Histogram; |
30 } | 31 } |
31 | 32 |
32 namespace net { | 33 namespace net { |
33 | 34 |
34 class CookieList; | 35 class CookieList; |
| 36 class CookieMonsterTask; |
35 | 37 |
36 // The cookie monster is the system for storing and retrieving cookies. It has | 38 // The cookie monster is the system for storing and retrieving cookies. It has |
37 // an in-memory list of all cookies, and synchronizes non-session cookies to an | 39 // an in-memory list of all cookies, and synchronizes non-session cookies to an |
38 // optional permanent storage that implements the PersistentCookieStore | 40 // optional permanent storage that implements the PersistentCookieStore |
39 // interface. | 41 // interface. |
40 // | 42 // |
41 // This class IS thread-safe. Normally, it is only used on the I/O thread, but | 43 // This class IS thread-safe. Normally, it is only used on the I/O thread, but |
42 // is also accessed directly through Automation for UI testing. | 44 // is also accessed directly through Automation for UI testing. |
43 // | 45 // |
44 // Several methods exist in asynchronous forms. Calls may be deferred if all | 46 // Several methods exist in asynchronous forms. Calls may be deferred if all |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 Delegate* delegate, | 133 Delegate* delegate, |
132 int last_access_threshold_milliseconds); | 134 int last_access_threshold_milliseconds); |
133 | 135 |
134 // Parses the string with the cookie time (very forgivingly). | 136 // Parses the string with the cookie time (very forgivingly). |
135 static base::Time ParseCookieTime(const std::string& time_string); | 137 static base::Time ParseCookieTime(const std::string& time_string); |
136 | 138 |
137 // Returns true if a domain string represents a host-only cookie, | 139 // Returns true if a domain string represents a host-only cookie, |
138 // i.e. it doesn't begin with a leading '.' character. | 140 // i.e. it doesn't begin with a leading '.' character. |
139 static bool DomainIsHostOnly(const std::string& domain_string); | 141 static bool DomainIsHostOnly(const std::string& domain_string); |
140 | 142 |
| 143 // Helper function that adds all cookies from |cookie_monster| into this |
| 144 // instance. |
| 145 bool InitializeFrom(const CookieList& list); |
| 146 |
| 147 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; |
| 148 typedef base::Callback<void(int num_deleted)> DeleteCallback; |
| 149 typedef base::Callback<void(bool)> DeleteCookieCallback; |
| 150 |
141 // Sets a cookie given explicit user-provided cookie attributes. The cookie | 151 // Sets a cookie given explicit user-provided cookie attributes. The cookie |
142 // name, value, domain, etc. are each provided as separate strings. This | 152 // name, value, domain, etc. are each provided as separate strings. This |
143 // function expects each attribute to be well-formed. It will check for | 153 // function expects each attribute to be well-formed. It will check for |
144 // disallowed characters (e.g. the ';' character is disallowed within the | 154 // disallowed characters (e.g. the ';' character is disallowed within the |
145 // cookie value attribute) and will return false without setting the cookie | 155 // cookie value attribute) and will return false without setting the cookie |
146 // if such characters are found. | 156 // if such characters are found. |
147 bool SetCookieWithDetails(const GURL& url, | |
148 const std::string& name, | |
149 const std::string& value, | |
150 const std::string& domain, | |
151 const std::string& path, | |
152 const base::Time& expiration_time, | |
153 bool secure, bool http_only); | |
154 void SetCookieWithDetailsAsync(const GURL& url, | 157 void SetCookieWithDetailsAsync(const GURL& url, |
155 const std::string& name, | 158 const std::string& name, |
156 const std::string& value, | 159 const std::string& value, |
157 const std::string& domain, | 160 const std::string& domain, |
158 const std::string& path, | 161 const std::string& path, |
159 const base::Time& expiration_time, | 162 const base::Time& expiration_time, |
160 bool secure, bool http_only, | 163 bool secure, bool http_only, |
161 const SetCookiesCallback& callback); | 164 const SetCookiesCallback& callback); |
162 | 165 |
163 | 166 |
164 // Helper function that adds all cookies from |cookie_monster| into this | |
165 // instance. | |
166 bool InitializeFrom(const CookieList& list); | |
167 | |
168 // Returns all the cookies, for use in management UI, etc. This does not mark | 167 // Returns all the cookies, for use in management UI, etc. This does not mark |
169 // the cookies as having been accessed. | 168 // the cookies as having been accessed. |
170 // The returned cookies are ordered by longest path, then by earliest | 169 // The returned cookies are ordered by longest path, then by earliest |
171 // creation date. | 170 // creation date. |
172 CookieList GetAllCookies(); | |
173 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | |
174 void GetAllCookiesAsync(const GetCookieListCallback& callback); | 171 void GetAllCookiesAsync(const GetCookieListCallback& callback); |
175 | 172 |
176 // Returns all the cookies, for use in management UI, etc. Filters results | 173 // Returns all the cookies, for use in management UI, etc. Filters results |
177 // using given url scheme, host / domain and path and options. This does not | 174 // using given url scheme, host / domain and path and options. This does not |
178 // mark the cookies as having been accessed. | 175 // mark the cookies as having been accessed. |
179 // The returned cookies are ordered by longest path, then earliest | 176 // The returned cookies are ordered by longest path, then earliest |
180 // creation date. | 177 // creation date. |
181 CookieList GetAllCookiesForURLWithOptions(const GURL& url, | |
182 const CookieOptions& options); | |
183 void GetAllCookiesForURLWithOptionsAsync( | 178 void GetAllCookiesForURLWithOptionsAsync( |
184 const GURL& url, | 179 const GURL& url, |
185 const CookieOptions& options, | 180 const CookieOptions& options, |
186 const GetCookieListCallback& callback); | 181 const GetCookieListCallback& callback); |
187 | 182 |
188 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP | 183 // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP |
189 // only cookies. | 184 // only cookies. |
190 CookieList GetAllCookiesForURL(const GURL& url); | |
191 void GetAllCookiesForURLAsync(const GURL& url, | 185 void GetAllCookiesForURLAsync(const GURL& url, |
192 const GetCookieListCallback& callback); | 186 const GetCookieListCallback& callback); |
193 | 187 |
194 // Deletes all of the cookies. | 188 // Deletes all of the cookies. |
195 int DeleteAll(bool sync_to_store); | 189 void DeleteAllAsync(const DeleteCallback& callback); |
| 190 |
196 // Deletes all of the cookies that have a creation_date greater than or equal | 191 // Deletes all of the cookies that have a creation_date greater than or equal |
197 // to |delete_begin| and less than |delete_end| | 192 // to |delete_begin| and less than |delete_end| |
198 // Returns the number of cookies that have been deleted. | 193 // Returns the number of cookies that have been deleted. |
199 int DeleteAllCreatedBetween(const base::Time& delete_begin, | |
200 const base::Time& delete_end, | |
201 bool sync_to_store); | |
202 typedef base::Callback<void(int num_deleted)> DeleteCallback; | |
203 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, | 194 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, |
204 const base::Time& delete_end, | 195 const base::Time& delete_end, |
205 bool sync_to_store, | |
206 const DeleteCallback& callback); | 196 const DeleteCallback& callback); |
207 | 197 |
208 // Deletes all cookies that match the host of the given URL | 198 // Deletes all cookies that match the host of the given URL |
209 // regardless of path. This includes all http_only and secure cookies, | 199 // regardless of path. This includes all http_only and secure cookies, |
210 // but does not include any domain cookies that may apply to this host. | 200 // but does not include any domain cookies that may apply to this host. |
211 // Returns the number of cookies deleted. | 201 // Returns the number of cookies deleted. |
212 int DeleteAllForHost(const GURL& url); | |
213 | |
214 void DeleteAllForHostAsync(const GURL& url, | 202 void DeleteAllForHostAsync(const GURL& url, |
215 const DeleteCallback& callback); | 203 const DeleteCallback& callback); |
216 | 204 |
217 // Deletes one specific cookie. | 205 // Deletes one specific cookie. |
218 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); | |
219 | |
220 typedef SetCookiesCallback DeleteCookieCallback; | |
221 | |
222 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, | 206 void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
223 const DeleteCookieCallback& callback); | 207 const DeleteCookieCallback& callback); |
224 | 208 |
225 // Override the default list of schemes that are allowed to be set in | 209 // Override the default list of schemes that are allowed to be set in |
226 // this cookie store. Calling his overrides the value of | 210 // this cookie store. Calling his overrides the value of |
227 // "enable_file_scheme_". | 211 // "enable_file_scheme_". |
228 // If this this method is called, it must be called before first use of | 212 // If this this method is called, it must be called before first use of |
229 // the instance (i.e. as part of the instance initialization process). | 213 // the instance (i.e. as part of the instance initialization process). |
230 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); | 214 void SetCookieableSchemes(const char* schemes[], size_t num_schemes); |
231 | 215 |
(...skipping 21 matching lines...) Expand all Loading... |
253 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. | 237 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. |
254 // It may be posted to the current thread, or it may run on the thread that | 238 // It may be posted to the current thread, or it may run on the thread that |
255 // actually does the flushing. Your Task should generally post a notification | 239 // actually does the flushing. Your Task should generally post a notification |
256 // to the thread you actually want to be notified on. | 240 // to the thread you actually want to be notified on. |
257 void FlushStore(Task* completion_task); | 241 void FlushStore(Task* completion_task); |
258 | 242 |
259 // CookieStore implementation. | 243 // CookieStore implementation. |
260 | 244 |
261 // Sets the cookies specified by |cookie_list| returned from |url| | 245 // Sets the cookies specified by |cookie_list| returned from |url| |
262 // with options |options| in effect. | 246 // with options |options| in effect. |
263 virtual bool SetCookieWithOptions(const GURL& url, | 247 virtual void SetCookieWithOptionsAsync( |
264 const std::string& cookie_line, | 248 const GURL& url, |
265 const CookieOptions& options); | 249 const std::string& cookie_line, |
266 | 250 const CookieOptions& options, |
267 virtual void SetCookieWithOptionsAsync(const GURL& url, | 251 const SetCookiesCallback& callback) OVERRIDE; |
268 const std::string& cookie_line, | |
269 const CookieOptions& options, | |
270 const SetCookiesCallback& callback); | |
271 | 252 |
272 // Gets all cookies that apply to |url| given |options|. | 253 // Gets all cookies that apply to |url| given |options|. |
273 // The returned cookies are ordered by longest path, then earliest | 254 // The returned cookies are ordered by longest path, then earliest |
274 // creation date. | 255 // creation date. |
275 virtual std::string GetCookiesWithOptions(const GURL& url, | |
276 const CookieOptions& options); | |
277 | |
278 virtual void GetCookiesWithOptionsAsync( | 256 virtual void GetCookiesWithOptionsAsync( |
279 const GURL& url, | 257 const GURL& url, |
280 const CookieOptions& options, | 258 const CookieOptions& options, |
281 const GetCookiesCallback& callback); | 259 const GetCookiesCallback& callback) OVERRIDE; |
282 | 260 |
283 virtual void GetCookiesWithInfo(const GURL& url, | 261 virtual void GetCookiesWithInfoAsync( |
284 const CookieOptions& options, | 262 const GURL& url, |
285 std::string* cookie_line, | 263 const CookieOptions& options, |
286 std::vector<CookieInfo>* cookie_infos); | 264 const GetCookieInfoCallback& callback) OVERRIDE; |
287 | |
288 virtual void GetCookiesWithInfoAsync(const GURL& url, | |
289 const CookieOptions& options, | |
290 const GetCookieInfoCallback& callback); | |
291 | 265 |
292 // Deletes all cookies with that might apply to |url| that has |cookie_name|. | 266 // Deletes all cookies with that might apply to |url| that has |cookie_name|. |
293 virtual void DeleteCookie(const GURL& url, const std::string& cookie_name); | |
294 virtual void DeleteCookieAsync( | 267 virtual void DeleteCookieAsync( |
295 const GURL& url, const std::string& cookie_name, | 268 const GURL& url, const std::string& cookie_name, |
296 const base::Closure& callback); | 269 const base::Closure& callback) OVERRIDE; |
297 | 270 |
298 virtual CookieMonster* GetCookieMonster(); | 271 virtual CookieMonster* GetCookieMonster() OVERRIDE; |
299 | 272 |
300 // Debugging method to perform various validation checks on the map. | 273 // Debugging method to perform various validation checks on the map. |
301 // Currently just checking that there are no null CanonicalCookie pointers | 274 // Currently just checking that there are no null CanonicalCookie pointers |
302 // in the map. | 275 // in the map. |
303 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs | 276 // Argument |arg| is to allow retaining of arbitrary data if the CHECKs |
304 // in the function trip. TODO(rdsmith):Remove hack. | 277 // in the function trip. TODO(rdsmith):Remove hack. |
305 void ValidateMap(int arg); | 278 void ValidateMap(int arg); |
306 | 279 |
307 // The default list of schemes the cookie monster can handle. | 280 // The default list of schemes the cookie monster can handle. |
308 static const char* kDefaultCookieableSchemes[]; | 281 static const char* kDefaultCookieableSchemes[]; |
309 static const int kDefaultCookieableSchemesCount; | 282 static const int kDefaultCookieableSchemesCount; |
310 | 283 |
311 private: | 284 private: |
| 285 // For queueing the cookie monster calls. |
| 286 friend class DeleteAllCreatedBetweenTask; |
| 287 friend class DeleteAllForHostTask; |
| 288 friend class DeleteAllTask; |
| 289 friend class DeleteCookieTask; |
| 290 friend class DeleteCanonicalCookieTask; |
| 291 friend class GetAllCookiesForURLWithOptionsTask; |
| 292 friend class GetAllCookiesTask; |
| 293 friend class GetCookiesWithOptionsTask; |
| 294 friend class GetCookiesWithInfoTask; |
| 295 friend class SetCookieWithDetailsTask; |
| 296 friend class SetCookieWithOptionsTask; |
| 297 |
312 // Testing support. | 298 // Testing support. |
313 // For SetCookieWithCreationTime. | 299 // For SetCookieWithCreationTime. |
314 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, | 300 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, |
315 TestCookieDeleteAllCreatedBetweenTimestamps); | 301 TestCookieDeleteAllCreatedBetweenTimestamps); |
316 | 302 |
317 // For gargage collection constants. | 303 // For gargage collection constants. |
318 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); | 304 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); |
319 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection); | 305 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection); |
320 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers); | 306 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers); |
321 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes); | 307 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 376 |
391 // Default value for key and expiry scheme scheme. | 377 // Default value for key and expiry scheme scheme. |
392 static const ExpiryAndKeyScheme expiry_and_key_default_ = | 378 static const ExpiryAndKeyScheme expiry_and_key_default_ = |
393 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; | 379 EKS_KEEP_RECENT_AND_PURGE_ETLDP1; |
394 | 380 |
395 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. | 381 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. |
396 static const int kRecordStatisticsIntervalSeconds = 10 * 60; | 382 static const int kRecordStatisticsIntervalSeconds = 10 * 60; |
397 | 383 |
398 virtual ~CookieMonster(); | 384 virtual ~CookieMonster(); |
399 | 385 |
| 386 // The following are synchronous calls to which the asynchronous methods |
| 387 // delegate either immediately (if the store is loaded) or through a deferred |
| 388 // task (if the store is not yet loaded). |
| 389 bool SetCookieWithDetails(const GURL& url, |
| 390 const std::string& name, |
| 391 const std::string& value, |
| 392 const std::string& domain, |
| 393 const std::string& path, |
| 394 const base::Time& expiration_time, |
| 395 bool secure, bool http_only); |
| 396 |
| 397 CookieList GetAllCookies(); |
| 398 |
| 399 CookieList GetAllCookiesForURLWithOptions(const GURL& url, |
| 400 const CookieOptions& options); |
| 401 |
| 402 CookieList GetAllCookiesForURL(const GURL& url); |
| 403 |
| 404 int DeleteAll(bool sync_to_store); |
| 405 |
| 406 int DeleteAllCreatedBetween(const base::Time& delete_begin, |
| 407 const base::Time& delete_end); |
| 408 |
| 409 int DeleteAllForHost(const GURL& url); |
| 410 |
| 411 bool DeleteCanonicalCookie(const CanonicalCookie& cookie); |
| 412 |
| 413 bool SetCookieWithOptions(const GURL& url, |
| 414 const std::string& cookie_line, |
| 415 const CookieOptions& options); |
| 416 |
| 417 std::string GetCookiesWithOptions(const GURL& url, |
| 418 const CookieOptions& options); |
| 419 |
| 420 void GetCookiesWithInfo(const GURL& url, |
| 421 const CookieOptions& options, |
| 422 std::string* cookie_line, |
| 423 std::vector<CookieInfo>* cookie_infos); |
| 424 |
| 425 void DeleteCookie(const GURL& url, const std::string& cookie_name); |
| 426 |
400 bool SetCookieWithCreationTime(const GURL& url, | 427 bool SetCookieWithCreationTime(const GURL& url, |
401 const std::string& cookie_line, | 428 const std::string& cookie_line, |
402 const base::Time& creation_time); | 429 const base::Time& creation_time); |
403 | 430 |
404 // Called by all non-static functions to ensure that the cookies store has | 431 // Called by all non-static functions to ensure that the cookies store has |
405 // been initialized. This is not done during creating so it doesn't block | 432 // been initialized. This is not done during creating so it doesn't block |
406 // the window showing. | 433 // the window showing. |
407 // Note: this method should always be called with lock_ held. | 434 // Note: this method should always be called with lock_ held. |
408 void InitIfNecessary() { | 435 void InitIfNecessary() { |
409 if (!initialized_) { | 436 if (!initialized_) { |
410 if (store_) | 437 if (store_) { |
411 InitStore(); | 438 InitStore(); |
| 439 } else { |
| 440 loaded_ = true; |
| 441 } |
412 initialized_ = true; | 442 initialized_ = true; |
413 } | 443 } |
414 } | 444 } |
415 | 445 |
416 // Initializes the backing store and reads existing cookies from it. | 446 // Initializes the backing store and reads existing cookies from it. |
417 // Should only be called by InitIfNecessary(). | 447 // Should only be called by InitIfNecessary(). |
418 void InitStore(); | 448 void InitStore(); |
419 | 449 |
| 450 // Stores cookies loaded from the backing store and invokes any deferred |
| 451 // calls. |
| 452 void OnLoaded(const std::vector<CanonicalCookie*>& cookies); |
| 453 |
| 454 // Stores the loaded cookies. |
| 455 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); |
| 456 |
| 457 // Invokes deferred calls. |
| 458 void InvokeQueue(); |
| 459 |
420 // Checks that |cookies_| matches our invariants, and tries to repair any | 460 // Checks that |cookies_| matches our invariants, and tries to repair any |
421 // inconsistencies. (In other words, it does not have duplicate cookies). | 461 // inconsistencies. (In other words, it does not have duplicate cookies). |
422 void EnsureCookiesMapIsValid(); | 462 void EnsureCookiesMapIsValid(); |
423 | 463 |
424 // Checks for any duplicate cookies for CookieMap key |key| which lie between | 464 // Checks for any duplicate cookies for CookieMap key |key| which lie between |
425 // |begin| and |end|. If any are found, all but the most recent are deleted. | 465 // |begin| and |end|. If any are found, all but the most recent are deleted. |
426 // Returns the number of duplicate cookies that were deleted. | 466 // Returns the number of duplicate cookies that were deleted. |
427 int TrimDuplicateCookiesForKey(const std::string& key, | 467 int TrimDuplicateCookiesForKey(const std::string& key, |
428 CookieMap::iterator begin, | 468 CookieMap::iterator begin, |
429 CookieMap::iterator end); | 469 CookieMap::iterator end); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 void RecordPeriodicStats(const base::Time& current_time); | 559 void RecordPeriodicStats(const base::Time& current_time); |
520 | 560 |
521 // Initialize the above variables; should only be called from | 561 // Initialize the above variables; should only be called from |
522 // the constructor. | 562 // the constructor. |
523 void InitializeHistograms(); | 563 void InitializeHistograms(); |
524 | 564 |
525 // The resolution of our time isn't enough, so we do something | 565 // The resolution of our time isn't enough, so we do something |
526 // ugly and increment when we've seen the same time twice. | 566 // ugly and increment when we've seen the same time twice. |
527 base::Time CurrentTime(); | 567 base::Time CurrentTime(); |
528 | 568 |
| 569 // Run the cookie request task if cookie loaded, otherwise added the task |
| 570 // to task queue. |
| 571 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); |
| 572 |
529 // Histogram variables; see CookieMonster::InitializeHistograms() in | 573 // Histogram variables; see CookieMonster::InitializeHistograms() in |
530 // cookie_monster.cc for details. | 574 // cookie_monster.cc for details. |
531 base::Histogram* histogram_expiration_duration_minutes_; | 575 base::Histogram* histogram_expiration_duration_minutes_; |
532 base::Histogram* histogram_between_access_interval_minutes_; | 576 base::Histogram* histogram_between_access_interval_minutes_; |
533 base::Histogram* histogram_evicted_last_access_minutes_; | 577 base::Histogram* histogram_evicted_last_access_minutes_; |
534 base::Histogram* histogram_count_; | 578 base::Histogram* histogram_count_; |
535 base::Histogram* histogram_domain_count_; | 579 base::Histogram* histogram_domain_count_; |
536 base::Histogram* histogram_etldp1_count_; | 580 base::Histogram* histogram_etldp1_count_; |
537 base::Histogram* histogram_domain_per_etldp1_count_; | 581 base::Histogram* histogram_domain_per_etldp1_count_; |
538 base::Histogram* histogram_number_duplicate_db_cookies_; | 582 base::Histogram* histogram_number_duplicate_db_cookies_; |
539 base::Histogram* histogram_cookie_deletion_cause_; | 583 base::Histogram* histogram_cookie_deletion_cause_; |
540 base::Histogram* histogram_time_get_; | 584 base::Histogram* histogram_time_get_; |
541 base::Histogram* histogram_time_mac_; | 585 base::Histogram* histogram_time_mac_; |
542 base::Histogram* histogram_time_load_; | 586 base::Histogram* histogram_time_load_; |
543 | 587 |
544 CookieMap cookies_; | 588 CookieMap cookies_; |
545 | 589 |
546 // Indicates whether the cookie store has been initialized. This happens | 590 // Indicates whether the cookie store has been initialized. This happens |
547 // lazily in InitStoreIfNecessary(). | 591 // lazily in InitStoreIfNecessary(). |
548 bool initialized_; | 592 bool initialized_; |
549 | 593 |
| 594 // Indicates whether loading from the backend store is completed and |
| 595 // calls may be immediately processed. |
| 596 bool loaded_; |
| 597 |
| 598 // Queues calls to CookieMonster until loading from the backend store is |
| 599 // completed. |
| 600 std::queue<base::Closure> queue_; |
| 601 |
550 // Indicates whether this cookie monster uses the new effective domain | 602 // Indicates whether this cookie monster uses the new effective domain |
551 // key scheme or not. | 603 // key scheme or not. |
552 ExpiryAndKeyScheme expiry_and_key_scheme_; | 604 ExpiryAndKeyScheme expiry_and_key_scheme_; |
553 | 605 |
554 scoped_refptr<PersistentCookieStore> store_; | 606 scoped_refptr<PersistentCookieStore> store_; |
555 | 607 |
556 base::Time last_time_seen_; | 608 base::Time last_time_seen_; |
557 | 609 |
558 // Minimum delay after updating a cookie's LastAccessDate before we will | 610 // Minimum delay after updating a cookie's LastAccessDate before we will |
559 // update it again. | 611 // update it again. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 }; | 906 }; |
855 | 907 |
856 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 908 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
857 RefcountedPersistentCookieStore; | 909 RefcountedPersistentCookieStore; |
858 | 910 |
859 class CookieMonster::PersistentCookieStore | 911 class CookieMonster::PersistentCookieStore |
860 : public RefcountedPersistentCookieStore { | 912 : public RefcountedPersistentCookieStore { |
861 public: | 913 public: |
862 virtual ~PersistentCookieStore() {} | 914 virtual ~PersistentCookieStore() {} |
863 | 915 |
| 916 typedef base::Callback<void(const std::vector< |
| 917 CookieMonster::CanonicalCookie*>&)> LoadedCallback; |
| 918 |
864 // Initializes the store and retrieves the existing cookies. This will be | 919 // Initializes the store and retrieves the existing cookies. This will be |
865 // called only once at startup. | 920 // called only once at startup. |
866 virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0; | 921 virtual bool Load(const LoadedCallback& loaded_callback) = 0; |
867 | 922 |
868 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 923 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
869 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 924 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
870 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 925 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
871 | 926 |
872 // Sets the value of the user preference whether the persistent storage | 927 // Sets the value of the user preference whether the persistent storage |
873 // must be deleted upon destruction. | 928 // must be deleted upon destruction. |
874 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 929 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
875 | 930 |
876 // Flush the store and post the given Task when complete. | 931 // Flush the store and post the given Task when complete. |
877 virtual void Flush(Task* completion_task) = 0; | 932 virtual void Flush(Task* completion_task) = 0; |
878 | 933 |
879 protected: | 934 protected: |
880 PersistentCookieStore() {} | 935 PersistentCookieStore() {} |
881 | 936 |
882 private: | 937 private: |
883 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 938 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
884 }; | 939 }; |
885 | 940 |
886 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 941 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
887 }; | 942 }; |
888 | 943 |
889 } // namespace net | 944 } // namespace net |
890 | 945 |
891 #endif // NET_BASE_COOKIE_MONSTER_H_ | 946 #endif // NET_BASE_COOKIE_MONSTER_H_ |
OLD | NEW |