summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-21 16:04:50 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-21 16:04:50 +0000
commit34d18e40e285579af3b5fae02ad21ce3d94745be (patch)
treef69d053360091d15a6adef6095c54f947a113812 /chrome
parent379418079f6f422db211d61f1b1142e4025b730c (diff)
downloadchromium_src-34d18e40e285579af3b5fae02ad21ce3d94745be.zip
chromium_src-34d18e40e285579af3b5fae02ad21ce3d94745be.tar.gz
chromium_src-34d18e40e285579af3b5fae02ad21ce3d94745be.tar.bz2
Revert 50296 (Causes DCHECK failures) - Make CookieMonster NonThreadSafe.
Made ExtensionFunction RefCountedThreadSafe so it can be posted to different threads. Used WaitableEvent in AutomationProvider. BUG=44083 Review URL: http://codereview.chromium.org/2756003 TBR=willchan@chromium.org Review URL: http://codereview.chromium.org/2860012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider.cc125
-rw-r--r--chrome/browser/extensions/extension_cookies_api.cc252
-rw-r--r--chrome/browser/extensions/extension_cookies_api.h79
-rw-r--r--chrome/browser/extensions/extension_cookies_helpers.cc5
-rw-r--r--chrome/browser/extensions/extension_cookies_helpers.h4
-rw-r--r--chrome/browser/extensions/extension_data_deleter.cc26
-rw-r--r--chrome/browser/extensions/extension_data_deleter.h4
-rw-r--r--chrome/browser/extensions/extension_function.h7
-rw-r--r--chrome/browser/net/cookie_policy_browsertest.cc62
9 files changed, 128 insertions, 436 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 5491459..3dccaaa 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -18,11 +18,9 @@
#include "base/process_util.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
-#include "base/task.h"
#include "base/thread.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
-#include "base/waitable_event.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/app/chrome_version_info.h"
#include "chrome/browser/app_modal_dialog.h"
@@ -1119,112 +1117,6 @@ Browser* AutomationProvider::FindAndActivateTab(
return browser;
}
-namespace {
-
-class GetCookiesTask : public Task {
- public:
- GetCookiesTask(const GURL& url,
- URLRequestContextGetter* context_getter,
- base::WaitableEvent* event,
- std::string* cookies)
- : url_(url),
- context_getter_(context_getter),
- event_(event),
- cookies_(cookies) {}
-
- virtual void Run() {
- *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_);
- event_->Signal();
- }
-
- private:
- const GURL& url_;
- URLRequestContextGetter* const context_getter_;
- base::WaitableEvent* const event_;
- std::string* const cookies_;
-
- DISALLOW_COPY_AND_ASSIGN(GetCookiesTask);
-};
-
-std::string GetCookiesForURL(
- const GURL& url,
- URLRequestContextGetter* context_getter) {
- std::string cookies;
- base::WaitableEvent event(true /* manual reset */,
- false /* not initially signaled */);
- CHECK(ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new GetCookiesTask(url, context_getter, &event, &cookies)));
- event.Wait();
- return cookies;
-}
-
-class SetCookieTask : public Task {
- public:
- SetCookieTask(const GURL& url,
- const std::string& value,
- URLRequestContextGetter* context_getter,
- base::WaitableEvent* event,
- bool* rv)
- : url_(url),
- value_(value),
- context_getter_(context_getter),
- event_(event),
- rv_(rv) {}
-
- virtual void Run() {
- *rv_ = context_getter_->GetCookieStore()->SetCookie(url_, value_);
- event_->Signal();
- }
-
- private:
- const GURL& url_;
- const std::string& value_;
- URLRequestContextGetter* const context_getter_;
- base::WaitableEvent* const event_;
- bool* const rv_;
-
- DISALLOW_COPY_AND_ASSIGN(SetCookieTask);
-};
-
-bool SetCookieForURL(
- const GURL& url,
- const std::string& value,
- URLRequestContextGetter* context_getter) {
- base::WaitableEvent event(true /* manual reset */,
- false /* not initially signaled */);
- bool rv = false;
- CHECK(ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new SetCookieTask(url, value, context_getter, &event, &rv)));
- event.Wait();
- return rv;
-}
-
-class DeleteCookieTask : public Task {
- public:
- DeleteCookieTask(const GURL& url,
- const std::string& name,
- const scoped_refptr<URLRequestContextGetter>& context_getter)
- : url_(url),
- name_(name),
- context_getter_(context_getter) {}
-
- virtual void Run() {
- net::CookieStore* cookie_store = context_getter_->GetCookieStore();
- cookie_store->DeleteCookie(url_, name_);
- }
-
- private:
- const GURL url_;
- const std::string name_;
- const scoped_refptr<URLRequestContextGetter> context_getter_;
-
- DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask);
-};
-
-} // namespace
-
void AutomationProvider::GetCookies(const GURL& url, int handle,
int* value_size,
std::string* value) {
@@ -1238,7 +1130,9 @@ void AutomationProvider::GetCookies(const GURL& url, int handle,
if (!request_context.get())
request_context = tab->profile()->GetRequestContext();
- *value = GetCookiesForURL(url, request_context.get());
+ net::CookieStore* cookie_store = request_context->GetCookieStore();
+
+ *value = cookie_store->GetCookies(url);
*value_size = static_cast<int>(value->size());
}
}
@@ -1257,7 +1151,11 @@ void AutomationProvider::SetCookie(const GURL& url,
if (!request_context.get())
request_context = tab->profile()->GetRequestContext();
- if (SetCookieForURL(url, value, request_context.get()))
+ // Since we are running on the UI thread don't call GetURLRequestContext().
+ scoped_refptr<net::CookieStore> cookie_store =
+ request_context->GetCookieStore();
+
+ if (cookie_store->SetCookie(url, value))
*response_value = 1;
}
}
@@ -1268,10 +1166,9 @@ void AutomationProvider::DeleteCookie(const GURL& url,
*success = false;
if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
NavigationController* tab = tab_tracker_->GetResource(handle);
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new DeleteCookieTask(url, cookie_name,
- tab->profile()->GetRequestContext()));
+ net::CookieStore* cookie_store =
+ tab->profile()->GetRequestContext()->GetCookieStore();
+ cookie_store->DeleteCookie(url, cookie_name);
*success = true;
}
}
diff --git a/chrome/browser/extensions/extension_cookies_api.cc b/chrome/browser/extensions/extension_cookies_api.cc
index c20d1eb..86cc0d8 100644
--- a/chrome/browser/extensions/extension_cookies_api.cc
+++ b/chrome/browser/extensions/extension_cookies_api.cc
@@ -7,9 +7,7 @@
#include "chrome/browser/extensions/extension_cookies_api.h"
#include "base/json/json_writer.h"
-#include "base/task.h"
#include "chrome/browser/browser_list.h"
-#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extension_cookies_api_constants.h"
#include "chrome/browser/extensions/extension_cookies_helpers.h"
#include "chrome/browser/extensions/extension_message_service.h"
@@ -101,10 +99,10 @@ bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url,
return true;
}
-bool CookiesFunction::ParseStoreContext(const DictionaryValue* details,
- URLRequestContextGetter** context,
- std::string* store_id) {
- DCHECK(details && (context || store_id));
+bool CookiesFunction::ParseCookieStore(const DictionaryValue* details,
+ net::CookieStore** store,
+ std::string* store_id) {
+ DCHECK(details && (store || store_id));
Profile* store_profile = NULL;
if (details->HasKey(keys::kStoreIdKey)) {
// The store ID was explicitly specified in the details dictionary.
@@ -132,17 +130,14 @@ bool CookiesFunction::ParseStoreContext(const DictionaryValue* details,
store_profile = current_browser->profile();
}
DCHECK(store_profile);
-
- if (context)
- *context = store_profile->GetRequestContext();
+ if (store)
+ *store = store_profile->GetRequestContext()->GetCookieStore();
if (store_id)
- *store_id = extension_cookies_helpers::GetStoreIdFromProfile(store_profile);
-
+ *store_id =
+ extension_cookies_helpers::GetStoreIdFromProfile(store_profile);
return true;
}
-GetCookieFunction::GetCookieFunction() {}
-
bool GetCookieFunction::RunImpl() {
// Return false if the arguments are malformed.
DictionaryValue* details;
@@ -150,115 +145,62 @@ bool GetCookieFunction::RunImpl() {
DCHECK(details);
// Read/validate input parameters.
- if (!ParseUrl(details, &url_, true))
+ GURL url;
+ if (!ParseUrl(details, &url, true))
return false;
+ std::string name;
// Get the cookie name string or return false.
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_));
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name));
- URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details, &store_context, &store_id_))
+ net::CookieStore* cookie_store;
+ std::string store_id;
+ if (!ParseCookieStore(details, &cookie_store, &store_id))
return false;
+ DCHECK(cookie_store && !store_id.empty());
- DCHECK(store_context && !store_id_.empty());
- store_context_ = store_context;
-
- bool rv = ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this, &GetCookieFunction::GetCookieOnIOThread));
- DCHECK(rv);
-
- // Will finish asynchronously.
- return true;
-}
-
-void GetCookieFunction::GetCookieOnIOThread() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- net::CookieStore* cookie_store = store_context_->GetCookieStore();
- cookie_list_ =
- extension_cookies_helpers::GetCookieListFromStore(cookie_store, url_);
-
- bool rv = ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &GetCookieFunction::RespondOnUIThread));
- DCHECK(rv);
-}
-
-void GetCookieFunction::RespondOnUIThread() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
+ net::CookieMonster::CookieList cookie_list =
+ extension_cookies_helpers::GetCookieListFromStore(cookie_store, url);
net::CookieMonster::CookieList::iterator it;
- for (it = cookie_list_.begin(); it != cookie_list_.end(); ++it) {
+ for (it = cookie_list.begin(); it != cookie_list.end(); ++it) {
// Return the first matching cookie. Relies on the fact that the
// CookieMonster retrieves them in reverse domain-length order.
const net::CookieMonster::CanonicalCookie& cookie = it->second;
- if (cookie.Name() == name_) {
+ if (cookie.Name() == name) {
result_.reset(
- extension_cookies_helpers::CreateCookieValue(*it, store_id_));
- break;
+ extension_cookies_helpers::CreateCookieValue(*it, store_id));
+ return true;
}
}
-
// The cookie doesn't exist; return null.
- if (it == cookie_list_.end())
- result_.reset(Value::CreateNullValue());
-
- SendResponse(true);
+ result_.reset(Value::CreateNullValue());
+ return true;
}
-GetAllCookiesFunction::GetAllCookiesFunction() {}
-
bool GetAllCookiesFunction::RunImpl() {
// Return false if the arguments are malformed.
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details_));
- DCHECK(details_);
+ DictionaryValue* details;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
+ DCHECK(details);
// Read/validate input parameters.
- if (details_->HasKey(keys::kUrlKey) && !ParseUrl(details_, &url_, false))
+ GURL url;
+ if (details->HasKey(keys::kUrlKey) && !ParseUrl(details, &url, false))
return false;
- URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details_, &store_context, &store_id_))
+ net::CookieStore* cookie_store;
+ std::string store_id;
+ if (!ParseCookieStore(details, &cookie_store, &store_id))
return false;
- DCHECK(store_context);
- store_context_ = store_context;
+ DCHECK(cookie_store);
- bool rv = ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this, &GetAllCookiesFunction::GetAllCookiesOnIOThread));
- DCHECK(rv);
-
- // Will finish asynchronously.
+ ListValue* matching_list = new ListValue();
+ extension_cookies_helpers::AppendMatchingCookiesToList(
+ cookie_store, store_id, url, details, GetExtension(), matching_list);
+ result_.reset(matching_list);
return true;
}
-void GetAllCookiesFunction::GetAllCookiesOnIOThread() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- net::CookieStore* cookie_store = store_context_->GetCookieStore();
- cookie_list_ =
- extension_cookies_helpers::GetCookieListFromStore(cookie_store, url_);
-
- bool rv = ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &GetAllCookiesFunction::RespondOnUIThread));
- DCHECK(rv);
-}
-
-void GetAllCookiesFunction::RespondOnUIThread() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
- const Extension* extension = GetExtension();
- if (extension) {
- ListValue* matching_list = new ListValue();
- extension_cookies_helpers::AppendMatchingCookiesToList(
- cookie_list_, store_id_, url_, details_, GetExtension(), matching_list);
- result_.reset(matching_list);
- }
- SendResponse(true);
-}
-
-SetCookieFunction::SetCookieFunction() : secure_(false), http_only_(false) {}
-
bool SetCookieFunction::RunImpl() {
// Return false if the arguments are malformed.
DictionaryValue* details;
@@ -266,26 +208,36 @@ bool SetCookieFunction::RunImpl() {
DCHECK(details);
// Read/validate input parameters.
- if (!ParseUrl(details, &url_, true))
+ GURL url;
+ if (!ParseUrl(details, &url, true))
return false;
// The macros below return false if argument types are not as expected.
- if (details->HasKey(keys::kNameKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_));
- if (details->HasKey(keys::kValueKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kValueKey, &value_));
- if (details->HasKey(keys::kDomainKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kDomainKey, &domain_));
- if (details->HasKey(keys::kPathKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kPathKey, &path_));
-
+ std::string name;
+ if (details->HasKey(keys::kNameKey)) {
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name));
+ }
+ std::string value;
+ if (details->HasKey(keys::kValueKey)) {
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kValueKey, &value));
+ }
+ std::string domain;
+ if (details->HasKey(keys::kDomainKey)) {
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kDomainKey, &domain));
+ }
+ std::string path;
+ if (details->HasKey(keys::kPathKey)) {
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kPathKey, &path));
+ }
+ bool secure = false;
if (details->HasKey(keys::kSecureKey)) {
- EXTENSION_FUNCTION_VALIDATE(
- details->GetBoolean(keys::kSecureKey, &secure_));
+ EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(keys::kSecureKey, &secure));
}
+ bool http_only = false;
if (details->HasKey(keys::kHttpOnlyKey)) {
EXTENSION_FUNCTION_VALIDATE(
- details->GetBoolean(keys::kHttpOnlyKey, &http_only_));
+ details->GetBoolean(keys::kHttpOnlyKey, &http_only));
}
+ base::Time expiration_time;
if (details->HasKey(keys::kExpirationDateKey)) {
Value* expiration_date_value;
EXTENSION_FUNCTION_VALIDATE(details->Get(keys::kExpirationDateKey,
@@ -300,73 +252,24 @@ bool SetCookieFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(
expiration_date_value->GetAsReal(&expiration_date));
}
- expiration_time_ = base::Time::FromDoubleT(expiration_date);
+ expiration_time = base::Time::FromDoubleT(expiration_date);
}
- URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details, &store_context, NULL))
+ net::CookieStore* cookie_store;
+ if (!ParseCookieStore(details, &cookie_store, NULL))
return false;
- DCHECK(store_context);
- store_context_ = store_context;
-
- bool rv = ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this, &SetCookieFunction::SetCookieOnIOThread));
- DCHECK(rv);
+ DCHECK(cookie_store);
- // Will finish asynchronously.
- return true;
-}
-
-void SetCookieFunction::SetCookieOnIOThread() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- net::CookieMonster* cookie_monster =
- store_context_->GetCookieStore()->GetCookieMonster();
- success_ = cookie_monster->SetCookieWithDetails(
- url_, name_, value_, domain_, path_, expiration_time_,
- secure_, http_only_);
-
- bool rv = ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &SetCookieFunction::RespondOnUIThread));
- DCHECK(rv);
-}
-
-void SetCookieFunction::RespondOnUIThread() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- if (!success_) {
+ if (!cookie_store->GetCookieMonster()->SetCookieWithDetails(
+ url, name, value, domain, path, expiration_time, secure,
+ http_only)) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
- keys::kCookieSetFailedError, name_);
+ keys::kCookieSetFailedError, name);
+ return false;
}
- SendResponse(success_);
+ return true;
}
-namespace {
-
-class RemoveCookieTask : public Task {
- public:
- RemoveCookieTask(const GURL& url,
- const std::string& name,
- const scoped_refptr<URLRequestContextGetter>& context_getter)
- : url_(url),
- name_(name),
- context_getter_(context_getter) {}
-
- virtual void Run() {
- net::CookieStore* cookie_store = context_getter_->GetCookieStore();
- cookie_store->DeleteCookie(url_, name_);
- }
-
- private:
- const GURL url_;
- const std::string name_;
- const scoped_refptr<URLRequestContextGetter> context_getter_;
-
- DISALLOW_COPY_AND_ASSIGN(RemoveCookieTask);
-};
-
-} // namespace
-
bool RemoveCookieFunction::RunImpl() {
// Return false if the arguments are malformed.
DictionaryValue* details;
@@ -382,19 +285,12 @@ bool RemoveCookieFunction::RunImpl() {
// Get the cookie name string or return false.
EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name));
- URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details, &store_context, NULL))
+ net::CookieStore* cookie_store;
+ if (!ParseCookieStore(details, &cookie_store, NULL))
return false;
- DCHECK(store_context);
-
- // We don't bother to synchronously wait for the result here, because
- // CookieMonster is only ever accessed on the IO thread, so any other accesses
- // should happen after this.
- bool rv = ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new RemoveCookieTask(url, name, store_context));
- DCHECK(rv);
+ DCHECK(cookie_store);
+ cookie_store->DeleteCookie(url, name);
return true;
}
diff --git a/chrome/browser/extensions/extension_cookies_api.h b/chrome/browser/extensions/extension_cookies_api.h
index a250524..c230b01 100644
--- a/chrome/browser/extensions/extension_cookies_api.h
+++ b/chrome/browser/extensions/extension_cookies_api.h
@@ -10,16 +10,14 @@
#include <string>
-#include "base/ref_counted.h"
#include "base/singleton.h"
-#include "base/time.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/net/chrome_cookie_notification_details.h"
#include "chrome/common/notification_registrar.h"
-#include "googleurl/src/gurl.h"
-#include "net/base/cookie_monster.h"
-class URLRequestContextGetter;
+namespace net {
+class CookieStore;
+} // namespace net
// Observes CookieMonster notifications and routes them as events to the
// extension system.
@@ -60,12 +58,10 @@ class ExtensionCookiesEventRouter : public NotificationObserver {
// Serves as a base class for all cookies API functions, and defines some
// common functionality for parsing cookies API function arguments.
-// Note that all of the functions in this file derive from
-// AsyncExtensionFunction, and are not threadsafe, so they should not be
-// concurrently accessed from multiple threads. They modify |result_| and other
-// member variables directly.
-// See chrome/browser/extensions/extension_function.h for more information.
-class CookiesFunction : public AsyncExtensionFunction {
+// Note that all of the functions in this file derive from ExtensionFunction,
+// and are not threadsafe. They modify the result_ member variable directly;
+// see chrome/browser/extensions/extension_function.h for more information.
+class CookiesFunction : public SyncExtensionFunction {
protected:
// Looks for a 'url' value in the given details dictionary and constructs a
// GURL from it. Returns false and assigns the internal error_ value if the
@@ -76,84 +72,41 @@ class CookiesFunction : public AsyncExtensionFunction {
bool check_host_permissions);
// Checks the given details dictionary for a 'storeId' value, and retrieves
- // the cookie store context and the store ID associated with it. If the
- // 'storeId' value isn't found in the dictionary, the current execution
- // context's cookie store context is retrieved. Returns false on error and
- // assigns the internal error_ value if that occurs.
+ // the cookie store and the store ID associated with it. If the 'storeId'
+ // value isn't found in the dictionary, the current execution context's
+ // cookie store is retrieved. Returns false on error and assigns the
+ // internal error_ value if that occurs.
// At least one of the output parameters store and store_id should be
- // non-NULL.
- bool ParseStoreContext(const DictionaryValue* details,
- URLRequestContextGetter** context,
- std::string* store_id);
+ // non-null.
+ bool ParseCookieStore(const DictionaryValue* details,
+ net::CookieStore** store, std::string* store_id);
};
// Implements the experimental.cookies.get() extension function.
class GetCookieFunction : public CookiesFunction {
public:
- GetCookieFunction();
virtual bool RunImpl();
DECLARE_EXTENSION_FUNCTION_NAME("experimental.cookies.get")
-
- private:
- void GetCookieOnIOThread();
- void RespondOnUIThread();
-
- std::string name_;
- GURL url_;
- std::string store_id_;
- scoped_refptr<URLRequestContextGetter> store_context_;
- net::CookieMonster::CookieList cookie_list_;
};
// Implements the experimental.cookies.getAll() extension function.
class GetAllCookiesFunction : public CookiesFunction {
public:
- GetAllCookiesFunction();
virtual bool RunImpl();
DECLARE_EXTENSION_FUNCTION_NAME("experimental.cookies.getAll")
-
- private:
- void GetAllCookiesOnIOThread();
- void RespondOnUIThread();
-
- DictionaryValue* details_;
- GURL url_;
- std::string store_id_;
- scoped_refptr<URLRequestContextGetter> store_context_;
- net::CookieMonster::CookieList cookie_list_;
};
// Implements the experimental.cookies.set() extension function.
class SetCookieFunction : public CookiesFunction {
public:
- SetCookieFunction();
virtual bool RunImpl();
DECLARE_EXTENSION_FUNCTION_NAME("experimental.cookies.set")
-
- private:
- void SetCookieOnIOThread();
- void RespondOnUIThread();
-
- GURL url_;
- std::string name_;
- std::string value_;
- std::string domain_;
- std::string path_;
- bool secure_;
- bool http_only_;
- base::Time expiration_time_;
- bool success_;
- scoped_refptr<URLRequestContextGetter> store_context_;
};
// Implements the experimental.cookies.remove() extension function.
class RemoveCookieFunction : public CookiesFunction {
public:
virtual bool RunImpl();
- // RemoveCookieFunction is sync.
- virtual void Run() {
- SendResponse(RunImpl());
- }
DECLARE_EXTENSION_FUNCTION_NAME("experimental.cookies.remove")
};
@@ -161,10 +114,6 @@ class RemoveCookieFunction : public CookiesFunction {
class GetAllCookieStoresFunction : public CookiesFunction {
public:
virtual bool RunImpl();
- // GetAllCookieStoresFunction is sync.
- virtual void Run() {
- SendResponse(RunImpl());
- }
DECLARE_EXTENSION_FUNCTION_NAME("experimental.cookies.getAllCookieStores")
};
diff --git a/chrome/browser/extensions/extension_cookies_helpers.cc b/chrome/browser/extensions/extension_cookies_helpers.cc
index 903e89e..ed881e2 100644
--- a/chrome/browser/extensions/extension_cookies_helpers.cc
+++ b/chrome/browser/extensions/extension_cookies_helpers.cc
@@ -94,11 +94,12 @@ GURL GetURLFromCookiePair(
}
void AppendMatchingCookiesToList(
- const net::CookieMonster::CookieList& all_cookies,
- const std::string& store_id,
+ net::CookieStore* cookie_store, const std::string& store_id,
const GURL& url, const DictionaryValue* details,
const Extension* extension,
ListValue* match_list) {
+ net::CookieMonster::CookieList all_cookies = GetCookieListFromStore(
+ cookie_store, url);
net::CookieMonster::CookieList::const_iterator it;
for (it = all_cookies.begin(); it != all_cookies.end(); ++it) {
// Ignore any cookie whose domain doesn't match the extension's
diff --git a/chrome/browser/extensions/extension_cookies_helpers.h b/chrome/browser/extensions/extension_cookies_helpers.h
index 77284c6..889a8c08 100644
--- a/chrome/browser/extensions/extension_cookies_helpers.h
+++ b/chrome/browser/extensions/extension_cookies_helpers.h
@@ -46,7 +46,6 @@ DictionaryValue* CreateCookieStoreValue(Profile* profile,
// Retrieves all cookies from the given cookie store corresponding to the given
// URL. If the URL is empty, all cookies in the cookie store are retrieved.
-// This can only be called on the IO thread.
net::CookieMonster::CookieList GetCookieListFromStore(
net::CookieStore* cookie_store, const GURL& url);
@@ -61,8 +60,7 @@ GURL GetURLFromCookiePair(
// match list all the cookies that both match the given URL and cookie details
// and are allowed by extension host permissions.
void AppendMatchingCookiesToList(
- const net::CookieMonster::CookieList& all_cookies,
- const std::string& store_id,
+ net::CookieStore* cookie_store, const std::string& store_id,
const GURL& url, const DictionaryValue* details,
const Extension* extension,
ListValue* match_list);
diff --git a/chrome/browser/extensions/extension_data_deleter.cc b/chrome/browser/extensions/extension_data_deleter.cc
index 1a9f84e..98cf433 100644
--- a/chrome/browser/extensions/extension_data_deleter.cc
+++ b/chrome/browser/extensions/extension_data_deleter.cc
@@ -23,28 +23,18 @@ ExtensionDataDeleter::ExtensionDataDeleter(Profile* profile,
void ExtensionDataDeleter::StartDeleting() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this, &ExtensionDataDeleter::DeleteCookiesOnIOThread));
-
- ChromeThread::PostTask(
- ChromeThread::WEBKIT, FROM_HERE,
- NewRunnableMethod(
- this, &ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread));
-
- ChromeThread::PostTask(
- ChromeThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &ExtensionDataDeleter::DeleteDatabaseOnFileThread));
-}
-
-void ExtensionDataDeleter::DeleteCookiesOnIOThread() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
net::CookieMonster* cookie_monster =
extension_request_context_->GetCookieStore()->GetCookieMonster();
if (cookie_monster)
cookie_monster->DeleteAllForURL(extension_url_, true);
+
+ ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE,
+ NewRunnableMethod(this,
+ &ExtensionDataDeleter::DeleteLocalStorageOnWebkitThread));
+
+ ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
+ NewRunnableMethod(this,
+ &ExtensionDataDeleter::DeleteDatabaseOnFileThread));
}
void ExtensionDataDeleter::DeleteDatabaseOnFileThread() {
diff --git a/chrome/browser/extensions/extension_data_deleter.h b/chrome/browser/extensions/extension_data_deleter.h
index 4b90509..d7f13327 100644
--- a/chrome/browser/extensions/extension_data_deleter.h
+++ b/chrome/browser/extensions/extension_data_deleter.h
@@ -33,10 +33,6 @@ class ExtensionDataDeleter
void StartDeleting();
private:
- // Deletes the cookies for the extension. May only be called on the io
- // thread.
- void DeleteCookiesOnIOThread();
-
// Deletes the database for the extension. May only be called on the file
// thread.
void DeleteDatabaseOnFileThread();
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index 27bd37c..d0e1d74 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -35,7 +35,10 @@ class QuotaLimitHeuristic;
// Abstract base class for extension functions the ExtensionFunctionDispatcher
// knows how to dispatch to.
-class ExtensionFunction : public base::RefCountedThreadSafe<ExtensionFunction> {
+//
+// TODO(aa): This will have to become reference counted when we introduce
+// APIs that live beyond a single stack frame.
+class ExtensionFunction : public base::RefCounted<ExtensionFunction> {
public:
ExtensionFunction() : request_id_(-1), name_(""), has_callback_(false) {}
@@ -95,7 +98,7 @@ class ExtensionFunction : public base::RefCountedThreadSafe<ExtensionFunction> {
virtual void Run() = 0;
protected:
- friend class base::RefCountedThreadSafe<ExtensionFunction>;
+ friend class base::RefCounted<ExtensionFunction>;
virtual ~ExtensionFunction() {}
diff --git a/chrome/browser/net/cookie_policy_browsertest.cc b/chrome/browser/net/cookie_policy_browsertest.cc
index dda544d..7a33ce9 100644
--- a/chrome/browser/net/cookie_policy_browsertest.cc
+++ b/chrome/browser/net/cookie_policy_browsertest.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/task.h"
-#include "base/waitable_event.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/profile.h"
@@ -12,51 +10,10 @@
#include "chrome/test/ui_test_utils.h"
#include "net/base/mock_host_resolver.h"
-namespace {
-
-class GetCookiesTask : public Task {
- public:
- GetCookiesTask(const GURL& url,
- URLRequestContextGetter* context_getter,
- base::WaitableEvent* event,
- std::string* cookies)
- : url_(url),
- context_getter_(context_getter),
- event_(event),
- cookies_(cookies) {}
-
- virtual void Run() {
- *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_);
- event_->Signal();
- }
-
- private:
- const GURL& url_;
- URLRequestContextGetter* const context_getter_;
- base::WaitableEvent* const event_;
- std::string* const cookies_;
-
- DISALLOW_COPY_AND_ASSIGN(GetCookiesTask);
-};
-
class CookiePolicyBrowserTest : public InProcessBrowserTest {
- protected:
+ public:
CookiePolicyBrowserTest() {}
- std::string GetCookies(const GURL& url) {
- std::string cookies;
- base::WaitableEvent event(true /* manual reset */,
- false /* not initially signaled */);
- URLRequestContextGetter* context_getter =
- browser()->profile()->GetRequestContext();
- EXPECT_TRUE(
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- new GetCookiesTask(url, context_getter, &event, &cookies)));
- EXPECT_TRUE(event.Wait());
- return cookies;
- }
-
private:
DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest);
};
@@ -69,17 +26,21 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) {
browser()->profile()->GetHostContentSettingsMap()->
SetBlockThirdPartyCookies(true);
+ net::CookieStore* cookie_store =
+ browser()->profile()->GetRequestContext()->GetCookieStore();
+
GURL url = server->TestServerPage("set-cookie?cookie1");
- std::string cookie = GetCookies(url);
+ std::string cookie = cookie_store->GetCookies(url);
ASSERT_EQ("", cookie);
ui_test_utils::NavigateToURL(browser(), url);
- cookie = GetCookies(url);
+ cookie = cookie_store->GetCookies(url);
EXPECT_EQ("cookie1", cookie);
}
+
// Visits a page that is a redirect across domain boundary to a page that sets
// a first-party cookie.
IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
@@ -90,6 +51,9 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
browser()->profile()->GetHostContentSettingsMap()->
SetBlockThirdPartyCookies(true);
+ net::CookieStore* cookie_store =
+ browser()->profile()->GetRequestContext()->GetCookieStore();
+
GURL url = server->TestServerPage("server-redirect?");
GURL redirected_url = server->TestServerPage("set-cookie?cookie2");
@@ -102,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
replacements.SetHostStr(new_host);
redirected_url = redirected_url.ReplaceComponents(replacements);
- std::string cookie = GetCookies(redirected_url);
+ std::string cookie = cookie_store->GetCookies(redirected_url);
ASSERT_EQ("", cookie);
host_resolver()->AddRule("www.example.com", "127.0.0.1");
@@ -110,8 +74,6 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
ui_test_utils::NavigateToURL(browser(),
GURL(url.spec() + redirected_url.spec()));
- cookie = GetCookies(redirected_url);
+ cookie = cookie_store->GetCookies(redirected_url);
EXPECT_EQ("cookie2", cookie);
}
-
-} // namespace