Shift extension API code to using Mojo CookieManager interface.
This CL includes the shift of one unit test over to CookieManager as well.
The other can't be changed yet, because it targets the extensions
URLRequestContext, which doesn't have a NetworkContext wrapper yet.
Bug: 721395
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I87590f3d3fa8d98fdb90935ac5e9b1540e4d4359
Reviewed-on: https://chromium-review.googlesource.com/776017
Commit-Queue: Randy Smith <[email protected]>
Reviewed-by: Tom Sepez <[email protected]>
Reviewed-by: Helen Li <[email protected]>
Reviewed-by: Devlin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#525989}
diff --git a/chrome/browser/extensions/BUILD.gn b/chrome/browser/extensions/BUILD.gn
index bd83907..cd4959ea 100644
--- a/chrome/browser/extensions/BUILD.gn
+++ b/chrome/browser/extensions/BUILD.gn
@@ -882,6 +882,7 @@
"//services/data_decoder/public/cpp",
"//services/device/public/interfaces",
"//services/identity/public/interfaces",
+ "//services/network/public/interfaces",
"//services/service_manager/public/cpp",
"//services/service_manager/public/interfaces",
"//skia",
diff --git a/chrome/browser/extensions/DEPS b/chrome/browser/extensions/DEPS
index c668eb2..d87bfeb4 100644
--- a/chrome/browser/extensions/DEPS
+++ b/chrome/browser/extensions/DEPS
@@ -9,6 +9,7 @@
"+ui/base",
"+components/arc",
"+components/vector_icons",
+ "+services/network/public/interfaces",
# For access to testing command line switches.
"+ppapi/shared_impl",
diff --git a/chrome/browser/extensions/api/DEPS b/chrome/browser/extensions/api/DEPS
index f151a879..fea8d34 100644
--- a/chrome/browser/extensions/api/DEPS
+++ b/chrome/browser/extensions/api/DEPS
@@ -8,6 +8,7 @@
# Enable remote assistance on Chrome OS
"+remoting/base",
"+remoting/host",
+ "+services/network/public/interfaces",
]
specific_include_rules = {
diff --git a/chrome/browser/extensions/api/cookies/cookies_api.cc b/chrome/browser/extensions/api/cookies/cookies_api.cc
index 4a705c1..8feb848 100644
--- a/chrome/browser/extensions/api/cookies/cookies_api.cc
+++ b/chrome/browser/extensions/api/cookies/cookies_api.cc
@@ -24,18 +24,17 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/extensions/api/cookies.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/storage_partition.h"
+#include "content/public/common/network_service.mojom.h"
#include "extensions/browser/event_router.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/permissions/permissions_data.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_constants.h"
-#include "net/cookies/cookie_monster.h"
-#include "net/cookies/cookie_store.h"
-#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_context_getter.h"
using content::BrowserThread;
@@ -71,10 +70,9 @@
return true;
}
-bool ParseStoreContext(ChromeAsyncExtensionFunction* function,
- std::string* store_id,
- net::URLRequestContextGetter** context) {
- DCHECK((context || store_id->empty()));
+network::mojom::CookieManager* ParseStoreCookieManager(
+ ChromeAsyncExtensionFunction* function,
+ std::string* store_id) {
Profile* store_profile = NULL;
if (!store_id->empty()) {
store_profile = cookies_helpers::ChooseProfileFromStoreId(
@@ -82,26 +80,25 @@
if (!store_profile) {
function->SetError(ErrorUtils::FormatErrorMessage(
keys::kInvalidStoreIdError, *store_id));
- return false;
+ return nullptr;
}
} else {
// The store ID was not specified; use the current execution context's
// cookie store by default.
// GetCurrentBrowser() already takes into account incognito settings.
+ // TODO(rdevlin.cronin): Relying on the current execution context is
+ // almost never the right answer; clean this up.
Browser* current_browser = function->GetCurrentBrowser();
if (!current_browser) {
function->SetError(keys::kNoCookieStoreFoundError);
- return false;
+ return nullptr;
}
store_profile = current_browser->profile();
*store_id = cookies_helpers::GetStoreIdFromProfile(store_profile);
}
- if (context)
- *context = store_profile->GetRequestContext();
- DCHECK(context);
-
- return true;
+ return content::BrowserContext::GetDefaultStoragePartition(store_profile)
+ ->GetCookieManagerForBrowserProcess();
}
} // namespace
@@ -212,38 +209,28 @@
std::string store_id =
parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id
: std::string();
- net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(this, &store_id, &store_context))
+ network::mojom::CookieManager* cookie_manager =
+ ParseStoreCookieManager(this, &store_id);
+ if (!cookie_manager)
return false;
- store_browser_context_ = store_context;
+
if (!parsed_args_->details.store_id.get())
parsed_args_->details.store_id.reset(new std::string(store_id));
- store_browser_context_ = store_context;
-
- bool rv = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::BindOnce(&CookiesGetFunction::GetCookieOnIOThread, this));
- DCHECK(rv);
+ cookies_helpers::GetCookieListFromManager(
+ cookie_manager, url_,
+ base::BindOnce(&CookiesGetFunction::GetCookieCallback, this));
// Will finish asynchronously.
return true;
}
-void CookiesGetFunction::GetCookieOnIOThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- net::CookieStore* cookie_store =
- store_browser_context_->GetURLRequestContext()->cookie_store();
- cookies_helpers::GetCookieListFromStore(
- cookie_store, url_,
- base::BindOnce(&CookiesGetFunction::GetCookieCallback, this));
-}
-
void CookiesGetFunction::GetCookieCallback(const net::CookieList& cookie_list) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
for (const net::CanonicalCookie& cookie : cookie_list) {
// Return the first matching cookie. Relies on the fact that the
- // CookieMonster returns them in canonical order (longest path, then
- // earliest creation time).
+ // CookieManager interface returns them in canonical order (longest path,
+ // then earliest creation time).
if (cookie.Name() == parsed_args_->details.name) {
cookies::Cookie api_cookie = cookies_helpers::CreateCookie(
cookie, *parsed_args_->details.store_id);
@@ -256,14 +243,6 @@
if (!results_)
SetResult(base::MakeUnique<base::Value>());
- bool rv = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::BindOnce(&CookiesGetFunction::RespondOnUIThread, this));
- DCHECK(rv);
-}
-
-void CookiesGetFunction::RespondOnUIThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
SendResponse(true);
}
@@ -285,33 +264,26 @@
std::string store_id =
parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id
: std::string();
- net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(this, &store_id, &store_context))
+ network::mojom::CookieManager* cookie_manager =
+ ParseStoreCookieManager(this, &store_id);
+ if (!cookie_manager)
return false;
- store_browser_context_ = store_context;
+
if (!parsed_args_->details.store_id.get())
parsed_args_->details.store_id.reset(new std::string(store_id));
- bool rv = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::BindOnce(&CookiesGetAllFunction::GetAllCookiesOnIOThread, this));
- DCHECK(rv);
+ DCHECK(url_.is_empty() || url_.is_valid());
+ cookies_helpers::GetCookieListFromManager(
+ cookie_manager, url_,
+ base::BindOnce(&CookiesGetAllFunction::GetAllCookiesCallback, this));
// Will finish asynchronously.
return true;
}
-void CookiesGetAllFunction::GetAllCookiesOnIOThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- net::CookieStore* cookie_store =
- store_browser_context_->GetURLRequestContext()->cookie_store();
- cookies_helpers::GetCookieListFromStore(
- cookie_store, url_,
- base::BindOnce(&CookiesGetAllFunction::GetAllCookiesCallback, this));
-}
-
void CookiesGetAllFunction::GetAllCookiesCallback(
const net::CookieList& cookie_list) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (extension()) {
std::vector<cookies::Cookie> match_vector;
cookies_helpers::AppendMatchingCookiesToVector(
@@ -319,19 +291,11 @@
results_ = GetAll::Results::Create(match_vector);
}
- bool rv = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::BindOnce(&CookiesGetAllFunction::RespondOnUIThread, this));
- DCHECK(rv);
-}
-
-void CookiesGetAllFunction::RespondOnUIThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
SendResponse(true);
}
-CookiesSetFunction::CookiesSetFunction() : success_(false) {
-}
+CookiesSetFunction::CookiesSetFunction()
+ : state_(NO_RESPONSE), success_(false) {}
CookiesSetFunction::~CookiesSetFunction() {
}
@@ -347,26 +311,14 @@
std::string store_id =
parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id
: std::string();
- net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(this, &store_id, &store_context))
+ network::mojom::CookieManager* cookie_manager =
+ ParseStoreCookieManager(this, &store_id);
+ if (!cookie_manager)
return false;
- store_browser_context_ = store_context;
+
if (!parsed_args_->details.store_id.get())
parsed_args_->details.store_id.reset(new std::string(store_id));
- bool rv = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::BindOnce(&CookiesSetFunction::SetCookieOnIOThread, this));
- DCHECK(rv);
-
- // Will finish asynchronously.
- return true;
-}
-
-void CookiesSetFunction::SetCookieOnIOThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- net::CookieStore* cookie_store =
- store_browser_context_->GetURLRequestContext()->cookie_store();
base::Time expiration_time;
if (parsed_args_->details.expiration_date.get()) {
@@ -414,26 +366,40 @@
net::COOKIE_PRIORITY_DEFAULT));
// clang-format on
if (!cc) {
- PullCookie(false);
- return;
+ // Return error through callbacks so that the proper error message
+ // is generated.
+ success_ = false;
+ state_ = SET_COMPLETED;
+ GetCookieListCallback(net::CookieList());
+ return true;
}
- cookie_store->SetCanonicalCookieAsync(
- std::move(cc), url_.SchemeIsCryptographic(), true /*modify_http_only*/,
- base::BindOnce(&CookiesSetFunction::PullCookie, this));
+
+ // Dispatch the setter, immediately followed by the getter. This
+ // plus FIFO ordering on the cookie_manager_ pipe means that no
+ // other extension function will affect the get result.
+ cookie_manager->SetCanonicalCookie(
+ *cc, url_.SchemeIsCryptographic(), true /*modify_http_only*/,
+ base::BindOnce(&CookiesSetFunction::SetCanonicalCookieCallback, this));
+ cookies_helpers::GetCookieListFromManager(
+ cookie_manager, url_,
+ base::BindOnce(&CookiesSetFunction::GetCookieListCallback, this));
+
+ // Will finish asynchronously.
+ return true;
}
-void CookiesSetFunction::PullCookie(bool set_cookie_result) {
- // Pull the newly set cookie.
- net::CookieStore* cookie_store =
- store_browser_context_->GetURLRequestContext()->cookie_store();
+void CookiesSetFunction::SetCanonicalCookieCallback(bool set_cookie_result) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK_EQ(NO_RESPONSE, state_);
+ state_ = SET_COMPLETED;
success_ = set_cookie_result;
- cookies_helpers::GetCookieListFromStore(
- cookie_store, url_,
- base::BindOnce(&CookiesSetFunction::PullCookieCallback, this));
}
-void CookiesSetFunction::PullCookieCallback(
+void CookiesSetFunction::GetCookieListCallback(
const net::CookieList& cookie_list) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK_EQ(SET_COMPLETED, state_);
+ state_ = GET_COMPLETED;
for (const net::CanonicalCookie& cookie : cookie_list) {
// Return the first matching cookie. Relies on the fact that the
// CookieMonster returns them in canonical order (longest path, then
@@ -449,18 +415,12 @@
}
}
- bool rv = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::BindOnce(&CookiesSetFunction::RespondOnUIThread, this));
- DCHECK(rv);
-}
-
-void CookiesSetFunction::RespondOnUIThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!success_) {
std::string name =
parsed_args_->details.name.get() ? *parsed_args_->details.name
: std::string();
+ // TODO(rdevlin.cronin): Avoid setting both error_ and results_ in the
+ // same call.
error_ = ErrorUtils::FormatErrorMessage(keys::kCookieSetFailedError, name);
}
SendResponse(success_);
@@ -483,35 +443,29 @@
std::string store_id =
parsed_args_->details.store_id.get() ? *parsed_args_->details.store_id
: std::string();
- net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(this, &store_id, &store_context))
+ network::mojom::CookieManager* cookie_manager =
+ ParseStoreCookieManager(this, &store_id);
+ if (!cookie_manager)
return false;
- store_browser_context_ = store_context;
+
if (!parsed_args_->details.store_id.get())
parsed_args_->details.store_id.reset(new std::string(store_id));
- // Pass the work off to the IO thread.
- bool rv = BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::BindOnce(&CookiesRemoveFunction::RemoveCookieOnIOThread, this));
- DCHECK(rv);
+ network::mojom::CookieDeletionFilterPtr filter(
+ network::mojom::CookieDeletionFilter::New());
+ filter->url = url_;
+ filter->cookie_name = parsed_args_->details.name;
+ cookie_manager->DeleteCookies(
+ std::move(filter),
+ base::BindOnce(&CookiesRemoveFunction::RemoveCookieCallback, this));
// Will return asynchronously.
return true;
}
-void CookiesRemoveFunction::RemoveCookieOnIOThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+void CookiesRemoveFunction::RemoveCookieCallback(uint32_t /* num_deleted */) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // Remove the cookie
- net::CookieStore* cookie_store =
- store_browser_context_->GetURLRequestContext()->cookie_store();
- cookie_store->DeleteCookieAsync(
- url_, parsed_args_->details.name,
- base::BindOnce(&CookiesRemoveFunction::RemoveCookieCallback, this));
-}
-
-void CookiesRemoveFunction::RemoveCookieCallback() {
// Build the callback result
Remove::Results::Details details;
details.name = parsed_args_->details.name;
@@ -519,15 +473,6 @@
details.store_id = *parsed_args_->details.store_id;
results_ = Remove::Results::Create(details);
- // Return to UI thread
- bool rv = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::BindOnce(&CookiesRemoveFunction::RespondOnUIThread, this));
- DCHECK(rv);
-}
-
-void CookiesRemoveFunction::RespondOnUIThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
SendResponse(true);
}
diff --git a/chrome/browser/extensions/api/cookies/cookies_api.h b/chrome/browser/extensions/api/cookies/cookies_api.h
index 4dfa71c..b5a5ad04 100644
--- a/chrome/browser/extensions/api/cookies/cookies_api.h
+++ b/chrome/browser/extensions/api/cookies/cookies_api.h
@@ -22,12 +22,9 @@
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "net/cookies/canonical_cookie.h"
+#include "services/network/public/interfaces/cookie_manager.mojom.h"
#include "url/gurl.h"
-namespace net {
-class URLRequestContextGetter;
-}
-
namespace extensions {
// Observes CookieMonster notifications and routes them as events to the
@@ -76,12 +73,10 @@
bool RunAsync() override;
private:
- void GetCookieOnIOThread();
- void RespondOnUIThread();
void GetCookieCallback(const net::CookieList& cookie_list);
GURL url_;
- scoped_refptr<net::URLRequestContextGetter> store_browser_context_;
+ network::mojom::CookieManagerPtr store_browser_cookie_manager_;
std::unique_ptr<api::cookies::Get::Params> parsed_args_;
};
@@ -99,12 +94,10 @@
bool RunAsync() override;
private:
- void GetAllCookiesOnIOThread();
- void RespondOnUIThread();
void GetAllCookiesCallback(const net::CookieList& cookie_list);
GURL url_;
- scoped_refptr<net::URLRequestContextGetter> store_browser_context_;
+ network::mojom::CookieManagerPtr store_browser_cookie_manager_;
std::unique_ptr<api::cookies::GetAll::Params> parsed_args_;
};
@@ -120,14 +113,13 @@
bool RunAsync() override;
private:
- void SetCookieOnIOThread();
- void RespondOnUIThread();
- void PullCookie(bool set_cookie_);
- void PullCookieCallback(const net::CookieList& cookie_list);
+ void SetCanonicalCookieCallback(bool set_cookie_);
+ void GetCookieListCallback(const net::CookieList& cookie_list);
+ enum { NO_RESPONSE, SET_COMPLETED, GET_COMPLETED } state_;
GURL url_;
bool success_;
- scoped_refptr<net::URLRequestContextGetter> store_browser_context_;
+ network::mojom::CookieManagerPtr store_browser_cookie_manager_;
std::unique_ptr<api::cookies::Set::Params> parsed_args_;
};
@@ -145,12 +137,10 @@
bool RunAsync() override;
private:
- void RemoveCookieOnIOThread();
- void RespondOnUIThread();
- void RemoveCookieCallback();
+ void RemoveCookieCallback(uint32_t /* num_deleted */);
GURL url_;
- scoped_refptr<net::URLRequestContextGetter> store_browser_context_;
+ network::mojom::CookieManagerPtr store_browser_cookie_manager_;
std::unique_ptr<api::cookies::Remove::Params> parsed_args_;
};
diff --git a/chrome/browser/extensions/api/cookies/cookies_helpers.cc b/chrome/browser/extensions/api/cookies/cookies_helpers.cc
index 42ca67b..a9b8840e 100644
--- a/chrome/browser/extensions/api/cookies/cookies_helpers.cc
+++ b/chrome/browser/extensions/api/cookies/cookies_helpers.cc
@@ -118,16 +118,20 @@
return cookie_store;
}
-void GetCookieListFromStore(
- net::CookieStore* cookie_store,
+void GetCookieListFromManager(
+ network::mojom::CookieManager* manager,
const GURL& url,
- net::CookieMonster::GetCookieListCallback callback) {
- DCHECK(cookie_store);
- if (!url.is_empty()) {
- DCHECK(url.is_valid());
- cookie_store->GetAllCookiesForURLAsync(url, std::move(callback));
+ network::mojom::CookieManager::GetCookieListCallback callback) {
+ if (url.is_empty()) {
+ manager->GetAllCookies(std::move(callback));
} else {
- cookie_store->GetAllCookiesAsync(std::move(callback));
+ net::CookieOptions options;
+ options.set_include_httponly();
+ options.set_same_site_cookie_mode(
+ net::CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
+ options.set_do_not_update_access_time();
+
+ manager->GetCookieList(url, options, std::move(callback));
}
}
diff --git a/chrome/browser/extensions/api/cookies/cookies_helpers.h b/chrome/browser/extensions/api/cookies/cookies_helpers.h
index 0fa58c69..ec287ff 100644
--- a/chrome/browser/extensions/api/cookies/cookies_helpers.h
+++ b/chrome/browser/extensions/api/cookies/cookies_helpers.h
@@ -15,8 +15,10 @@
#include <vector>
#include "chrome/common/extensions/api/cookies.h"
-#include "net/cookies/cookie_monster.h"
#include "net/cookies/canonical_cookie.h"
+#include "net/cookies/cookie_monster.h"
+#include "net/cookies/cookie_options.h"
+#include "services/network/public/interfaces/cookie_manager.mojom.h"
class Browser;
class Profile;
@@ -55,12 +57,12 @@
Profile* profile,
std::unique_ptr<base::ListValue> tab_ids);
-// 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.
-void GetCookieListFromStore(net::CookieStore* cookie_store,
- const GURL& url,
- net::CookieMonster::GetCookieListCallback callback);
+// Dispatch a request to the CookieManager for cookies associated with
+// |url|, or all cookies if |url.is_empty()|.
+void GetCookieListFromManager(
+ network::mojom::CookieManager* manager,
+ const GURL& url,
+ network::mojom::CookieManager::GetCookieListCallback callback);
// Constructs a URL from a cookie's information for use in checking
// a cookie against the extension's host permissions. The Secure
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 943aae57..b344cfc 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -35,6 +35,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
#include "base/values.h"
#include "base/version.h"
#include "build/build_config.h"
@@ -99,6 +100,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_constants.h"
+#include "content/public/common/network_service.mojom.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_prefs.h"
@@ -128,11 +130,13 @@
#include "extensions/common/switches.h"
#include "extensions/common/url_pattern.h"
#include "extensions/common/value_builder.h"
+#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h"
#include "net/cookies/cookie_store.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "ppapi/features/features.h"
+#include "services/network/public/interfaces/cookie_manager.mojom.h"
#include "storage/browser/database/database_tracker.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/common/database/database_identifier.h"
@@ -4792,6 +4796,20 @@
EXPECT_FALSE(base::DirectoryExists(idb_path));
}
+void SetCookieSaveData(bool* result_out,
+ base::OnceClosure callback,
+ bool result) {
+ *result_out = result;
+ std::move(callback).Run();
+}
+
+void GetCookiesSaveData(std::vector<net::CanonicalCookie>* result_out,
+ base::OnceClosure callback,
+ const std::vector<net::CanonicalCookie>& result) {
+ *result_out = result;
+ std::move(callback).Run();
+}
+
// Verifies app state is removed upon uninstall.
TEST_F(ExtensionServiceTest, ClearAppData) {
InitializeEmptyExtensionService();
@@ -4828,25 +4846,37 @@
EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
origin2));
- // Set a cookie for the extension.
- net::CookieStore* cookie_store = profile()->GetRequestContext()
- ->GetURLRequestContext()
- ->cookie_store();
- ASSERT_TRUE(cookie_store);
- net::CookieOptions options;
- cookie_store->SetCookieWithOptionsAsync(
- origin1, "dummy=value", options,
- base::Bind(&ExtensionCookieCallback::SetCookieCallback,
- base::Unretained(&callback)));
- content::RunAllTasksUntilIdle();
- EXPECT_TRUE(callback.result_);
+ content::mojom::NetworkContext* network_context =
+ content::BrowserContext::GetDefaultStoragePartition(profile())
+ ->GetNetworkContext();
+ network::mojom::CookieManagerPtr cookie_manager_ptr;
+ network_context->GetCookieManager(mojo::MakeRequest(&cookie_manager_ptr));
- cookie_store->GetAllCookiesForURLAsync(
- origin1,
- base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
- base::Unretained(&callback)));
- content::RunAllTasksUntilIdle();
- EXPECT_EQ(1U, callback.list_.size());
+ std::unique_ptr<net::CanonicalCookie> cc(net::CanonicalCookie::Create(
+ origin1, "dummy=value", base::Time::Now(), net::CookieOptions()));
+ ASSERT_TRUE(cc.get());
+
+ {
+ bool set_result = false;
+ base::RunLoop run_loop;
+ cookie_manager_ptr->SetCanonicalCookie(
+ *cc.get(), origin1.SchemeIsCryptographic(), true /* modify_http_only */,
+ base::BindOnce(&SetCookieSaveData, &set_result,
+ run_loop.QuitClosure()));
+ run_loop.Run();
+ EXPECT_TRUE(set_result);
+ }
+
+ {
+ base::RunLoop run_loop;
+ std::vector<net::CanonicalCookie> cookies_result;
+ cookie_manager_ptr->GetCookieList(
+ origin1, net::CookieOptions(),
+ base::BindOnce(&GetCookiesSaveData, &cookies_result,
+ run_loop.QuitClosure()));
+ run_loop.Run();
+ EXPECT_EQ(1U, cookies_result.size());
+ }
// Open a database.
storage::DatabaseTracker* db_tracker =
@@ -4885,13 +4915,17 @@
EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
origin1));
- // Check that the cookie is still there.
- cookie_store->GetAllCookiesForURLAsync(
- origin1,
- base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
- base::Unretained(&callback)));
- content::RunAllTasksUntilIdle();
- EXPECT_EQ(1U, callback.list_.size());
+ {
+ // Check that the cookie is still there.
+ base::RunLoop run_loop;
+ std::vector<net::CanonicalCookie> cookies_result;
+ cookie_manager_ptr->GetCookieList(
+ origin1, net::CookieOptions(),
+ base::BindOnce(&GetCookiesSaveData, &cookies_result,
+ run_loop.QuitClosure()));
+ run_loop.Run();
+ EXPECT_EQ(1U, cookies_result.size());
+ }
// Now uninstall the other. Storage should be cleared for the apps.
UninstallExtension(id2);
@@ -4900,13 +4934,17 @@
profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
origin1));
- // Check that the cookie is gone.
- cookie_store->GetAllCookiesForURLAsync(
- origin1,
- base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
- base::Unretained(&callback)));
- content::RunAllTasksUntilIdle();
- EXPECT_EQ(0U, callback.list_.size());
+ {
+ // Check that the cookie is gone.
+ base::RunLoop run_loop;
+ std::vector<net::CanonicalCookie> cookies_result;
+ cookie_manager_ptr->GetCookieList(
+ origin1, net::CookieOptions(),
+ base::BindOnce(&GetCookiesSaveData, &cookies_result,
+ run_loop.QuitClosure()));
+ run_loop.Run();
+ EXPECT_EQ(0U, cookies_result.size());
+ }
// The database should have vanished as well.
db_tracker->task_runner()->PostTask(