Commit 2cc7d67e authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Count cookies and site data by host instead of origin

Similar to site settings and chrome://settings/siteData, cookies
should by counted by the number of hosts instead of origins to avoid
confusion.

Change-Id: Ib148c5c1131a63adadce523e30e1453f69c9b318
Reviewed-on: https://chromium-review.googlesource.com/997842
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548435}
parent 1d469b09
...@@ -233,11 +233,11 @@ void SiteDataCountingHelper::Done(const std::vector<GURL>& origins) { ...@@ -233,11 +233,11 @@ void SiteDataCountingHelper::Done(const std::vector<GURL>& origins) {
DCHECK(tasks_ > 0); DCHECK(tasks_ > 0);
for (const GURL& origin : origins) { for (const GURL& origin : origins) {
if (BrowsingDataHelper::HasWebScheme(origin)) if (BrowsingDataHelper::HasWebScheme(origin))
unique_origins_.insert(origin); unique_hosts_.insert(origin.host());
} }
if (--tasks_ > 0) if (--tasks_ > 0)
return; return;
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(completion_callback_, unique_origins_.size())); FROM_HERE, base::BindOnce(completion_callback_, unique_hosts_.size()));
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
} }
...@@ -68,7 +68,7 @@ class SiteDataCountingHelper { ...@@ -68,7 +68,7 @@ class SiteDataCountingHelper {
base::Time begin_; base::Time begin_;
base::Callback<void(int)> completion_callback_; base::Callback<void(int)> completion_callback_;
int tasks_; int tasks_;
std::set<GURL> unique_origins_; std::set<std::string> unique_hosts_;
scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper_; scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper_;
}; };
......
...@@ -115,8 +115,8 @@ class SiteDataCountingHelperTest : public testing::Test { ...@@ -115,8 +115,8 @@ class SiteDataCountingHelperTest : public testing::Test {
cookie_store->SetCanonicalCookieAsync( cookie_store->SetCanonicalCookieAsync(
net::CanonicalCookie::CreateSanitizedCookie( net::CanonicalCookie::CreateSanitizedCookie(
url, "name", "A=1", url.host(), url.path(), time, base::Time(), url, "name", "A=1", url.host(), url.path(), time, base::Time(),
time, true, false, net::CookieSameSite::DEFAULT_MODE, time, url.SchemeIsCryptographic(), false,
net::COOKIE_PRIORITY_DEFAULT), net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT),
url.SchemeIsCryptographic(), true /*modify_http_only*/, url.SchemeIsCryptographic(), true /*modify_http_only*/,
base::BindOnce(&SiteDataCountingHelperTest::DoneOnIOThread, base::BindOnce(&SiteDataCountingHelperTest::DoneOnIOThread,
base::Unretained(this))); base::Unretained(this)));
...@@ -195,7 +195,7 @@ TEST_F(SiteDataCountingHelperTest, LocalStorage) { ...@@ -195,7 +195,7 @@ TEST_F(SiteDataCountingHelperTest, LocalStorage) {
TEST_F(SiteDataCountingHelperTest, CookiesAndLocalStorage) { TEST_F(SiteDataCountingHelperTest, CookiesAndLocalStorage) {
base::Time now = base::Time::Now(); base::Time now = base::Time::Now();
CreateCookies(now, {"https://example.com", "https://google.com"}); CreateCookies(now, {"http://example.com", "https://google.com"});
CreateLocalStorage(now, CreateLocalStorage(now,
{FILE_PATH_LITERAL("https_example.com_443.localstorage"), {FILE_PATH_LITERAL("https_example.com_443.localstorage"),
FILE_PATH_LITERAL("https_bing.com_443.localstorage")}); FILE_PATH_LITERAL("https_bing.com_443.localstorage")});
...@@ -205,3 +205,15 @@ TEST_F(SiteDataCountingHelperTest, CookiesAndLocalStorage) { ...@@ -205,3 +205,15 @@ TEST_F(SiteDataCountingHelperTest, CookiesAndLocalStorage) {
WaitForTasksOnIOThread(); WaitForTasksOnIOThread();
DCHECK_EQ(3, GetResult()); DCHECK_EQ(3, GetResult());
} }
TEST_F(SiteDataCountingHelperTest, SameHostDifferentScheme) {
base::Time now = base::Time::Now();
CreateCookies(now, {"http://google.com", "https://google.com"});
CreateLocalStorage(now,
{FILE_PATH_LITERAL("https_google.com_443.localstorage"),
FILE_PATH_LITERAL("http_google.com_80.localstorage")});
WaitForTasksOnIOThread();
CountEntries(base::Time());
WaitForTasksOnIOThread();
DCHECK_EQ(1, GetResult());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment