Commit 9c770cf3 authored by tfarina's avatar tfarina Committed by Commit bot

net: make CanonicalCookie's constructor private

Since almost everything was converted to Create method, now
it can be moved to private section.

While doing this, CanonicalCookieTest::Constructor had to be
converted to Create method as well.

BUG=57061
TEST=net_unittests --gtest_filter=CanonicalCookieTest.Constructor
TEST=ios_net_unittests
R=mmenke@chromium.org

Review-Url: https://codereview.chromium.org/2159373002
Cr-Commit-Position: refs/heads/master@{#407312}
parent 1243666b
...@@ -157,16 +157,17 @@ static void RestoreCookies(JNIEnv* env, ...@@ -157,16 +157,17 @@ static void RestoreCookies(JNIEnv* env,
scoped_refptr<net::URLRequestContextGetter> getter( scoped_refptr<net::URLRequestContextGetter> getter(
profile->GetRequestContext()); profile->GetRequestContext());
net::CanonicalCookie cookie( net::CanonicalCookie cookie(*net::CanonicalCookie::Create(
GURL(), base::android::ConvertJavaStringToUTF8(env, name), base::android::ConvertJavaStringToUTF8(env, name),
base::android::ConvertJavaStringToUTF8(env, value), base::android::ConvertJavaStringToUTF8(env, value),
base::android::ConvertJavaStringToUTF8(env, domain), base::android::ConvertJavaStringToUTF8(env, domain),
base::android::ConvertJavaStringToUTF8(env, path), base::android::ConvertJavaStringToUTF8(env, path),
base::Time::FromInternalValue(creation), base::Time::FromInternalValue(creation),
base::Time::FromInternalValue(expiration), base::Time::FromInternalValue(expiration),
base::Time::FromInternalValue(last_access), secure, httponly, base::Time::FromInternalValue(last_access),
secure, httponly,
static_cast<net::CookieSameSite>(same_site), static_cast<net::CookieSameSite>(same_site),
static_cast<net::CookiePriority>(priority)); static_cast<net::CookiePriority>(priority)));
// The rest must be done from the IO thread. // The rest must be done from the IO thread.
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
......
...@@ -17,10 +17,10 @@ namespace { ...@@ -17,10 +17,10 @@ namespace {
CanonicalCookie MakeCookie(const GURL& url, CanonicalCookie MakeCookie(const GURL& url,
const std::string& name, const std::string& name,
const std::string& value) { const std::string& value) {
return CanonicalCookie(url, name, value, url.host(), url.path(), base::Time(), return *CanonicalCookie::Create(url, name, value, std::string(), url.path(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false,
net::CookieSameSite::DEFAULT_MODE, net::CookieSameSite::DEFAULT_MODE, false,
net::COOKIE_PRIORITY_DEFAULT); net::COOKIE_PRIORITY_DEFAULT);
} }
} // namespace } // namespace
......
...@@ -259,16 +259,17 @@ class TestPersistentCookieStore ...@@ -259,16 +259,17 @@ class TestPersistentCookieStore
// Some canonical cookies cannot be converted into System cookies, for // Some canonical cookies cannot be converted into System cookies, for
// example if value is not valid utf8. Such cookies are ignored. // example if value is not valid utf8. Such cookies are ignored.
net::CanonicalCookie* bad_canonical_cookie = new net::CanonicalCookie( std::unique_ptr<net::CanonicalCookie> bad_canonical_cookie(
kTestCookieURL, "name", "\x81r\xe4\xbd\xa0\xe5\xa5\xbd", "domain", net::CanonicalCookie::Create(GURL("http://domain/"), "name",
"path/", "\x81r\xe4\xbd\xa0\xe5\xa5\xbd",
base::Time(), // creation std::string(), "/path/",
base::Time(), // expires base::Time(), // creation
base::Time(), // last_access base::Time(), // expires
false, // secure false, // secure
false, // httponly false, // httponly
net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT); net::CookieSameSite::DEFAULT_MODE, false,
cookies.push_back(bad_canonical_cookie); net::COOKIE_PRIORITY_DEFAULT));
cookies.push_back(bad_canonical_cookie.release());
loaded_callback_.Run(cookies); loaded_callback_.Run(cookies);
} }
......
...@@ -66,8 +66,8 @@ void ReportUMACookieLoss(CookieLossType loss, CookieEvent event) { ...@@ -66,8 +66,8 @@ void ReportUMACookieLoss(CookieLossType loss, CookieEvent event) {
net::CanonicalCookie CanonicalCookieFromSystemCookie( net::CanonicalCookie CanonicalCookieFromSystemCookie(
NSHTTPCookie* cookie, NSHTTPCookie* cookie,
const base::Time& ceation_time) { const base::Time& ceation_time) {
return net::CanonicalCookie( return *net::CanonicalCookie::Create(
GURL(), base::SysNSStringToUTF8([cookie name]), base::SysNSStringToUTF8([cookie name]),
base::SysNSStringToUTF8([cookie value]), base::SysNSStringToUTF8([cookie value]),
base::SysNSStringToUTF8([cookie domain]), base::SysNSStringToUTF8([cookie domain]),
base::SysNSStringToUTF8([cookie path]), ceation_time, base::SysNSStringToUTF8([cookie path]), ceation_time,
......
...@@ -26,8 +26,8 @@ const char kCookieValueInvalidUtf8[] = "\x81r\xe4\xbd\xa0\xe5\xa5\xbd"; ...@@ -26,8 +26,8 @@ const char kCookieValueInvalidUtf8[] = "\x81r\xe4\xbd\xa0\xe5\xa5\xbd";
void CheckSystemCookie(const base::Time& expires, bool secure, bool httponly) { void CheckSystemCookie(const base::Time& expires, bool secure, bool httponly) {
// Generate a canonical cookie. // Generate a canonical cookie.
net::CanonicalCookie canonical_cookie = net::CanonicalCookie( net::CanonicalCookie canonical_cookie = *net::CanonicalCookie::Create(
GURL(), kCookieName, kCookieValue, kCookieDomain, kCookiePath, kCookieName, kCookieValue, kCookieDomain, kCookiePath,
base::Time(), // creation base::Time(), // creation
expires, expires,
base::Time(), // last_access base::Time(), // last_access
...@@ -116,8 +116,8 @@ TEST(CookieUtil, SystemCookieFromCanonicalCookie) { ...@@ -116,8 +116,8 @@ TEST(CookieUtil, SystemCookieFromCanonicalCookie) {
TEST(CookieUtil, SystemCookieFromBadCanonicalCookie) { TEST(CookieUtil, SystemCookieFromBadCanonicalCookie) {
// Generate a bad canonical cookie (value is invalid utf8). // Generate a bad canonical cookie (value is invalid utf8).
net::CanonicalCookie bad_canonical_cookie = net::CanonicalCookie( net::CanonicalCookie bad_canonical_cookie = *net::CanonicalCookie::Create(
GURL(), kCookieName, kCookieValueInvalidUtf8, kCookieDomain, kCookiePath, kCookieName, kCookieValueInvalidUtf8, kCookieDomain, kCookiePath,
base::Time(), // creation base::Time(), // creation
base::Time(), // expires base::Time(), // expires
base::Time(), // last_access base::Time(), // last_access
......
...@@ -125,34 +125,9 @@ CanonicalCookie::CanonicalCookie() ...@@ -125,34 +125,9 @@ CanonicalCookie::CanonicalCookie()
httponly_(false) { httponly_(false) {
} }
CanonicalCookie::CanonicalCookie(const GURL& url,
const std::string& name,
const std::string& value,
const std::string& domain,
const std::string& path,
const base::Time& creation,
const base::Time& expiration,
const base::Time& last_access,
bool secure,
bool httponly,
CookieSameSite same_site,
CookiePriority priority)
: name_(name),
value_(value),
domain_(domain),
path_(path),
creation_date_(creation),
expiry_date_(expiration),
last_access_date_(last_access),
secure_(secure),
httponly_(httponly),
same_site_(same_site),
priority_(priority) {}
CanonicalCookie::CanonicalCookie(const CanonicalCookie& other) = default; CanonicalCookie::CanonicalCookie(const CanonicalCookie& other) = default;
CanonicalCookie::~CanonicalCookie() { CanonicalCookie::~CanonicalCookie() {}
}
// static // static
std::string CanonicalCookie::CanonPath(const GURL& url, std::string CanonicalCookie::CanonPath(const GURL& url,
...@@ -480,6 +455,30 @@ bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const { ...@@ -480,6 +455,30 @@ bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const {
return Priority() < other.Priority(); return Priority() < other.Priority();
} }
CanonicalCookie::CanonicalCookie(const GURL& url,
const std::string& name,
const std::string& value,
const std::string& domain,
const std::string& path,
const base::Time& creation,
const base::Time& expiration,
const base::Time& last_access,
bool secure,
bool httponly,
CookieSameSite same_site,
CookiePriority priority)
: name_(name),
value_(value),
domain_(domain),
path_(path),
creation_date_(creation),
expiry_date_(expiration),
last_access_date_(last_access),
secure_(secure),
httponly_(httponly),
same_site_(same_site),
priority_(priority) {}
// static // static
CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix( CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix(
const std::string& name) { const std::string& name) {
......
...@@ -23,25 +23,7 @@ class ParsedCookie; ...@@ -23,25 +23,7 @@ class ParsedCookie;
class NET_EXPORT CanonicalCookie { class NET_EXPORT CanonicalCookie {
public: public:
// These constructors do no validation or canonicalization of their inputs;
// the resulting CanonicalCookies should not be relied on to be canonical
// unless the caller has done appropriate validation and canonicalization
// themselves.
CanonicalCookie(); CanonicalCookie();
// TODO(mmenke): Remove |url|, as it's not used.
CanonicalCookie(const GURL& url,
const std::string& name,
const std::string& value,
const std::string& domain,
const std::string& path,
const base::Time& creation,
const base::Time& expiration,
const base::Time& last_access,
bool secure,
bool httponly,
CookieSameSite same_site,
CookiePriority priority);
CanonicalCookie(const CanonicalCookie& other); CanonicalCookie(const CanonicalCookie& other);
~CanonicalCookie(); ~CanonicalCookie();
...@@ -182,6 +164,24 @@ class NET_EXPORT CanonicalCookie { ...@@ -182,6 +164,24 @@ class NET_EXPORT CanonicalCookie {
COOKIE_PREFIX_LAST COOKIE_PREFIX_LAST
}; };
// This constructor does not validate or canonicalize their inputs;
// the resulting CanonicalCookies should not be relied on to be canonical
// unless the caller has done appropriate validation and canonicalization
// themselves.
// TODO(mmenke): Remove |url|, as it's not used.
CanonicalCookie(const GURL& url,
const std::string& name,
const std::string& value,
const std::string& domain,
const std::string& path,
const base::Time& creation,
const base::Time& expiration,
const base::Time& last_access,
bool secure,
bool httponly,
CookieSameSite same_site,
CookiePriority priority);
// Returns the CookiePrefix (or COOKIE_PREFIX_NONE if none) that // Returns the CookiePrefix (or COOKIE_PREFIX_NONE if none) that
// applies to the given cookie |name|. // applies to the given cookie |name|.
static CookiePrefix GetCookiePrefix(const std::string& name); static CookiePrefix GetCookiePrefix(const std::string& name);
......
...@@ -18,28 +18,28 @@ TEST(CanonicalCookieTest, Constructor) { ...@@ -18,28 +18,28 @@ TEST(CanonicalCookieTest, Constructor) {
GURL url("http://www.example.com/test"); GURL url("http://www.example.com/test");
base::Time current_time = base::Time::Now(); base::Time current_time = base::Time::Now();
CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
current_time, base::Time(), current_time, false, false, url, "A", "2", std::string(), "/test", current_time, base::Time(), false,
CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); false, CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ("A", cookie.Name()); EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie.Value()); EXPECT_EQ("2", cookie->Value());
EXPECT_EQ("www.example.com", cookie.Domain()); EXPECT_EQ("www.example.com", cookie->Domain());
EXPECT_EQ("/test", cookie.Path()); EXPECT_EQ("/test", cookie->Path());
EXPECT_FALSE(cookie.IsSecure()); EXPECT_FALSE(cookie->IsSecure());
EXPECT_FALSE(cookie.IsHttpOnly()); EXPECT_FALSE(cookie->IsHttpOnly());
EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie.SameSite()); EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(), std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create(
current_time, base::Time(), current_time, false, url, "A", "2", ".www.example.com", std::string(), current_time,
false, CookieSameSite::DEFAULT_MODE, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false,
COOKIE_PRIORITY_DEFAULT); COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ("A", cookie2.Name()); EXPECT_EQ("A", cookie2->Name());
EXPECT_EQ("2", cookie2.Value()); EXPECT_EQ("2", cookie2->Value());
EXPECT_EQ("", cookie2.Domain()); EXPECT_EQ(".www.example.com", cookie2->Domain());
EXPECT_EQ("", cookie2.Path()); EXPECT_EQ("/", cookie2->Path());
EXPECT_FALSE(cookie2.IsSecure()); EXPECT_FALSE(cookie2->IsSecure());
EXPECT_FALSE(cookie2.IsHttpOnly()); EXPECT_FALSE(cookie2->IsHttpOnly());
EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2.SameSite()); EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite());
} }
TEST(CanonicalCookieTest, Create) { TEST(CanonicalCookieTest, Create) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment