Chromium Code Reviews| 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 <queue> |
| 13 #include <set> | |
| 13 #include <string> | 14 #include <string> |
| 14 #include <utility> | 15 #include <utility> |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 18 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
| 19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
| 22 #include "base/task.h" | 23 #include "base/task.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 } | 444 } |
| 444 } | 445 } |
| 445 | 446 |
| 446 // Initializes the backing store and reads existing cookies from it. | 447 // Initializes the backing store and reads existing cookies from it. |
| 447 // Should only be called by InitIfNecessary(). | 448 // Should only be called by InitIfNecessary(). |
| 448 void InitStore(); | 449 void InitStore(); |
| 449 | 450 |
| 450 // Stores cookies loaded from the backing store and invokes any deferred | 451 // Stores cookies loaded from the backing store and invokes any deferred |
| 451 // calls. |beginning_time| should be the moment PersistentCookieStore::Load | 452 // calls. |beginning_time| should be the moment PersistentCookieStore::Load |
| 452 // was invoked and is used for reporting histogram_time_load_. | 453 // was invoked and is used for reporting histogram_time_load_. |
| 454 // See PersistentCookieStore::Load for details on the contents of cookies. | |
|
erikwright (departed)
2011/09/16 18:58:57
The comments I asked for apply to the interface co
guohui
2011/09/16 19:31:50
Done.
| |
| 453 void OnLoaded(base::TimeTicks beginning_time, | 455 void OnLoaded(base::TimeTicks beginning_time, |
| 454 const std::vector<CanonicalCookie*>& cookies); | 456 const std::vector<CanonicalCookie*>& cookies); |
| 455 | 457 |
| 458 // Stores cookies loaded from the backing store and invokes deferred callback. | |
| 459 // Called when all cookies for the domain key(eTLD+1) has been loaded from DB. | |
| 460 // See PersistentCookieStore::Load for details on the contents of cookies. | |
| 461 void CookieMonster::OnKeyLoaded( | |
| 462 const base::Closure& request_task, const std::string& key, | |
| 463 const std::vector<CanonicalCookie*>& cookies); | |
| 464 | |
| 456 // Stores the loaded cookies. | 465 // Stores the loaded cookies. |
| 457 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); | 466 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); |
| 458 | 467 |
| 459 // Invokes deferred calls. | 468 // Invokes deferred calls. |
| 460 void InvokeQueue(); | 469 void InvokeQueue(); |
| 461 | 470 |
| 462 // Checks that |cookies_| matches our invariants, and tries to repair any | 471 // Checks that |cookies_| matches our invariants, and tries to repair any |
| 463 // inconsistencies. (In other words, it does not have duplicate cookies). | 472 // inconsistencies. (In other words, it does not have duplicate cookies). |
| 464 void EnsureCookiesMapIsValid(); | 473 void EnsureCookiesMapIsValid(); |
| 465 | 474 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 void RecordPeriodicStats(const base::Time& current_time); | 570 void RecordPeriodicStats(const base::Time& current_time); |
| 562 | 571 |
| 563 // Initialize the above variables; should only be called from | 572 // Initialize the above variables; should only be called from |
| 564 // the constructor. | 573 // the constructor. |
| 565 void InitializeHistograms(); | 574 void InitializeHistograms(); |
| 566 | 575 |
| 567 // The resolution of our time isn't enough, so we do something | 576 // The resolution of our time isn't enough, so we do something |
| 568 // ugly and increment when we've seen the same time twice. | 577 // ugly and increment when we've seen the same time twice. |
| 569 base::Time CurrentTime(); | 578 base::Time CurrentTime(); |
| 570 | 579 |
| 571 // Run the cookie request task if cookie loaded, otherwise added the task | 580 // Runs the task if, or defers the task until, |
|
erikwright (departed)
2011/09/16 18:58:57
Correct line wrapping to 80 columns.
guohui
2011/09/16 19:31:50
Done.
| |
| 572 // to task queue. | 581 // the full cookie database is loaded. |
| 573 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); | 582 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); |
| 574 | 583 |
| 584 // Runs the task if, or defers the task until, | |
|
erikwright (departed)
2011/09/16 18:58:57
Line wrapping.
guohui
2011/09/16 19:31:50
Done.
| |
| 585 // the cookies for the given URL are loaded. | |
| 586 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item, | |
| 587 const GURL& url); | |
| 588 | |
| 575 // Histogram variables; see CookieMonster::InitializeHistograms() in | 589 // Histogram variables; see CookieMonster::InitializeHistograms() in |
| 576 // cookie_monster.cc for details. | 590 // cookie_monster.cc for details. |
| 577 base::Histogram* histogram_expiration_duration_minutes_; | 591 base::Histogram* histogram_expiration_duration_minutes_; |
| 578 base::Histogram* histogram_between_access_interval_minutes_; | 592 base::Histogram* histogram_between_access_interval_minutes_; |
| 579 base::Histogram* histogram_evicted_last_access_minutes_; | 593 base::Histogram* histogram_evicted_last_access_minutes_; |
| 580 base::Histogram* histogram_count_; | 594 base::Histogram* histogram_count_; |
| 581 base::Histogram* histogram_domain_count_; | 595 base::Histogram* histogram_domain_count_; |
| 582 base::Histogram* histogram_etldp1_count_; | 596 base::Histogram* histogram_etldp1_count_; |
| 583 base::Histogram* histogram_domain_per_etldp1_count_; | 597 base::Histogram* histogram_domain_per_etldp1_count_; |
| 584 base::Histogram* histogram_number_duplicate_db_cookies_; | 598 base::Histogram* histogram_number_duplicate_db_cookies_; |
| 585 base::Histogram* histogram_cookie_deletion_cause_; | 599 base::Histogram* histogram_cookie_deletion_cause_; |
| 586 base::Histogram* histogram_time_get_; | 600 base::Histogram* histogram_time_get_; |
| 587 base::Histogram* histogram_time_mac_; | 601 base::Histogram* histogram_time_mac_; |
| 588 base::Histogram* histogram_time_load_; | 602 base::Histogram* histogram_time_load_; |
| 589 | 603 |
| 590 CookieMap cookies_; | 604 CookieMap cookies_; |
| 591 | 605 |
| 592 // Indicates whether the cookie store has been initialized. This happens | 606 // Indicates whether the cookie store has been initialized. This happens |
| 593 // lazily in InitStoreIfNecessary(). | 607 // lazily in InitStoreIfNecessary(). |
| 594 bool initialized_; | 608 bool initialized_; |
| 595 | 609 |
| 596 // Indicates whether loading from the backend store is completed and | 610 // Indicates whether loading from the backend store is completed and |
| 597 // calls may be immediately processed. | 611 // calls may be immediately processed. |
| 598 bool loaded_; | 612 bool loaded_; |
| 599 | 613 |
| 614 // List of domain keys that have been loaded from DB | |
| 615 std::set<std::string> keys_loaded_; | |
| 616 | |
| 600 // Queues calls to CookieMonster until loading from the backend store is | 617 // Queues calls to CookieMonster until loading from the backend store is |
| 601 // completed. | 618 // completed. |
| 602 std::queue<scoped_refptr<CookieMonsterTask> > queue_; | 619 std::queue<scoped_refptr<CookieMonsterTask> > queue_; |
| 603 | 620 |
| 604 // Indicates whether this cookie monster uses the new effective domain | 621 // Indicates whether this cookie monster uses the new effective domain |
| 605 // key scheme or not. | 622 // key scheme or not. |
| 606 ExpiryAndKeyScheme expiry_and_key_scheme_; | 623 ExpiryAndKeyScheme expiry_and_key_scheme_; |
| 607 | 624 |
| 608 scoped_refptr<PersistentCookieStore> store_; | 625 scoped_refptr<PersistentCookieStore> store_; |
| 609 | 626 |
| 610 base::Time last_time_seen_; | 627 base::Time last_time_seen_; |
| 611 | 628 |
| 612 // Minimum delay after updating a cookie's LastAccessDate before we will | 629 // Minimum delay after updating a cookie's LastAccessDate before we will |
| 613 // update it again. | 630 // update it again. |
| 614 const base::TimeDelta last_access_threshold_; | 631 const base::TimeDelta last_access_threshold_; |
| 615 | 632 |
| 616 // Approximate date of access time of least recently accessed cookie | 633 // Approximate date of access time of least recently accessed cookie |
| 617 // in |cookies_|. Note that this is not guaranteed to be accurate, only a) | 634 // in |cookies_|. Note that this is not guaranteed to be accurate, only a) |
| 618 // to be before or equal to the actual time, and b) to be accurate | 635 // to be before or equal to the actual time, and b) to be accurate |
| 619 // immediately after a garbage collection that scans through all the cookies. | 636 // immediately after a garbage collection that scans through all the cookies. |
| 620 // This value is used to determine whether global garbage collection might | 637 // This value is used to determine whether global garbage collection might |
| 621 // find cookies to purge. | 638 // find cookies to purge. |
| 622 // Note: The default Time() constructor will create a value that compares | 639 // Note: The default Time() constructor will create a value that compares |
| 623 // earlier than any other time value, which is is wanted. Thus this | 640 // earlier than any other time value, which is wanted. Thus this |
| 624 // value is not initialized. | 641 // value is not initialized. |
| 625 base::Time earliest_access_time_; | 642 base::Time earliest_access_time_; |
| 626 | 643 |
| 644 // Avoid ever letting cookies with duplicate creation times into the store; | |
|
erikwright (departed)
2011/09/16 18:58:57
"During loading, holds the set of all loaded cooki
guohui
2011/09/16 19:31:50
Done.
| |
| 645 // that way we don't have to worry about what sections of code are safe | |
| 646 // to call while it's in that state. | |
| 647 std::set<int64> creation_times; | |
|
erikwright (departed)
2011/09/16 18:58:57
Suffix with a '_'.
guohui
2011/09/16 19:31:50
Done.
| |
| 648 | |
| 627 std::vector<std::string> cookieable_schemes_; | 649 std::vector<std::string> cookieable_schemes_; |
| 628 | 650 |
| 629 scoped_refptr<Delegate> delegate_; | 651 scoped_refptr<Delegate> delegate_; |
| 630 | 652 |
| 631 // Lock for thread-safety | 653 // Lock for thread-safety |
| 632 base::Lock lock_; | 654 base::Lock lock_; |
| 633 | 655 |
| 634 base::Time last_statistic_record_time_; | 656 base::Time last_statistic_record_time_; |
| 635 | 657 |
| 636 bool keep_expired_cookies_; | 658 bool keep_expired_cookies_; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 class CookieMonster::PersistentCookieStore | 935 class CookieMonster::PersistentCookieStore |
| 914 : public RefcountedPersistentCookieStore { | 936 : public RefcountedPersistentCookieStore { |
| 915 public: | 937 public: |
| 916 virtual ~PersistentCookieStore() {} | 938 virtual ~PersistentCookieStore() {} |
| 917 | 939 |
| 918 typedef base::Callback<void(const std::vector< | 940 typedef base::Callback<void(const std::vector< |
| 919 CookieMonster::CanonicalCookie*>&)> LoadedCallback; | 941 CookieMonster::CanonicalCookie*>&)> LoadedCallback; |
| 920 | 942 |
| 921 // Initializes the store and retrieves the existing cookies. This will be | 943 // Initializes the store and retrieves the existing cookies. This will be |
| 922 // called only once at startup. | 944 // called only once at startup. |
| 923 virtual bool Load(const LoadedCallback& loaded_callback) = 0; | 945 virtual void Load(const LoadedCallback& loaded_callback) = 0; |
| 946 | |
| 947 // Load all cookies for a domain key(eTLD+1). | |
| 948 virtual void LoadCookiesForKey(const std::string& key, | |
| 949 const LoadedCallback& loaded_callback) = 0; | |
| 924 | 950 |
| 925 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 951 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
| 926 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 952 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
| 927 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 953 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
| 928 | 954 |
| 929 // Sets the value of the user preference whether the persistent storage | 955 // Sets the value of the user preference whether the persistent storage |
| 930 // must be deleted upon destruction. | 956 // must be deleted upon destruction. |
| 931 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 957 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
| 932 | 958 |
| 933 // Flush the store and post the given Task when complete. | 959 // Flush the store and post the given Task when complete. |
| 934 virtual void Flush(Task* completion_task) = 0; | 960 virtual void Flush(Task* completion_task) = 0; |
| 935 | 961 |
| 936 protected: | 962 protected: |
| 937 PersistentCookieStore() {} | 963 PersistentCookieStore() {} |
| 938 | 964 |
| 939 private: | 965 private: |
| 940 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 966 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 941 }; | 967 }; |
| 942 | 968 |
| 943 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 969 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
| 944 }; | 970 }; |
| 945 | 971 |
| 946 } // namespace net | 972 } // namespace net |
| 947 | 973 |
| 948 #endif // NET_BASE_COOKIE_MONSTER_H_ | 974 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |