Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: net/base/cookie_monster.h

Issue 7598001: Remove the old synchronous CookieMonster API. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/cookie_monster.h
===================================================================
--- net/base/cookie_monster.h (revision 95998)
+++ net/base/cookie_monster.h (working copy)
@@ -8,6 +8,7 @@
#define NET_BASE_COOKIE_MONSTER_H_
#pragma once
+#include <deque>
#include <map>
#include <string>
#include <utility>
@@ -17,6 +18,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop_proxy.h"
erikwright (departed) 2011/08/11 13:58:24 Why is this added here?
ycxiao 2011/08/12 02:35:24 I think I can move this to .cc, and added an "clas
#include "base/synchronization/lock.h"
#include "base/task.h"
#include "base/time.h"
@@ -138,19 +140,20 @@
// 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 |cookie_monster| into this
+ // instance.
+ bool InitializeFrom(const CookieList& list);
erikwright (departed) 2011/08/11 13:58:24 Who uses this? Must it be public? If nothing else,
ycxiao 2011/08/12 02:35:24 The login_uitls.cc create this function. The previ
+
+ typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback;
+ typedef base::Callback<void(int num_deleted)> DeleteCallback;
+ typedef SetCookiesCallback 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,
@@ -160,17 +163,10 @@
bool secure, bool http_only,
const SetCookiesCallback& callback);
-
- // Helper function that adds all cookies from |cookie_monster| into this
- // instance.
- bool InitializeFrom(CookieMonster* cookie_monster);
-
// 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
@@ -178,8 +174,6 @@
// 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,
@@ -187,19 +181,16 @@
// 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.
- int DeleteAll(bool sync_to_store);
+ void DeleteAllAsync(bool sync_to_store,
+ const DeleteCallback& callback);
+
// 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,
@@ -209,16 +200,10 @@
// 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);
@@ -260,10 +245,6 @@
// Sets the cookies specified by |cookie_list| returned from |url|
// with options |options| in effect.
- virtual bool SetCookieWithOptions(const GURL& url,
- const std::string& cookie_line,
- const CookieOptions& options);
-
virtual void SetCookieWithOptionsAsync(const GURL& url,
erikwright (departed) 2011/08/11 13:58:24 Add OVERRIDE as appropriate.
ycxiao 2011/08/12 02:35:24 Done.
const std::string& cookie_line,
const CookieOptions& options,
@@ -272,25 +253,16 @@
// 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);
- 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);
@@ -304,6 +276,9 @@
// in the function trip. TODO(rdsmith):Remove hack.
void ValidateMap(int arg);
+ // Reads the existing cookies loaded form the backing store.
+ void OnLoaded(const std::vector<CanonicalCookie*>& cookies);
erikwright (departed) 2011/08/11 13:58:24 Why is this not private?
ycxiao 2011/08/12 02:35:24 You are right, it should be.
+
// The default list of schemes the cookie monster can handle.
static const char* kDefaultCookieableSchemes[];
static const int kDefaultCookieableSchemesCount;
@@ -397,6 +372,45 @@
virtual ~CookieMonster();
+ 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,
+ bool sync_to_store);
+
+ 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);
@@ -407,8 +421,11 @@
// Note: this method should always be called with lock_ held.
void InitIfNecessary() {
if (!initialized_) {
- if (store_)
+ if (store_) {
InitStore();
+ } else {
+ loaded_ = true;
+ }
initialized_ = true;
}
}
@@ -417,6 +434,10 @@
// Should only be called by InitIfNecessary().
void InitStore();
+ // Invoke the queueing calls of CookieMonster when loading cookies from
+ // the back store is complete.
+ 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();
@@ -526,6 +547,95 @@
// ugly and increment when we've seen the same time twice.
base::Time CurrentTime();
+ // Store the parameters of cookie monster API.
+ class CookieAPIParameters {
erikwright (departed) 2011/08/11 13:58:24 In cookie_monster.cc, define a class named CookieM
ycxiao 2011/08/12 02:35:24 Done.
+ public:
+ CookieAPIParameters()
+ : secure(false),
+ http_only(false),
+ sync_to_store(false) { }
+
+ GURL* url;
+ CookieOptions options;
+ std::string name;
+ std::string value;
+ std::string domain;
+ std::string path;
+ std::string cookie_line;
+ bool secure;
+ bool http_only;
+ bool sync_to_store;
+ base::Time delete_begin;
+ base::Time delete_end;
+ base::Time expiration_time;
+ CanonicalCookie* cookie;
+ };
+
+ // Run the cookie request task if cookie loaded, otherwise added the task
+ // to task queue.
+ void DoCookieTask(const base::Closure& task);
erikwright (departed) 2011/08/11 13:58:24 All of these task methods go away and become class
ycxiao 2011/08/12 02:35:24 Done.
+
+ // Task functions for queueing the coming request.
+
+ void SetCookieWithDetailsTask(
+ const SetCookiesCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void GetAllCookiesTask(
+ const GetCookieListCallback& callback,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void GetAllCookiesForURLWithOptionsTask(
+ const GetCookieListCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void GetAllCookiesForURLTask(
+ const GetCookieListCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void DeleteAllTask(
+ const DeleteCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void DeleteAllCreatedBetweenTask(
+ const DeleteCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void DeleteAllForHostTask(
+ const DeleteCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void DeleteCanonicalCookieTask(
+ const DeleteCookieCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void SetCookieWithOptionsTask(
+ const SetCookiesCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void GetCookiesWithOptionsTask(
+ const GetCookiesCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void GetCookiesWithInfoTask(
+ const GetCookieInfoCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
+ void DeleteCookieTask(
+ const base::Closure& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread);
+
// Histogram variables; see CookieMonster::InitializeHistograms() in
// cookie_monster.cc for details.
base::Histogram* histogram_expiration_duration_minutes_;
@@ -547,6 +657,13 @@
// lazily in InitStoreIfNecessary().
bool initialized_;
+ // Indicate whether the cookies are loaded from disk.
erikwright (departed) 2011/08/11 13:58:24 "Indicates whether loading from the backend store
ycxiao 2011/08/12 02:35:24 Done.
+ bool loaded_;
+
+ // Queue the calls of CookieMonster while the loadind form the back
erikwright (departed) 2011/08/11 13:58:24 "Queues calls to CookieMonster until loading from
ycxiao 2011/08/12 02:35:24 Done.
+ // store haven't complete.
+ std::deque<base::Closure> queue_;
erikwright (departed) 2011/08/11 13:58:24 Can you define this as std::queue<base::Closure> i
ycxiao 2011/08/12 02:35:24 Done.
+
// Indicates whether this cookie monster uses the new effective domain
// key scheme or not.
ExpiryAndKeyScheme expiry_and_key_scheme_;
@@ -617,6 +734,12 @@
// Supports the default copy constructor.
+ // Creates a canonical cookie from parsed cookie.
+ // Canonicalizes and validates inputs. May return NULL if an attribute
+ // value is invalid.
+ static CanonicalCookie* Create(const GURL& url,
+ const ParsedCookie& pc);
+
// Creates a canonical cookie from unparsed attribute values.
// Canonicalizes and validates inputs. May return NULL if an attribute
// value is invalid.
@@ -855,9 +978,12 @@
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(std::vector<CookieMonster::CanonicalCookie*>* cookies) = 0;
+ virtual bool Load(const LoadedCallback& loaded_callback) = 0;
virtual void AddCookie(const CanonicalCookie& cc) = 0;
virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0;

Powered by Google App Engine
This is Rietveld 408576698