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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 initialized_ = true; | 443 initialized_ = true; |
| 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_. |
|
erikwright (departed)
2011/09/15 20:56:27
Add a note that the cookie list received here, com
erikwright (departed)
2011/09/15 21:01:56
Actually, add this note to PersistentCookieStore::
guohui
2011/09/16 18:21:09
Comments added to SQLitePersistentCookieStore::Bac
| |
| 453 void OnLoaded(base::TimeTicks beginning_time, | 454 void OnLoaded(base::TimeTicks beginning_time, |
| 454 const std::vector<CanonicalCookie*>& cookies); | 455 const std::vector<CanonicalCookie*>& cookies); |
| 455 | 456 |
| 457 // Stores cookies loaded from the backing store and invokes deferred callback. | |
| 458 // Called when all cookies for the domain key(eTLD+1) has been loaded from DB. | |
|
erikwright (departed)
2011/09/15 20:56:27
Add a note that cookies contains a superset of the
erikwright (departed)
2011/09/15 21:01:56
In fact, it should say that it "normally" contains
guohui
2011/09/16 18:21:09
Done.
| |
| 459 void CookieMonster::OnKeyLoaded( | |
| 460 const base::Closure& request_task, const std::string& key, | |
| 461 const std::vector<CanonicalCookie*>& cookies); | |
| 462 | |
| 456 // Stores the loaded cookies. | 463 // Stores the loaded cookies. |
| 457 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); | 464 void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); |
| 458 | 465 |
| 459 // Invokes deferred calls. | 466 // Invokes deferred calls. |
| 460 void InvokeQueue(); | 467 void InvokeQueue(); |
| 461 | 468 |
| 462 // Checks that |cookies_| matches our invariants, and tries to repair any | 469 // Checks that |cookies_| matches our invariants, and tries to repair any |
| 463 // inconsistencies. (In other words, it does not have duplicate cookies). | 470 // inconsistencies. (In other words, it does not have duplicate cookies). |
| 464 void EnsureCookiesMapIsValid(); | 471 void EnsureCookiesMapIsValid(); |
| 465 | 472 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 void RecordPeriodicStats(const base::Time& current_time); | 568 void RecordPeriodicStats(const base::Time& current_time); |
| 562 | 569 |
| 563 // Initialize the above variables; should only be called from | 570 // Initialize the above variables; should only be called from |
| 564 // the constructor. | 571 // the constructor. |
| 565 void InitializeHistograms(); | 572 void InitializeHistograms(); |
| 566 | 573 |
| 567 // The resolution of our time isn't enough, so we do something | 574 // The resolution of our time isn't enough, so we do something |
| 568 // ugly and increment when we've seen the same time twice. | 575 // ugly and increment when we've seen the same time twice. |
| 569 base::Time CurrentTime(); | 576 base::Time CurrentTime(); |
| 570 | 577 |
| 571 // Run the cookie request task if cookie loaded, otherwise added the task | 578 // Run the cookie request task if cookie loaded, otherwise added the task |
|
erikwright (departed)
2011/09/15 20:56:27
Correct to:
Runs the task if, or defers the task
guohui
2011/09/16 18:21:09
Done.
| |
| 572 // to task queue. | 579 // to task queue. |
| 573 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); | 580 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); |
| 574 | 581 |
| 582 // Run the cookie request task for a specific URL | |
|
erikwright (departed)
2011/09/15 20:56:27
Correct to:
Runs the task if, or defers the task
guohui
2011/09/16 18:21:09
Done.
| |
| 583 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item, | |
| 584 const GURL& url); | |
| 585 | |
| 575 // Histogram variables; see CookieMonster::InitializeHistograms() in | 586 // Histogram variables; see CookieMonster::InitializeHistograms() in |
| 576 // cookie_monster.cc for details. | 587 // cookie_monster.cc for details. |
| 577 base::Histogram* histogram_expiration_duration_minutes_; | 588 base::Histogram* histogram_expiration_duration_minutes_; |
| 578 base::Histogram* histogram_between_access_interval_minutes_; | 589 base::Histogram* histogram_between_access_interval_minutes_; |
| 579 base::Histogram* histogram_evicted_last_access_minutes_; | 590 base::Histogram* histogram_evicted_last_access_minutes_; |
| 580 base::Histogram* histogram_count_; | 591 base::Histogram* histogram_count_; |
| 581 base::Histogram* histogram_domain_count_; | 592 base::Histogram* histogram_domain_count_; |
| 582 base::Histogram* histogram_etldp1_count_; | 593 base::Histogram* histogram_etldp1_count_; |
| 583 base::Histogram* histogram_domain_per_etldp1_count_; | 594 base::Histogram* histogram_domain_per_etldp1_count_; |
| 584 base::Histogram* histogram_number_duplicate_db_cookies_; | 595 base::Histogram* histogram_number_duplicate_db_cookies_; |
| 585 base::Histogram* histogram_cookie_deletion_cause_; | 596 base::Histogram* histogram_cookie_deletion_cause_; |
| 586 base::Histogram* histogram_time_get_; | 597 base::Histogram* histogram_time_get_; |
| 587 base::Histogram* histogram_time_mac_; | 598 base::Histogram* histogram_time_mac_; |
| 588 base::Histogram* histogram_time_load_; | 599 base::Histogram* histogram_time_load_; |
| 589 | 600 |
| 590 CookieMap cookies_; | 601 CookieMap cookies_; |
| 591 | 602 |
| 592 // Indicates whether the cookie store has been initialized. This happens | 603 // Indicates whether the cookie store has been initialized. This happens |
| 593 // lazily in InitStoreIfNecessary(). | 604 // lazily in InitStoreIfNecessary(). |
| 594 bool initialized_; | 605 bool initialized_; |
| 595 | 606 |
| 596 // Indicates whether loading from the backend store is completed and | 607 // Indicates whether loading from the backend store is completed and |
| 597 // calls may be immediately processed. | 608 // calls may be immediately processed. |
| 598 bool loaded_; | 609 bool loaded_; |
| 599 | 610 |
| 611 // List of domain keys that have been loaded from DB | |
| 612 std::set<std::string> keys_loaded_; | |
| 613 | |
| 600 // Queues calls to CookieMonster until loading from the backend store is | 614 // Queues calls to CookieMonster until loading from the backend store is |
| 601 // completed. | 615 // completed. |
| 602 std::queue<scoped_refptr<CookieMonsterTask> > queue_; | 616 std::queue<scoped_refptr<CookieMonsterTask> > queue_; |
| 603 | 617 |
| 604 // Indicates whether this cookie monster uses the new effective domain | 618 // Indicates whether this cookie monster uses the new effective domain |
| 605 // key scheme or not. | 619 // key scheme or not. |
| 606 ExpiryAndKeyScheme expiry_and_key_scheme_; | 620 ExpiryAndKeyScheme expiry_and_key_scheme_; |
| 607 | 621 |
| 608 scoped_refptr<PersistentCookieStore> store_; | 622 scoped_refptr<PersistentCookieStore> store_; |
| 609 | 623 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 class CookieMonster::PersistentCookieStore | 927 class CookieMonster::PersistentCookieStore |
| 914 : public RefcountedPersistentCookieStore { | 928 : public RefcountedPersistentCookieStore { |
| 915 public: | 929 public: |
| 916 virtual ~PersistentCookieStore() {} | 930 virtual ~PersistentCookieStore() {} |
| 917 | 931 |
| 918 typedef base::Callback<void(const std::vector< | 932 typedef base::Callback<void(const std::vector< |
| 919 CookieMonster::CanonicalCookie*>&)> LoadedCallback; | 933 CookieMonster::CanonicalCookie*>&)> LoadedCallback; |
| 920 | 934 |
| 921 // Initializes the store and retrieves the existing cookies. This will be | 935 // Initializes the store and retrieves the existing cookies. This will be |
| 922 // called only once at startup. | 936 // called only once at startup. |
| 923 virtual bool Load(const LoadedCallback& loaded_callback) = 0; | 937 virtual bool Load(const LoadedCallback& loaded_callback) = 0; |
|
erikwright (departed)
2011/09/15 20:56:27
Make these two methods void and declare that they
guohui
2011/09/16 18:21:09
Done.
| |
| 924 | 938 |
| 939 // Load all cookies for a domain key(eTLD+1) | |
| 940 virtual bool LoadCookiesForKey(const std::string& key, | |
| 941 const LoadedCallback& loaded_callback) = 0; | |
| 942 | |
| 925 virtual void AddCookie(const CanonicalCookie& cc) = 0; | 943 virtual void AddCookie(const CanonicalCookie& cc) = 0; |
| 926 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; | 944 virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |
| 927 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; | 945 virtual void DeleteCookie(const CanonicalCookie& cc) = 0; |
| 928 | 946 |
| 929 // Sets the value of the user preference whether the persistent storage | 947 // Sets the value of the user preference whether the persistent storage |
| 930 // must be deleted upon destruction. | 948 // must be deleted upon destruction. |
| 931 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; | 949 virtual void SetClearLocalStateOnExit(bool clear_local_state) = 0; |
| 932 | 950 |
| 933 // Flush the store and post the given Task when complete. | 951 // Flush the store and post the given Task when complete. |
| 934 virtual void Flush(Task* completion_task) = 0; | 952 virtual void Flush(Task* completion_task) = 0; |
| 935 | 953 |
| 936 protected: | 954 protected: |
| 937 PersistentCookieStore() {} | 955 PersistentCookieStore() {} |
| 938 | 956 |
| 939 private: | 957 private: |
| 940 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); | 958 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); |
| 941 }; | 959 }; |
| 942 | 960 |
| 943 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { | 961 class CookieList : public std::vector<CookieMonster::CanonicalCookie> { |
| 944 }; | 962 }; |
| 945 | 963 |
| 946 } // namespace net | 964 } // namespace net |
| 947 | 965 |
| 948 #endif // NET_BASE_COOKIE_MONSTER_H_ | 966 #endif // NET_BASE_COOKIE_MONSTER_H_ |
| OLD | NEW |