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 the letter D and the number 2. | 5 // Brought to you by the letter D and the number 2. |
6 | 6 |
7 #ifndef NET_COOKIES_COOKIE_MONSTER_H_ | 7 #ifndef NET_COOKIES_COOKIE_MONSTER_H_ |
8 #define NET_COOKIES_COOKIE_MONSTER_H_ | 8 #define NET_COOKIES_COOKIE_MONSTER_H_ |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // The cookie monster is the system for storing and retrieving cookies. It has | 44 // The cookie monster is the system for storing and retrieving cookies. It has |
45 // an in-memory list of all cookies, and synchronizes non-session cookies to an | 45 // an in-memory list of all cookies, and synchronizes non-session cookies to an |
46 // optional permanent storage that implements the PersistentCookieStore | 46 // optional permanent storage that implements the PersistentCookieStore |
47 // interface. | 47 // interface. |
48 // | 48 // |
49 // Tasks may be deferred if all affected cookies are not yet loaded from the | 49 // Tasks may be deferred if all affected cookies are not yet loaded from the |
50 // backing store. Otherwise, callbacks may be invoked immediately. | 50 // backing store. Otherwise, callbacks may be invoked immediately. |
51 // | 51 // |
52 // A cookie task is either pending loading of the entire cookie store, or | 52 // A cookie task is either pending loading of the entire cookie store, or |
53 // loading of cookies for a specific domain key(eTLD+1). In the former case, the | 53 // loading of cookies for a specific domain key(eTLD+1). In the former case, the |
54 // cookie task will be queued in tasks_pending_ while PersistentCookieStore | 54 // cookie callback will be queued in tasks_pending_ while PersistentCookieStore |
55 // chain loads the cookie store on DB thread. In the latter case, the cookie | 55 // chain loads the cookie store on DB thread. In the latter case, the cookie |
56 // task will be queued in tasks_pending_for_key_ while PermanentCookieStore | 56 // callback will be queued in tasks_pending_for_key_ while PermanentCookieStore |
57 // loads cookies for the specified domain key(eTLD+1) on DB thread. | 57 // loads cookies for the specified domain key(eTLD+1) on DB thread. |
58 // | 58 // |
59 // TODO(deanm) Implement CookieMonster, the cookie database. | 59 // TODO(deanm) Implement CookieMonster, the cookie database. |
60 // - Verify that our domain enforcement and non-dotted handling is correct | 60 // - Verify that our domain enforcement and non-dotted handling is correct |
61 class NET_EXPORT CookieMonster : public CookieStore { | 61 class NET_EXPORT CookieMonster : public CookieStore { |
62 public: | 62 public: |
63 class PersistentCookieStore; | 63 class PersistentCookieStore; |
64 | 64 |
65 // Terminology: | 65 // Terminology: |
66 // * The 'top level domain' (TLD) of an internet domain name is | 66 // * The 'top level domain' (TLD) of an internet domain name is |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 const CookieChangedCallback& callback) override; | 227 const CookieChangedCallback& callback) override; |
228 | 228 |
229 bool IsEphemeral() override; | 229 bool IsEphemeral() override; |
230 | 230 |
231 private: | 231 private: |
232 CookieMonster(PersistentCookieStore* store, | 232 CookieMonster(PersistentCookieStore* store, |
233 CookieMonsterDelegate* delegate, | 233 CookieMonsterDelegate* delegate, |
234 ChannelIDService* channel_id_service, | 234 ChannelIDService* channel_id_service, |
235 base::TimeDelta last_access_threshold); | 235 base::TimeDelta last_access_threshold); |
236 | 236 |
237 // For queueing the cookie monster calls. | |
238 class CookieMonsterTask; | |
239 template <typename Result> | |
240 class DeleteTask; | |
241 class DeleteAllCreatedBetweenTask; | |
242 class DeleteAllCreatedBetweenWithPredicateTask; | |
243 class DeleteCookieTask; | |
244 class DeleteCanonicalCookieTask; | |
245 class GetCookieListForURLWithOptionsTask; | |
246 class GetAllCookiesTask; | |
247 class GetCookiesWithOptionsTask; | |
248 class GetCookieListWithOptionsTask; | |
249 class SetAllCookiesTask; | |
250 class SetCookieWithDetailsTask; | |
251 class SetCookieWithOptionsTask; | |
252 class SetCanonicalCookieTask; | |
253 class DeleteSessionCookiesTask; | |
254 | |
255 // Testing support. | 237 // Testing support. |
256 // For SetCookieWithCreationTime. | 238 // For SetCookieWithCreationTime. |
257 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, | 239 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, |
258 TestCookieDeleteAllCreatedBetweenTimestamps); | 240 TestCookieDeleteAllCreatedBetweenTimestamps); |
259 FRIEND_TEST_ALL_PREFIXES( | 241 FRIEND_TEST_ALL_PREFIXES( |
260 CookieMonsterTest, | 242 CookieMonsterTest, |
261 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate); | 243 TestCookieDeleteAllCreatedBetweenTimestampsWithPredicate); |
262 | 244 |
263 // For garbage collection constants. | 245 // For garbage collection constants. |
264 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); | 246 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 // Not exposed as we don't want callers to have the ability | 535 // Not exposed as we don't want callers to have the ability |
554 // to specify (potentially duplicate) creation times. | 536 // to specify (potentially duplicate) creation times. |
555 bool SetCookieWithCreationTimeAndOptions(const GURL& url, | 537 bool SetCookieWithCreationTimeAndOptions(const GURL& url, |
556 const std::string& cookie_line, | 538 const std::string& cookie_line, |
557 const base::Time& creation_time, | 539 const base::Time& creation_time, |
558 const CookieOptions& options); | 540 const CookieOptions& options); |
559 | 541 |
560 // Sets all cookies from |list| after deleting any equivalent cookie. | 542 // Sets all cookies from |list| after deleting any equivalent cookie. |
561 // For data gathering purposes, this routine is treated as if it is | 543 // For data gathering purposes, this routine is treated as if it is |
562 // restoring saved cookies; some statistics are not gathered in this case. | 544 // restoring saved cookies; some statistics are not gathered in this case. |
563 bool SetAllCookies(const CookieList& list); | 545 bool SetAllCookies(CookieList list); |
564 | 546 |
565 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, | 547 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, |
566 const base::Time& current_time); | 548 const base::Time& current_time); |
567 | 549 |
568 // |deletion_cause| argument is used for collecting statistics and choosing | 550 // |deletion_cause| argument is used for collecting statistics and choosing |
569 // the correct CookieStore::ChangeCause for OnCookieChanged | 551 // the correct CookieStore::ChangeCause for OnCookieChanged |
570 // notifications. Guarantee: All iterators to cookies_ except to the | 552 // notifications. Guarantee: All iterators to cookies_ except to the |
571 // deleted entry remain valid. | 553 // deleted entry remain valid. |
572 void InternalDeleteCookie(CookieMap::iterator it, | 554 void InternalDeleteCookie(CookieMap::iterator it, |
573 bool sync_to_store, | 555 bool sync_to_store, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 void RecordPeriodicStats(const base::Time& current_time); | 619 void RecordPeriodicStats(const base::Time& current_time); |
638 | 620 |
639 // Initialize the above variables; should only be called from | 621 // Initialize the above variables; should only be called from |
640 // the constructor. | 622 // the constructor. |
641 void InitializeHistograms(); | 623 void InitializeHistograms(); |
642 | 624 |
643 // The resolution of our time isn't enough, so we do something | 625 // The resolution of our time isn't enough, so we do something |
644 // ugly and increment when we've seen the same time twice. | 626 // ugly and increment when we've seen the same time twice. |
645 base::Time CurrentTime(); | 627 base::Time CurrentTime(); |
646 | 628 |
647 // Runs the task if, or defers the task until, the full cookie database is | 629 // Runs the callback if, or defers the callback until, the full cookie |
648 // loaded. | 630 // database is loaded. |
649 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); | 631 void DoCookieCallback(base::OnceClosure callback); |
650 | 632 |
651 // Runs the task if, or defers the task until, the cookies for the given URL | 633 // Runs the callback if, or defers the callback until, the cookies for the |
652 // are loaded. | 634 // given URL are loaded. |
653 void DoCookieTaskForURL(const scoped_refptr<CookieMonsterTask>& task_item, | 635 void DoCookieCallbackForURL(base::OnceClosure callback, const GURL& url); |
654 const GURL& url); | |
655 | 636 |
656 // Computes the difference between |old_cookies| and |new_cookies|, and writes | 637 // Computes the difference between |old_cookies| and |new_cookies|, and writes |
657 // the result in |cookies_to_add| and |cookies_to_delete|. | 638 // the result in |cookies_to_add| and |cookies_to_delete|. |
658 // This function has the side effect of changing the order of |old_cookies| | 639 // This function has the side effect of changing the order of |old_cookies| |
659 // and |new_cookies|. |cookies_to_add| and |cookies_to_delete| must be empty, | 640 // and |new_cookies|. |cookies_to_add| and |cookies_to_delete| must be empty, |
660 // and none of the arguments can be null. | 641 // and none of the arguments can be null. |
661 void ComputeCookieDiff(CookieList* old_cookies, | 642 void ComputeCookieDiff(CookieList* old_cookies, |
662 CookieList* new_cookies, | 643 CookieList* new_cookies, |
663 CookieList* cookies_to_add, | 644 CookieList* cookies_to_add, |
664 CookieList* cookies_to_delete); | 645 CookieList* cookies_to_delete); |
665 | 646 |
666 // Runs the given callback. Used to avoid running callbacks after the store | |
667 // has been destroyed. | |
668 void RunCallback(base::OnceClosure callback); | |
669 | |
670 // Run all cookie changed callbacks that are monitoring |cookie|. | 647 // Run all cookie changed callbacks that are monitoring |cookie|. |
671 // |removed| is true if the cookie was deleted. | 648 // |removed| is true if the cookie was deleted. |
672 void RunCookieChangedCallbacks(const CanonicalCookie& cookie, | 649 void RunCookieChangedCallbacks(const CanonicalCookie& cookie, |
673 CookieStore::ChangeCause cause); | 650 CookieStore::ChangeCause cause); |
674 | 651 |
675 // Histogram variables; see CookieMonster::InitializeHistograms() in | 652 // Histogram variables; see CookieMonster::InitializeHistograms() in |
676 // cookie_monster.cc for details. | 653 // cookie_monster.cc for details. |
677 base::HistogramBase* histogram_expiration_duration_minutes_; | 654 base::HistogramBase* histogram_expiration_duration_minutes_; |
678 base::HistogramBase* histogram_evicted_last_access_minutes_; | 655 base::HistogramBase* histogram_evicted_last_access_minutes_; |
679 base::HistogramBase* histogram_count_; | 656 base::HistogramBase* histogram_count_; |
(...skipping 14 matching lines...) Expand all Loading... |
694 bool finished_fetching_all_cookies_; | 671 bool finished_fetching_all_cookies_; |
695 // The strategy to use for fetching cookies. | 672 // The strategy to use for fetching cookies. |
696 FetchStrategy fetch_strategy_; | 673 FetchStrategy fetch_strategy_; |
697 | 674 |
698 // List of domain keys that have been loaded from the DB. | 675 // List of domain keys that have been loaded from the DB. |
699 std::set<std::string> keys_loaded_; | 676 std::set<std::string> keys_loaded_; |
700 | 677 |
701 // Map of domain keys to their associated task queues. These tasks are blocked | 678 // Map of domain keys to their associated task queues. These tasks are blocked |
702 // until all cookies for the associated domain key eTLD+1 are loaded from the | 679 // until all cookies for the associated domain key eTLD+1 are loaded from the |
703 // backend store. | 680 // backend store. |
704 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask>>> | 681 std::map<std::string, std::deque<base::OnceClosure>> tasks_pending_for_key_; |
705 tasks_pending_for_key_; | |
706 | 682 |
707 // Queues tasks that are blocked until all cookies are loaded from the backend | 683 // Queues tasks that are blocked until all cookies are loaded from the backend |
708 // store. | 684 // store. |
709 std::deque<scoped_refptr<CookieMonsterTask>> tasks_pending_; | 685 std::deque<base::OnceClosure> tasks_pending_; |
710 | 686 |
711 // Once a global cookie task has been seen, all per-key tasks must be put in | 687 // Once a global cookie task has been seen, all per-key tasks must be put in |
712 // |tasks_pending_| instead of |tasks_pending_for_key_| to ensure a reasonable | 688 // |tasks_pending_| instead of |tasks_pending_for_key_| to ensure a reasonable |
713 // view of the cookie store. This more to ensure fancy cookie export/import | 689 // view of the cookie store. This is more to ensure fancy cookie export/import |
714 // code has a consistent view of the CookieStore, rather than out of concern | 690 // code has a consistent view of the CookieStore, rather than out of concern |
715 // for typical use. | 691 // for typical use. |
716 bool seen_global_task_; | 692 bool seen_global_task_; |
717 | 693 |
718 scoped_refptr<PersistentCookieStore> store_; | 694 scoped_refptr<PersistentCookieStore> store_; |
719 | 695 |
720 base::Time last_time_seen_; | 696 base::Time last_time_seen_; |
721 | 697 |
722 // Minimum delay after updating a cookie's LastAccessDate before we will | 698 // Minimum delay after updating a cookie's LastAccessDate before we will |
723 // update it again. | 699 // update it again. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 virtual ~PersistentCookieStore() {} | 806 virtual ~PersistentCookieStore() {} |
831 | 807 |
832 private: | 808 private: |
833 friend class base::RefCountedThreadSafe<PersistentCookieStore>; | 809 friend class base::RefCountedThreadSafe<PersistentCookieStore>; |
834 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 810 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
835 }; | 811 }; |
836 | 812 |
837 } // namespace net | 813 } // namespace net |
838 | 814 |
839 #endif // NET_COOKIES_COOKIE_MONSTER_H_ | 815 #endif // NET_COOKIES_COOKIE_MONSTER_H_ |
OLD | NEW |