| 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 <deque> | 10 #include <deque> |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // of stored cookies. Please do not reorder the list when adding new entries. | 409 // of stored cookies. Please do not reorder the list when adding new entries. |
| 410 // New items MUST be added at the end of the list, just before | 410 // New items MUST be added at the end of the list, just before |
| 411 // COOKIE_TYPE_LAST_ENTRY; | 411 // COOKIE_TYPE_LAST_ENTRY; |
| 412 enum CookieType { | 412 enum CookieType { |
| 413 COOKIE_TYPE_FIRSTPARTYONLY = 0, | 413 COOKIE_TYPE_FIRSTPARTYONLY = 0, |
| 414 COOKIE_TYPE_HTTPONLY, | 414 COOKIE_TYPE_HTTPONLY, |
| 415 COOKIE_TYPE_SECURE, | 415 COOKIE_TYPE_SECURE, |
| 416 COOKIE_TYPE_LAST_ENTRY | 416 COOKIE_TYPE_LAST_ENTRY |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 // The strategy for fetching cookies. Controlled by Finch experiment. |
| 420 enum FetchStrategy { |
| 421 // Fetches all cookies only when they're needed. |
| 422 kFetchWhenNecessary = 0, |
| 423 // Fetches all cookies as soon as any cookie is needed. |
| 424 // This is the default behavior. |
| 425 kAlwaysFetch, |
| 426 // The fetch strategy is not yet determined. |
| 427 kUnknownFetch, |
| 428 }; |
| 429 |
| 419 // The number of days since last access that cookies will not be subject | 430 // The number of days since last access that cookies will not be subject |
| 420 // to global garbage collection. | 431 // to global garbage collection. |
| 421 static const int kSafeFromGlobalPurgeDays; | 432 static const int kSafeFromGlobalPurgeDays; |
| 422 | 433 |
| 423 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. | 434 // Record statistics every kRecordStatisticsIntervalSeconds of uptime. |
| 424 static const int kRecordStatisticsIntervalSeconds = 10 * 60; | 435 static const int kRecordStatisticsIntervalSeconds = 10 * 60; |
| 425 | 436 |
| 426 ~CookieMonster() override; | 437 ~CookieMonster() override; |
| 427 | 438 |
| 428 // The following are synchronous calls to which the asynchronous methods | 439 // The following are synchronous calls to which the asynchronous methods |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 void DeleteCookie(const GURL& url, const std::string& cookie_name); | 479 void DeleteCookie(const GURL& url, const std::string& cookie_name); |
| 469 | 480 |
| 470 bool SetCookieWithCreationTime(const GURL& url, | 481 bool SetCookieWithCreationTime(const GURL& url, |
| 471 const std::string& cookie_line, | 482 const std::string& cookie_line, |
| 472 const base::Time& creation_time); | 483 const base::Time& creation_time); |
| 473 | 484 |
| 474 int DeleteSessionCookies(); | 485 int DeleteSessionCookies(); |
| 475 | 486 |
| 476 bool HasCookiesForETLDP1(const std::string& etldp1); | 487 bool HasCookiesForETLDP1(const std::string& etldp1); |
| 477 | 488 |
| 478 // Called by all non-static functions to ensure that the cookies store has | 489 // The first access to the cookie store initializes it. This method should be |
| 479 // been initialized. This is not done during creating so it doesn't block | 490 // called before any access to the cookie store. |
| 480 // the window showing. | 491 void MarkCookieStoreAsInitialized(); |
| 492 |
| 493 // Fetches all cookies if the backing store exists and they're not already |
| 494 // being fetched. |
| 481 // Note: this method should always be called with lock_ held. | 495 // Note: this method should always be called with lock_ held. |
| 482 void InitIfNecessary() { | 496 void FetchAllCookiesIfNecessary(); |
| 483 if (!initialized_) { | |
| 484 if (store_.get()) { | |
| 485 InitStore(); | |
| 486 } else { | |
| 487 loaded_ = true; | |
| 488 } | |
| 489 initialized_ = true; | |
| 490 } | |
| 491 } | |
| 492 | 497 |
| 493 // Initializes the backing store and reads existing cookies from it. | 498 // Fetches all cookies from the backing store. |
| 494 // Should only be called by InitIfNecessary(). | 499 // Note: this method should always be called with lock_ held. |
| 495 void InitStore(); | 500 void FetchAllCookies(); |
| 501 |
| 502 // Whether all cookies should be fetched as soon as any is requested. |
| 503 bool ShouldFetchAllCookiesWhenFetchingAnyCookie(); |
| 496 | 504 |
| 497 // Stores cookies loaded from the backing store and invokes any deferred | 505 // Stores cookies loaded from the backing store and invokes any deferred |
| 498 // calls. |beginning_time| should be the moment PersistentCookieStore::Load | 506 // calls. |beginning_time| should be the moment PersistentCookieStore::Load |
| 499 // was invoked and is used for reporting histogram_time_blocked_on_load_. | 507 // was invoked and is used for reporting histogram_time_blocked_on_load_. |
| 500 // See PersistentCookieStore::Load for details on the contents of cookies. | 508 // See PersistentCookieStore::Load for details on the contents of cookies. |
| 501 void OnLoaded(base::TimeTicks beginning_time, | 509 void OnLoaded(base::TimeTicks beginning_time, |
| 502 const std::vector<CanonicalCookie*>& cookies); | 510 const std::vector<CanonicalCookie*>& cookies); |
| 503 | 511 |
| 504 // Stores cookies loaded from the backing store and invokes the deferred | 512 // Stores cookies loaded from the backing store and invokes the deferred |
| 505 // task(s) pending loading of cookies associated with the domain key | 513 // task(s) pending loading of cookies associated with the domain key |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 base::HistogramBase* histogram_etldp1_count_; | 670 base::HistogramBase* histogram_etldp1_count_; |
| 663 base::HistogramBase* histogram_domain_per_etldp1_count_; | 671 base::HistogramBase* histogram_domain_per_etldp1_count_; |
| 664 base::HistogramBase* histogram_number_duplicate_db_cookies_; | 672 base::HistogramBase* histogram_number_duplicate_db_cookies_; |
| 665 base::HistogramBase* histogram_cookie_deletion_cause_; | 673 base::HistogramBase* histogram_cookie_deletion_cause_; |
| 666 base::HistogramBase* histogram_cookie_type_; | 674 base::HistogramBase* histogram_cookie_type_; |
| 667 base::HistogramBase* histogram_time_mac_; | 675 base::HistogramBase* histogram_time_mac_; |
| 668 base::HistogramBase* histogram_time_blocked_on_load_; | 676 base::HistogramBase* histogram_time_blocked_on_load_; |
| 669 | 677 |
| 670 CookieMap cookies_; | 678 CookieMap cookies_; |
| 671 | 679 |
| 672 // Indicates whether the cookie store has been initialized. This happens | 680 // Indicates whether the cookie store has been initialized. |
| 673 // lazily in InitStoreIfNecessary(). | |
| 674 bool initialized_; | 681 bool initialized_; |
| 675 | 682 |
| 676 // Indicates whether loading from the backend store is completed and | 683 // Indicates whether the cookie store has started fetching all cookies. |
| 677 // calls may be immediately processed. | 684 bool started_fetching_all_cookies_; |
| 678 bool loaded_; | 685 // Indicates whether the cookie store has finished fetching all cookies. |
| 686 bool finished_fetching_all_cookies_; |
| 687 // The strategy to use for fetching cookies. |
| 688 FetchStrategy fetch_strategy_; |
| 679 | 689 |
| 680 // List of domain keys that have been loaded from the DB. | 690 // List of domain keys that have been loaded from the DB. |
| 681 std::set<std::string> keys_loaded_; | 691 std::set<std::string> keys_loaded_; |
| 682 | 692 |
| 683 // Map of domain keys to their associated task queues. These tasks are blocked | 693 // Map of domain keys to their associated task queues. These tasks are blocked |
| 684 // until all cookies for the associated domain key eTLD+1 are loaded from the | 694 // until all cookies for the associated domain key eTLD+1 are loaded from the |
| 685 // backend store. | 695 // backend store. |
| 686 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask>>> | 696 std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask>>> |
| 687 tasks_pending_for_key_; | 697 tasks_pending_for_key_; |
| 688 | 698 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 788 |
| 779 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> | 789 typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore> |
| 780 RefcountedPersistentCookieStore; | 790 RefcountedPersistentCookieStore; |
| 781 | 791 |
| 782 class NET_EXPORT CookieMonster::PersistentCookieStore | 792 class NET_EXPORT CookieMonster::PersistentCookieStore |
| 783 : public RefcountedPersistentCookieStore { | 793 : public RefcountedPersistentCookieStore { |
| 784 public: | 794 public: |
| 785 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)> | 795 typedef base::Callback<void(const std::vector<CanonicalCookie*>&)> |
| 786 LoadedCallback; | 796 LoadedCallback; |
| 787 | 797 |
| 798 // TODO(erikchen): Depending on the results of the cookie monster Finch |
| 799 // experiment, update the name and description of this method. The behavior |
| 800 // of this method doesn't change, but it has different semantics for the two |
| 801 // different logic paths. See http://crbug.com/473483. |
| 788 // Initializes the store and retrieves the existing cookies. This will be | 802 // Initializes the store and retrieves the existing cookies. This will be |
| 789 // called only once at startup. The callback will return all the cookies | 803 // called only once at startup. The callback will return all the cookies |
| 790 // that are not yet returned to CookieMonster by previous priority loads. | 804 // that are not yet returned to CookieMonster by previous priority loads. |
| 791 virtual void Load(const LoadedCallback& loaded_callback) = 0; | 805 virtual void Load(const LoadedCallback& loaded_callback) = 0; |
| 792 | 806 |
| 793 // Does a priority load of all cookies for the domain key (eTLD+1). The | 807 // Does a priority load of all cookies for the domain key (eTLD+1). The |
| 794 // callback will return all the cookies that are not yet returned by previous | 808 // callback will return all the cookies that are not yet returned by previous |
| 795 // loads, which includes cookies for the requested domain key if they are not | 809 // loads, which includes cookies for the requested domain key if they are not |
| 796 // already returned, plus all cookies that are chain-loaded and not yet | 810 // already returned, plus all cookies that are chain-loaded and not yet |
| 797 // returned to CookieMonster. | 811 // returned to CookieMonster. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 813 virtual ~PersistentCookieStore() {} | 827 virtual ~PersistentCookieStore() {} |
| 814 | 828 |
| 815 private: | 829 private: |
| 816 friend class base::RefCountedThreadSafe<PersistentCookieStore>; | 830 friend class base::RefCountedThreadSafe<PersistentCookieStore>; |
| 817 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 831 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 818 }; | 832 }; |
| 819 | 833 |
| 820 } // namespace net | 834 } // namespace net |
| 821 | 835 |
| 822 #endif // NET_COOKIES_COOKIE_MONSTER_H_ | 836 #endif // NET_COOKIES_COOKIE_MONSTER_H_ |
| OLD | NEW |