Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: net/extras/sqlite/sqlite_persistent_cookie_store.cc

Issue 1773133002: SameSite: Implement 'Strict'/'Lax' attribute parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke@ Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h" 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 case kCookiePriorityMedium: 366 case kCookiePriorityMedium:
367 return COOKIE_PRIORITY_MEDIUM; 367 return COOKIE_PRIORITY_MEDIUM;
368 case kCookiePriorityHigh: 368 case kCookiePriorityHigh:
369 return COOKIE_PRIORITY_HIGH; 369 return COOKIE_PRIORITY_HIGH;
370 } 370 }
371 371
372 NOTREACHED(); 372 NOTREACHED();
373 return COOKIE_PRIORITY_DEFAULT; 373 return COOKIE_PRIORITY_DEFAULT;
374 } 374 }
375 375
376 // Possible values for the 'samesite' column
377 enum DBCookieSameSite {
378 kCookieSameSiteNoRestriction = 0,
379 kCookieSameSiteLax = 1,
380 kCookieSameSiteStrict = 2,
381 };
382
383 DBCookieSameSite CookieSameSiteToDBCookieSameSite(CookieSameSite value) {
384 switch (value) {
385 case CookieSameSite::NO_RESTRICTION:
386 return kCookieSameSiteNoRestriction;
387 case CookieSameSite::LAX_MODE:
388 return kCookieSameSiteLax;
389 case CookieSameSite::STRICT_MODE:
390 return kCookieSameSiteStrict;
391 }
392
393 NOTREACHED();
394 return kCookieSameSiteNoRestriction;
395 }
396
397 CookieSameSite DBCookieSameSiteToCookieSameSite(DBCookieSameSite value) {
398 switch (value) {
399 case kCookieSameSiteNoRestriction:
400 return CookieSameSite::NO_RESTRICTION;
401 case kCookieSameSiteLax:
402 return CookieSameSite::LAX_MODE;
403 case kCookieSameSiteStrict:
404 return CookieSameSite::STRICT_MODE;
405 }
406
407 NOTREACHED();
408 return CookieSameSite::DEFAULT_MODE;
409 }
410
376 // Increments a specified TimeDelta by the duration between this object's 411 // Increments a specified TimeDelta by the duration between this object's
377 // constructor and destructor. Not thread safe. Multiple instances may be 412 // constructor and destructor. Not thread safe. Multiple instances may be
378 // created with the same delta instance as long as their lifetimes are nested. 413 // created with the same delta instance as long as their lifetimes are nested.
379 // The shortest lived instances have no impact. 414 // The shortest lived instances have no impact.
380 class IncrementTimeDelta { 415 class IncrementTimeDelta {
381 public: 416 public:
382 explicit IncrementTimeDelta(base::TimeDelta* delta) 417 explicit IncrementTimeDelta(base::TimeDelta* delta)
383 : delta_(delta), original_value_(*delta), start_(base::Time::Now()) {} 418 : delta_(delta), original_value_(*delta), start_(base::Time::Now()) {}
384 419
385 ~IncrementTimeDelta() { 420 ~IncrementTimeDelta() {
(...skipping 21 matching lines...) Expand all
407 "value TEXT NOT NULL," 442 "value TEXT NOT NULL,"
408 "path TEXT NOT NULL," 443 "path TEXT NOT NULL,"
409 "expires_utc INTEGER NOT NULL," 444 "expires_utc INTEGER NOT NULL,"
410 "secure INTEGER NOT NULL," 445 "secure INTEGER NOT NULL,"
411 "httponly INTEGER NOT NULL," 446 "httponly INTEGER NOT NULL,"
412 "last_access_utc INTEGER NOT NULL, " 447 "last_access_utc INTEGER NOT NULL, "
413 "has_expires INTEGER NOT NULL DEFAULT 1, " 448 "has_expires INTEGER NOT NULL DEFAULT 1, "
414 "persistent INTEGER NOT NULL DEFAULT 1," 449 "persistent INTEGER NOT NULL DEFAULT 1,"
415 "priority INTEGER NOT NULL DEFAULT %d," 450 "priority INTEGER NOT NULL DEFAULT %d,"
416 "encrypted_value BLOB DEFAULT ''," 451 "encrypted_value BLOB DEFAULT '',"
417 "firstpartyonly INTEGER NOT NULL DEFAULT 0)", 452 "firstpartyonly INTEGER NOT NULL DEFAULT %d)",
418 CookiePriorityToDBCookiePriority(COOKIE_PRIORITY_DEFAULT))); 453 CookiePriorityToDBCookiePriority(COOKIE_PRIORITY_DEFAULT),
454 CookieSameSiteToDBCookieSameSite(CookieSameSite::DEFAULT_MODE)));
419 if (!db->Execute(stmt.c_str())) 455 if (!db->Execute(stmt.c_str()))
420 return false; 456 return false;
421 457
422 if (!db->Execute("CREATE INDEX domain ON cookies(host_key)")) 458 if (!db->Execute("CREATE INDEX domain ON cookies(host_key)"))
423 return false; 459 return false;
424 460
425 #if defined(OS_IOS) 461 #if defined(OS_IOS)
426 // iOS 8.1 and older doesn't support partial indices. iOS 8.2 supports 462 // iOS 8.1 and older doesn't support partial indices. iOS 8.2 supports
427 // partial indices. 463 // partial indices.
428 if (!db->Execute("CREATE INDEX is_transient ON cookies(persistent)")) { 464 if (!db->Execute("CREATE INDEX is_transient ON cookies(persistent)")) {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 GURL(), // Source 824 GURL(), // Source
789 smt.ColumnString(2), // name 825 smt.ColumnString(2), // name
790 value, // value 826 value, // value
791 smt.ColumnString(1), // domain 827 smt.ColumnString(1), // domain
792 smt.ColumnString(5), // path 828 smt.ColumnString(5), // path
793 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc 829 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc
794 Time::FromInternalValue(smt.ColumnInt64(6)), // expires_utc 830 Time::FromInternalValue(smt.ColumnInt64(6)), // expires_utc
795 Time::FromInternalValue(smt.ColumnInt64(10)), // last_access_utc 831 Time::FromInternalValue(smt.ColumnInt64(10)), // last_access_utc
796 smt.ColumnInt(7) != 0, // secure 832 smt.ColumnInt(7) != 0, // secure
797 smt.ColumnInt(8) != 0, // httponly 833 smt.ColumnInt(8) != 0, // httponly
798 smt.ColumnInt(9) != 0, // firstpartyonly 834 DBCookieSameSiteToCookieSameSite(
835 static_cast<DBCookieSameSite>(smt.ColumnInt(9))), // samesite
799 DBCookiePriorityToCookiePriority( 836 DBCookiePriorityToCookiePriority(
800 static_cast<DBCookiePriority>(smt.ColumnInt(13))))); // priority 837 static_cast<DBCookiePriority>(smt.ColumnInt(13))))); // priority
801 DLOG_IF(WARNING, cc->CreationDate() > Time::Now()) 838 DLOG_IF(WARNING, cc->CreationDate() > Time::Now())
802 << L"CreationDate too recent"; 839 << L"CreationDate too recent";
803 cookies->push_back(cc.release()); 840 cookies->push_back(cc.release());
804 ++num_cookies_read_; 841 ++num_cookies_read_;
805 } 842 }
806 } 843 }
807 844
808 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() { 845 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 add_smt.BindBlob(4, encrypted_value.data(), 1160 add_smt.BindBlob(4, encrypted_value.data(),
1124 static_cast<int>(encrypted_value.length())); 1161 static_cast<int>(encrypted_value.length()));
1125 } else { 1162 } else {
1126 add_smt.BindString(3, po->cc().Value()); 1163 add_smt.BindString(3, po->cc().Value());
1127 add_smt.BindBlob(4, "", 0); // encrypted_value 1164 add_smt.BindBlob(4, "", 0); // encrypted_value
1128 } 1165 }
1129 add_smt.BindString(5, po->cc().Path()); 1166 add_smt.BindString(5, po->cc().Path());
1130 add_smt.BindInt64(6, po->cc().ExpiryDate().ToInternalValue()); 1167 add_smt.BindInt64(6, po->cc().ExpiryDate().ToInternalValue());
1131 add_smt.BindInt(7, po->cc().IsSecure()); 1168 add_smt.BindInt(7, po->cc().IsSecure());
1132 add_smt.BindInt(8, po->cc().IsHttpOnly()); 1169 add_smt.BindInt(8, po->cc().IsHttpOnly());
1133 add_smt.BindInt(9, po->cc().IsSameSite()); 1170 add_smt.BindInt(9,
1171 CookieSameSiteToDBCookieSameSite(po->cc().SameSite()));
1134 add_smt.BindInt64(10, po->cc().LastAccessDate().ToInternalValue()); 1172 add_smt.BindInt64(10, po->cc().LastAccessDate().ToInternalValue());
1135 add_smt.BindInt(11, po->cc().IsPersistent()); 1173 add_smt.BindInt(11, po->cc().IsPersistent());
1136 add_smt.BindInt(12, po->cc().IsPersistent()); 1174 add_smt.BindInt(12, po->cc().IsPersistent());
1137 add_smt.BindInt(13, 1175 add_smt.BindInt(13,
1138 CookiePriorityToDBCookiePriority(po->cc().Priority())); 1176 CookiePriorityToDBCookiePriority(po->cc().Priority()));
1139 if (!add_smt.Run()) 1177 if (!add_smt.Run())
1140 NOTREACHED() << "Could not add a cookie to the DB."; 1178 NOTREACHED() << "Could not add a cookie to the DB.";
1141 break; 1179 break;
1142 1180
1143 case PendingOperation::COOKIE_UPDATEACCESS: 1181 case PendingOperation::COOKIE_UPDATEACCESS:
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { 1440 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) {
1403 if (backend_) 1441 if (backend_)
1404 backend_->Flush(callback); 1442 backend_->Flush(callback);
1405 } 1443 }
1406 1444
1407 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { 1445 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
1408 Close(base::Closure()); 1446 Close(base::Closure());
1409 } 1447 }
1410 1448
1411 } // namespace net 1449 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/parsed_cookie_unittest.cc ('k') | net/extras/sqlite/sqlite_persistent_cookie_store_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698