summaryrefslogtreecommitdiff
path: root/chromium/net/cookies
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-05-24 11:40:17 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-05-24 12:42:11 +0000
commit5d87695f37678f96492b258bbab36486c59866b4 (patch)
treebe9783bbaf04fb930c4d74ca9c00b5e7954c8bc6 /chromium/net/cookies
parent6c11fb357ec39bf087b8b632e2b1e375aef1b38b (diff)
downloadqtwebengine-chromium-5d87695f37678f96492b258bbab36486c59866b4.tar.gz
BASELINE: Update Chromium to 75.0.3770.56
Change-Id: I86d2007fd27a45d5797eee06f4c9369b8b50ac4f Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/net/cookies')
-rw-r--r--chromium/net/cookies/canonical_cookie.cc40
-rw-r--r--chromium/net/cookies/canonical_cookie.h27
-rw-r--r--chromium/net/cookies/canonical_cookie_unittest.cc183
-rw-r--r--chromium/net/cookies/cookie_constants.cc14
-rw-r--r--chromium/net/cookies/cookie_constants.h6
-rw-r--r--chromium/net/cookies/cookie_deletion_info_unittest.cc21
-rw-r--r--chromium/net/cookies/cookie_monster.cc92
-rw-r--r--chromium/net/cookies/cookie_monster.h44
-rw-r--r--chromium/net/cookies/cookie_monster_netlog_params.cc2
-rw-r--r--chromium/net/cookies/cookie_monster_netlog_params.h1
-rw-r--r--chromium/net/cookies/cookie_monster_perftest.cc14
-rw-r--r--chromium/net/cookies/cookie_monster_store_test.cc49
-rw-r--r--chromium/net/cookies/cookie_monster_store_test.h29
-rw-r--r--chromium/net/cookies/cookie_monster_unittest.cc949
-rw-r--r--chromium/net/cookies/cookie_options.h2
-rw-r--r--chromium/net/cookies/cookie_store.h21
-rw-r--r--chromium/net/cookies/cookie_store_test_callbacks.cc20
-rw-r--r--chromium/net/cookies/cookie_store_test_callbacks.h22
-rw-r--r--chromium/net/cookies/cookie_store_test_helpers.cc22
-rw-r--r--chromium/net/cookies/cookie_store_test_helpers.h11
-rw-r--r--chromium/net/cookies/cookie_store_unittest.h102
-rw-r--r--chromium/net/cookies/cookie_util.cc36
-rw-r--r--chromium/net/cookies/cookie_util.h30
-rw-r--r--chromium/net/cookies/cookie_util_unittest.cc67
-rw-r--r--chromium/net/cookies/parsed_cookie.cc6
-rw-r--r--chromium/net/cookies/parsed_cookie_unittest.cc8
26 files changed, 966 insertions, 852 deletions
diff --git a/chromium/net/cookies/canonical_cookie.cc b/chromium/net/cookies/canonical_cookie.cc
index aec043d3392..f75dc144314 100644
--- a/chromium/net/cookies/canonical_cookie.cc
+++ b/chromium/net/cookies/canonical_cookie.cc
@@ -46,11 +46,13 @@
#include <utility>
+#include "base/feature_list.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "net/base/features.h"
#include "net/base/url_util.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
@@ -203,13 +205,14 @@ std::unique_ptr<CanonicalCookie> CanonicalCookie::Create(
ParsedCookie parsed_cookie(cookie_line);
if (!parsed_cookie.IsValid()) {
- VLOG(net::cookie_util::kVlogSetCookies) << "WARNING: Couldn't parse cookie";
+ DVLOG(net::cookie_util::kVlogSetCookies)
+ << "WARNING: Couldn't parse cookie";
*status = CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE;
return nullptr;
}
if (options.exclude_httponly() && parsed_cookie.IsHttpOnly()) {
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "Create() is not creating a httponly cookie";
*status = CookieInclusionStatus::EXCLUDE_HTTP_ONLY;
return nullptr;
@@ -217,7 +220,7 @@ std::unique_ptr<CanonicalCookie> CanonicalCookie::Create(
std::string cookie_domain;
if (!GetCookieDomain(url, parsed_cookie, &cookie_domain)) {
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "Create() failed to get a cookie domain";
*status = CookieInclusionStatus::EXCLUDE_INVALID_DOMAIN;
return nullptr;
@@ -228,7 +231,7 @@ std::unique_ptr<CanonicalCookie> CanonicalCookie::Create(
// URL does not have a secure scheme, the cookie should be thrown away.
// https://tools.ietf.org/html/draft-ietf-httpbis-cookie-alone
if (parsed_cookie.IsSecure() && !url.SchemeIsCryptographic()) {
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "Create() is trying to create a secure cookie from an insecure URL";
*status = CookieInclusionStatus::EXCLUDE_SECURE_ONLY;
return nullptr;
@@ -250,7 +253,7 @@ std::unique_ptr<CanonicalCookie> CanonicalCookie::Create(
bool is_cookie_valid = IsCookiePrefixValid(prefix, url, parsed_cookie);
RecordCookiePrefixMetrics(prefix, is_cookie_valid);
if (!is_cookie_valid) {
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "Create() failed because the cookie violated prefix rules.";
*status = CookieInclusionStatus::EXCLUDE_INVALID_PREFIX;
return nullptr;
@@ -365,6 +368,23 @@ bool CanonicalCookie::IsDomainMatch(const std::string& host) const {
return cookie_util::IsDomainMatch(domain_, host);
}
+CookieSameSite CanonicalCookie::GetEffectiveSameSite() const {
+ // If a cookie does not have a SameSite attribute, the effective SameSite
+ // mode depends on the SameSiteByDefaultCookies setting.
+ if (SameSite() == CookieSameSite::UNSPECIFIED) {
+ if (base::FeatureList::IsEnabled(features::kSameSiteByDefaultCookies))
+ return CookieSameSite::LAX_MODE;
+ return CookieSameSite::NO_RESTRICTION;
+ }
+
+ // TODO(crbug.com/953995): Implement extended mode once first-party sets are
+ // available.
+ if (SameSite() == CookieSameSite::EXTENDED_MODE)
+ return CookieSameSite::LAX_MODE;
+
+ return SameSite();
+}
+
CanonicalCookie::CookieInclusionStatus CanonicalCookie::IncludeForRequestURL(
const GURL& url,
const CookieOptions& options) const {
@@ -383,7 +403,7 @@ CanonicalCookie::CookieInclusionStatus CanonicalCookie::IncludeForRequestURL(
if (!IsOnPath(url.path()))
return CanonicalCookie::CookieInclusionStatus::EXCLUDE_NOT_ON_PATH;
// Don't include same-site cookies for cross-site requests.
- switch (SameSite()) {
+ switch (GetEffectiveSameSite()) {
case CookieSameSite::STRICT_MODE:
if (options.same_site_cookie_context() <
CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT) {
@@ -393,7 +413,11 @@ CanonicalCookie::CookieInclusionStatus CanonicalCookie::IncludeForRequestURL(
case CookieSameSite::LAX_MODE:
if (options.same_site_cookie_context() <
CookieOptions::SameSiteCookieContext::SAME_SITE_LAX) {
- return CanonicalCookie::CookieInclusionStatus::EXCLUDE_SAMESITE_LAX;
+ return (SameSite() == CookieSameSite::UNSPECIFIED)
+ ? CanonicalCookie::CookieInclusionStatus::
+ EXCLUDE_SAMESITE_UNSPECIFIED_TREATED_AS_LAX
+ : CanonicalCookie::CookieInclusionStatus::
+ EXCLUDE_SAMESITE_LAX;
}
break;
default:
@@ -442,6 +466,8 @@ bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const {
if (IsHttpOnly() != other.IsHttpOnly())
return IsHttpOnly();
+ // TODO(chlily): This should also compare the SameSite attribute.
+
return Priority() < other.Priority();
}
diff --git a/chromium/net/cookies/canonical_cookie.h b/chromium/net/cookies/canonical_cookie.h
index f82e9e58b15..6b46da3df77 100644
--- a/chromium/net/cookies/canonical_cookie.h
+++ b/chromium/net/cookies/canonical_cookie.h
@@ -59,6 +59,17 @@ class NET_EXPORT CanonicalCookie {
EXCLUDE_NOT_ON_PATH,
EXCLUDE_SAMESITE_STRICT,
EXCLUDE_SAMESITE_LAX,
+ // TODO(crbug.com/953995): Implement EXTENDED_MODE which will use the
+ // following value.
+ EXCLUDE_SAMESITE_EXTENDED,
+ // The following two are used for the SameSiteByDefaultCookies experiment,
+ // where if the SameSite attribute is not specified, it will be treated as
+ // SameSite=Lax by default.
+ EXCLUDE_SAMESITE_UNSPECIFIED_TREATED_AS_LAX,
+ // This is used if SameSite=None is specified, but the cookie is not Secure.
+ // TODO(chlily): Implement the above.
+ EXCLUDE_SAMESITE_NONE_INSECURE,
+ EXCLUDE_USER_PREFERENCES,
// Statuses specific to setting cookies
EXCLUDE_FAILURE_TO_STORE,
@@ -67,7 +78,9 @@ class NET_EXPORT CanonicalCookie {
EXCLUDE_OVERWRITE_HTTP_ONLY,
EXCLUDE_INVALID_DOMAIN,
EXCLUDE_INVALID_PREFIX,
- EXCLUDE_THIRD_PARTY_POLICY
+
+ // Please keep last
+ EXCLUDE_UNKNOWN_ERROR
};
// Creates a new |CanonicalCookie| from the |cookie_line| and the
@@ -166,6 +179,16 @@ class NET_EXPORT CanonicalCookie {
// section 5.1.3 of RFC 6265.
bool IsDomainMatch(const std::string& host) const;
+ // Returns the effective SameSite mode to apply to this cookie. Depends on the
+ // value of the given SameSite attribute and whether the
+ // SameSiteByDefaultCookies feature is enabled.
+ // Note: If you are converting to a different representation of a cookie, you
+ // probably want to use SameSite() instead of this method. Otherwise, if you
+ // are considering using this method, consider whether you should use
+ // IncludeForRequestURL() or IsSetPermittedInContext() instead of doing the
+ // SameSite computation yourself.
+ CookieSameSite GetEffectiveSameSite() const;
+
// Returns if the cookie should be included (and if not, why) for the given
// request |url| using the CookieInclusionStatus enum. HTTP only cookies can
// be filter by using appropriate cookie |options|. PLEASE NOTE that this
@@ -191,6 +214,8 @@ class NET_EXPORT CanonicalCookie {
// are identical for PartialCompare().
bool PartialCompare(const CanonicalCookie& other) const;
+ // TODO(chlily): Remove this. There should not be multiple cookies for which
+ // PartialCompare disagrees. This is only used in tests.
// Returns true if the cookie is less than |other|, considering all fields.
// FullCompare() is consistent with PartialCompare(): cookies sorted using
// FullCompare() are also sorted with respect to PartialCompare().
diff --git a/chromium/net/cookies/canonical_cookie_unittest.cc b/chromium/net/cookies/canonical_cookie_unittest.cc
index 2602b80872d..2b99086ae0d 100644
--- a/chromium/net/cookies/canonical_cookie_unittest.cc
+++ b/chromium/net/cookies/canonical_cookie_unittest.cc
@@ -5,6 +5,8 @@
#include "net/cookies/canonical_cookie.h"
#include "base/test/metrics/histogram_tester.h"
+#include "base/test/scoped_feature_list.h"
+#include "net/base/features.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_options.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,7 +34,7 @@ TEST(CanonicalCookieTest, Constructor) {
std::unique_ptr<CanonicalCookie> cookie(std::make_unique<CanonicalCookie>(
"A", "2", "www.example.com", "/test", current_time, base::Time(),
- base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
@@ -44,7 +46,7 @@ TEST(CanonicalCookieTest, Constructor) {
std::unique_ptr<CanonicalCookie> cookie2(std::make_unique<CanonicalCookie>(
"A", "2", ".www.example.com", "/", current_time, base::Time(),
- base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ("A", cookie2->Name());
EXPECT_EQ("2", cookie2->Value());
@@ -122,16 +124,18 @@ TEST(CanonicalCookieTest, Create) {
CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time,
same_site_options);
- EXPECT_TRUE(cookie.get());
+ ASSERT_TRUE(cookie.get());
EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time,
same_site_options);
+ ASSERT_TRUE(cookie.get());
+ EXPECT_EQ(CookieSameSite::LAX_MODE, cookie->SameSite());
// Test the creating cookies using specific parameter instead of a cookie
// string.
cookie = std::make_unique<CanonicalCookie>(
"A", "2", ".www.example.com", "/test", creation_time, base::Time(),
- base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
@@ -143,7 +147,7 @@ TEST(CanonicalCookieTest, Create) {
cookie = std::make_unique<CanonicalCookie>(
"A", "2", ".www.example.com", "/test", creation_time, base::Time(),
- base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
@@ -420,6 +424,53 @@ TEST(CanonicalCookieTest, IsOnPath) {
EXPECT_TRUE(cookie->IsOnPath("/test/sample/bar.html"));
}
+TEST(CanonicalCookieTest, GetEffectiveSameSite) {
+ struct EffectiveSameSiteTestCase {
+ CookieSameSite same_site;
+ CookieSameSite effective_same_site;
+ };
+
+ base::Time creation_time = base::Time::Now();
+ {
+ base::test::ScopedFeatureList feature_list;
+ feature_list.InitAndDisableFeature(features::kSameSiteByDefaultCookies);
+
+ const EffectiveSameSiteTestCase test_cases[] = {
+ {CookieSameSite::NO_RESTRICTION, CookieSameSite::NO_RESTRICTION},
+ {CookieSameSite::LAX_MODE, CookieSameSite::LAX_MODE},
+ {CookieSameSite::STRICT_MODE, CookieSameSite::STRICT_MODE},
+ {CookieSameSite::EXTENDED_MODE, CookieSameSite::LAX_MODE},
+ {CookieSameSite::UNSPECIFIED, CookieSameSite::NO_RESTRICTION}};
+
+ for (const auto& test_case : test_cases) {
+ CanonicalCookie cookie("A", "2", "example.test", "/", creation_time,
+ base::Time(), base::Time(), true /* secure */,
+ false /* httponly */, test_case.same_site,
+ COOKIE_PRIORITY_DEFAULT);
+ EXPECT_EQ(test_case.effective_same_site, cookie.GetEffectiveSameSite());
+ }
+ }
+ {
+ base::test::ScopedFeatureList feature_list;
+ feature_list.InitAndEnableFeature(features::kSameSiteByDefaultCookies);
+
+ const EffectiveSameSiteTestCase test_cases[] = {
+ {CookieSameSite::NO_RESTRICTION, CookieSameSite::NO_RESTRICTION},
+ {CookieSameSite::LAX_MODE, CookieSameSite::LAX_MODE},
+ {CookieSameSite::STRICT_MODE, CookieSameSite::STRICT_MODE},
+ {CookieSameSite::EXTENDED_MODE, CookieSameSite::LAX_MODE},
+ {CookieSameSite::UNSPECIFIED, CookieSameSite::LAX_MODE}};
+
+ for (const auto& test_case : test_cases) {
+ CanonicalCookie cookie("A", "2", "example.test", "/", creation_time,
+ base::Time(), base::Time(), true /* secure */,
+ false /* httponly */, test_case.same_site,
+ COOKIE_PRIORITY_DEFAULT);
+ EXPECT_EQ(test_case.effective_same_site, cookie.GetEffectiveSameSite());
+ }
+ }
+}
+
TEST(CanonicalCookieTest, IncludeForRequestURL) {
GURL url("http://www.example.com");
base::Time creation_time = base::Time::Now();
@@ -516,6 +567,69 @@ TEST(CanonicalCookieTest, IncludeSameSiteForSameSiteURL) {
CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
CanonicalCookie::CookieInclusionStatus::INCLUDE);
+
+ // TODO(chlily): Use SameSite=None once ParsedCookie supports it.
+ // Cookies without a SameSite attribute are parsed as
+ // CookieSameSite::NO_RESTRICTION, and are included for all URLs.
+ cookie = CanonicalCookie::Create(url, "A=2", creation_time, options);
+ EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::CROSS_SITE);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::SAME_SITE_LAX);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+
+ // TODO(chlily): Use Create() once ParsedCookie supports UNSPECIFIED.
+ // Cookies with CookieSameSite::UNSPECIFIED depend on the FeatureList.
+ cookie = std::make_unique<CanonicalCookie>(
+ "A", "2", "example.test", "/", creation_time, base::Time(), base::Time(),
+ false, false, CookieSameSite::UNSPECIFIED, COOKIE_PRIORITY_DEFAULT);
+ EXPECT_EQ(CookieSameSite::UNSPECIFIED, cookie->SameSite());
+ {
+ base::test::ScopedFeatureList feature_list;
+ feature_list.InitAndDisableFeature(features::kSameSiteByDefaultCookies);
+
+ // With SameSiteByDefault disabled, the cookie is included for all requests.
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::CROSS_SITE);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::SAME_SITE_LAX);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ }
+ {
+ base::test::ScopedFeatureList feature_list;
+ feature_list.InitAndEnableFeature(features::kSameSiteByDefaultCookies);
+
+ // With SameSiteByDefault enabled, the cookie is included for a URL only if
+ // the options' SameSiteCookieMode is SAME_SITE_STRICT or SAME_SITE_LAX.
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::CROSS_SITE);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::
+ EXCLUDE_SAMESITE_UNSPECIFIED_TREATED_AS_LAX);
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::SAME_SITE_LAX);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ options.set_same_site_cookie_context(
+ CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
+ EXPECT_EQ(cookie->IncludeForRequestURL(url, options),
+ CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ }
}
TEST(CanonicalCookieTest, PartialCompare) {
@@ -1040,7 +1154,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(cc);
EXPECT_EQ("A", cc->Name());
@@ -1060,7 +1174,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
two_hours_ago, base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(cc);
EXPECT_EQ(two_hours_ago, cc->CreationDate());
@@ -1069,7 +1183,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
two_hours_ago, base::Time(), one_hour_ago, false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(cc);
EXPECT_EQ(one_hour_ago, cc->LastAccessDate());
@@ -1078,7 +1192,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
base::Time(), one_hour_from_now, base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(cc);
EXPECT_EQ(one_hour_from_now, cc->ExpiryDate());
@@ -1087,7 +1201,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), true /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(cc);
EXPECT_TRUE(cc->IsSecure());
@@ -1096,7 +1210,8 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- true /*httponly*/, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
+ true /*httponly*/, CookieSameSite::NO_RESTRICTION,
+ COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(cc);
EXPECT_TRUE(cc->IsHttpOnly());
@@ -1112,7 +1227,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_LOW);
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW);
EXPECT_TRUE(cc);
EXPECT_EQ(COOKIE_PRIORITY_LOW, cc->Priority());
@@ -1120,7 +1235,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Inputs) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "A", "B", "www.foo.com", "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(cc);
EXPECT_TRUE(cc->IsDomainCookie());
@@ -1137,70 +1252,70 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Logic) {
EXPECT_TRUE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", std::string(), "/foo",
one_hour_ago, one_hour_from_now, base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_TRUE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/bar"), "C", "D", "www.foo.com", "/",
two_hours_ago, base::Time(), one_hour_ago, false /*secure*/,
- true /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ true /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_TRUE(CanonicalCookie::CreateSanitizedCookie(
GURL("https://www.foo.com"), "E", "F", std::string(), std::string(),
base::Time(), base::Time(), base::Time(), true /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
// Test that malformed attributes fail to set the cookie.
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), " A", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A;", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A=", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com"), "A", " B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com"), "A", "B", "www.foo.com ", "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", "foo.ozzzzzzle", "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", std::string(), "foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com"), "A", "B", std::string(), "/foo ",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", "%2Efoo.com", "/foo",
one_hour_ago, one_hour_from_now, base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://domaintest.%E3%81%BF%E3%82%93%E3%81%AA"), "A", "B",
"domaintest.%E3%81%BF%E3%82%93%E3%81%AA", "/foo", base::Time(),
base::Time(), base::Time(), false /*secure*/, false /*httponly*/,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT));
std::unique_ptr<CanonicalCookie> cc;
@@ -1209,7 +1324,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Logic) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", "www.foo.com", "/foo",
one_hour_ago, one_hour_from_now, base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
ASSERT_TRUE(cc);
EXPECT_TRUE(cc->IsDomainCookie());
@@ -1218,7 +1333,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Logic) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", ".www.foo.com", "/foo",
one_hour_ago, one_hour_from_now, base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
ASSERT_TRUE(cc);
EXPECT_TRUE(cc->IsDomainCookie());
@@ -1227,7 +1342,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Logic) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", ".foo.com", "/foo",
one_hour_ago, one_hour_from_now, base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
ASSERT_TRUE(cc);
EXPECT_TRUE(cc->IsDomainCookie());
@@ -1236,7 +1351,7 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Logic) {
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com/foo"), "A", "B", ".www2.www.foo.com", "/foo",
one_hour_ago, one_hour_from_now, base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
EXPECT_FALSE(cc);
@@ -1244,26 +1359,26 @@ TEST(CanonicalCookieTest, CreateSanitizedCookie_Logic) {
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com"), "A", "B", std::string(), "/foo ",
base::Time(), base::Time(), base::Time(), true /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
// Null creation date/non-null last access date conflict.
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com"), "A", "B", std::string(), "/foo", base::Time(),
base::Time(), base::Time::Now(), false /*secure*/, false /*httponly*/,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT));
// Domain doesn't match URL
EXPECT_FALSE(CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com"), "A", "B", "www.bar.com", "/", base::Time(),
base::Time(), base::Time(), false /*secure*/, false /*httponly*/,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT));
// Path with unusual characters escaped.
cc = CanonicalCookie::CreateSanitizedCookie(
GURL("http://www.foo.com"), "A", "B", std::string(), "/foo",
base::Time(), base::Time(), base::Time(), false /*secure*/,
- false /*httponly*/, CookieSameSite::DEFAULT_MODE,
+ false /*httponly*/, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT);
ASSERT_TRUE(cc);
EXPECT_EQ("/foo%7F", cc->Path());
diff --git a/chromium/net/cookies/cookie_constants.cc b/chromium/net/cookies/cookie_constants.cc
index 14140d3d5d0..1215c1bc4d1 100644
--- a/chromium/net/cookies/cookie_constants.cc
+++ b/chromium/net/cookies/cookie_constants.cc
@@ -17,7 +17,9 @@ const char kPriorityHigh[] = "high";
const char kSameSiteLax[] = "lax";
const char kSameSiteStrict[] = "strict";
-const char kSameSiteDefault[] = "default";
+const char kSameSiteNone[] = "none";
+const char kSameSiteExtended[] = "extended";
+const char kSameSiteUnspecified[] = "unspecified";
} // namespace
@@ -54,8 +56,12 @@ std::string CookieSameSiteToString(CookieSameSite same_site) {
return kSameSiteLax;
case CookieSameSite::STRICT_MODE:
return kSameSiteStrict;
- case CookieSameSite::DEFAULT_MODE:
- return kSameSiteDefault;
+ case CookieSameSite::NO_RESTRICTION:
+ return kSameSiteNone;
+ case CookieSameSite::EXTENDED_MODE:
+ return kSameSiteExtended;
+ case CookieSameSite::UNSPECIFIED:
+ return kSameSiteUnspecified;
}
return "INVALID";
}
@@ -65,7 +71,7 @@ CookieSameSite StringToCookieSameSite(const std::string& same_site) {
return CookieSameSite::LAX_MODE;
if (base::EqualsCaseInsensitiveASCII(same_site, kSameSiteStrict))
return CookieSameSite::STRICT_MODE;
- return CookieSameSite::DEFAULT_MODE;
+ return CookieSameSite::NO_RESTRICTION;
}
} // namespace net
diff --git a/chromium/net/cookies/cookie_constants.h b/chromium/net/cookies/cookie_constants.h
index d4f82afbf50..8dde49af478 100644
--- a/chromium/net/cookies/cookie_constants.h
+++ b/chromium/net/cookies/cookie_constants.h
@@ -21,11 +21,13 @@ enum CookiePriority {
// See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00
// and https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis for
// information about same site cookie restrictions.
+// Note: Don't renumber, as these values are persisted to a database.
enum class CookieSameSite {
+ UNSPECIFIED = -1,
NO_RESTRICTION = 0,
LAX_MODE = 1,
STRICT_MODE = 2,
- DEFAULT_MODE = NO_RESTRICTION
+ EXTENDED_MODE = 3
};
// Returns the Set-Cookie header priority token corresponding to |priority|.
@@ -42,7 +44,7 @@ NET_EXPORT CookiePriority StringToCookiePriority(const std::string& priority);
NET_EXPORT std::string CookieSameSiteToString(CookieSameSite same_site);
// Converts the Set-Cookie header SameSite token |same_site| to a
-// CookieSameSite. Defaults to CookieSameSite::DEFAULT_MODE for empty or
+// CookieSameSite. Defaults to CookieSameSite::NO_RESTRICTION for empty or
// unrecognized strings.
NET_EXPORT CookieSameSite StringToCookieSameSite(const std::string& same_site);
diff --git a/chromium/net/cookies/cookie_deletion_info_unittest.cc b/chromium/net/cookies/cookie_deletion_info_unittest.cc
index 2d44aa71437..a6e85353e1c 100644
--- a/chromium/net/cookies/cookie_deletion_info_unittest.cc
+++ b/chromium/net/cookies/cookie_deletion_info_unittest.cc
@@ -86,7 +86,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchSessionControl) {
/*last_access=*/base::Time::Now(),
/*secure=*/false,
/*httponly=*/false,
- CookieSameSite::DEFAULT_MODE,
+ CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
CanonicalCookie session_cookie(
@@ -95,7 +95,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchSessionControl) {
/*expiration=*/base::Time(),
/*last_access=*/base::Time::Now(),
/*secure=*/false,
- /*httponly=*/false, CookieSameSite::DEFAULT_MODE,
+ /*httponly=*/false, CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
CookieDeletionInfo delete_info;
@@ -121,7 +121,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchHost) {
/*last_access=*/base::Time::Now(),
/*secure=*/false,
/*httponly=*/false,
- CookieSameSite::DEFAULT_MODE,
+ CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
CanonicalCookie host_cookie("host-cookie", "host-cookie-value",
@@ -130,7 +130,8 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchHost) {
/*expiration=*/base::Time::Max(),
/*last_access=*/base::Time::Now(),
/*secure=*/false,
- /*httponly=*/false, CookieSameSite::DEFAULT_MODE,
+ /*httponly=*/false,
+ CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
EXPECT_TRUE(domain_cookie.IsDomainCookie());
@@ -160,7 +161,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchName) {
/*expiration=*/base::Time::Max(),
/*last_access=*/base::Time::Now(),
/*secure=*/false,
- /*httponly=*/false, CookieSameSite::DEFAULT_MODE,
+ /*httponly=*/false, CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
CanonicalCookie cookie2("cookie2-name", "cookie2-value",
/*domain=*/".example.com", "/path",
@@ -168,7 +169,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchName) {
/*expiration=*/base::Time::Max(),
/*last_access=*/base::Time::Now(),
/*secure=*/false,
- /*httponly=*/false, CookieSameSite::DEFAULT_MODE,
+ /*httponly=*/false, CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
CookieDeletionInfo delete_info;
@@ -184,7 +185,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchValue) {
/*expiration=*/base::Time::Max(),
/*last_access=*/base::Time::Now(),
/*secure=*/false,
- /*httponly=*/false, CookieSameSite::DEFAULT_MODE,
+ /*httponly=*/false, CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
CanonicalCookie cookie2("cookie2-name", "cookie2-value",
/*domain=*/".example.com", "/path",
@@ -192,7 +193,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchValue) {
/*expiration=*/base::Time::Max(),
/*last_access=*/base::Time::Now(),
/*secure=*/false,
- /*httponly=*/false, CookieSameSite::DEFAULT_MODE,
+ /*httponly=*/false, CookieSameSite::NO_RESTRICTION,
CookiePriority::COOKIE_PRIORITY_DEFAULT);
CookieDeletionInfo delete_info;
@@ -237,7 +238,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoDomainMatchesDomain) {
/*last_access=*/base::Time::FromDoubleT(kTestMinEpoch + 1),
/*secure=*/false,
/*httponly=*/false,
- /*same_site=*/CookieSameSite::DEFAULT_MODE,
+ /*same_site=*/CookieSameSite::NO_RESTRICTION,
/*priority=*/CookiePriority::COOKIE_PRIORITY_DEFAULT);
return cookie;
};
@@ -273,7 +274,7 @@ TEST(CookieDeletionInfoTest, CookieDeletionInfoMatchesDomainList) {
/*last_access=*/base::Time::Now(),
/*secure=*/false,
/*httponly=*/false,
- /*same_site=*/CookieSameSite::DEFAULT_MODE,
+ /*same_site=*/CookieSameSite::NO_RESTRICTION,
/*priority=*/CookiePriority::COOKIE_PRIORITY_DEFAULT);
return cookie;
};
diff --git a/chromium/net/cookies/cookie_monster.cc b/chromium/net/cookies/cookie_monster.cc
index 4fa8571a9f7..e7ad8df8817 100644
--- a/chromium/net/cookies/cookie_monster.cc
+++ b/chromium/net/cookies/cookie_monster.cc
@@ -69,7 +69,6 @@
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
#include "net/log/net_log.h"
-#include "net/ssl/channel_id_service.h"
#include "url/origin.h"
using base::Time;
@@ -337,24 +336,15 @@ size_t CountCookiesForPossibleDeletion(
} // namespace
CookieMonster::CookieMonster(scoped_refptr<PersistentCookieStore> store,
- ChannelIDService* channel_id_service,
NetLog* net_log)
: CookieMonster(
std::move(store),
- channel_id_service,
base::TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds),
net_log) {}
CookieMonster::CookieMonster(scoped_refptr<PersistentCookieStore> store,
base::TimeDelta last_access_threshold,
NetLog* net_log)
- : CookieMonster(std::move(store), nullptr, last_access_threshold, net_log) {
-}
-
-CookieMonster::CookieMonster(scoped_refptr<PersistentCookieStore> store,
- ChannelIDService* channel_id_service,
- base::TimeDelta last_access_threshold,
- NetLog* net_log)
: initialized_(false),
started_fetching_all_cookies_(false),
finished_fetching_all_cookies_(false),
@@ -362,7 +352,6 @@ CookieMonster::CookieMonster(scoped_refptr<PersistentCookieStore> store,
net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::COOKIE_STORE)),
store_(std::move(store)),
last_access_threshold_(last_access_threshold),
- channel_id_service_(channel_id_service),
last_statistic_record_time_(base::Time::Now()),
persist_session_cookies_(false),
weak_ptr_factory_(this) {
@@ -370,21 +359,10 @@ CookieMonster::CookieMonster(scoped_refptr<PersistentCookieStore> store,
cookieable_schemes_.insert(
cookieable_schemes_.begin(), kDefaultCookieableSchemes,
kDefaultCookieableSchemes + kDefaultCookieableSchemesCount);
- if (channel_id_service_ && store_) {
- // |store_| can outlive this CookieMonster, but there are no guarantees
- // about the lifetime of |channel_id_service_| relative to |store_|. The
- // only guarantee is that |channel_id_service_| will outlive this
- // CookieMonster. To avoid the PersistentCookieStore retaining a pointer to
- // the ChannelIDStore via this callback after this CookieMonster is
- // destroyed, CookieMonster's d'tor sets the callback to a null callback.
- store_->SetBeforeFlushCallback(
- base::Bind(&ChannelIDStore::Flush,
- base::Unretained(channel_id_service_->GetChannelIDStore())));
- }
net_log_.BeginEvent(
NetLogEventType::COOKIE_STORE_ALIVE,
base::BindRepeating(&NetLogCookieMonsterConstructorCallback,
- store != nullptr, channel_id_service != nullptr));
+ store != nullptr));
}
// Asynchronous CookieMonster API
@@ -420,7 +398,7 @@ void CookieMonster::SetAllCookiesAsync(const CookieList& list,
void CookieMonster::SetCanonicalCookieAsync(
std::unique_ptr<CanonicalCookie> cookie,
std::string source_scheme,
- bool modify_http_only,
+ const CookieOptions& options,
SetCookiesCallback callback) {
DCHECK(cookie->IsCanonical());
@@ -431,7 +409,7 @@ void CookieMonster::SetCanonicalCookieAsync(
// the callback on |*this|, so the callback will not outlive
// the object.
&CookieMonster::SetCanonicalCookie, base::Unretained(this),
- std::move(cookie), std::move(source_scheme), modify_http_only,
+ std::move(cookie), std::move(source_scheme), options,
std::move(callback)),
domain);
}
@@ -515,15 +493,19 @@ void CookieMonster::DeleteSessionCookiesAsync(
}
void CookieMonster::SetCookieableSchemes(
- const std::vector<std::string>& schemes) {
+ const std::vector<std::string>& schemes,
+ SetCookieableSchemesCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
// Calls to this method will have no effect if made after a WebView or
// CookieManager instance has been created.
- if (initialized_)
+ if (initialized_) {
+ MaybeRunCookieCallback(std::move(callback), false);
return;
+ }
cookieable_schemes_ = schemes;
+ MaybeRunCookieCallback(std::move(callback), true);
}
// This function must be called before the CookieMonster is used.
@@ -584,10 +566,6 @@ void CookieMonster::DumpMemoryStats(
CookieMonster::~CookieMonster() {
DCHECK(thread_checker_.CalledOnValidThread());
- if (channel_id_service_ && store_) {
- store_->SetBeforeFlushCallback(base::Closure());
- }
-
// TODO(mmenke): Does it really make sense to run
// CookieChanged callbacks when the CookieStore is destroyed?
for (auto cookie_it = cookies_.begin(); cookie_it != cookies_.end();) {
@@ -611,7 +589,7 @@ void CookieMonster::GetAllCookies(GetCookieListCallback callback) {
// Note that this does not prune cookies to be below our limits (if we've
// exceeded them) the way that calling GarbageCollect() would.
GarbageCollectExpired(
- Time::Now(), CookieMapItPair(cookies_.begin(), cookies_.end()), NULL);
+ Time::Now(), CookieMapItPair(cookies_.begin(), cookies_.end()), nullptr);
// Copy the CanonicalCookie pointers from the map so that we can use the same
// sorter as elsewhere, then copy the result out.
@@ -711,7 +689,7 @@ void CookieMonster::SetCookieWithOptions(const GURL& url,
return;
}
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "SetCookie() line: " << cookie_line;
CanonicalCookie::CookieInclusionStatus status;
@@ -721,15 +699,14 @@ void CookieMonster::SetCookieWithOptions(const GURL& url,
if (status != CanonicalCookie::CookieInclusionStatus::INCLUDE) {
DCHECK(!cc);
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "WARNING: Failed to allocate CanonicalCookie";
MaybeRunCookieCallback(std::move(callback), status);
return;
}
DCHECK(cc);
- SetCanonicalCookie(std::move(cc), url.scheme(), !options.exclude_httponly(),
- std::move(callback));
+ SetCanonicalCookie(std::move(cc), url.scheme(), options, std::move(callback));
}
void CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie,
@@ -800,8 +777,8 @@ void CookieMonster::FetchAllCookies() {
// We bind in the current time so that we can report the wall-clock time for
// loading cookies.
- store_->Load(base::Bind(&CookieMonster::OnLoaded,
- weak_ptr_factory_.GetWeakPtr(), TimeTicks::Now()),
+ store_->Load(base::BindOnce(&CookieMonster::OnLoaded,
+ weak_ptr_factory_.GetWeakPtr(), TimeTicks::Now()),
net_log_);
}
@@ -1189,9 +1166,10 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie(
auto inserted = cookies_.insert(CookieMap::value_type(key, std::move(cc)));
// See InitializeHistograms() for details.
- int32_t type_sample = cc_ptr->SameSite() != CookieSameSite::NO_RESTRICTION
- ? 1 << COOKIE_TYPE_SAME_SITE
- : 0;
+ int32_t type_sample =
+ cc_ptr->GetEffectiveSameSite() != CookieSameSite::NO_RESTRICTION
+ ? 1 << COOKIE_TYPE_SAME_SITE
+ : 0;
type_sample |= cc_ptr->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0;
type_sample |= cc_ptr->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0;
histogram_cookie_type_->Add(type_sample);
@@ -1203,7 +1181,7 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie(
void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
std::string source_scheme,
- bool modify_http_only,
+ const CookieOptions& options,
SetCookiesCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -1216,7 +1194,7 @@ void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
return;
}
- if ((cc->IsHttpOnly() && !modify_http_only)) {
+ if (cc->IsHttpOnly() && options.exclude_httponly()) {
MaybeRunCookieCallback(
std::move(callback),
CanonicalCookie::CookieInclusionStatus::EXCLUDE_HTTP_ONLY);
@@ -1241,9 +1219,9 @@ void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
base::Time creation_date_to_inherit;
- CanonicalCookie::CookieInclusionStatus status =
- DeleteAnyEquivalentCookie(key, *cc, secure_source, !modify_http_only,
- already_expired, &creation_date_to_inherit);
+ CanonicalCookie::CookieInclusionStatus status = DeleteAnyEquivalentCookie(
+ key, *cc, secure_source, options.exclude_httponly(), already_expired,
+ &creation_date_to_inherit);
if (status != CanonicalCookie::CookieInclusionStatus::INCLUDE) {
std::string error;
@@ -1251,12 +1229,12 @@ void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
"SetCookie() not clobbering httponly cookie or secure cookie for "
"insecure scheme";
- VLOG(net::cookie_util::kVlogSetCookies) << error;
+ DVLOG(net::cookie_util::kVlogSetCookies) << error;
MaybeRunCookieCallback(std::move(callback), status);
return;
}
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "SetCookie() key: " << key << " cc: " << cc->DebugString();
// Realize that we might be setting an expired cookie, and the only point
@@ -1289,7 +1267,7 @@ void CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc,
InternalInsertCookie(key, std::move(cc), true);
} else {
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "SetCookie() not storing already expired cookie.";
}
@@ -1368,7 +1346,7 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it,
"kChangeCauseMapping size should match DeletionCause size");
CanonicalCookie* cc = it->second.get();
- VLOG(net::cookie_util::kVlogSetCookies)
+ DVLOG(net::cookie_util::kVlogSetCookies)
<< "InternalDeleteCookie()"
<< ", cause:" << deletion_cause << ", cc: " << cc->DebugString();
@@ -1398,7 +1376,7 @@ size_t CookieMonster::GarbageCollect(const Time& current,
// Collect garbage for this key, minding cookie priorities.
if (cookies_.count(key) > kDomainMaxCookies) {
- VLOG(net::cookie_util::kVlogGarbageCollection)
+ DVLOG(net::cookie_util::kVlogGarbageCollection)
<< "GarbageCollect() key: " << key;
CookieItVector* cookie_its;
@@ -1409,7 +1387,7 @@ size_t CookieMonster::GarbageCollect(const Time& current,
GarbageCollectExpired(current, cookies_.equal_range(key), cookie_its);
if (cookie_its->size() > kDomainMaxCookies) {
- VLOG(net::cookie_util::kVlogGarbageCollection)
+ DVLOG(net::cookie_util::kVlogGarbageCollection)
<< "Deep Garbage Collect domain.";
size_t purge_goal =
cookie_its->size() - (kDomainMaxCookies - kDomainPurgeCookies);
@@ -1488,7 +1466,7 @@ size_t CookieMonster::GarbageCollect(const Time& current,
// Collect garbage for everything. With firefox style we want to preserve
// cookies accessed in kSafeFromGlobalPurgeDays, otherwise evict.
if (cookies_.size() > kMaxCookies && earliest_access_time_ < safe_date) {
- VLOG(net::cookie_util::kVlogGarbageCollection)
+ DVLOG(net::cookie_util::kVlogGarbageCollection)
<< "GarbageCollect() everything";
CookieItVector cookie_its;
@@ -1497,7 +1475,7 @@ size_t CookieMonster::GarbageCollect(const Time& current,
&cookie_its);
if (cookie_its.size() > kMaxCookies) {
- VLOG(net::cookie_util::kVlogGarbageCollection)
+ DVLOG(net::cookie_util::kVlogGarbageCollection)
<< "Deep Garbage Collect everything.";
size_t purge_goal = cookie_its.size() - (kMaxCookies - kPurgeCookies);
DCHECK(purge_goal > kPurgeCookies);
@@ -1714,7 +1692,7 @@ bool CookieMonster::HasCookieableScheme(const GURL& url) {
}
// The scheme didn't match any in our whitelist.
- VLOG(net::cookie_util::kVlogPerCookieMonster)
+ DVLOG(net::cookie_util::kVlogPerCookieMonster)
<< "WARNING: Unsupported cookie scheme: " << url.scheme();
return false;
}
@@ -1843,8 +1821,8 @@ void CookieMonster::DoCookieCallbackForHostOrDomain(
auto it = tasks_pending_for_key_.find(key);
if (it == tasks_pending_for_key_.end()) {
store_->LoadCookiesForKey(
- key, base::Bind(&CookieMonster::OnKeyLoaded,
- weak_ptr_factory_.GetWeakPtr(), key));
+ key, base::BindOnce(&CookieMonster::OnKeyLoaded,
+ weak_ptr_factory_.GetWeakPtr(), key));
it = tasks_pending_for_key_
.insert(std::make_pair(
key, base::circular_deque<base::OnceClosure>()))
diff --git a/chromium/net/cookies/cookie_monster.h b/chromium/net/cookies/cookie_monster.h
index b9aeaaf204c..747b3789374 100644
--- a/chromium/net/cookies/cookie_monster.h
+++ b/chromium/net/cookies/cookie_monster.h
@@ -40,7 +40,6 @@ class HistogramBase;
namespace net {
-class ChannelIDService;
class CookieChangeDispatcher;
// The cookie monster is the system for storing and retrieving cookies. It has
@@ -131,12 +130,8 @@ class NET_EXPORT CookieMonster : public CookieStore {
// class will take care of initializing it. The backing store is NOT owned by
// this class, but it must remain valid for the duration of the cookie
// monster's existence. If |store| is NULL, then no backing store will be
- // updated. |channel_id_service| is a non-owninng pointer for the
- // corresponding ChannelIDService used with this CookieStore. The
- // |channel_id_service| must outlive the CookieMonster. |net_log| must outlive
- // the CookieMonster. Both |channel_id_service| and |net_log| can be null.
+ // updated. |net_log| must outlive the CookieMonster and can be null.
CookieMonster(scoped_refptr<PersistentCookieStore> store,
- ChannelIDService* channel_id_service,
NetLog* net_log);
// Only used during unit testing.
@@ -162,7 +157,7 @@ class NET_EXPORT CookieMonster : public CookieStore {
SetCookiesCallback callback) override;
void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie,
std::string source_scheme,
- bool modify_http_only,
+ const CookieOptions& options,
SetCookiesCallback callback) override;
void GetCookieListWithOptionsAsync(const GURL& url,
const CookieOptions& options,
@@ -179,11 +174,8 @@ class NET_EXPORT CookieMonster : public CookieStore {
void FlushStore(base::OnceClosure callback) override;
void SetForceKeepSessionState() override;
CookieChangeDispatcher& GetChangeDispatcher() override;
-
- // Resets the list of cookieable schemes to the supplied schemes. Does
- // nothing if called after first use of the instance (i.e. after the
- // instance initialization process).
- void SetCookieableSchemes(const std::vector<std::string>& schemes);
+ void SetCookieableSchemes(const std::vector<std::string>& schemes,
+ SetCookieableSchemesCallback callback) override;
// Enables writing session cookies into the cookie database. If this this
// method is called, it must be called before first use of the instance
@@ -210,11 +202,6 @@ class NET_EXPORT CookieMonster : public CookieStore {
static std::string GetKey(base::StringPiece domain);
private:
- CookieMonster(scoped_refptr<PersistentCookieStore> store,
- ChannelIDService* channel_id_service,
- base::TimeDelta last_access_threshold,
- NetLog* net_log);
-
// For garbage collection constants.
FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection);
FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers);
@@ -359,13 +346,15 @@ class NET_EXPORT CookieMonster : public CookieStore {
static const int kRecordStatisticsIntervalSeconds = 10 * 60;
// Sets a canonical cookie, deletes equivalents and performs garbage
- // collection. |source_secure| indicates if the cookie is being set
- // from a secure source (e.g. a cryptographic scheme).
- // |modify_http_only| indicates if this setting operation is allowed
- // to affect http_only cookies.
+ // collection. |source_scheme| indicates what scheme the cookie is being set
+ // from; secure cookies cannot be altered from insecure schemes, and some
+ // schemes may not be authorized.
+ //
+ // |options| indicates if this setting operation is allowed
+ // to affect http_only or same-site cookies.
void SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cookie,
std::string source_scheme,
- bool can_modify_httponly,
+ const CookieOptions& options,
SetCookiesCallback callback);
void GetAllCookies(GetCookieListCallback callback);
@@ -631,8 +620,6 @@ class NET_EXPORT CookieMonster : public CookieStore {
std::vector<std::string> cookieable_schemes_;
- ChannelIDService* channel_id_service_;
-
base::Time last_statistic_record_time_;
bool persist_session_cookies_;
@@ -650,7 +637,8 @@ typedef base::RefCountedThreadSafe<CookieMonster::PersistentCookieStore>
class NET_EXPORT CookieMonster::PersistentCookieStore
: public RefcountedPersistentCookieStore {
public:
- typedef base::Callback<void(std::vector<std::unique_ptr<CanonicalCookie>>)>
+ typedef base::OnceCallback<void(
+ std::vector<std::unique_ptr<CanonicalCookie>>)>
LoadedCallback;
// Initializes the store and retrieves the existing cookies. This will be
@@ -660,7 +648,7 @@ class NET_EXPORT CookieMonster::PersistentCookieStore
// |loaded_callback| may not be NULL.
// |net_log| is a NetLogWithSource that may be copied if the persistent
// store wishes to log NetLog events.
- virtual void Load(const LoadedCallback& loaded_callback,
+ virtual void Load(LoadedCallback loaded_callback,
const NetLogWithSource& net_log) = 0;
// Does a priority load of all cookies for the domain key (eTLD+1). The
@@ -671,7 +659,7 @@ class NET_EXPORT CookieMonster::PersistentCookieStore
//
// |loaded_callback| may not be NULL.
virtual void LoadCookiesForKey(const std::string& key,
- const LoadedCallback& loaded_callback) = 0;
+ LoadedCallback loaded_callback) = 0;
virtual void AddCookie(const CanonicalCookie& cc) = 0;
virtual void UpdateCookieAccessTime(const CanonicalCookie& cc) = 0;
@@ -683,7 +671,7 @@ class NET_EXPORT CookieMonster::PersistentCookieStore
// Sets a callback that will be run before the store flushes. If |callback|
// performs any async operations, the store will not wait for those to finish
// before flushing.
- virtual void SetBeforeFlushCallback(base::RepeatingClosure callback) = 0;
+ virtual void SetBeforeCommitCallback(base::RepeatingClosure callback) = 0;
// Flushes the store and posts |callback| when complete. |callback| may be
// NULL.
diff --git a/chromium/net/cookies/cookie_monster_netlog_params.cc b/chromium/net/cookies/cookie_monster_netlog_params.cc
index b4b17d286f7..dff8422d739 100644
--- a/chromium/net/cookies/cookie_monster_netlog_params.cc
+++ b/chromium/net/cookies/cookie_monster_netlog_params.cc
@@ -11,12 +11,10 @@ namespace net {
std::unique_ptr<base::Value> NetLogCookieMonsterConstructorCallback(
bool persistent_store,
- bool channel_id_service,
NetLogCaptureMode /* capture_mode */) {
std::unique_ptr<base::Value> dict =
std::make_unique<base::Value>(base::Value::Type::DICTIONARY);
dict->SetKey("persistent_store", base::Value(persistent_store));
- dict->SetKey("channel_id_service", base::Value(channel_id_service));
return dict;
}
diff --git a/chromium/net/cookies/cookie_monster_netlog_params.h b/chromium/net/cookies/cookie_monster_netlog_params.h
index 8a5dc1fc2e1..16ab7727076 100644
--- a/chromium/net/cookies/cookie_monster_netlog_params.h
+++ b/chromium/net/cookies/cookie_monster_netlog_params.h
@@ -20,7 +20,6 @@ namespace net {
// a CookieMonster.
std::unique_ptr<base::Value> NetLogCookieMonsterConstructorCallback(
bool persistent_store,
- bool channel_id_service,
NetLogCaptureMode capture_mode);
// Returns a Value containing NetLog parameters for adding a cookie.
diff --git a/chromium/net/cookies/cookie_monster_perftest.cc b/chromium/net/cookies/cookie_monster_perftest.cc
index b7c90ec0787..55e2cc72962 100644
--- a/chromium/net/cookies/cookie_monster_perftest.cc
+++ b/chromium/net/cookies/cookie_monster_perftest.cc
@@ -137,7 +137,7 @@ TEST(ParsedCookieTest, TestParseBigCookies) {
}
TEST_F(CookieMonsterTest, TestAddCookiesOnSingleHost) {
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, nullptr);
+ auto cm = std::make_unique<CookieMonster>(nullptr, nullptr);
std::vector<std::string> cookies;
for (int i = 0; i < kNumCookies; i++) {
cookies.push_back(base::StringPrintf("a%03d=b", i));
@@ -170,7 +170,7 @@ TEST_F(CookieMonsterTest, TestAddCookiesOnSingleHost) {
}
TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) {
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, nullptr);
+ auto cm = std::make_unique<CookieMonster>(nullptr, nullptr);
std::string cookie(kCookieLine);
std::vector<GURL> gurls; // just wanna have ffffuunnn
for (int i = 0; i < kNumCookies; ++i) {
@@ -203,7 +203,7 @@ TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) {
}
TEST_F(CookieMonsterTest, TestDomainTree) {
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, nullptr);
+ auto cm = std::make_unique<CookieMonster>(nullptr, nullptr);
GetCookieListCallback getCookieListCallback;
SetCookieCallback setCookieCallback;
const char domain_cookie_format_tree[] = "a=b; domain=%s";
@@ -259,7 +259,7 @@ TEST_F(CookieMonsterTest, TestDomainTree) {
}
TEST_F(CookieMonsterTest, TestDomainLine) {
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, nullptr);
+ auto cm = std::make_unique<CookieMonster>(nullptr, nullptr);
SetCookieCallback setCookieCallback;
GetCookieListCallback getCookieListCallback;
std::vector<std::string> domain_list;
@@ -320,8 +320,7 @@ TEST_F(CookieMonsterTest, TestImport) {
store->SetLoadExpectation(true, std::move(initial_cookies));
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, nullptr));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr));
// Import will happen on first access.
GURL gurl("www.foo.com");
@@ -335,8 +334,7 @@ TEST_F(CookieMonsterTest, TestImport) {
}
TEST_F(CookieMonsterTest, TestGetKey) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, nullptr));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
base::PerfTimeLogger timer("Cookie_monster_get_key");
for (int i = 0; i < kNumCookies; i++)
cm->GetKey("www.foo.com");
diff --git a/chromium/net/cookies/cookie_monster_store_test.cc b/chromium/net/cookies/cookie_monster_store_test.cc
index d31091b9ce1..b50d1b074f1 100644
--- a/chromium/net/cookies/cookie_monster_store_test.cc
+++ b/chromium/net/cookies/cookie_monster_store_test.cc
@@ -20,16 +20,14 @@ namespace net {
CookieStoreCommand::CookieStoreCommand(
Type type,
- const CookieMonster::PersistentCookieStore::LoadedCallback& loaded_callback,
+ CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback,
const std::string& key)
- : type(type), loaded_callback(loaded_callback), key(key) {}
+ : type(type), loaded_callback(std::move(loaded_callback)), key(key) {}
CookieStoreCommand::CookieStoreCommand(Type type, const CanonicalCookie& cookie)
: type(type), cookie(cookie) {}
-CookieStoreCommand::CookieStoreCommand(const CookieStoreCommand& other) =
- default;
-
+CookieStoreCommand::CookieStoreCommand(CookieStoreCommand&& other) = default;
CookieStoreCommand::~CookieStoreCommand() = default;
MockPersistentCookieStore::MockPersistentCookieStore()
@@ -42,11 +40,11 @@ void MockPersistentCookieStore::SetLoadExpectation(
load_result_.swap(result);
}
-void MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback,
+void MockPersistentCookieStore::Load(LoadedCallback loaded_callback,
const NetLogWithSource& /* net_log */) {
if (store_load_commands_) {
- commands_.push_back(
- CookieStoreCommand(CookieStoreCommand::LOAD, loaded_callback, ""));
+ commands_.push_back(CookieStoreCommand(CookieStoreCommand::LOAD,
+ std::move(loaded_callback), ""));
return;
}
std::vector<std::unique_ptr<CanonicalCookie>> out_cookies;
@@ -55,23 +53,26 @@ void MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback,
loaded_ = true;
}
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::BindOnce(loaded_callback, std::move(out_cookies)));
+ FROM_HERE,
+ base::BindOnce(std::move(loaded_callback), std::move(out_cookies)));
}
void MockPersistentCookieStore::LoadCookiesForKey(
const std::string& key,
- const LoadedCallback& loaded_callback) {
+ LoadedCallback loaded_callback) {
if (store_load_commands_) {
- commands_.push_back(CookieStoreCommand(
- CookieStoreCommand::LOAD_COOKIES_FOR_KEY, loaded_callback, key));
+ commands_.push_back(
+ CookieStoreCommand(CookieStoreCommand::LOAD_COOKIES_FOR_KEY,
+ std::move(loaded_callback), key));
return;
}
if (!loaded_) {
- Load(loaded_callback, NetLogWithSource());
+ Load(std::move(loaded_callback), NetLogWithSource());
} else {
std::vector<std::unique_ptr<CanonicalCookie>> empty_cookies;
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::BindOnce(loaded_callback, std::move(empty_cookies)));
+ FROM_HERE,
+ base::BindOnce(std::move(loaded_callback), std::move(empty_cookies)));
}
}
@@ -89,7 +90,7 @@ void MockPersistentCookieStore::DeleteCookie(const CanonicalCookie& cookie) {
void MockPersistentCookieStore::SetForceKeepSessionState() {}
-void MockPersistentCookieStore::SetBeforeFlushCallback(
+void MockPersistentCookieStore::SetBeforeCommitCallback(
base::RepeatingClosure callback) {}
void MockPersistentCookieStore::Flush(base::OnceClosure callback) {
@@ -139,7 +140,7 @@ MockSimplePersistentCookieStore::MockSimplePersistentCookieStore()
}
void MockSimplePersistentCookieStore::Load(
- const LoadedCallback& loaded_callback,
+ LoadedCallback loaded_callback,
const NetLogWithSource& /* net_log */) {
std::vector<std::unique_ptr<CanonicalCookie>> out_cookies;
@@ -147,19 +148,21 @@ void MockSimplePersistentCookieStore::Load(
out_cookies.push_back(std::make_unique<CanonicalCookie>(it->second));
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::BindOnce(loaded_callback, std::move(out_cookies)));
+ FROM_HERE,
+ base::BindOnce(std::move(loaded_callback), std::move(out_cookies)));
loaded_ = true;
}
void MockSimplePersistentCookieStore::LoadCookiesForKey(
const std::string& key,
- const LoadedCallback& loaded_callback) {
+ LoadedCallback loaded_callback) {
if (!loaded_) {
- Load(loaded_callback, NetLogWithSource());
+ Load(std::move(loaded_callback), NetLogWithSource());
} else {
std::vector<std::unique_ptr<CanonicalCookie>> empty_cookies;
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::BindOnce(loaded_callback, std::move(empty_cookies)));
+ FROM_HERE,
+ base::BindOnce(std::move(loaded_callback), std::move(empty_cookies)));
}
}
@@ -186,7 +189,7 @@ void MockSimplePersistentCookieStore::DeleteCookie(
void MockSimplePersistentCookieStore::SetForceKeepSessionState() {}
-void MockSimplePersistentCookieStore::SetBeforeFlushCallback(
+void MockSimplePersistentCookieStore::SetBeforeCommitCallback(
base::RepeatingClosure callback) {}
void MockSimplePersistentCookieStore::Flush(base::OnceClosure callback) {
@@ -233,12 +236,12 @@ std::unique_ptr<CookieMonster> CreateMonsterFromStoreForGC(
std::unique_ptr<CanonicalCookie> cc(std::make_unique<CanonicalCookie>(
"a", "1", base::StringPrintf("h%05d.izzle", i), "/path", creation_time,
expiration_time, base::Time(), secure, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT));
cc->SetLastAccessDate(last_access_time);
store->AddCookie(*cc);
}
- return std::make_unique<CookieMonster>(store.get(), nullptr, nullptr);
+ return std::make_unique<CookieMonster>(store.get(), nullptr);
}
MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() = default;
diff --git a/chromium/net/cookies/cookie_monster_store_test.h b/chromium/net/cookies/cookie_monster_store_test.h
index cc8b25a28d0..4f034827484 100644
--- a/chromium/net/cookies/cookie_monster_store_test.h
+++ b/chromium/net/cookies/cookie_monster_store_test.h
@@ -46,16 +46,14 @@ struct CookieStoreCommand {
// Constructor for LOAD and LOAD_COOKIES_FOR_KEY calls. |key| should be empty
// for LOAD_COOKIES_FOR_KEY.
- CookieStoreCommand(Type type,
- const CookieMonster::PersistentCookieStore::LoadedCallback&
- loaded_callback,
- const std::string& key);
+ CookieStoreCommand(
+ Type type,
+ CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback,
+ const std::string& key);
// Constructor for ADD, UPDATE_ACCESS_TIME, and REMOVE calls.
CookieStoreCommand(Type type, const CanonicalCookie& cookie);
-
- CookieStoreCommand(const CookieStoreCommand& other);
-
+ CookieStoreCommand(CookieStoreCommand&& other);
~CookieStoreCommand();
Type type;
@@ -89,12 +87,17 @@ class MockPersistentCookieStore : public CookieMonster::PersistentCookieStore {
std::vector<std::unique_ptr<CanonicalCookie>> result);
const CommandList& commands() const { return commands_; }
+ CommandList TakeCommands() { return std::move(commands_); }
+ CookieMonster::PersistentCookieStore::LoadedCallback TakeCallbackAt(
+ size_t i) {
+ return std::move(commands_[i].loaded_callback);
+ }
- void Load(const LoadedCallback& loaded_callback,
+ void Load(LoadedCallback loaded_callback,
const NetLogWithSource& net_log) override;
void LoadCookiesForKey(const std::string& key,
- const LoadedCallback& loaded_callback) override;
+ LoadedCallback loaded_callback) override;
void AddCookie(const CanonicalCookie& cookie) override;
@@ -104,7 +107,7 @@ class MockPersistentCookieStore : public CookieMonster::PersistentCookieStore {
void SetForceKeepSessionState() override;
- void SetBeforeFlushCallback(base::RepeatingClosure callback) override;
+ void SetBeforeCommitCallback(base::RepeatingClosure callback) override;
void Flush(base::OnceClosure callback) override;
@@ -145,11 +148,11 @@ class MockSimplePersistentCookieStore
public:
MockSimplePersistentCookieStore();
- void Load(const LoadedCallback& loaded_callback,
+ void Load(LoadedCallback loaded_callback,
const NetLogWithSource& net_log) override;
void LoadCookiesForKey(const std::string& key,
- const LoadedCallback& loaded_callback) override;
+ LoadedCallback loaded_callback) override;
void AddCookie(const CanonicalCookie& cookie) override;
@@ -159,7 +162,7 @@ class MockSimplePersistentCookieStore
void SetForceKeepSessionState() override;
- void SetBeforeFlushCallback(base::RepeatingClosure callback) override;
+ void SetBeforeCommitCallback(base::RepeatingClosure callback) override;
void Flush(base::OnceClosure callback) override;
diff --git a/chromium/net/cookies/cookie_monster_unittest.cc b/chromium/net/cookies/cookie_monster_unittest.cc
index b4c354cbe77..3256a998441 100644
--- a/chromium/net/cookies/cookie_monster_unittest.cc
+++ b/chromium/net/cookies/cookie_monster_unittest.cc
@@ -25,6 +25,7 @@
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/stringprintf.h"
+#include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/threading/thread.h"
@@ -57,32 +58,6 @@ using CookieDeletionInfo = net::CookieDeletionInfo;
namespace {
-// TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and
-// brethren) with this one, and remove the 'New' prefix.
-class NewMockPersistentCookieStore
- : public CookieMonster::PersistentCookieStore {
- public:
- MOCK_METHOD2(Load,
- void(const LoadedCallback& loaded_callback,
- const NetLogWithSource& net_log));
- MOCK_METHOD2(LoadCookiesForKey,
- void(const std::string& key,
- const LoadedCallback& loaded_callback));
- MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc));
- MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc));
- MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc));
- MOCK_METHOD1(SetBeforeFlushCallback, void(base::RepeatingClosure));
- void Flush(base::OnceClosure callback) override {
- if (!callback.is_null())
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- std::move(callback));
- }
- MOCK_METHOD0(SetForceKeepSessionState, void());
-
- private:
- ~NewMockPersistentCookieStore() override = default;
-};
-
// False means 'less than or equal', so we test both ways for full equal.
MATCHER_P(CookieEquals, expected, "") {
return !(arg.FullCompare(expected) || expected.FullCompare(arg));
@@ -97,7 +72,6 @@ const char kOtherDomain[] = "http://www.mit.edu";
struct CookieMonsterTestTraits {
static std::unique_ptr<CookieStore> Create() {
return std::make_unique<CookieMonster>(nullptr /* store */,
- nullptr /* channel_id_service */,
nullptr /* netlog */);
}
@@ -145,10 +119,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
const CookieOptions& options) {
DCHECK(cm);
GetCookieListCallback callback;
- cm->GetCookieListWithOptionsAsync(
- url, options,
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&callback)));
+ cm->GetCookieListWithOptionsAsync(url, options, callback.MakeCallback());
callback.WaitUntilDone();
return callback.cookies();
}
@@ -159,10 +130,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
const CookieOptions& options) {
DCHECK(cm);
GetCookieListCallback callback;
- cm->GetCookieListWithOptionsAsync(
- url, options,
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&callback)));
+ cm->GetCookieListWithOptionsAsync(url, options, callback.MakeCallback());
callback.WaitUntilDone();
return callback.excluded_cookies();
}
@@ -170,10 +138,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
bool SetAllCookies(CookieMonster* cm, const CookieList& list) {
DCHECK(cm);
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> callback;
- cm->SetAllCookiesAsync(
- list, base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&callback)));
+ cm->SetAllCookiesAsync(list, callback.MakeCallback());
callback.WaitUntilDone();
return callback.result() == CanonicalCookie::CookieInclusionStatus::INCLUDE;
}
@@ -188,10 +153,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
cm->SetCanonicalCookieAsync(
CanonicalCookie::Create(url, cookie_line, creation_time,
CookieOptions()),
- url.scheme(), /* modify_httponly = */ false,
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&callback)));
+ url.scheme(), CookieOptions(), callback.MakeCallback());
callback.WaitUntilDone();
return callback.result() == CanonicalCookie::CookieInclusionStatus::INCLUDE;
}
@@ -200,10 +162,8 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
const TimeRange& creation_range) {
DCHECK(cm);
ResultSavingCookieCallback<uint32_t> callback;
- cm->DeleteAllCreatedInTimeRangeAsync(
- creation_range,
- base::BindRepeating(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&callback)));
+ cm->DeleteAllCreatedInTimeRangeAsync(creation_range,
+ callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -212,10 +172,8 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
CookieDeletionInfo delete_info) {
DCHECK(cm);
ResultSavingCookieCallback<uint32_t> callback;
- cm->DeleteAllMatchingInfoAsync(
- std::move(delete_info),
- base::BindOnce(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&callback)));
+ cm->DeleteAllMatchingInfoAsync(std::move(delete_info),
+ callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -244,14 +202,14 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
cm,
std::make_unique<CanonicalCookie>(
"dom_1", "A", ".harvard.edu", "/", base::Time(), base::Time(),
- base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie(
cm,
std::make_unique<CanonicalCookie>(
"dom_2", "B", ".math.harvard.edu", "/", base::Time(), base::Time(),
- base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie(
@@ -259,7 +217,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"dom_3", "C", ".bourbaki.math.harvard.edu", "/", base::Time(),
base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
// Host cookies
@@ -268,21 +226,21 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"host_1", "A", url_top_level_domain_plus_1, "/", base::Time(),
base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie(
cm,
std::make_unique<CanonicalCookie>(
"host_2", "B", url_top_level_domain_plus_2, "/", base::Time(),
base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie(
cm,
std::make_unique<CanonicalCookie>(
"host_3", "C", url_top_level_domain_plus_3, "/", base::Time(),
base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
// http_only cookie
@@ -291,7 +249,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"httpo_check", "A", url_top_level_domain_plus_2, "/", base::Time(),
base::Time(), base::Time(), false, true,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
// same-site cookie
@@ -309,7 +267,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"sec_dom", "A", ".math.harvard.edu", "/", base::Time(),
base::Time(), base::Time(), true, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"https", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie(
@@ -317,7 +275,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"sec_host", "B", url_top_level_domain_plus_2, "/", base::Time(),
base::Time(), base::Time(), true, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"https", true /*modify_httponly*/));
// Domain path cookies
@@ -326,14 +284,14 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"dom_path_1", "A", ".math.harvard.edu", "/dir1", base::Time(),
base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie(
cm,
std::make_unique<CanonicalCookie>(
"dom_path_2", "B", ".math.harvard.edu", "/dir1/dir2", base::Time(),
base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
// Host path cookies
@@ -342,7 +300,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"host_path_1", "A", url_top_level_domain_plus_2, "/dir1",
base::Time(), base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie(
@@ -350,7 +308,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>(
"host_path_2", "B", url_top_level_domain_plus_2, "/dir1/dir2",
base::Time(), base::Time(), base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
EXPECT_EQ(14U, this->GetAllCookies(cm).size());
@@ -382,7 +340,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
(domain_max_cookies + domain_purge_cookies) * 2;
// Add a bunch of cookies on a single host, should purge them.
{
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(nullptr, &net_log_);
for (int i = 0; i < more_than_enough_cookies; ++i) {
std::string cookie = base::StringPrintf("a%03d=b", i);
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), cookie));
@@ -399,7 +357,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
// between them. We shouldn't go above kDomainMaxCookies for both together.
GURL url_google_specific(http_www_foo_.Format("http://www.gmail.%D"));
{
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(nullptr, &net_log_);
for (int i = 0; i < more_than_enough_cookies; ++i) {
std::string cookie_general = base::StringPrintf("a%03d=b", i);
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), cookie_general));
@@ -576,7 +534,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::unique_ptr<CookieMonster> cm;
if (alt_host_entries == nullptr) {
- cm.reset(new CookieMonster(nullptr, nullptr, &net_log_));
+ cm.reset(new CookieMonster(nullptr, &net_log_));
} else {
// When generating all of these cookies on alternate hosts, they need to
// be all older than the max "safe" date for GC, which is currently 30
@@ -621,7 +579,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
CookieMonster::kDomainPurgeCookies);
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(nullptr, &net_log_);
// Each test case adds 181 cookies, so 31 cookies are evicted.
// Cookie same priority, repeated for each priority.
@@ -684,7 +642,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
CookieMonster::kDomainPurgeCookies);
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(nullptr, &net_log_);
// Each test case adds 181 cookies, so 31 cookies are evicted.
// Cookie same priority, repeated for each priority.
@@ -741,7 +699,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
CookieMonster::kDomainPurgeCookies);
- auto cm = std::make_unique<CookieMonster>(nullptr, nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(nullptr, &net_log_);
// Each test case adds 180 secure cookies, and some non-secure cookie. The
// secure cookies take priority, so the non-secure cookie is removed, along
@@ -847,7 +805,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
// Function for creating a CM with a number of cookies in it,
// no store (and hence no ability to affect access time).
CookieMonster* CreateMonsterForGC(int num_cookies) {
- CookieMonster* cm(new CookieMonster(nullptr, nullptr, &net_log_));
+ CookieMonster* cm(new CookieMonster(nullptr, &net_log_));
for (int i = 0; i < num_cookies; i++) {
SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1");
}
@@ -875,15 +833,6 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
using CookieMonsterTest = CookieMonsterTestBase<CookieMonsterTestTraits>;
-// TODO(erikwright): Replace the other callbacks and synchronous helper methods
-// in this test suite with these Mocks.
-using MockClosure = base::MockCallback<base::Closure>;
-using MockSetCookiesCallback =
- base::MockCallback<CookieStore::SetCookiesCallback>;
-using MockGetCookieListCallback =
- base::MockCallback<CookieMonster::GetCookieListCallback>;
-using MockDeleteCallback = base::MockCallback<CookieMonster::DeleteCallback>;
-
struct CookiesInputInfo {
const GURL url;
const std::string name;
@@ -897,63 +846,6 @@ struct CookiesInputInfo {
CookiePriority priority;
};
-ACTION_P(QuitRunLoop, run_loop) {
- run_loop->Quit();
-}
-
-// TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed,
-// rename these, removing the 'Action' suffix.
-ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) {
- cookie_monster->SetCookieWithOptionsAsync(url, cookie_line, CookieOptions(),
- callback->Get());
-}
-ACTION_P3(SetAllCookiesAction, cookie_monster, list, callback) {
- cookie_monster->SetAllCookiesAsync(list, callback->Get());
-}
-ACTION_P3(DeleteAllCreatedInTimeRangeAction,
- cookie_monster,
- creation_range,
- callback) {
- cookie_monster->DeleteAllCreatedInTimeRangeAsync(creation_range,
- callback->Get());
-}
-ACTION_P2(GetAllCookiesAction, cookie_monster, callback) {
- cookie_monster->GetAllCookiesAsync(callback->Get());
-}
-
-ACTION_P3(DeleteAllCreatedMatchingInfoAction,
- cookie_monster,
- delete_info,
- callback) {
- cookie_monster->DeleteAllMatchingInfoAsync(std::move(delete_info),
- callback->Get());
-}
-
-ACTION_P3(DeleteCanonicalCookieAction, cookie_monster, cookie, callback) {
- cookie_monster->DeleteCanonicalCookieAsync(cookie, callback->Get());
-}
-
-ACTION_P2(DeleteAllAction, cookie_monster, callback) {
- cookie_monster->DeleteAllAsync(callback->Get());
-}
-
-ACTION_P3(GetCookieListForUrlWithOptionsAction, cookie_monster, url, callback) {
- cookie_monster->GetCookieListWithOptionsAsync(url, CookieOptions(),
- callback->Get());
-}
-
-ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) {
- cookie_monster->GetAllCookiesForURLAsync(url, callback->Get());
-}
-
-ACTION_P(PushCallbackAction, callback_vector) {
- callback_vector->push(arg1);
-}
-
-ACTION_P2(DeleteSessionCookiesAction, cookie_monster, callback) {
- cookie_monster->DeleteSessionCookiesAsync(callback->Get());
-}
-
} // namespace
// This test suite verifies the task deferral behaviour of the CookieMonster.
@@ -965,10 +857,11 @@ ACTION_P2(DeleteSessionCookiesAction, cookie_monster, callback) {
// 3. Invocations after the loading has completed complete immediately.
class DeferredCookieTaskTest : public CookieMonsterTest {
protected:
- DeferredCookieTaskTest() : expect_load_called_(false) {
- persistent_store_ = new NewMockPersistentCookieStore();
- cookie_monster_ = std::make_unique<CookieMonster>(persistent_store_.get(),
- nullptr, &net_log_);
+ DeferredCookieTaskTest() {
+ persistent_store_ = base::MakeRefCounted<MockPersistentCookieStore>();
+ persistent_store_->set_store_load_commands(true);
+ cookie_monster_ =
+ std::make_unique<CookieMonster>(persistent_store_.get(), &net_log_);
}
// Defines a cookie to be returned from PersistentCookieStore::Load
@@ -978,88 +871,48 @@ class DeferredCookieTaskTest : public CookieMonsterTest {
AddCookieToList(url, cookie_line, creation_time, &loaded_cookies_);
}
- // Runs the message loop, waiting until PersistentCookieStore::Load is called.
- // Call CompleteLoading to cause the load to complete.
- void WaitForLoadCall() {
- load_run_loop_.Run();
-
- // Verify that PeristentStore::Load was called.
- testing::Mock::VerifyAndClear(persistent_store_.get());
- }
-
- // Invokes the PersistentCookieStore::LoadCookiesForKey completion callbacks
- // and PersistentCookieStore::Load completion callback.
- void CompleteLoading() {
- while (!loaded_for_key_callbacks_.empty()) {
- loaded_for_key_callbacks_.front().Run(std::move(loaded_cookies_));
- loaded_cookies_.clear();
- loaded_for_key_callbacks_.pop();
+ void ExecuteLoads(CookieStoreCommand::Type type) {
+ const auto& commands = persistent_store_->commands();
+ for (size_t i = 0; i < commands.size(); ++i) {
+ // Only the first load command will produce the cookies.
+ if (commands[i].type == type) {
+ persistent_store_->TakeCallbackAt(i).Run(std::move(loaded_cookies_));
+ }
}
- loaded_callback_.Run(std::move(loaded_cookies_));
- }
-
- // Performs the provided action, expecting it to cause a call to
- // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call
- // is received.
- void BeginWith(testing::Action<void(void)> action) {
- EXPECT_CALL(*this, Begin()).WillOnce(action);
- ExpectLoadCall();
- Begin();
}
- void BeginWithForDomainKey(std::string key,
- testing::Action<void(void)> action) {
- EXPECT_CALL(*this, Begin()).WillOnce(action);
- ExpectLoadCall();
- ExpectLoadForKeyCall(key);
- Begin();
- }
-
- // Declares an expectation that PersistentCookieStore::Load will be called,
- // saving the provided callback and sending a quit to |load_run_loop_|.
- void ExpectLoadCall() {
- // Make sure the |load_run_loop_| is not reused.
- CHECK(!expect_load_called_);
- expect_load_called_ = true;
- EXPECT_CALL(*persistent_store_.get(), Load(testing::_, testing::_))
- .WillOnce(testing::DoAll(testing::SaveArg<0>(&loaded_callback_),
- QuitRunLoop(&load_run_loop_)));
+ std::string CommandSummary(
+ const MockPersistentCookieStore::CommandList& commands) {
+ std::string out;
+ for (const auto& command : commands) {
+ switch (command.type) {
+ case CookieStoreCommand::LOAD:
+ base::StrAppend(&out, {"LOAD; "});
+ break;
+ case CookieStoreCommand::LOAD_COOKIES_FOR_KEY:
+ base::StrAppend(&out, {"LOAD_FOR_KEY:", command.key, "; "});
+ break;
+ case CookieStoreCommand::ADD:
+ base::StrAppend(&out, {"ADD; "});
+ break;
+ case CookieStoreCommand::REMOVE:
+ base::StrAppend(&out, {"REMOVE; "});
+ break;
+ }
+ }
+ return out;
}
- // Declares an expectation that PersistentCookieStore::LoadCookiesForKey
- // will be called, saving the provided callback.
- void ExpectLoadForKeyCall(const std::string& key) {
- EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
- .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_));
+ std::string TakeCommandSummary() {
+ return CommandSummary(persistent_store_->TakeCommands());
}
- // Invokes the initial action.
- MOCK_METHOD0(Begin, void(void));
-
- // Returns the CookieMonster instance under test.
- CookieMonster& cookie_monster() { return *cookie_monster_.get(); }
-
- private:
- // Declares that mock expectations in this test suite are strictly ordered.
- testing::InSequence in_sequence_;
// Holds cookies to be returned from PersistentCookieStore::Load or
// PersistentCookieStore::LoadCookiesForKey.
std::vector<std::unique_ptr<CanonicalCookie>> loaded_cookies_;
- // Stores the callback passed from the CookieMonster to the
- // PersistentCookieStore::Load
- CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_;
- // Stores the callback passed from the CookieMonster to the
- // PersistentCookieStore::LoadCookiesForKey
- base::queue<CookieMonster::PersistentCookieStore::LoadedCallback>
- loaded_for_key_callbacks_;
- // base::RunLoop used to wait for PersistentCookieStore::Load to be called.
- base::RunLoop load_run_loop_;
- // Indicates whether ExpectLoadCall() has been called.
- bool expect_load_called_;
- // Stores the CookieMonster under test.
+
std::unique_ptr<CookieMonster> cookie_monster_;
- // Stores the mock PersistentCookieStore.
- scoped_refptr<NewMockPersistentCookieStore> persistent_store_;
+ scoped_refptr<MockPersistentCookieStore> persistent_store_;
};
TEST_F(DeferredCookieTaskTest, DeferredGetCookieList) {
@@ -1067,79 +920,83 @@ TEST_F(DeferredCookieTaskTest, DeferredGetCookieList) {
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
- MockGetCookieListCallback get_cookie_list_callback;
-
- BeginWithForDomainKey(
- http_www_foo_.domain(),
- GetCookieListForUrlWithOptionsAction(
- &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback));
-
- WaitForLoadCall();
-
- EXPECT_CALL(get_cookie_list_callback,
- Run(MatchesCookieLine("X=1"), testing::_))
- .WillOnce(GetCookieListForUrlWithOptionsAction(
- &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback));
+ GetCookieListCallback call1;
+ cookie_monster_->GetCookieListWithOptionsAsync(
+ http_www_foo_.url(), CookieOptions(), call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- base::RunLoop loop;
- EXPECT_CALL(get_cookie_list_callback,
- Run(MatchesCookieLine("X=1"), testing::_))
- .WillOnce(QuitRunLoop(&loop));
+ // Finish the per-key load, not everything-load (which is always initiated).
+ ExecuteLoads(CookieStoreCommand::LOAD_COOKIES_FOR_KEY);
+ call1.WaitUntilDone();
+ EXPECT_THAT(call1.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("LOAD; LOAD_FOR_KEY:foo.com; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ GetCookieListCallback call2;
+ cookie_monster_->GetCookieListWithOptionsAsync(
+ http_www_foo_.url(), CookieOptions(), call2.MakeCallback());
+ // Already ready, no need for second load.
+ EXPECT_THAT(call2.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredSetCookie) {
- MockSetCookiesCallback set_cookies_callback;
-
- BeginWithForDomainKey(http_www_foo_.domain(),
- SetCookieAction(&cookie_monster(), http_www_foo_.url(),
- "A=B", &set_cookies_callback));
+ // Generate puts to store w/o needing a proper expiration.
+ cookie_monster_->SetPersistSessionCookies(true);
- WaitForLoadCall();
+ ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> call1;
+ cookie_monster_->SetCanonicalCookieAsync(
+ CanonicalCookie::Create(http_www_foo_.url(), "A=B", base::Time::Now(),
+ CookieOptions()),
+ http_www_foo_.url().scheme(), CookieOptions(), call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(set_cookies_callback,
- Run(CanonicalCookie::CookieInclusionStatus::INCLUDE))
- .WillOnce(SetCookieAction(&cookie_monster(), http_www_foo_.url(), "X=Y",
- &set_cookies_callback));
- base::RunLoop loop;
- EXPECT_CALL(set_cookies_callback,
- Run(CanonicalCookie::CookieInclusionStatus::INCLUDE))
- .WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD_COOKIES_FOR_KEY);
+ call1.WaitUntilDone();
+ EXPECT_EQ(call1.result(), CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ EXPECT_EQ("LOAD; LOAD_FOR_KEY:foo.com; ADD; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> call2;
+ cookie_monster_->SetCanonicalCookieAsync(
+ CanonicalCookie::Create(http_www_foo_.url(), "X=Y", base::Time::Now(),
+ CookieOptions()),
+ http_www_foo_.url().scheme(), CookieOptions(), call2.MakeCallback());
+ ASSERT_TRUE(call2.was_run());
+ EXPECT_EQ(call2.result(), CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ EXPECT_EQ("ADD; ", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) {
- MockSetCookiesCallback set_cookies_callback;
+ // Generate puts to store w/o needing a proper expiration.
+ cookie_monster_->SetPersistSessionCookies(true);
+
CookieList list;
list.push_back(CanonicalCookie("A", "B", "." + http_www_foo_.domain(), "/",
base::Time::Now(), base::Time(), base::Time(),
- false, true, CookieSameSite::DEFAULT_MODE,
+ false, true, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
list.push_back(CanonicalCookie("C", "D", "." + http_www_foo_.domain(), "/",
base::Time::Now(), base::Time(), base::Time(),
- false, true, CookieSameSite::DEFAULT_MODE,
+ false, true, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
- BeginWith(
- SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback));
-
- WaitForLoadCall();
+ ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> call1;
+ cookie_monster_->SetAllCookiesAsync(list, call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(set_cookies_callback,
- Run(CanonicalCookie::CookieInclusionStatus::INCLUDE))
- .WillOnce(
- SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback));
- base::RunLoop loop;
- EXPECT_CALL(set_cookies_callback,
- Run(CanonicalCookie::CookieInclusionStatus::INCLUDE))
- .WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD);
+ call1.WaitUntilDone();
+ EXPECT_EQ(call1.result(), CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ EXPECT_EQ("LOAD; ADD; ADD; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ // 2nd set doesn't need to read from store. It erases the old cookies, though.
+ ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> call2;
+ cookie_monster_->SetAllCookiesAsync(list, call2.MakeCallback());
+ ASSERT_TRUE(call2.was_run());
+ EXPECT_EQ(call2.result(), CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ EXPECT_EQ("REMOVE; REMOVE; ADD; ADD; ", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
@@ -1147,21 +1004,21 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
- MockGetCookieListCallback get_cookie_list_callback;
-
- BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
-
- WaitForLoadCall();
+ GetCookieListCallback call1;
+ cookie_monster_->GetAllCookiesAsync(call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(get_cookie_list_callback, Run(testing::_, testing::_))
- .WillOnce(
- GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
- base::RunLoop loop;
- EXPECT_CALL(get_cookie_list_callback, Run(testing::_, testing::_))
- .WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD);
+ call1.WaitUntilDone();
+ EXPECT_THAT(call1.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("LOAD; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ GetCookieListCallback call2;
+ cookie_monster_->GetAllCookiesAsync(call2.MakeCallback());
+ EXPECT_TRUE(call2.was_run());
+ EXPECT_THAT(call2.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) {
@@ -1169,24 +1026,23 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) {
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
- MockGetCookieListCallback get_cookie_list_callback;
-
- BeginWithForDomainKey(
- http_www_foo_.domain(),
- GetAllCookiesForUrlAction(&cookie_monster(), http_www_foo_.url(),
- &get_cookie_list_callback));
-
- WaitForLoadCall();
+ GetCookieListCallback call1;
+ cookie_monster_->GetAllCookiesForURLAsync(http_www_foo_.url(),
+ call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(get_cookie_list_callback, Run(testing::_, testing::_))
- .WillOnce(GetAllCookiesForUrlAction(
- &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback));
- base::RunLoop loop;
- EXPECT_CALL(get_cookie_list_callback, Run(testing::_, testing::_))
- .WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD_COOKIES_FOR_KEY);
+ call1.WaitUntilDone();
+ EXPECT_THAT(call1.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("LOAD; LOAD_FOR_KEY:foo.com; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ GetCookieListCallback call2;
+ cookie_monster_->GetAllCookiesForURLAsync(http_www_foo_.url(),
+ call2.MakeCallback());
+ EXPECT_TRUE(call2.was_run());
+ EXPECT_THAT(call2.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) {
@@ -1194,166 +1050,197 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) {
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
- MockGetCookieListCallback get_cookie_list_callback;
-
- BeginWithForDomainKey(
- http_www_foo_.domain(),
- GetCookieListForUrlWithOptionsAction(
- &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback));
-
- WaitForLoadCall();
+ GetCookieListCallback call1;
+ cookie_monster_->GetCookieListWithOptionsAsync(
+ http_www_foo_.url(), CookieOptions(), call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(get_cookie_list_callback, Run(testing::_, testing::_))
- .WillOnce(GetCookieListForUrlWithOptionsAction(
- &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback));
- base::RunLoop loop;
- EXPECT_CALL(get_cookie_list_callback, Run(testing::_, testing::_))
- .WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD_COOKIES_FOR_KEY);
+ call1.WaitUntilDone();
+ EXPECT_THAT(call1.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("LOAD; LOAD_FOR_KEY:foo.com; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ GetCookieListCallback call2;
+ cookie_monster_->GetCookieListWithOptionsAsync(
+ http_www_foo_.url(), CookieOptions(), call2.MakeCallback());
+ EXPECT_TRUE(call2.was_run());
+ EXPECT_THAT(call2.cookies(), MatchesCookieLine("X=1"));
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) {
- MockDeleteCallback delete_callback;
-
- BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback));
-
- WaitForLoadCall();
+ DeclareLoadedCookie(http_www_foo_.url(),
+ "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
+ Time::Now() + TimeDelta::FromDays(3));
- EXPECT_CALL(delete_callback, Run(false))
- .WillOnce(DeleteAllAction(&cookie_monster(), &delete_callback));
+ ResultSavingCookieCallback<uint32_t> call1;
+ cookie_monster_->DeleteAllAsync(call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- base::RunLoop loop;
- EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD);
+ call1.WaitUntilDone();
+ EXPECT_EQ(1u, call1.result());
+ EXPECT_EQ("LOAD; REMOVE; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ ResultSavingCookieCallback<uint32_t> call2;
+ cookie_monster_->DeleteAllAsync(call2.MakeCallback());
+ // This needs an event loop spin since DeleteAllAsync always reports
+ // asynchronously.
+ call2.WaitUntilDone();
+ EXPECT_EQ(0u, call2.result());
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedInTimeRangeCookies) {
- MockDeleteCallback delete_callback;
-
const TimeRange time_range(base::Time(), base::Time::Now());
- BeginWith(DeleteAllCreatedInTimeRangeAction(&cookie_monster(), time_range,
- &delete_callback));
- WaitForLoadCall();
+ ResultSavingCookieCallback<uint32_t> call1;
+ cookie_monster_->DeleteAllCreatedInTimeRangeAsync(time_range,
+ call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(delete_callback, Run(false))
- .WillOnce(DeleteAllCreatedInTimeRangeAction(&cookie_monster(), time_range,
- &delete_callback));
- base::RunLoop loop;
- EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD);
+ call1.WaitUntilDone();
+ EXPECT_EQ(0u, call1.result());
+ EXPECT_EQ("LOAD; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ ResultSavingCookieCallback<uint32_t> call2;
+ cookie_monster_->DeleteAllCreatedInTimeRangeAsync(time_range,
+ call2.MakeCallback());
+ call2.WaitUntilDone();
+ EXPECT_EQ(0u, call2.result());
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest,
DeferredDeleteAllWithPredicateCreatedInTimeRangeCookies) {
- MockDeleteCallback delete_callback;
-
- BeginWith(DeleteAllCreatedMatchingInfoAction(
- &cookie_monster(), CookieDeletionInfo(Time(), Time::Now()),
- &delete_callback));
-
- WaitForLoadCall();
+ ResultSavingCookieCallback<uint32_t> call1;
+ cookie_monster_->DeleteAllMatchingInfoAsync(
+ CookieDeletionInfo(Time(), Time::Now()), call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(delete_callback, Run(false))
- .WillOnce(DeleteAllCreatedMatchingInfoAction(
- &cookie_monster(), CookieDeletionInfo(Time(), Time::Now()),
- &delete_callback));
- base::RunLoop loop;
- EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD);
+ call1.WaitUntilDone();
+ EXPECT_EQ(0u, call1.result());
+ EXPECT_EQ("LOAD; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ ResultSavingCookieCallback<uint32_t> call2;
+ cookie_monster_->DeleteAllMatchingInfoAsync(
+ CookieDeletionInfo(Time(), Time::Now()), call2.MakeCallback());
+ call2.WaitUntilDone();
+ EXPECT_EQ(0u, call2.result());
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
- std::vector<std::unique_ptr<CanonicalCookie>> cookies;
std::unique_ptr<CanonicalCookie> cookie = BuildCanonicalCookie(
http_www_foo_.url(), "X=1; path=/", base::Time::Now());
- MockDeleteCallback delete_cookie_callback;
-
- BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), *cookie,
- &delete_cookie_callback));
-
- WaitForLoadCall();
+ ResultSavingCookieCallback<uint32_t> call1;
+ cookie_monster_->DeleteCanonicalCookieAsync(*cookie, call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(delete_cookie_callback, Run(0))
- .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), *cookie,
- &delete_cookie_callback));
- base::RunLoop loop;
- EXPECT_CALL(delete_cookie_callback, Run(0)).WillOnce(QuitRunLoop(&loop));
+ // TODO(morlovich): Fix DeleteCanonicalCookieAsync. This test should pass
+ // when using LOAD_COOKIES_FOR_KEY instead, with that reflected in
+ // TakeCommandSummary() as well.
+ ExecuteLoads(CookieStoreCommand::LOAD);
+ call1.WaitUntilDone();
+ EXPECT_EQ(0u, call1.result());
+ EXPECT_EQ("LOAD; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ ResultSavingCookieCallback<uint32_t> call2;
+ cookie_monster_->DeleteCanonicalCookieAsync(*cookie, call2.MakeCallback());
+ call2.WaitUntilDone();
+ EXPECT_EQ(0u, call2.result());
+ EXPECT_EQ("", TakeCommandSummary());
}
TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) {
- MockDeleteCallback delete_callback;
-
- BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
-
- WaitForLoadCall();
+ ResultSavingCookieCallback<uint32_t> call1;
+ cookie_monster_->DeleteSessionCookiesAsync(call1.MakeCallback());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(call1.was_run());
- EXPECT_CALL(delete_callback, Run(false))
- .WillOnce(
- DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
- base::RunLoop loop;
- EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop));
+ ExecuteLoads(CookieStoreCommand::LOAD);
+ call1.WaitUntilDone();
+ EXPECT_EQ(0u, call1.result());
+ EXPECT_EQ("LOAD; ", TakeCommandSummary());
- CompleteLoading();
- loop.Run();
+ ResultSavingCookieCallback<uint32_t> call2;
+ cookie_monster_->DeleteSessionCookiesAsync(call2.MakeCallback());
+ call2.WaitUntilDone();
+ EXPECT_EQ(0u, call2.result());
+ EXPECT_EQ("", TakeCommandSummary());
}
// Verify that a series of queued tasks are executed in order upon loading of
// the backing store and that new tasks received while the queued tasks are
// being dispatched go to the end of the queue.
TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) {
+ cookie_monster_->SetPersistSessionCookies(true);
DeclareLoadedCookie(http_www_foo_.url(),
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
- MockGetCookieListCallback get_cookie_list_callback;
- MockSetCookiesCallback set_cookies_callback;
- MockGetCookieListCallback get_cookie_list_callback_deferred;
-
- EXPECT_CALL(*this, Begin())
- .WillOnce(testing::DoAll(
- GetCookieListForUrlWithOptionsAction(&cookie_monster(),
- http_www_foo_.url(),
- &get_cookie_list_callback),
- SetCookieAction(&cookie_monster(), http_www_foo_.url(), "A=B",
- &set_cookies_callback)));
- ExpectLoadCall();
- ExpectLoadForKeyCall(http_www_foo_.domain());
- Begin();
-
- WaitForLoadCall();
- EXPECT_CALL(get_cookie_list_callback,
- Run(MatchesCookieLine("X=1"), testing::_))
- .WillOnce(GetCookieListForUrlWithOptionsAction(
- &cookie_monster(), http_www_foo_.url(),
- &get_cookie_list_callback_deferred));
- EXPECT_CALL(set_cookies_callback,
- Run(CanonicalCookie::CookieInclusionStatus::INCLUDE));
- base::RunLoop loop;
- EXPECT_CALL(get_cookie_list_callback_deferred,
- Run(MatchesCookieLine("A=B; X=1"), testing::_))
- .WillOnce(QuitRunLoop(&loop));
-
- CompleteLoading();
- loop.Run();
+ bool get_cookie_list_callback_was_run = false;
+ GetCookieListCallback get_cookie_list_callback_deferred;
+ ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus>
+ set_cookies_callback;
+ base::RunLoop run_loop;
+ cookie_monster_->GetCookieListWithOptionsAsync(
+ http_www_foo_.url(), CookieOptions(),
+ base::BindLambdaForTesting([&](const CookieList& cookies,
+ const CookieStatusList& excluded_list) {
+ // This should complete before the set.
+ get_cookie_list_callback_was_run = true;
+ EXPECT_FALSE(set_cookies_callback.was_run());
+ EXPECT_THAT(cookies, MatchesCookieLine("X=1"));
+ // Can't use TakeCommandSummary here since ExecuteLoads is walking
+ // through the data it takes.
+ EXPECT_EQ("LOAD; LOAD_FOR_KEY:foo.com; ",
+ CommandSummary(persistent_store_->commands()));
+
+ // Queue up a second get. It should see the result of the set queued
+ // before it.
+ cookie_monster_->GetCookieListWithOptionsAsync(
+ http_www_foo_.url(), CookieOptions(),
+ get_cookie_list_callback_deferred.MakeCallback());
+
+ run_loop.Quit();
+ }));
+
+ cookie_monster_->SetCanonicalCookieAsync(
+ CanonicalCookie::Create(http_www_foo_.url(), "A=B", base::Time::Now(),
+ CookieOptions()),
+ http_www_foo_.url().scheme(), CookieOptions(),
+ set_cookies_callback.MakeCallback());
+
+ // Nothing happened yet, before loads are done.
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(get_cookie_list_callback_was_run);
+ EXPECT_FALSE(set_cookies_callback.was_run());
+
+ ExecuteLoads(CookieStoreCommand::LOAD_COOKIES_FOR_KEY);
+ run_loop.Run();
+ EXPECT_EQ("LOAD; LOAD_FOR_KEY:foo.com; ADD; ", TakeCommandSummary());
+ EXPECT_TRUE(get_cookie_list_callback_was_run);
+ ASSERT_TRUE(set_cookies_callback.was_run());
+ EXPECT_EQ(CanonicalCookie::CookieInclusionStatus::INCLUDE,
+ set_cookies_callback.result());
+
+ ASSERT_TRUE(get_cookie_list_callback_deferred.was_run());
+ EXPECT_THAT(get_cookie_list_callback_deferred.cookies(),
+ MatchesCookieLine("A=B; X=1"));
}
TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
CookieOptions options;
options.set_include_httponly();
@@ -1384,8 +1271,7 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
}
TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedInTimeRangeTimestamps) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
Time now = Time::Now();
// Nothing has been added so nothing should be deleted.
@@ -1432,8 +1318,7 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedInTimeRangeTimestamps) {
TEST_F(CookieMonsterTest,
TestCookieDeleteAllCreatedInTimeRangeTimestampsWithInfo) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
Time now = Time::Now();
CanonicalCookie test_cookie;
@@ -1543,15 +1428,16 @@ TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionMixed) {
}
TEST_F(CookieMonsterTest, SetCookieableSchemes) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
- std::unique_ptr<CookieMonster> cm_foo(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, &net_log_));
// Only cm_foo should allow foo:// cookies.
std::vector<std::string> schemes;
schemes.push_back("foo");
- cm_foo->SetCookieableSchemes(schemes);
+ ResultSavingCookieCallback<bool> cookie_scheme_callback;
+ cm_foo->SetCookieableSchemes(schemes, cookie_scheme_callback.MakeCallback());
+ cookie_scheme_callback.WaitUntilDone();
+ EXPECT_TRUE(cookie_scheme_callback.result());
GURL foo_url("foo://host/path");
GURL http_url("http://host/path");
@@ -1739,8 +1625,7 @@ TEST_F(CookieMonsterTest, GetExcludedCookiesForURL) {
}
TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
CookieOptions options;
EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_foo_foo_.url(),
@@ -1778,8 +1663,7 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
}
TEST_F(CookieMonsterTest, GetExcludedCookiesForURLPathMatching) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
CookieOptions options;
EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_foo_foo_.url(),
@@ -1814,8 +1698,7 @@ TEST_F(CookieMonsterTest, GetExcludedCookiesForURLPathMatching) {
}
TEST_F(CookieMonsterTest, CookieSorting) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B1; path=/"));
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B2; path=/foo"));
@@ -1839,8 +1722,7 @@ TEST_F(CookieMonsterTest, CookieSorting) {
}
TEST_F(CookieMonsterTest, InheritCreationDate) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
base::Time the_not_so_distant_past(base::Time::Now() -
base::TimeDelta::FromSeconds(1000));
@@ -1872,8 +1754,7 @@ TEST_F(CookieMonsterTest, InheritCreationDate) {
// Check that GetAllCookiesForURL() does not return expired cookies and deletes
// them.
TEST_F(CookieMonsterTest, DeleteExpiredCookiesOnGet) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=B;"));
@@ -1945,8 +1826,7 @@ TEST_F(CookieMonsterTest, DontImportDuplicateCookies) {
// Inject our initial cookies into the mock PersistentCookieStore.
store->SetLoadExpectation(true, std::move(initial_cookies));
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
// Verify that duplicates were not imported for path "/".
// (If this had failed, GetCookies() would have also returned X=1, X=2, X=4).
@@ -2002,8 +1882,7 @@ TEST_F(CookieMonsterTest, ImportDuplicateCreationTimes) {
// Inject our initial cookies into the mock PersistentCookieStore.
store->SetLoadExpectation(true, std::move(initial_cookies));
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
CookieList list(GetAllCookies(cm.get()));
EXPECT_EQ(2U, list.size());
@@ -2016,8 +1895,7 @@ TEST_F(CookieMonsterTest, ImportDuplicateCreationTimes) {
}
TEST_F(CookieMonsterTest, PredicateSeesAllCookies) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
PopulateCmForPredicateCheck(cm.get());
// We test that we can see all cookies with |delete_info|. This includes
// host, http_only, host secure, and all domain cookies.
@@ -2039,8 +1917,7 @@ TEST_F(CookieMonsterTest, PredicateSeesAllCookies) {
// Mainly a test of GetEffectiveDomain, or more specifically, of the
// expected behavior of GetEffectiveDomain within the CookieMonster.
TEST_F(CookieMonsterTest, GetKey) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
// This test is really only interesting if GetKey() actually does something.
EXPECT_EQ("foo.com", cm->GetKey("www.foo.com"));
@@ -2072,11 +1949,11 @@ TEST_F(CookieMonsterTest, BackingStoreCommunication) {
const CookiesInputInfo input_info[] = {
{GURL("http://a.b.foo.com"), "a", "1", "a.b.foo.com", "/path/to/cookie",
- expires, false, false, CookieSameSite::DEFAULT_MODE,
+ expires, false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT},
{GURL("https://www.foo.com"), "b", "2", ".foo.com", "/path/from/cookie",
expires + TimeDelta::FromSeconds(10), true, true,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT},
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT},
{GURL("https://foo.com"), "c", "3", "foo.com", "/another/path/to/cookie",
base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false,
CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT}};
@@ -2085,7 +1962,7 @@ TEST_F(CookieMonsterTest, BackingStoreCommunication) {
// Create new cookies and flush them to the store.
{
std::unique_ptr<CookieMonster> cmout(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ new CookieMonster(store.get(), &net_log_));
for (const auto& cookie : input_info) {
EXPECT_TRUE(SetCanonicalCookie(
cmout.get(),
@@ -2104,7 +1981,7 @@ TEST_F(CookieMonsterTest, BackingStoreCommunication) {
// Create a new cookie monster and make sure that everything is correct
{
std::unique_ptr<CookieMonster> cmin(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ new CookieMonster(store.get(), &net_log_));
CookieList cookies(GetAllCookies(cmin.get()));
ASSERT_EQ(2u, cookies.size());
// Ordering is path length, then creation time. So second cookie
@@ -2138,7 +2015,7 @@ TEST_F(CookieMonsterTest, RestoreDifferentCookieSameCreationTime) {
base::MakeRefCounted<MockPersistentCookieStore>();
{
- CookieMonster cmout(store.get(), nullptr, &net_log_);
+ CookieMonster cmout(store.get(), &net_log_);
GURL url("http://www.example.com/");
EXPECT_TRUE(
SetCookieWithCreationTime(&cmout, url, "A=1; max-age=600", current));
@@ -2160,7 +2037,7 @@ TEST_F(CookieMonsterTest, RestoreDifferentCookieSameCreationTime) {
// Now read them in. Should get two cookies, not one.
{
- CookieMonster cmin(store2.get(), nullptr, &net_log_);
+ CookieMonster cmin(store2.get(), &net_log_);
CookieList cookies(GetAllCookies(&cmin));
ASSERT_EQ(2u, cookies.size());
}
@@ -2169,8 +2046,7 @@ TEST_F(CookieMonsterTest, RestoreDifferentCookieSameCreationTime) {
TEST_F(CookieMonsterTest, CookieListOrdering) {
// Put a random set of cookies into a monster and make sure
// they're returned in the right order.
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
EXPECT_TRUE(
SetCookie(cm.get(), GURL("http://d.c.b.a.foo.com/aa/x.html"), "c=1"));
EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.foo.com/aa/bb/cc/x.html"),
@@ -2305,22 +2181,16 @@ TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) {
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
store->set_store_load_commands(true);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
// Get all cookies task that queues a task to set a cookie when executed.
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus>
set_cookie_callback;
- cm->SetCookieWithOptionsAsync(
- kUrl, "a=b", CookieOptions(),
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&set_cookie_callback)));
+ cm->SetCookieWithOptionsAsync(kUrl, "a=b", CookieOptions(),
+ set_cookie_callback.MakeCallback());
GetCookieListCallback get_cookie_list_callback1;
- cm->GetAllCookiesAsync(
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&get_cookie_list_callback1)));
+ cm->GetAllCookiesAsync(get_cookie_list_callback1.MakeCallback());
// Two load events should have been queued.
ASSERT_EQ(2u, store->commands().size());
@@ -2329,8 +2199,7 @@ TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) {
store->commands()[1].type);
// The main load completes first (With no cookies).
- store->commands()[0].loaded_callback.Run(
- std::vector<std::unique_ptr<CanonicalCookie>>());
+ store->TakeCallbackAt(0).Run(std::vector<std::unique_ptr<CanonicalCookie>>());
// The tasks should run in order, and the get should see the cookies.
@@ -2343,14 +2212,11 @@ TEST_F(CookieMonsterTest, WhileLoadingLoadCompletesBeforeKeyLoadCompletes) {
// The loaded for key event completes late, with not cookies (Since they
// were already loaded).
- store->commands()[1].loaded_callback.Run(
- std::vector<std::unique_ptr<CanonicalCookie>>());
+ store->TakeCallbackAt(1).Run(std::vector<std::unique_ptr<CanonicalCookie>>());
// The just set cookie should still be in the store.
GetCookieListCallback get_cookie_list_callback2;
- cm->GetAllCookiesAsync(
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&get_cookie_list_callback2)));
+ cm->GetAllCookiesAsync(get_cookie_list_callback2.MakeCallback());
get_cookie_list_callback2.WaitUntilDone();
EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size());
}
@@ -2363,18 +2229,14 @@ TEST_F(CookieMonsterTest, WhileLoadingDeleteAllGetForURL) {
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
store->set_store_load_commands(true);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
ResultSavingCookieCallback<uint32_t> delete_callback;
- cm->DeleteAllAsync(base::BindOnce(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&delete_callback)));
+ cm->DeleteAllAsync(delete_callback.MakeCallback());
GetCookieListCallback get_cookie_list_callback;
- cm->GetCookieListWithOptionsAsync(
- kUrl, CookieOptions(),
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&get_cookie_list_callback)));
+ cm->GetCookieListWithOptionsAsync(kUrl, CookieOptions(),
+ get_cookie_list_callback.MakeCallback());
// Only the main load should have been queued.
ASSERT_EQ(1u, store->commands().size());
@@ -2386,7 +2248,7 @@ TEST_F(CookieMonsterTest, WhileLoadingDeleteAllGetForURL) {
cookies.push_back(
CanonicalCookie::Create(kUrl, "a=b", base::Time::Now(), CookieOptions()));
ASSERT_TRUE(cookies[0]);
- store->commands()[0].loaded_callback.Run(std::move(cookies));
+ store->TakeCallbackAt(0).Run(std::move(cookies));
delete_callback.WaitUntilDone();
EXPECT_EQ(1u, delete_callback.result());
@@ -2404,34 +2266,25 @@ TEST_F(CookieMonsterTest, WhileLoadingGetAllSetGetAll) {
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
store->set_store_load_commands(true);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
GetCookieListCallback get_cookie_list_callback1;
- cm->GetAllCookiesAsync(
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&get_cookie_list_callback1)));
+ cm->GetAllCookiesAsync(get_cookie_list_callback1.MakeCallback());
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus>
set_cookie_callback;
- cm->SetCookieWithOptionsAsync(
- kUrl, "a=b", CookieOptions(),
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&set_cookie_callback)));
+ cm->SetCookieWithOptionsAsync(kUrl, "a=b", CookieOptions(),
+ set_cookie_callback.MakeCallback());
GetCookieListCallback get_cookie_list_callback2;
- cm->GetAllCookiesAsync(
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&get_cookie_list_callback2)));
+ cm->GetAllCookiesAsync(get_cookie_list_callback2.MakeCallback());
// Only the main load should have been queued.
ASSERT_EQ(1u, store->commands().size());
ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type);
// The load completes (With no cookies).
- store->commands()[0].loaded_callback.Run(
- std::vector<std::unique_ptr<CanonicalCookie>>());
+ store->TakeCallbackAt(0).Run(std::vector<std::unique_ptr<CanonicalCookie>>());
get_cookie_list_callback1.WaitUntilDone();
EXPECT_EQ(0u, get_cookie_list_callback1.cookies().size());
@@ -2462,35 +2315,28 @@ TEST_F(CookieMonsterTest, CheckOrderOfCookieTaskQueueWhenLoadingCompletes) {
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
store->set_store_load_commands(true);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
// Get all cookies task that queues a task to set a cookie when executed.
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus>
set_cookie_callback;
cm->GetAllCookiesAsync(base::BindOnce(
&RunClosureOnCookieListReceived,
- base::BindOnce(
- &CookieStore::SetCookieWithOptionsAsync, base::Unretained(cm.get()),
- kUrl, "a=b", CookieOptions(),
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&set_cookie_callback)))));
+ base::BindOnce(&CookieStore::SetCookieWithOptionsAsync,
+ base::Unretained(cm.get()), kUrl, "a=b", CookieOptions(),
+ set_cookie_callback.MakeCallback())));
// Get cookie task. Queued before the delete task is executed, so should not
// see the set cookie.
GetCookieListCallback get_cookie_list_callback1;
- cm->GetAllCookiesAsync(
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&get_cookie_list_callback1)));
+ cm->GetAllCookiesAsync(get_cookie_list_callback1.MakeCallback());
// Only the main load should have been queued.
ASSERT_EQ(1u, store->commands().size());
ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type);
// The load completes.
- store->commands()[0].loaded_callback.Run(
- std::vector<std::unique_ptr<CanonicalCookie>>());
+ store->TakeCallbackAt(0).Run(std::vector<std::unique_ptr<CanonicalCookie>>());
// The get cookies call should see no cookies set.
get_cookie_list_callback1.WaitUntilDone();
@@ -2502,9 +2348,7 @@ TEST_F(CookieMonsterTest, CheckOrderOfCookieTaskQueueWhenLoadingCompletes) {
// A subsequent get cookies call should see the new cookie.
GetCookieListCallback get_cookie_list_callback2;
- cm->GetAllCookiesAsync(
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&get_cookie_list_callback2)));
+ cm->GetAllCookiesAsync(get_cookie_list_callback2.MakeCallback());
get_cookie_list_callback2.WaitUntilDone();
EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size());
}
@@ -2513,7 +2357,7 @@ TEST_F(CookieMonsterTest, CheckOrderOfCookieTaskQueueWhenLoadingCompletes) {
TEST_F(CookieMonsterTest, FlushStore) {
auto counter = base::MakeRefCounted<CallbackCounter>();
auto store = base::MakeRefCounted<FlushablePersistentStore>();
- auto cm = std::make_unique<CookieMonster>(store, nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(store, &net_log_);
ASSERT_EQ(0, store->flush_count());
ASSERT_EQ(0, counter->callback_count());
@@ -2548,7 +2392,7 @@ TEST_F(CookieMonsterTest, FlushStore) {
ASSERT_EQ(2, counter->callback_count());
// If there's no backing store, FlushStore() is always a safe no-op.
- cm.reset(new CookieMonster(nullptr, nullptr, &net_log_));
+ cm.reset(new CookieMonster(nullptr, &net_log_));
GetAllCookies(cm.get()); // Force init.
cm->FlushStore(base::DoNothing());
base::RunLoop().RunUntilIdle();
@@ -2561,23 +2405,9 @@ TEST_F(CookieMonsterTest, FlushStore) {
ASSERT_EQ(3, counter->callback_count());
}
-TEST_F(CookieMonsterTest, SetBeforeFlushCallbackIsCalled) {
- std::unique_ptr<ChannelIDService> channel_id_service(
- new ChannelIDService(nullptr));
-
- scoped_refptr<NewMockPersistentCookieStore> store(
- new NewMockPersistentCookieStore());
-
- // SetBeforeFlushCallback should be called in both the c'tor and d'tor.
- EXPECT_CALL(*store, SetBeforeFlushCallback(testing::_)).Times(2);
-
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), channel_id_service.get(), &net_log_));
-}
-
TEST_F(CookieMonsterTest, SetAllCookies) {
scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore());
- auto cm = std::make_unique<CookieMonster>(store.get(), nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(store.get(), &net_log_);
cm->SetPersistSessionCookies(true);
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "U=V; path=/"));
@@ -2587,15 +2417,15 @@ TEST_F(CookieMonsterTest, SetAllCookies) {
CookieList list;
list.push_back(CanonicalCookie(
"A", "B", "." + http_www_foo_.url().host(), "/", base::Time::Now(),
- base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
list.push_back(CanonicalCookie(
"W", "X", "." + http_www_foo_.url().host(), "/bar", base::Time::Now(),
- base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
list.push_back(CanonicalCookie(
"Y", "Z", "." + http_www_foo_.url().host(), "/", base::Time::Now(),
- base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), base::Time(), false, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT));
// SetAllCookies must not flush.
@@ -2640,7 +2470,7 @@ TEST_F(CookieMonsterTest, SetAllCookies) {
// works).
TEST_F(CookieMonsterTest, DeleteAll) {
scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore());
- auto cm = std::make_unique<CookieMonster>(store.get(), nullptr, &net_log_);
+ auto cm = std::make_unique<CookieMonster>(store.get(), &net_log_);
cm->SetPersistSessionCookies(true);
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "X=Y; path=/"));
@@ -2668,8 +2498,7 @@ TEST_F(CookieMonsterTest, DeleteAll) {
}
TEST_F(CookieMonsterTest, HistogramCheck) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
// Should match call in InitializeHistograms, but doesn't really matter
// since the histogram should have been initialized by the CM construction
// above.
@@ -2684,7 +2513,8 @@ TEST_F(CookieMonsterTest, HistogramCheck) {
std::make_unique<CanonicalCookie>(
"a", "b", "a.url", "/", base::Time(),
base::Time::Now() + base::TimeDelta::FromMinutes(59), base::Time(),
- false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ false, false, CookieSameSite::NO_RESTRICTION,
+ COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/));
std::unique_ptr<base::HistogramSamples> samples2(
@@ -2711,8 +2541,7 @@ TEST_F(CookieMonsterTest, InvalidExpiryTime) {
// CookieStore if the "persist session cookies" option is on.
TEST_F(CookieMonsterTest, PersistSessionCookies) {
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
cm->SetPersistSessionCookies(true);
// All cookies set with SetCookie are session cookies.
@@ -2749,8 +2578,7 @@ TEST_F(CookieMonsterTest, PersistSessionCookies) {
// Test the commands sent to the persistent cookie store.
TEST_F(CookieMonsterTest, PersisentCookieStorageTest) {
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
// Add a cookie.
EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(),
@@ -2811,7 +2639,7 @@ TEST_F(CookieMonsterTest, ControlCharacterPurge) {
"\x05"
"boo",
"." + domain, path, now2, later, base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT);
initial_cookies.push_back(std::move(cc));
AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies);
@@ -2819,8 +2647,7 @@ TEST_F(CookieMonsterTest, ControlCharacterPurge) {
// Inject our initial cookies into the mock PersistentCookieStore.
store->SetLoadExpectation(true, std::move(initial_cookies));
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url));
}
@@ -2831,8 +2658,7 @@ TEST_F(CookieMonsterTest, CookieSourceHistogram) {
const std::string cookie_source_histogram = "Cookie.CookieSourceScheme";
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
histograms.ExpectTotalCount(cookie_source_histogram, 0);
@@ -2894,8 +2720,7 @@ TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) {
const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent";
scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(store.get(), nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), &net_log_));
// Set a secure cookie from a secure origin
EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), "A=B; Secure"));
@@ -2993,8 +2818,7 @@ TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) {
}
TEST_F(CookieMonsterTest, SetSecureCookies) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, &net_log_));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, &net_log_));
GURL http_url("http://www.foo.com");
GURL http_superdomain_url("http://foo.com");
GURL https_url("https://www.foo.com");
@@ -3264,8 +3088,7 @@ TEST_F(CookieMonsterTest, EvictSecureCookies) {
// Tests that strict secure cookies doesn't trip equivalent cookie checks
// accidentally. Regression test for https://crbug.com/569943.
TEST_F(CookieMonsterTest, EquivalentCookies) {
- std::unique_ptr<CookieMonster> cm(
- new CookieMonster(nullptr, nullptr, nullptr));
+ std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
GURL http_url("http://www.foo.com");
GURL http_superdomain_url("http://foo.com");
GURL https_url("https://www.foo.com");
@@ -3293,7 +3116,7 @@ TEST_F(CookieMonsterTest, SetCanonicalCookieDoesNotBlockForLoadAll) {
base::MakeRefCounted<MockPersistentCookieStore>();
// Collect load commands so we have control over their execution.
persistent_store->set_store_load_commands(true);
- CookieMonster cm(persistent_store.get(), nullptr, nullptr);
+ CookieMonster cm(persistent_store.get(), nullptr);
// Start of a canonical cookie set.
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus>
@@ -3301,22 +3124,18 @@ TEST_F(CookieMonsterTest, SetCanonicalCookieDoesNotBlockForLoadAll) {
cm.SetCanonicalCookieAsync(
CanonicalCookie::Create(GURL("http://a.com/"), "A=B", base::Time::Now(),
CookieOptions()),
- "http", false /* modify_httponly */,
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&callback_set)));
+ "http", CookieOptions(), callback_set.MakeCallback());
// Get cookies for a different URL.
GetCookieListCallback callback_get;
- cm.GetCookieListWithOptionsAsync(
- GURL("http://b.com/"), CookieOptions(),
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&callback_get)));
+ cm.GetCookieListWithOptionsAsync(GURL("http://b.com/"), CookieOptions(),
+ callback_get.MakeCallback());
// Now go through the store commands, and execute individual loads.
- for (const CookieStoreCommand& command : persistent_store->commands()) {
- if (command.type == CookieStoreCommand::LOAD_COOKIES_FOR_KEY)
- command.loaded_callback.Run(
+ const auto& commands = persistent_store->commands();
+ for (size_t i = 0; i < commands.size(); ++i) {
+ if (commands[i].type == CookieStoreCommand::LOAD_COOKIES_FOR_KEY)
+ persistent_store->TakeCallbackAt(i).Run(
std::vector<std::unique_ptr<CanonicalCookie>>());
}
@@ -3325,9 +3144,9 @@ TEST_F(CookieMonsterTest, SetCanonicalCookieDoesNotBlockForLoadAll) {
callback_get.WaitUntilDone();
// Now execute full-store loads as well.
- for (const CookieStoreCommand& command : persistent_store->commands()) {
- if (command.type == CookieStoreCommand::LOAD)
- command.loaded_callback.Run(
+ for (size_t i = 0; i < commands.size(); ++i) {
+ if (commands[i].type == CookieStoreCommand::LOAD)
+ persistent_store->TakeCallbackAt(i).Run(
std::vector<std::unique_ptr<CanonicalCookie>>());
}
}
@@ -3341,7 +3160,7 @@ TEST_F(CookieMonsterTest, DeleteDuplicateCTime) {
// that the implementation doesn't just happen to pick the right one because
// of implementation details.
for (size_t run = 0; run < base::size(kNames); ++run) {
- CookieMonster cm(nullptr, nullptr, nullptr);
+ CookieMonster cm(nullptr, nullptr);
Time now = Time::Now();
GURL url("http://www.example.com");
@@ -3378,37 +3197,29 @@ TEST_F(CookieMonsterTest, DeleteCookieWithInheritedTimestamps) {
GURL url("http://www.example.com");
std::string cookie_line = "foo=bar";
CookieOptions options;
- CookieMonster cm(nullptr, nullptr, nullptr);
+ CookieMonster cm(nullptr, nullptr);
// Write a cookie created at |t1|.
auto cookie = CanonicalCookie::Create(url, cookie_line, t1, options);
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus>
set_callback_1;
- cm.SetCanonicalCookieAsync(
- std::move(cookie), url.scheme(), !options.exclude_httponly(),
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&set_callback_1)));
+ cm.SetCanonicalCookieAsync(std::move(cookie), url.scheme(), options,
+ set_callback_1.MakeCallback());
set_callback_1.WaitUntilDone();
// Overwrite the cookie at |t2|.
cookie = CanonicalCookie::Create(url, cookie_line, t2, options);
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus>
set_callback_2;
- cm.SetCanonicalCookieAsync(
- std::move(cookie), url.scheme(), !options.exclude_httponly(),
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&set_callback_2)));
+ cm.SetCanonicalCookieAsync(std::move(cookie), url.scheme(), options,
+ set_callback_2.MakeCallback());
set_callback_2.WaitUntilDone();
// The second cookie overwrites the first one but it will inherit the creation
// timestamp |t1|. Test that deleting the new cookie still works.
cookie = CanonicalCookie::Create(url, cookie_line, t2, options);
ResultSavingCookieCallback<unsigned int> delete_callback;
- cm.DeleteCanonicalCookieAsync(
- *cookie, base::BindOnce(&ResultSavingCookieCallback<unsigned int>::Run,
- base::Unretained(&delete_callback)));
+ cm.DeleteCanonicalCookieAsync(*cookie, delete_callback.MakeCallback());
delete_callback.WaitUntilDone();
EXPECT_EQ(1U, delete_callback.result());
}
@@ -3418,7 +3229,7 @@ class CookieMonsterNotificationTest : public CookieMonsterTest {
CookieMonsterNotificationTest()
: test_url_("http://www.foo.com/foo"),
store_(new MockPersistentCookieStore),
- monster_(new CookieMonster(store_.get(), nullptr, nullptr)) {}
+ monster_(new CookieMonster(store_.get(), nullptr)) {}
~CookieMonsterNotificationTest() override = default;
@@ -3449,7 +3260,7 @@ TEST_F(CookieMonsterNotificationTest, GlobalNotBroadcast) {
store->set_store_load_commands(true);
// Bind it to a CookieMonster
- auto monster = std::make_unique<CookieMonster>(store.get(), nullptr, nullptr);
+ auto monster = std::make_unique<CookieMonster>(store.get(), nullptr);
// Trigger load dispatch and confirm it.
monster->GetAllCookiesAsync(CookieStore::GetCookieListCallback());
@@ -3476,7 +3287,7 @@ TEST_F(CookieMonsterNotificationTest, GlobalNotBroadcast) {
&initial_cookies);
// Execute the load
- store->commands()[0].loaded_callback.Run(std::move(initial_cookies));
+ store->TakeCallbackAt(0).Run(std::move(initial_cookies));
base::RunLoop().RunUntilIdle();
// We should see two insertions, no deletions, and only one cookie in the
diff --git a/chromium/net/cookies/cookie_options.h b/chromium/net/cookies/cookie_options.h
index 52d4fe54fb6..2633272b7aa 100644
--- a/chromium/net/cookies/cookie_options.h
+++ b/chromium/net/cookies/cookie_options.h
@@ -28,8 +28,8 @@ class NET_EXPORT CookieOptions {
//
// * Excludes HttpOnly cookies
// * Excludes SameSite cookies
- // * Does not enforce prefix restrictions (e.g. "$Secure-*")
// * Updates last-accessed time.
+ // * Does not report excluded cookies in APIs that can do so.
//
// These settings can be altered by calling:
//
diff --git a/chromium/net/cookies/cookie_store.h b/chromium/net/cookies/cookie_store.h
index fb89b5d982a..c1146a9e32f 100644
--- a/chromium/net/cookies/cookie_store.h
+++ b/chromium/net/cookies/cookie_store.h
@@ -49,6 +49,7 @@ class NET_EXPORT CookieStore {
CanonicalCookie::CookieInclusionStatus status)>
SetCookiesCallback;
typedef base::OnceCallback<void(uint32_t num_deleted)> DeleteCallback;
+ typedef base::OnceCallback<void(bool success)> SetCookieableSchemesCallback;
virtual ~CookieStore();
@@ -65,13 +66,15 @@ class NET_EXPORT CookieStore {
SetCookiesCallback callback) = 0;
// Set the cookie on the cookie store. |cookie.IsCanonical()| must
- // be true. |source_scheme| denotes the scheme of the resource setting this,
- // and |modify_http_only| indicates if the source of the setting may modify
- // http_only cookies. The current time will be used in place of a null
- // creation time.
+ // be true. |source_scheme| denotes the scheme of the resource setting this.
+ //
+ // |options| is used to determine the context the operation is run in, and
+ // which cookies it can alter (e.g. http only, or same site).
+ //
+ // The current time will be used in place of a null creation time.
virtual void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie,
std::string source_scheme,
- bool modify_http_only,
+ const CookieOptions& options,
SetCookiesCallback callback) = 0;
// Obtains a CookieList for the given |url| and |options|. The returned
@@ -134,6 +137,14 @@ class NET_EXPORT CookieStore {
// The interface used to observe changes to this CookieStore's contents.
virtual CookieChangeDispatcher& GetChangeDispatcher() = 0;
+ // Resets the list of cookieable schemes to the supplied schemes. Does nothing
+ // (and returns false) if called after first use of the instance (i.e. after
+ // the instance initialization process). Otherwise, this returns true to
+ // indicate success. CookieStores which do not support modifying cookieable
+ // schemes will always return false.
+ virtual void SetCookieableSchemes(const std::vector<std::string>& schemes,
+ SetCookieableSchemesCallback callback) = 0;
+
// Returns true if this cookie store is ephemeral, and false if it is backed
// by some sort of persistence layer.
// TODO(nharper): Remove this method once crbug.com/548423 has been closed.
diff --git a/chromium/net/cookies/cookie_store_test_callbacks.cc b/chromium/net/cookies/cookie_store_test_callbacks.cc
index 58a9c25c712..3f1136fd8dc 100644
--- a/chromium/net/cookies/cookie_store_test_callbacks.cc
+++ b/chromium/net/cookies/cookie_store_test_callbacks.cc
@@ -14,15 +14,16 @@
namespace net {
CookieCallback::CookieCallback(base::Thread* run_in_thread)
- : run_in_thread_(run_in_thread) {}
+ : run_in_thread_(run_in_thread), was_run_(false) {}
CookieCallback::CookieCallback()
- : run_in_thread_(NULL),
- run_in_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
+ : run_in_thread_(nullptr),
+ run_in_task_runner_(base::ThreadTaskRunnerHandle::Get()),
+ was_run_(false) {}
CookieCallback::~CookieCallback() = default;
-void CookieCallback::CallbackEpilogue() {
+void CookieCallback::ValidateThread() const {
scoped_refptr<base::SingleThreadTaskRunner> expected_task_runner;
if (run_in_thread_) {
DCHECK(!run_in_task_runner_);
@@ -31,8 +32,12 @@ void CookieCallback::CallbackEpilogue() {
expected_task_runner = run_in_task_runner_;
}
ASSERT_TRUE(expected_task_runner);
-
EXPECT_TRUE(expected_task_runner->BelongsToCurrentThread());
+}
+
+void CookieCallback::CallbackEpilogue() {
+ ValidateThread();
+ was_run_ = true;
loop_to_quit_.Quit();
}
@@ -40,6 +45,11 @@ void CookieCallback::WaitUntilDone() {
loop_to_quit_.Run();
}
+bool CookieCallback::was_run() const {
+ ValidateThread();
+ return was_run_;
+}
+
NoResultCookieCallback::NoResultCookieCallback() = default;
NoResultCookieCallback::NoResultCookieCallback(base::Thread* run_in_thread)
: CookieCallback(run_in_thread) {}
diff --git a/chromium/net/cookies/cookie_store_test_callbacks.h b/chromium/net/cookies/cookie_store_test_callbacks.h
index 4a5ea9eecca..ff9e2d2f6a0 100644
--- a/chromium/net/cookies/cookie_store_test_callbacks.h
+++ b/chromium/net/cookies/cookie_store_test_callbacks.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
@@ -28,6 +29,10 @@ class CookieCallback {
// Waits until the callback is invoked.
void WaitUntilDone();
+ // Returns whether the callback was invoked. Should only be used on the thread
+ // the callback runs on.
+ bool was_run() const;
+
protected:
// Constructs a callback that expects to be called in the given thread.
explicit CookieCallback(base::Thread* run_in_thread);
@@ -43,9 +48,12 @@ class CookieCallback {
void CallbackEpilogue();
private:
+ void ValidateThread() const;
+
base::Thread* run_in_thread_;
scoped_refptr<base::SingleThreadTaskRunner> run_in_task_runner_;
base::RunLoop loop_to_quit_;
+ bool was_run_;
};
// Callback implementations for the asynchronous CookieStore methods.
@@ -64,6 +72,13 @@ class ResultSavingCookieCallback : public CookieCallback {
CallbackEpilogue();
}
+ // Makes a callback that will invoke Run. Assumes that |this| will be kept
+ // alive till the time the callback is used.
+ base::OnceCallback<void(T)> MakeCallback() {
+ return base::BindOnce(&ResultSavingCookieCallback<T>::Run,
+ base::Unretained(this));
+ }
+
const T& result() { return result_; }
private:
@@ -89,6 +104,13 @@ class GetCookieListCallback : public CookieCallback {
void Run(const CookieList& cookies, const CookieStatusList& excluded_cookies);
+ // Makes a callback that will invoke Run. Assumes that |this| will be kept
+ // alive till the time the callback is used.
+ base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+ MakeCallback() {
+ return base::BindOnce(&GetCookieListCallback::Run, base::Unretained(this));
+ }
+
const CookieList& cookies() { return cookies_; }
const CookieStatusList& excluded_cookies() { return excluded_cookies_; }
diff --git a/chromium/net/cookies/cookie_store_test_helpers.cc b/chromium/net/cookies/cookie_store_test_helpers.cc
index 047082fd88d..d32e57ce479 100644
--- a/chromium/net/cookies/cookie_store_test_helpers.cc
+++ b/chromium/net/cookies/cookie_store_test_helpers.cc
@@ -65,7 +65,6 @@ DelayedCookieMonsterChangeDispatcher::AddCallbackForAllChanges(
DelayedCookieMonster::DelayedCookieMonster()
: cookie_monster_(new CookieMonster(nullptr /* store */,
- nullptr /* channel_id_service */,
nullptr /* netlog */)),
did_run_(false),
result_(
@@ -107,11 +106,11 @@ void DelayedCookieMonster::SetCookieWithOptionsAsync(
void DelayedCookieMonster::SetCanonicalCookieAsync(
std::unique_ptr<CanonicalCookie> cookie,
std::string source_scheme,
- bool modify_http_only,
+ const CookieOptions& options,
SetCookiesCallback callback) {
did_run_ = false;
cookie_monster_->SetCanonicalCookieAsync(
- std::move(cookie), std::move(source_scheme), modify_http_only,
+ std::move(cookie), std::move(source_scheme), options,
base::Bind(&DelayedCookieMonster::SetCookiesInternalCallback,
base::Unretained(this)));
DCHECK_EQ(did_run_, true);
@@ -194,6 +193,12 @@ CookieChangeDispatcher& DelayedCookieMonster::GetChangeDispatcher() {
return change_dispatcher_;
}
+void DelayedCookieMonster::SetCookieableSchemes(
+ const std::vector<std::string>& schemes,
+ SetCookieableSchemesCallback callback) {
+ ADD_FAILURE();
+}
+
bool DelayedCookieMonster::IsEphemeral() {
return true;
}
@@ -224,17 +229,18 @@ std::string CookieURLHelper::Format(const std::string& format_string) const {
//
FlushablePersistentStore::FlushablePersistentStore() : flush_count_(0) {}
-void FlushablePersistentStore::Load(const LoadedCallback& loaded_callback,
+void FlushablePersistentStore::Load(LoadedCallback loaded_callback,
const NetLogWithSource& /* net_log */) {
std::vector<std::unique_ptr<CanonicalCookie>> out_cookies;
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::BindOnce(loaded_callback, std::move(out_cookies)));
+ FROM_HERE,
+ base::BindOnce(std::move(loaded_callback), std::move(out_cookies)));
}
void FlushablePersistentStore::LoadCookiesForKey(
const std::string& key,
- const LoadedCallback& loaded_callback) {
- Load(loaded_callback, NetLogWithSource());
+ LoadedCallback loaded_callback) {
+ Load(std::move(loaded_callback), NetLogWithSource());
}
void FlushablePersistentStore::AddCookie(const CanonicalCookie&) {}
@@ -245,7 +251,7 @@ void FlushablePersistentStore::DeleteCookie(const CanonicalCookie&) {}
void FlushablePersistentStore::SetForceKeepSessionState() {}
-void FlushablePersistentStore::SetBeforeFlushCallback(
+void FlushablePersistentStore::SetBeforeCommitCallback(
base::RepeatingClosure callback) {}
void FlushablePersistentStore::Flush(base::OnceClosure callback) {
diff --git a/chromium/net/cookies/cookie_store_test_helpers.h b/chromium/net/cookies/cookie_store_test_helpers.h
index 85935fa673f..9feb25979e5 100644
--- a/chromium/net/cookies/cookie_store_test_helpers.h
+++ b/chromium/net/cookies/cookie_store_test_helpers.h
@@ -59,7 +59,7 @@ class DelayedCookieMonster : public CookieStore {
void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie,
std::string source_scheme,
- bool modify_http_only,
+ const CookieOptions& options,
SetCookiesCallback callback) override;
void GetCookieListWithOptionsAsync(const GURL& url,
@@ -88,6 +88,9 @@ class DelayedCookieMonster : public CookieStore {
CookieChangeDispatcher& GetChangeDispatcher() override;
+ void SetCookieableSchemes(const std::vector<std::string>& schemes,
+ SetCookieableSchemesCallback callback) override;
+
bool IsEphemeral() override;
private:
@@ -148,15 +151,15 @@ class FlushablePersistentStore : public CookieMonster::PersistentCookieStore {
FlushablePersistentStore();
// CookieMonster::PersistentCookieStore implementation:
- void Load(const LoadedCallback& loaded_callback,
+ void Load(LoadedCallback loaded_callback,
const NetLogWithSource& net_log) override;
void LoadCookiesForKey(const std::string& key,
- const LoadedCallback& loaded_callback) override;
+ LoadedCallback loaded_callback) override;
void AddCookie(const CanonicalCookie&) override;
void UpdateCookieAccessTime(const CanonicalCookie&) override;
void DeleteCookie(const CanonicalCookie&) override;
void SetForceKeepSessionState() override;
- void SetBeforeFlushCallback(base::RepeatingClosure callback) override;
+ void SetBeforeCommitCallback(base::RepeatingClosure callback) override;
void Flush(base::OnceClosure callback) override;
int flush_count();
diff --git a/chromium/net/cookies/cookie_store_unittest.h b/chromium/net/cookies/cookie_store_unittest.h
index 5608fead96c..67892c3153d 100644
--- a/chromium/net/cookies/cookie_store_unittest.h
+++ b/chromium/net/cookies/cookie_store_unittest.h
@@ -141,9 +141,7 @@ class CookieStoreTest : public testing::Test {
const CookieOptions& options) {
DCHECK(cs);
GetCookieListCallback callback;
- cs->GetCookieListWithOptionsAsync(
- url, options,
- base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback)));
+ cs->GetCookieListWithOptionsAsync(url, options, callback.MakeCallback());
callback.WaitUntilDone();
return CanonicalCookie::BuildCookieLine(callback.cookies());
}
@@ -153,9 +151,7 @@ class CookieStoreTest : public testing::Test {
const CookieOptions& options) {
DCHECK(cs);
GetCookieListCallback callback;
- cs->GetCookieListWithOptionsAsync(
- url, options,
- base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback)));
+ cs->GetCookieListWithOptionsAsync(url, options, callback.MakeCallback());
callback.WaitUntilDone();
return callback.cookies();
}
@@ -163,8 +159,7 @@ class CookieStoreTest : public testing::Test {
CookieList GetAllCookiesForURL(CookieStore* cs, const GURL& url) {
DCHECK(cs);
GetCookieListCallback callback;
- cs->GetAllCookiesForURLAsync(url, base::Bind(&GetCookieListCallback::Run,
- base::Unretained(&callback)));
+ cs->GetAllCookiesForURLAsync(url, callback.MakeCallback());
callback.WaitUntilDone();
return callback.cookies();
}
@@ -177,10 +172,7 @@ class CookieStoreTest : public testing::Test {
options.set_same_site_cookie_context(
CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
options.set_return_excluded_cookies();
- cs->GetCookieListWithOptionsAsync(
- url, options,
- base::BindOnce(&GetCookieListCallback::Run,
- base::Unretained(&callback)));
+ cs->GetCookieListWithOptionsAsync(url, options, callback.MakeCallback());
callback.WaitUntilDone();
return callback.excluded_cookies();
}
@@ -188,8 +180,7 @@ class CookieStoreTest : public testing::Test {
CookieList GetAllCookies(CookieStore* cs) {
DCHECK(cs);
GetCookieListCallback callback;
- cs->GetAllCookiesAsync(
- base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback)));
+ cs->GetAllCookiesAsync(callback.MakeCallback());
callback.WaitUntilDone();
return callback.cookies();
}
@@ -200,11 +191,8 @@ class CookieStoreTest : public testing::Test {
const CookieOptions& options) {
DCHECK(cs);
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> callback;
- cs->SetCookieWithOptionsAsync(
- url, cookie_line, options,
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&callback)));
+ cs->SetCookieWithOptionsAsync(url, cookie_line, options,
+ callback.MakeCallback());
callback.WaitUntilDone();
return callback.result() == CanonicalCookie::CookieInclusionStatus::INCLUDE;
}
@@ -215,11 +203,11 @@ class CookieStoreTest : public testing::Test {
bool can_modify_httponly) {
DCHECK(cs);
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> callback;
- cs->SetCanonicalCookieAsync(
- std::move(cookie), std::move(source_scheme), can_modify_httponly,
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&callback)));
+ CookieOptions options;
+ if (can_modify_httponly)
+ options.set_include_httponly();
+ cs->SetCanonicalCookieAsync(std::move(cookie), std::move(source_scheme),
+ options, callback.MakeCallback());
callback.WaitUntilDone();
return callback.result() == CanonicalCookie::CookieInclusionStatus::INCLUDE;
}
@@ -254,11 +242,8 @@ class CookieStoreTest : public testing::Test {
DCHECK(cs);
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> callback;
- cs->SetCookieWithOptionsAsync(
- url, cookie_line, options,
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&callback)));
+ cs->SetCookieWithOptionsAsync(url, cookie_line, options,
+ callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -270,11 +255,11 @@ class CookieStoreTest : public testing::Test {
bool can_modify_httponly) {
DCHECK(cs);
ResultSavingCookieCallback<CanonicalCookie::CookieInclusionStatus> callback;
- cs->SetCanonicalCookieAsync(
- std::move(cookie), std::move(source_scheme), can_modify_httponly,
- base::BindOnce(&ResultSavingCookieCallback<
- CanonicalCookie::CookieInclusionStatus>::Run,
- base::Unretained(&callback)));
+ CookieOptions options;
+ if (can_modify_httponly)
+ options.set_include_httponly();
+ cs->SetCanonicalCookieAsync(std::move(cookie), std::move(source_scheme),
+ options, callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -283,9 +268,7 @@ class CookieStoreTest : public testing::Test {
const CanonicalCookie& cookie) {
DCHECK(cs);
ResultSavingCookieCallback<uint32_t> callback;
- cs->DeleteCanonicalCookieAsync(
- cookie, base::Bind(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&callback)));
+ cs->DeleteCanonicalCookieAsync(cookie, callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -294,10 +277,8 @@ class CookieStoreTest : public testing::Test {
const TimeRange& creation_range) {
DCHECK(cs);
ResultSavingCookieCallback<uint32_t> callback;
- cs->DeleteAllCreatedInTimeRangeAsync(
- creation_range,
- base::BindRepeating(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&callback)));
+ cs->DeleteAllCreatedInTimeRangeAsync(creation_range,
+ callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -306,10 +287,8 @@ class CookieStoreTest : public testing::Test {
CookieDeletionInfo delete_info) {
DCHECK(cs);
ResultSavingCookieCallback<uint32_t> callback;
- cs->DeleteAllMatchingInfoAsync(
- std::move(delete_info),
- base::Bind(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&callback)));
+ cs->DeleteAllMatchingInfoAsync(std::move(delete_info),
+ callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -317,9 +296,7 @@ class CookieStoreTest : public testing::Test {
uint32_t DeleteSessionCookies(CookieStore* cs) {
DCHECK(cs);
ResultSavingCookieCallback<uint32_t> callback;
- cs->DeleteSessionCookiesAsync(
- base::Bind(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&callback)));
+ cs->DeleteSessionCookiesAsync(callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -327,8 +304,7 @@ class CookieStoreTest : public testing::Test {
uint32_t DeleteAll(CookieStore* cs) {
DCHECK(cs);
ResultSavingCookieCallback<uint32_t> callback;
- cs->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<uint32_t>::Run,
- base::Unretained(&callback)));
+ cs->DeleteAllAsync(callback.MakeCallback());
callback.WaitUntilDone();
return callback.result();
}
@@ -418,7 +394,7 @@ TYPED_TEST_P(CookieStoreTest, FilterTest) {
std::unique_ptr<CanonicalCookie> cc(CanonicalCookie::CreateSanitizedCookie(
this->www_foo_foo_.url(), "A", "B", std::string(), "/foo", one_hour_ago,
one_hour_from_now, base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT));
ASSERT_TRUE(cc);
EXPECT_TRUE(this->SetCanonicalCookie(cs, std::move(cc), "https",
true /*modify_httponly*/));
@@ -428,7 +404,7 @@ TYPED_TEST_P(CookieStoreTest, FilterTest) {
cc = CanonicalCookie::CreateSanitizedCookie(
this->www_foo_bar_.url(), "C", "D", this->www_foo_bar_.domain(), "/bar",
two_hours_ago, base::Time(), one_hour_ago, false, true,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT);
ASSERT_TRUE(cc);
EXPECT_TRUE(this->SetCanonicalCookie(cs, std::move(cc), "https",
true /*modify_httponly*/));
@@ -439,13 +415,13 @@ TYPED_TEST_P(CookieStoreTest, FilterTest) {
cc = CanonicalCookie::CreateSanitizedCookie(
this->http_www_foo_.url(), "E", "F", std::string(), std::string(),
base::Time(), base::Time(), base::Time(), true, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT);
ASSERT_FALSE(cc);
cc = CanonicalCookie::CreateSanitizedCookie(
this->https_www_foo_.url(), "E", "F", std::string(), std::string(),
base::Time(), base::Time(), base::Time(), true, false,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT);
ASSERT_TRUE(cc);
EXPECT_TRUE(this->SetCanonicalCookie(cs, std::move(cc), "https",
true /*modify_httponly*/));
@@ -551,7 +527,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>(
"A", "B", foo_foo_host, "/foo", one_hour_ago, one_hour_from_now,
base::Time(), false /* secure */, false /* httponly */,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true));
// Note that for the creation time to be set exactly, without modification,
// it must be different from the one set by the line above.
@@ -559,7 +535,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
cs,
std::make_unique<CanonicalCookie>(
"C", "D", "." + foo_bar_domain, "/bar", two_hours_ago, base::Time(),
- one_hour_ago, false, true, CookieSameSite::DEFAULT_MODE,
+ one_hour_ago, false, true, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT),
"http", true));
@@ -569,7 +545,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
cs,
std::make_unique<CanonicalCookie>(
"E", "F", http_foo_host, "/", base::Time(), base::Time(),
- base::Time(), true, false, CookieSameSite::DEFAULT_MODE,
+ base::Time(), true, false, CookieSameSite::NO_RESTRICTION,
COOKIE_PRIORITY_DEFAULT),
"http", true));
@@ -580,7 +556,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>(
"E", "F", http_foo_host, "/", base::Time(), base::Time(),
base::Time(), true /* secure */, false /* httponly */,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"https", true /* modify_http_only */));
EXPECT_EQ(CanonicalCookie::CookieInclusionStatus::EXCLUDE_SECURE_ONLY,
@@ -589,7 +565,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>(
"E", "F", http_foo_host, "/", base::Time(), base::Time(),
base::Time(), true /* secure */, false /* httponly */,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /* modify_http_only */));
if (TypeParam::supports_http_only) {
@@ -602,7 +578,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), base::Time(),
base::Time(), false /* secure */, true /* httponly */,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", false /* modify_http_only */));
// Permission to modify httponly cookies is also required to overwrite
@@ -612,7 +588,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), base::Time(),
base::Time(), false /* secure */, true /* httponly */,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /* modify_http_only */));
EXPECT_EQ(
@@ -622,7 +598,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), base::Time(),
base::Time(), false /* secure */, true /* httponly */,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", false /* modify_http_only */));
} else {
// Leave store in same state as if the above tests had been run.
@@ -631,7 +607,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), base::Time(),
base::Time(), false /* secure */, true /* httponly */,
- CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT),
+ CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT),
"http", true /* modify_http_only */));
}
diff --git a/chromium/net/cookies/cookie_util.cc b/chromium/net/cookies/cookie_util.cc
index 1da63d10842..fea7419bfa6 100644
--- a/chromium/net/cookies/cookie_util.cc
+++ b/chromium/net/cookies/cookie_util.cc
@@ -7,6 +7,8 @@
#include <cstdio>
#include <cstdlib>
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_piece.h"
@@ -431,5 +433,39 @@ CookieOptions::SameSiteCookieContext ComputeSameSiteContextForRequest(
return same_site_context;
}
+base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+IgnoreCookieStatusList(base::OnceCallback<void(const CookieList&)> callback) {
+ return base::BindOnce(
+ [](base::OnceCallback<void(const CookieList&)> callback,
+ const CookieList& cookies, const CookieStatusList& excluded_list) {
+ std::move(callback).Run(cookies);
+ },
+ std::move(callback));
+}
+
+base::OnceCallback<void(const CookieList&)> AddCookieStatusList(
+ base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+ callback) {
+ return base::BindOnce(
+ [](base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+ inner_callback,
+ const CookieList& cookies) {
+ std::move(inner_callback).Run(cookies, net::CookieStatusList());
+ },
+ std::move(callback));
+}
+
+base::OnceCallback<void(net::CanonicalCookie::CookieInclusionStatus)>
+AdaptCookieInclusionStatusToBool(base::OnceCallback<void(bool)> callback) {
+ return base::BindOnce(
+ [](base::OnceCallback<void(bool)> inner_callback,
+ const net::CanonicalCookie::CookieInclusionStatus status) {
+ bool success =
+ (status == net::CanonicalCookie::CookieInclusionStatus::INCLUDE);
+ std::move(inner_callback).Run(success);
+ },
+ std::move(callback));
+}
+
} // namespace cookie_util
} // namespace net
diff --git a/chromium/net/cookies/cookie_util.h b/chromium/net/cookies/cookie_util.h
index 706617d2c1e..528740781df 100644
--- a/chromium/net/cookies/cookie_util.h
+++ b/chromium/net/cookies/cookie_util.h
@@ -9,8 +9,10 @@
#include <utility>
#include <vector>
+#include "base/callback_forward.h"
#include "base/time/time.h"
#include "net/base/net_export.h"
+#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h"
#include "url/origin.h"
@@ -111,6 +113,34 @@ ComputeSameSiteContextForRequest(const std::string& http_method,
const base::Optional<url::Origin>& initiator,
bool attach_same_site_cookies);
+// Takes a OnceCallback with only a CookieList and binds it to a callback that
+// also accepts a CookieStatusList, making it compatible with
+// CookieStore::GetCookieListCallback.
+//
+// Can be used when the CookieWithStatus list (the list of
+// cookies excluded from being sent) is not needed and therefore isn't in the
+// callback signature. Also useful if you're using
+NET_EXPORT base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+IgnoreCookieStatusList(base::OnceCallback<void(const CookieList&)> callback);
+
+// Takes a CookieStore::GetCookieListCallback and binds a function that only
+// takes a CookieList, sending an empty CookieStatusList.
+//
+// Can be used if you have a callback that's used with both GetCookieList and
+// GetAllCookies and you want to use the excluded cookies list when you have it.
+NET_EXPORT base::OnceCallback<void(const CookieList&)> AddCookieStatusList(
+ base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+ callback);
+
+// Takes a callback accepting a CookieInclusionStatus and returns a callback
+// that accepts a bool, setting the bool to true if the CookieInclusionStatus
+// was set to INCLUDE, else sending false.
+//
+// Can be used with SetCanonicalCookie when you don't need to know why a cookie
+// was blocked, only if it was blocked.
+NET_EXPORT base::OnceCallback<void(CanonicalCookie::CookieInclusionStatus)>
+AdaptCookieInclusionStatusToBool(base::OnceCallback<void(bool)> callback);
+
} // namespace cookie_util
} // namespace net
diff --git a/chromium/net/cookies/cookie_util_unittest.cc b/chromium/net/cookies/cookie_util_unittest.cc
index 7f02f28258d..c0359ffa8a0 100644
--- a/chromium/net/cookies/cookie_util_unittest.cc
+++ b/chromium/net/cookies/cookie_util_unittest.cc
@@ -5,7 +5,9 @@
#include <string>
#include <utility>
+#include "base/callback.h"
#include "base/strings/string_split.h"
+#include "base/test/bind_test_util.h"
#include "net/cookies/cookie_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -356,6 +358,71 @@ TEST(CookieUtilTest, ComputeSameSiteContextForRequest) {
false /*attach_same_site_cookies*/));
}
+TEST(CookieUtilTest, IgnoreCookieStatusList) {
+ CookieList cookie_list_out;
+ base::OnceCallback<void(const CookieList&)> callback =
+ base::BindLambdaForTesting(
+ [&cookie_list_out](const CookieList& cookie_list) {
+ cookie_list_out = cookie_list;
+ });
+ base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+ adapted_callback =
+ cookie_util::IgnoreCookieStatusList(std::move(callback));
+
+ CookieList cookie_list_in = {CanonicalCookie()};
+ std::move(adapted_callback).Run(cookie_list_in, CookieStatusList());
+
+ EXPECT_EQ(1u, cookie_list_out.size());
+}
+
+TEST(CookieUtilTest, AddCookieStatusList) {
+ CookieList cookie_list_out;
+ CookieStatusList excluded_cookies_out = {CookieWithStatus()};
+ base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
+ callback = base::BindLambdaForTesting(
+ [&cookie_list_out, &excluded_cookies_out](
+ const CookieList& cookie_list,
+ const CookieStatusList& excluded_cookies) {
+ cookie_list_out = cookie_list;
+ excluded_cookies_out = excluded_cookies;
+ });
+ base::OnceCallback<void(const CookieList&)> adapted_callback =
+ cookie_util::AddCookieStatusList(std::move(callback));
+
+ CookieList cookie_list_in = {CanonicalCookie()};
+ std::move(adapted_callback).Run(cookie_list_in);
+
+ EXPECT_EQ(1u, cookie_list_out.size());
+ EXPECT_EQ(0u, excluded_cookies_out.size());
+}
+
+TEST(CookieUtilTest, AdaptCookieInclusionStatusToBool) {
+ bool result_out = true;
+ base::OnceCallback<void(bool)> callback = base::BindLambdaForTesting(
+ [&result_out](bool result) { result_out = result; });
+
+ base::OnceCallback<void(CanonicalCookie::CookieInclusionStatus)>
+ adapted_callback =
+ cookie_util::AdaptCookieInclusionStatusToBool(std::move(callback));
+
+ std::move(adapted_callback)
+ .Run(CanonicalCookie::CookieInclusionStatus::EXCLUDE_UNKNOWN_ERROR);
+
+ EXPECT_FALSE(result_out);
+
+ result_out = false;
+ callback = base::BindLambdaForTesting(
+ [&result_out](bool result) { result_out = result; });
+
+ adapted_callback =
+ cookie_util::AdaptCookieInclusionStatusToBool(std::move(callback));
+
+ std::move(adapted_callback)
+ .Run(CanonicalCookie::CookieInclusionStatus::INCLUDE);
+
+ EXPECT_TRUE(result_out);
+}
+
} // namespace
} // namespace net
diff --git a/chromium/net/cookies/parsed_cookie.cc b/chromium/net/cookies/parsed_cookie.cc
index 9cc4c828dc4..d8e6d621774 100644
--- a/chromium/net/cookies/parsed_cookie.cc
+++ b/chromium/net/cookies/parsed_cookie.cc
@@ -69,7 +69,7 @@ const char kTokenSeparator[] = ";=";
// Returns true if |c| occurs in |chars|
// TODO(erikwright): maybe make this take an iterator, could check for end also?
inline bool CharIsA(const char c, const char* chars) {
- return strchr(chars, c) != NULL;
+ return strchr(chars, c) != nullptr;
}
// Seek the iterator to the first occurrence of a character in |chars|.
// Returns true if it hit the end, false otherwise.
@@ -138,7 +138,7 @@ ParsedCookie::ParsedCookie(const std::string& cookie_line)
same_site_index_(0),
priority_index_(0) {
if (cookie_line.size() > kMaxCookieSize) {
- VLOG(1) << "Not parsing cookie, too large: " << cookie_line.size();
+ DVLOG(1) << "Not parsing cookie, too large: " << cookie_line.size();
return;
}
@@ -155,7 +155,7 @@ bool ParsedCookie::IsValid() const {
CookieSameSite ParsedCookie::SameSite() const {
return (same_site_index_ == 0)
- ? CookieSameSite::DEFAULT_MODE
+ ? CookieSameSite::NO_RESTRICTION
: StringToCookieSameSite(pairs_[same_site_index_].second);
}
diff --git a/chromium/net/cookies/parsed_cookie_unittest.cc b/chromium/net/cookies/parsed_cookie_unittest.cc
index 92d0aaccc23..6252fd98bff 100644
--- a/chromium/net/cookies/parsed_cookie_unittest.cc
+++ b/chromium/net/cookies/parsed_cookie_unittest.cc
@@ -181,7 +181,7 @@ TEST(ParsedCookieTest, MultipleEquals) {
EXPECT_FALSE(pc.HasDomain());
EXPECT_TRUE(pc.IsSecure());
EXPECT_TRUE(pc.IsHttpOnly());
- EXPECT_EQ(CookieSameSite::DEFAULT_MODE, pc.SameSite());
+ EXPECT_EQ(CookieSameSite::NO_RESTRICTION, pc.SameSite());
EXPECT_EQ(COOKIE_PRIORITY_DEFAULT, pc.Priority());
EXPECT_EQ(4U, pc.NumberOfAttributes());
}
@@ -465,7 +465,7 @@ TEST(ParsedCookieTest, SetSameSite) {
EXPECT_TRUE(pc.IsValid());
EXPECT_EQ("name=value", pc.ToCookieLine());
- EXPECT_EQ(CookieSameSite::DEFAULT_MODE, pc.SameSite());
+ EXPECT_EQ(CookieSameSite::NO_RESTRICTION, pc.SameSite());
// Test each samesite directive, expect case-insensitive compare.
EXPECT_TRUE(pc.SetSameSite("strict"));
@@ -486,7 +486,7 @@ TEST(ParsedCookieTest, SetSameSite) {
// Remove the SameSite attribute.
EXPECT_TRUE(pc.SetSameSite(""));
EXPECT_EQ("name=value", pc.ToCookieLine());
- EXPECT_EQ(CookieSameSite::DEFAULT_MODE, pc.SameSite());
+ EXPECT_EQ(CookieSameSite::NO_RESTRICTION, pc.SameSite());
EXPECT_TRUE(pc.IsValid());
EXPECT_TRUE(pc.SetSameSite("Blah"));
@@ -504,7 +504,7 @@ TEST(ParsedCookieTest, SameSiteValues) {
{"n=v; samesite=lax", true, CookieSameSite::LAX_MODE},
{"n=v; samesite=boo", true, CookieSameSite::NO_RESTRICTION},
{"n=v; samesite", true, CookieSameSite::NO_RESTRICTION},
- {"n=v", true, CookieSameSite::DEFAULT_MODE}};
+ {"n=v", true, CookieSameSite::NO_RESTRICTION}};
for (const auto& test : cases) {
SCOPED_TRACE(test.cookie);