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

Unified Diff: net/base/cookie_monster.cc

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.cc
===================================================================
--- net/base/cookie_monster.cc (revision 95998)
+++ net/base/cookie_monster.cc (working copy)
@@ -48,6 +48,7 @@
#include <set>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -419,6 +420,7 @@
CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate)
: initialized_(false),
+ loaded_(false),
expiry_and_key_scheme_(expiry_and_key_default_),
store_(store),
last_access_threshold_(
@@ -434,6 +436,7 @@
Delegate* delegate,
int last_access_threshold_milliseconds)
: initialized_(false),
+ loaded_(false),
expiry_and_key_scheme_(expiry_and_key_default_),
store_(store),
last_access_threshold_(base::TimeDelta::FromMilliseconds(
@@ -567,17 +570,457 @@
return (domain_string.empty() || domain_string[0] != '.');
}
+
+
+void InvokeSetCookiesCallbackOnOtherThread(
erikwright (departed) 2011/08/11 13:58:24 These functions should not be needed if you define
ycxiao 2011/08/12 02:35:24 Since callback is not reference counted thread saf
+ const CookieMonster::SetCookiesCallback& callback,
+ bool success) {
+ if (!callback.is_null())
+ callback.Run(success);
+}
+
+void InvokeGetCookieListCallbackOnOtherThread(
+ const CookieMonster::GetCookieListCallback& callback,
+ const CookieList& cookies) {
+ if (!callback.is_null())
+ callback.Run(cookies);
+}
+
+void InvokeDeleteCallbackOnOtherThread(
+ const CookieMonster::DeleteCallback& callback,
+ int num_deleted) {
+ if (!callback.is_null())
+ callback.Run(num_deleted);
+}
+
+void InvokeGetCookiesCallbackOnOtherThread(
+ const CookieMonster::GetCookiesCallback& callback,
+ const std::string& cookie) {
+ if (!callback.is_null())
+ callback.Run(cookie);
+}
+
+void InvokeGetCookieInfoCallbackOnOtherThread(
+ const CookieMonster::GetCookieInfoCallback& callback,
+ const std::string& cookie_line,
+ const std::vector<CookieStore::CookieInfo>& cookie_infos) {
+ if (!callback.is_null()) {
+ std::string line = cookie_line;
+ std::vector<CookieStore::CookieInfo> info = cookie_infos;
+ callback.Run(&line, &info);
+ }
+}
+
+// Asynchronous CookieMonster API
+
+void CookieMonster::SetCookieWithDetailsAsync(
+ 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,
+ const SetCookiesCallback& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+ parameters.name = name;
+ parameters.value = value;
+ parameters.domain = domain;
+ parameters.path =path;
+ parameters.expiration_time = expiration_time;
+ parameters.secure = secure;
+ parameters.http_only = http_only;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::SetCookieWithDetailsTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) {
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::GetAllCookiesTask,
+ this, callback, thread);
+ DoCookieTask(task);
+}
+
+
+void CookieMonster::GetAllCookiesForURLWithOptionsAsync(
+ const GURL& url,
+ const CookieOptions& options,
+ const GetCookieListCallback& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+ parameters.options = options;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task =
+ base::Bind(&CookieMonster::GetAllCookiesForURLWithOptionsTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::GetAllCookiesForURLAsync(
+ const GURL& url, const GetCookieListCallback& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::GetAllCookiesForURLTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::DeleteAllAsync(bool sync_to_store,
+ const DeleteCallback& callback) {
+ CookieAPIParameters parameters;
+ parameters.sync_to_store = sync_to_store;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::DeleteAllTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::DeleteAllCreatedBetweenAsync(
+ const Time& delete_begin, const Time& delete_end,
+ bool sync_to_store,
+ const DeleteCallback& callback) {
+ CookieAPIParameters parameters;
+ parameters.delete_begin = delete_begin;
+ parameters.delete_end = delete_end;
+ parameters.sync_to_store = sync_to_store;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::DeleteAllCreatedBetweenTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::DeleteAllForHostAsync(
+ const GURL& url, const DeleteCallback& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::DeleteAllForHostTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::DeleteCanonicalCookieAsync(
+ const CanonicalCookie& cookie,
+ const DeleteCookieCallback& callback) {
+ CanonicalCookie delete_cookie = cookie;
+ CookieAPIParameters parameters;
+ parameters.cookie = &delete_cookie;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::DeleteCanonicalCookieTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::SetCookieWithOptionsAsync(
+ const GURL& url,
+ const std::string& cookie_line,
+ const CookieOptions& options,
+ const SetCookiesCallback& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+ parameters.cookie_line = cookie_line;
+ parameters.options = options;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::SetCookieWithOptionsTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::GetCookiesWithOptionsAsync(
+ const GURL& url, const CookieOptions& options,
+ const GetCookiesCallback& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+ parameters.options = options;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::GetCookiesWithOptionsTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::GetCookiesWithInfoAsync(
+ const GURL& url,
+ const CookieOptions& options,
+ const GetCookieInfoCallback& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+ parameters.options = options;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::GetCookiesWithInfoTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::DeleteCookieAsync(const GURL& url,
+ const std::string& cookie_name,
+ const base::Closure& callback) {
+ GURL gurl = url;
+ CookieAPIParameters parameters;
+ parameters.url = &gurl;
+ parameters.name = cookie_name;
+
+ scoped_refptr<base::MessageLoopProxy> thread(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ base::Closure task = base::Bind(&CookieMonster::DeleteCookieTask,
+ this, callback, parameters, thread);
+ DoCookieTask(task);
+}
+
+void CookieMonster::DoCookieTask(const base::Closure& task) {
erikwright (departed) 2011/08/11 13:58:24 We discussed offline a more minimal use of locking
ycxiao 2011/08/12 02:35:24 Done.
+ DCHECK(!task.is_null());
+ InitIfNecessary();
+ base::AutoLock autolock(lock_);
+ if (loaded_) {
+ task.Run();
+ } else {
+ queue_.push_back(task);
+ }
+}
+
+void CookieMonster::SetCookieWithDetailsTask(
erikwright (departed) 2011/08/11 13:58:24 See comments in .h file regarding CookieMonsterTas
ycxiao 2011/08/12 02:35:24 Done.
+ const SetCookiesCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ bool success = SetCookieWithDetails(
+ *para.url, para.name, para.value, para.domain, para.path,
+ para.expiration_time, para.secure, para.http_only);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(success);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeSetCookiesCallbackOnOtherThread,
+ callback, success));
+ }
+ }
+}
+
+void CookieMonster::GetAllCookiesTask(
+ const GetCookieListCallback& callback,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ if (!callback.is_null()) {
+ CookieList cookies = GetAllCookies();
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(cookies);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeGetCookieListCallbackOnOtherThread,
+ callback, cookies));
+ }
+ }
+}
+
+void CookieMonster::GetAllCookiesForURLWithOptionsTask(
+ const GetCookieListCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ if (!callback.is_null()) {
+ CookieList cookies = GetAllCookiesForURLWithOptions(
+ *para.url, para.options);
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(cookies);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeGetCookieListCallbackOnOtherThread,
+ callback, cookies));
+ }
+ }
+}
+
+void CookieMonster::GetAllCookiesForURLTask(
+ const GetCookieListCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ if (!callback.is_null()) {
+ CookieList cookies = GetAllCookiesForURL(*para.url);
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(cookies);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeGetCookieListCallbackOnOtherThread,
+ callback, cookies));
+ }
+ }
+}
+
+void CookieMonster::DeleteAllTask(
+ const DeleteCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ int num_deleted = DeleteAll(para.sync_to_store);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(num_deleted);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeDeleteCallbackOnOtherThread,
+ callback, num_deleted));
+ }
+ }
+}
+
+void CookieMonster::DeleteAllCreatedBetweenTask(
+ const DeleteCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ int num_deleted = DeleteAllCreatedBetween(
+ para.delete_begin, para.delete_end, para.sync_to_store);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(num_deleted);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeDeleteCallbackOnOtherThread,
+ callback, num_deleted));
+ }
+ }
+}
+
+void CookieMonster::DeleteAllForHostTask(
+ const DeleteCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ int num_deleted = DeleteAllForHost(*para.url);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(num_deleted);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeDeleteCallbackOnOtherThread,
+ callback, num_deleted));
+ }
+ }
+}
+
+void CookieMonster::DeleteCanonicalCookieTask(
+ const DeleteCookieCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ bool result = DeleteCanonicalCookie(*para.cookie);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(result);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeSetCookiesCallbackOnOtherThread,
+ callback, result));
+ }
+ }
+}
+
+void CookieMonster::SetCookieWithOptionsTask(
+ const SetCookiesCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ bool result = SetCookieWithOptions(*para.url, para.cookie_line, para.options);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(result);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeSetCookiesCallbackOnOtherThread,
+ callback, result));
+ }
+ }
+}
+
+void CookieMonster::GetCookiesWithOptionsTask(
+ const GetCookiesCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ std::string cookie = GetCookiesWithOptions(*para.url, para.options);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(cookie);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeGetCookiesCallbackOnOtherThread,
+ callback, cookie));
+ }
+ }
+}
+
+void CookieMonster::GetCookiesWithInfoTask(
+ const GetCookieInfoCallback& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ if (!callback.is_null()) {
+ std::string cookie_line;
+ std::vector<CookieInfo> cookie_infos;
+ GetCookiesWithInfo(*para.url, para.options, &cookie_line, &cookie_infos);
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run(&cookie_line, &cookie_infos);
+ } else {
+ thread->PostTask(
+ FROM_HERE, base::Bind(&InvokeGetCookieInfoCallbackOnOtherThread,
+ callback, cookie_line, cookie_infos));
+ }
+ }
+}
+
+void CookieMonster::DeleteCookieTask(
+ const base::Closure& callback,
+ const CookieAPIParameters& para,
+ scoped_refptr<base::MessageLoopProxy> thread) {
+ DeleteCookie(*para.url, para.name);
+ if (!callback.is_null()) {
+ if (thread->BelongsToCurrentThread()) {
+ base::AutoUnlock autounlock(lock_);
+ callback.Run();
+ } else {
+ thread->PostTask(FROM_HERE, callback);
+ }
+ }
+}
+
bool CookieMonster::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) {
- base::AutoLock autolock(lock_);
+ lock_.AssertAcquired();
if (!HasCookieableScheme(url))
return false;
- InitIfNecessary();
-
Time creation_time = CurrentTime();
last_time_seen_ = creation_time;
@@ -600,20 +1043,7 @@
return SetCanonicalCookie(&cc, creation_time, options);
}
-void CookieMonster::SetCookieWithDetailsAsync(
- 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,
- const SetCookiesCallback& callback) {
- bool success_ = SetCookieWithDetails(url, name, value, domain, path,
- expiration_time, secure, http_only);
- if (!callback.is_null())
- callback.Run(success_);
-}
-
-bool CookieMonster::InitializeFrom(CookieMonster* cookie_monster) {
- net::CookieList list = cookie_monster->GetAllCookies();
-
+bool CookieMonster::InitializeFrom(const CookieList& list) {
base::AutoLock autolock(lock_);
InitIfNecessary();
for (net::CookieList::const_iterator iter = list.begin();
@@ -631,8 +1061,7 @@
}
CookieList CookieMonster::GetAllCookies() {
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
// This function is being called to scrape the cookie list for management UI
// or similar. We shouldn't show expired cookies in this list since it will
@@ -663,16 +1092,10 @@
return cookie_list;
}
-void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) {
- if (!callback.is_null())
- callback.Run(GetAllCookies());
-}
-
CookieList CookieMonster::GetAllCookiesForURLWithOptions(
const GURL& url,
const CookieOptions& options) {
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
std::vector<CanonicalCookie*> cookie_ptrs;
FindCookiesForHostAndDomain(url, options, false, &cookie_ptrs);
@@ -686,14 +1109,6 @@
return cookies;
}
-void CookieMonster::GetAllCookiesForURLWithOptionsAsync(
- const GURL& url,
- const CookieOptions& options,
- const GetCookieListCallback& callback) {
- if (!callback.is_null())
- callback.Run(GetAllCookiesForURLWithOptions(url, options));
-}
-
CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) {
CookieOptions options;
options.set_include_httponly();
@@ -701,16 +1116,8 @@
return GetAllCookiesForURLWithOptions(url, options);
}
-void CookieMonster::GetAllCookiesForURLAsync(
- const GURL& url, const GetCookieListCallback& callback) {
- if (!callback.is_null())
- callback.Run(GetAllCookiesForURL(url));
-}
-
int CookieMonster::DeleteAll(bool sync_to_store) {
- base::AutoLock autolock(lock_);
- if (sync_to_store)
- InitIfNecessary();
+ lock_.AssertAcquired();
int num_deleted = 0;
for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
@@ -728,8 +1135,7 @@
int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin,
const Time& delete_end,
bool sync_to_store) {
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
int num_deleted = 0;
for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
@@ -747,19 +1153,8 @@
return num_deleted;
}
-void CookieMonster::DeleteAllCreatedBetweenAsync(
- const Time& delete_begin, const Time& delete_end,
- bool sync_to_store,
- const DeleteCallback& callback) {
- int num_deleted = DeleteAllCreatedBetween(
- delete_begin, delete_end, sync_to_store);
- if (!callback.is_null())
- callback.Run(num_deleted);
-}
-
int CookieMonster::DeleteAllForHost(const GURL& url) {
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
if (!HasCookieableScheme(url))
return 0;
@@ -788,16 +1183,8 @@
return num_deleted;
}
-void CookieMonster::DeleteAllForHostAsync(
- const GURL& url, const DeleteCallback& callback) {
- int num_deleted = DeleteAllForHost(url);
- if (!callback.is_null())
- callback.Run(num_deleted);
-}
-
bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) {
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain()));
its.first != its.second; ++its.first) {
@@ -810,14 +1197,6 @@
return false;
}
-void CookieMonster::DeleteCanonicalCookieAsync(
- const CanonicalCookie& cookie,
- const DeleteCookieCallback& callback) {
- bool result = DeleteCanonicalCookie(cookie);
- if (!callback.is_null())
- callback.Run(result);
-}
-
void CookieMonster::SetCookieableSchemes(
const char* schemes[], size_t num_schemes) {
base::AutoLock autolock(lock_);
@@ -860,31 +1239,18 @@
bool CookieMonster::SetCookieWithOptions(const GURL& url,
const std::string& cookie_line,
const CookieOptions& options) {
- base::AutoLock autolock(lock_);
+ lock_.AssertAcquired();
if (!HasCookieableScheme(url)) {
return false;
}
- InitIfNecessary();
-
return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options);
}
-void CookieMonster::SetCookieWithOptionsAsync(
- const GURL& url,
- const std::string& cookie_line,
- const CookieOptions& options,
- const SetCookiesCallback& callback) {
- bool result = SetCookieWithOptions(url, cookie_line, options);
- if (!callback.is_null())
- callback.Run(result);
-}
-
std::string CookieMonster::GetCookiesWithOptions(const GURL& url,
const CookieOptions& options) {
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
if (!HasCookieableScheme(url))
return std::string();
@@ -904,14 +1270,6 @@
return cookie_line;
}
-void CookieMonster::GetCookiesWithOptionsAsync(
- const GURL& url, const CookieOptions& options,
- const GetCookiesCallback& callback) {
- std::string cookie = GetCookiesWithOptions(url, options);
- if (!callback.is_null())
- callback.Run(cookie);
-}
-
void CookieMonster::GetCookiesWithInfo(const GURL& url,
const CookieOptions& options,
std::string* cookie_line,
@@ -919,8 +1277,7 @@
DCHECK(cookie_line->empty());
DCHECK(cookie_infos->empty());
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
if (!HasCookieableScheme(url))
return;
@@ -939,22 +1296,9 @@
histogram_time_mac_->AddTime(TimeTicks::Now() - mac_start_time);
}
-void CookieMonster::GetCookiesWithInfoAsync(
- const GURL& url,
- const CookieOptions& options,
- const GetCookieInfoCallback& callback) {
- std::string cookie_line;
- std::vector<CookieInfo> cookie_infos;
- GetCookiesWithInfo(url, options, &cookie_line, &cookie_infos);
-
- if (!callback.is_null())
- callback.Run(&cookie_line, &cookie_infos);
-}
-
void CookieMonster::DeleteCookie(const GURL& url,
const std::string& cookie_name) {
- base::AutoLock autolock(lock_);
- InitIfNecessary();
+ lock_.AssertAcquired();
if (!HasCookieableScheme(url))
return;
@@ -984,25 +1328,20 @@
}
}
-void CookieMonster::DeleteCookieAsync(const GURL& url,
- const std::string& cookie_name,
- const base::Closure& callback) {
- DeleteCookie(url, cookie_name);
- if (!callback.is_null())
- callback.Run();
-}
-
CookieMonster* CookieMonster::GetCookieMonster() {
return this;
}
CookieMonster::~CookieMonster() {
+ base::AutoLock autolock(lock_);
DeleteAll(false);
}
bool CookieMonster::SetCookieWithCreationTime(const GURL& url,
const std::string& cookie_line,
const base::Time& creation_time) {
+ // Only for CookieMonster unit test usage.
erikwright (departed) 2011/08/11 13:58:24 DCHECK(!store_) << "This method is only to be used
ycxiao 2011/08/12 02:35:24 Done.
+ DCHECK(!store_);
base::AutoLock autolock(lock_);
if (!HasCookieableScheme(url)) {
@@ -1016,17 +1355,15 @@
void CookieMonster::InitStore() {
DCHECK(store_) << "Store must exist to initialize";
+ store_->Load(base::Bind(&CookieMonster::OnLoaded, this));
+}
- TimeTicks beginning_time(TimeTicks::Now());
-
+void CookieMonster::OnLoaded(const std::vector<CanonicalCookie*>& cookies) {
// Initialize the store and sync in any saved persistent cookies. We don't
// care if it's expired, insert it so it can be garbage collected, removed,
// and sync'd.
- std::vector<CanonicalCookie*> cookies;
- // Reserve space for the maximum amount of cookies a database should have.
- // This prevents multiple vector growth / copies as we append cookies.
- cookies.reserve(kMaxCookies);
- store_->Load(&cookies);
+ base::AutoLock autolock(lock_);
+ TimeTicks beginning_time(TimeTicks::Now());
// Avoid ever letting cookies with duplicate creation times into the store;
// that way we don't have to worry about what sections of code are safe
@@ -1067,8 +1404,22 @@
EnsureCookiesMapIsValid();
histogram_time_load_->AddTime(TimeTicks::Now() - beginning_time);
+
+ // Invoke the task queue of cookie request.
+ InvokeQueue();
}
+void CookieMonster::InvokeQueue() {
erikwright (departed) 2011/08/11 13:58:24 Refer to offline discussion about minimal lock hol
ycxiao 2011/08/12 02:35:24 Done.
+ while (true) {
+ if (queue_.empty()) {
+ loaded_ = true;
+ break;
+ }
+ queue_.front().Run();
+ queue_.pop_front();
+ }
+}
+
void CookieMonster::EnsureCookiesMapIsValid() {
lock_.AssertAcquired();
@@ -2152,6 +2503,31 @@
}
CookieMonster::CanonicalCookie* CookieMonster::CanonicalCookie::Create(
+ const GURL& url,
+ const ParsedCookie& pc) {
+ if (!pc.IsValid()) {
+ return NULL;
+ }
+
+ std::string domain_string;
+ if (!GetCookieDomain(url, pc, &domain_string)) {
+ return NULL;
+ }
+ std::string path_string = CanonPath(url, pc);
+ std::string mac_key = pc.HasMACKey() ? pc.MACKey() : std::string();
+ std::string mac_algorithm = pc.HasMACAlgorithm() ?
+ pc.MACAlgorithm() : std::string();
+ Time creation_time = Time::Now();
+ Time expiration_time;
+ if (pc.HasExpires())
+ expiration_time = net::CookieMonster::ParseCookieTime(pc.Expires());
+
+ return (Create(url, pc.Name(), pc.Value(), domain_string, path_string,
+ mac_key, mac_algorithm, creation_time, expiration_time,
+ pc.IsSecure(), pc.IsHttpOnly()));
+}
+
+CookieMonster::CanonicalCookie* CookieMonster::CanonicalCookie::Create(
const GURL& url,
const std::string& name,
const std::string& value,

Powered by Google App Engine
This is Rietveld 408576698