diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-09 02:33:15 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-09 02:33:15 +0000 |
commit | 4aa89e8ece48729ea064568b673ff43d19a1b40d (patch) | |
tree | f959786d66def8e80548b1393ea502291b25376b /net/base/cookie_monster.h | |
parent | 8ce1f6165f0ffc1564b25dc9fef90d05816ae634 (diff) | |
download | chromium_src-4aa89e8ece48729ea064568b673ff43d19a1b40d.zip chromium_src-4aa89e8ece48729ea064568b673ff43d19a1b40d.tar.gz chromium_src-4aa89e8ece48729ea064568b673ff43d19a1b40d.tar.bz2 |
Revert 100188 - Finalize a CL originally by departed intern ycxiao@ that detaches the loading of cookies from the IO thread.
They are now loaded on the DB thread. Cookie operations received in the meantime are queued and executed, on the IO thread, in the order they were received, when loading completes.
A few straggler clients are updated to use the asynchronous CookieStore/CookieMonster API as part of this CL, as the synchronous API is removed.
BUG=68657
TEST=net_unittests / DeferredCookieTaskTest.* and CookieMonsterTest.*
Review URL: http://codereview.chromium.org/7833042
TBR=erikwright@chromium.org
Review URL: http://codereview.chromium.org/7860026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/cookie_monster.h')
-rw-r--r-- | net/base/cookie_monster.h | 163 |
1 files changed, 53 insertions, 110 deletions
diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index e272466..cd24707 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -9,7 +9,6 @@ #pragma once #include <map> -#include <queue> #include <string> #include <utility> #include <vector> @@ -28,7 +27,6 @@ class GURL; namespace base { class Histogram; -class TimeTicks; } namespace net { @@ -140,19 +138,19 @@ class NET_EXPORT CookieMonster : public CookieStore { // i.e. it doesn't begin with a leading '.' character. static bool DomainIsHostOnly(const std::string& domain_string); - // Helper function that adds all cookies from |list| into this instance. - bool InitializeFrom(const CookieList& list); - - typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; - typedef base::Callback<void(int num_deleted)> DeleteCallback; - typedef base::Callback<void(bool)> DeleteCookieCallback; - // Sets a cookie given explicit user-provided cookie attributes. The cookie // name, value, domain, etc. are each provided as separate strings. This // function expects each attribute to be well-formed. It will check for // disallowed characters (e.g. the ';' character is disallowed within the // cookie value attribute) and will return false without setting the cookie // if such characters are found. + bool SetCookieWithDetails(const GURL& url, + const std::string& name, + const std::string& value, + const std::string& domain, + const std::string& path, + const base::Time& expiration_time, + bool secure, bool http_only); void SetCookieWithDetailsAsync(const GURL& url, const std::string& name, const std::string& value, @@ -163,10 +161,16 @@ class NET_EXPORT CookieMonster : public CookieStore { const SetCookiesCallback& callback); + // Helper function that adds all cookies from |cookie_monster| into this + // instance. + bool InitializeFrom(const CookieList& list); + // Returns all the cookies, for use in management UI, etc. This does not mark // the cookies as having been accessed. // The returned cookies are ordered by longest path, then by earliest // creation date. + CookieList GetAllCookies(); + typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; void GetAllCookiesAsync(const GetCookieListCallback& callback); // Returns all the cookies, for use in management UI, etc. Filters results @@ -174,6 +178,8 @@ class NET_EXPORT CookieMonster : public CookieStore { // mark the cookies as having been accessed. // The returned cookies are ordered by longest path, then earliest // creation date. + CookieList GetAllCookiesForURLWithOptions(const GURL& url, + const CookieOptions& options); void GetAllCookiesForURLWithOptionsAsync( const GURL& url, const CookieOptions& options, @@ -181,27 +187,38 @@ class NET_EXPORT CookieMonster : public CookieStore { // Invokes GetAllCookiesForURLWithOptions with options set to include HTTP // only cookies. + CookieList GetAllCookiesForURL(const GURL& url); void GetAllCookiesForURLAsync(const GURL& url, const GetCookieListCallback& callback); // Deletes all of the cookies. - void DeleteAllAsync(const DeleteCallback& callback); - + int DeleteAll(bool sync_to_store); // Deletes all of the cookies that have a creation_date greater than or equal // to |delete_begin| and less than |delete_end| // Returns the number of cookies that have been deleted. + int DeleteAllCreatedBetween(const base::Time& delete_begin, + const base::Time& delete_end, + bool sync_to_store); + typedef base::Callback<void(int num_deleted)> DeleteCallback; void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, const base::Time& delete_end, + bool sync_to_store, const DeleteCallback& callback); // Deletes all cookies that match the host of the given URL // regardless of path. This includes all http_only and secure cookies, // but does not include any domain cookies that may apply to this host. // Returns the number of cookies deleted. + int DeleteAllForHost(const GURL& url); + void DeleteAllForHostAsync(const GURL& url, const DeleteCallback& callback); // Deletes one specific cookie. + bool DeleteCanonicalCookie(const CanonicalCookie& cookie); + + typedef SetCookiesCallback DeleteCookieCallback; + void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, const DeleteCookieCallback& callback); @@ -243,31 +260,42 @@ class NET_EXPORT CookieMonster : public CookieStore { // Sets the cookies specified by |cookie_list| returned from |url| // with options |options| in effect. - virtual void SetCookieWithOptionsAsync( - const GURL& url, - const std::string& cookie_line, - const CookieOptions& options, - const SetCookiesCallback& callback) OVERRIDE; + virtual bool SetCookieWithOptions(const GURL& url, + const std::string& cookie_line, + const CookieOptions& options); + + virtual void SetCookieWithOptionsAsync(const GURL& url, + const std::string& cookie_line, + const CookieOptions& options, + const SetCookiesCallback& callback); // Gets all cookies that apply to |url| given |options|. // The returned cookies are ordered by longest path, then earliest // creation date. + virtual std::string GetCookiesWithOptions(const GURL& url, + const CookieOptions& options); + virtual void GetCookiesWithOptionsAsync( const GURL& url, const CookieOptions& options, - const GetCookiesCallback& callback) OVERRIDE; + const GetCookiesCallback& callback); - virtual void GetCookiesWithInfoAsync( - const GURL& url, - const CookieOptions& options, - const GetCookieInfoCallback& callback) OVERRIDE; + virtual void GetCookiesWithInfo(const GURL& url, + const CookieOptions& options, + std::string* cookie_line, + std::vector<CookieInfo>* cookie_infos); + + virtual void GetCookiesWithInfoAsync(const GURL& url, + const CookieOptions& options, + const GetCookieInfoCallback& callback); // Deletes all cookies with that might apply to |url| that has |cookie_name|. + virtual void DeleteCookie(const GURL& url, const std::string& cookie_name); virtual void DeleteCookieAsync( const GURL& url, const std::string& cookie_name, - const base::Closure& callback) OVERRIDE; + const base::Closure& callback); - virtual CookieMonster* GetCookieMonster() OVERRIDE; + virtual CookieMonster* GetCookieMonster(); // Debugging method to perform various validation checks on the map. // Currently just checking that there are no null CanonicalCookie pointers @@ -281,20 +309,6 @@ class NET_EXPORT CookieMonster : public CookieStore { static const int kDefaultCookieableSchemesCount; private: - // For queueing the cookie monster calls. - class CookieMonsterTask; - class DeleteAllCreatedBetweenTask; - class DeleteAllForHostTask; - class DeleteAllTask; - class DeleteCookieTask; - class DeleteCanonicalCookieTask; - class GetAllCookiesForURLWithOptionsTask; - class GetAllCookiesTask; - class GetCookiesWithOptionsTask; - class GetCookiesWithInfoTask; - class SetCookieWithDetailsTask; - class SetCookieWithOptionsTask; - // Testing support. // For SetCookieWithCreationTime. FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, @@ -383,47 +397,6 @@ class NET_EXPORT CookieMonster : public CookieStore { virtual ~CookieMonster(); - // The following are synchronous calls to which the asynchronous methods - // delegate either immediately (if the store is loaded) or through a deferred - // task (if the store is not yet loaded). - bool SetCookieWithDetails(const GURL& url, - const std::string& name, - const std::string& value, - const std::string& domain, - const std::string& path, - const base::Time& expiration_time, - bool secure, bool http_only); - - CookieList GetAllCookies(); - - CookieList GetAllCookiesForURLWithOptions(const GURL& url, - const CookieOptions& options); - - CookieList GetAllCookiesForURL(const GURL& url); - - int DeleteAll(bool sync_to_store); - - int DeleteAllCreatedBetween(const base::Time& delete_begin, - const base::Time& delete_end); - - int DeleteAllForHost(const GURL& url); - - bool DeleteCanonicalCookie(const CanonicalCookie& cookie); - - bool SetCookieWithOptions(const GURL& url, - const std::string& cookie_line, - const CookieOptions& options); - - std::string GetCookiesWithOptions(const GURL& url, - const CookieOptions& options); - - void GetCookiesWithInfo(const GURL& url, - const CookieOptions& options, - std::string* cookie_line, - std::vector<CookieInfo>* cookie_infos); - - void DeleteCookie(const GURL& url, const std::string& cookie_name); - bool SetCookieWithCreationTime(const GURL& url, const std::string& cookie_line, const base::Time& creation_time); @@ -434,11 +407,8 @@ class NET_EXPORT CookieMonster : public CookieStore { // Note: this method should always be called with lock_ held. void InitIfNecessary() { if (!initialized_) { - if (store_) { + if (store_) InitStore(); - } else { - loaded_ = true; - } initialized_ = true; } } @@ -447,18 +417,6 @@ class NET_EXPORT CookieMonster : public CookieStore { // Should only be called by InitIfNecessary(). void InitStore(); - // Stores cookies loaded from the backing store and invokes any deferred - // calls. |beginning_time| should be the moment PersistentCookieStore::Load - // was invoked and is used for reporting histogram_time_load_. - void OnLoaded(base::TimeTicks beginning_time, - const std::vector<CanonicalCookie*>& cookies); - - // Stores the loaded cookies. - void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies); - - // Invokes deferred calls. - void InvokeQueue(); - // Checks that |cookies_| matches our invariants, and tries to repair any // inconsistencies. (In other words, it does not have duplicate cookies). void EnsureCookiesMapIsValid(); @@ -568,10 +526,6 @@ class NET_EXPORT CookieMonster : public CookieStore { // ugly and increment when we've seen the same time twice. base::Time CurrentTime(); - // Run the cookie request task if cookie loaded, otherwise added the task - // to task queue. - void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); - // Histogram variables; see CookieMonster::InitializeHistograms() in // cookie_monster.cc for details. base::Histogram* histogram_expiration_duration_minutes_; @@ -593,14 +547,6 @@ class NET_EXPORT CookieMonster : public CookieStore { // lazily in InitStoreIfNecessary(). bool initialized_; - // Indicates whether loading from the backend store is completed and - // calls may be immediately processed. - bool loaded_; - - // Queues calls to CookieMonster until loading from the backend store is - // completed. - std::queue<scoped_refptr<CookieMonsterTask> > queue_; - // Indicates whether this cookie monster uses the new effective domain // key scheme or not. ExpiryAndKeyScheme expiry_and_key_scheme_; @@ -915,12 +861,9 @@ class CookieMonster::PersistentCookieStore public: virtual ~PersistentCookieStore() {} - typedef base::Callback<void(const std::vector< - CookieMonster::CanonicalCookie*>&)> LoadedCallback; - // Initializes the store and retrieves the existing cookies. This will be // called only once at startup. - virtual bool Load(const LoadedCallback& loaded_callback) = 0; + virtual bool Load(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0; virtual void AddCookie(const CanonicalCookie& cc) = 0; virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0; |