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

Unified Diff: content/browser/net/sqlite_persistent_cookie_store.cc

Issue 14208017: Add cookie priority to the cookie database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Sam's comments re: patchset 2 Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/net/sqlite_persistent_cookie_store.cc
diff --git a/content/browser/net/sqlite_persistent_cookie_store.cc b/content/browser/net/sqlite_persistent_cookie_store.cc
index 82bdd06d5d98661fe49a23d849b93ebeb2390835..ab047d51681badef9126113aad847d297727c33a 100644
--- a/content/browser/net/sqlite_persistent_cookie_store.cc
+++ b/content/browser/net/sqlite_persistent_cookie_store.cc
@@ -315,6 +315,9 @@ int SQLitePersistentCookieStore::Backend::KillDatabaseErrorDelegate::OnError(
// Version number of the database.
//
+// Version 6 adds cookie priorities. This allows developers to influence the
+// order in which cookies are evicted in order to meet domain cookie limits.
+//
// Version 5 adds the columns has_expires and is_persistent, so that the
// database can store session cookies as well as persistent cookies. Databases
// of version 5 are incompatible with older versions of code. If a database of
@@ -328,7 +331,7 @@ int SQLitePersistentCookieStore::Backend::KillDatabaseErrorDelegate::OnError(
// Version 3 updated the database to include the last access time, so we can
// expire them in decreasing order of use when we've reached the maximum
// number of cookies.
-static const int kCurrentVersionNumber = 5;
+static const int kCurrentVersionNumber = 6;
static const int kCompatibleVersionNumber = 5;
namespace {
@@ -359,18 +362,20 @@ class IncrementTimeDelta {
// Initializes the cookies table, returning true on success.
bool InitTable(sql::Connection* db) {
if (!db->DoesTableExist("cookies")) {
- if (!db->Execute("CREATE TABLE cookies ("
- "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY,"
- "host_key TEXT NOT NULL,"
- "name TEXT NOT NULL,"
- "value TEXT NOT NULL,"
- "path TEXT NOT NULL,"
- "expires_utc INTEGER NOT NULL,"
- "secure INTEGER NOT NULL,"
- "httponly INTEGER NOT NULL,"
- "last_access_utc INTEGER NOT NULL, "
- "has_expires INTEGER NOT NULL DEFAULT 1, "
- "persistent INTEGER NOT NULL DEFAULT 1)"))
+ if (!db->Execute(
+ "CREATE TABLE cookies ("
+ "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY,"
+ "host_key TEXT NOT NULL,"
+ "name TEXT NOT NULL,"
+ "value TEXT NOT NULL,"
+ "path TEXT NOT NULL,"
+ "expires_utc INTEGER NOT NULL,"
+ "secure INTEGER NOT NULL,"
+ "httponly INTEGER NOT NULL,"
+ "last_access_utc INTEGER NOT NULL, "
+ "has_expires INTEGER NOT NULL DEFAULT 1, "
+ "persistent INTEGER NOT NULL DEFAULT 1,"
+ "priority INTEGER NOT NULL DEFAULT 1")) { // Medium priority.
return false;
}
@@ -659,13 +664,13 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
smt.Assign(db_->GetCachedStatement(
SQL_FROM_HERE,
"SELECT creation_utc, host_key, name, value, path, expires_utc, "
- "secure, httponly, last_access_utc, has_expires, persistent "
+ "secure, httponly, last_access_utc, has_expires, persistent, priority "
"FROM cookies WHERE host_key = ?"));
} else {
smt.Assign(db_->GetCachedStatement(
SQL_FROM_HERE,
"SELECT creation_utc, host_key, name, value, path, expires_utc, "
- "secure, httponly, last_access_utc, has_expires, persistent "
+ "secure, httponly, last_access_utc, has_expires, persistent, priority "
"FROM cookies WHERE host_key = ? AND persistent = 1"));
}
if (!smt.is_valid()) {
@@ -692,7 +697,8 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc
Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc
smt.ColumnInt(6) != 0, // secure
- smt.ColumnInt(7) != 0)); // httponly
+ smt.ColumnInt(7) != 0), // httponly
+ smt.ColumnInt(9)); // priority
DLOG_IF(WARNING,
cc->CreationDate() > Time::Now()) << L"CreationDate too recent";
cookies_per_origin_[CookieOrigin(cc->Domain(), cc->IsSecure())]++;
@@ -793,6 +799,27 @@ bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() {
base::TimeTicks::Now() - start_time);
}
+ if (cur_version == 5) {
+ const base::TimeTicks start_time = base::TimeTicks::Now();
+ sql::Transaction transaction(db_.get());
+ if (!transaction.Begin())
+ return false;
+ // Alter the table to add the priority collum with a default value of
erikwright (departed) 2013/04/16 20:41:03 collum -> column
Roger McFarlane (Chromium) 2013/04/18 18:54:29 Done.
+ // 1 (Medium) for the value.
+ if (!db_->Execute("ALTER TABLE cookies "
+ "ADD COLUMN priority INTEGER DEFAULT 1")) {
+ LOG(WARNING) << "Unable to update cookie database to version 6.";
+ return false;
+ }
+ ++cur_version;
+ meta_table_.SetVersionNumber(cur_version);
+ meta_table_.SetCompatibleVersionNumber(
+ std::min(cur_version, kCompatibleVersionNumber));
+ transaction.Commit();
+ UMA_HISTOGRAM_TIMES("Cookie.TimeDatabaseMigrationToV6",
+ base::TimeTicks::Now() - start_time);
+ }
+
// Put future migration cases here.
if (cur_version < kCurrentVersionNumber) {
@@ -879,8 +906,8 @@ void SQLitePersistentCookieStore::Backend::Commit() {
sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE,
"INSERT INTO cookies (creation_utc, host_key, name, value, path, "
"expires_utc, secure, httponly, last_access_utc, has_expires, "
- "persistent) "
- "VALUES (?,?,?,?,?,?,?,?,?,?,?)"));
+ "persistent, priority) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"));
if (!add_smt.is_valid())
return;
@@ -918,6 +945,7 @@ void SQLitePersistentCookieStore::Backend::Commit() {
add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue());
add_smt.BindInt(9, po->cc().IsPersistent());
add_smt.BindInt(10, po->cc().IsPersistent());
+ add_smg.BindInt(11, po->cc().Priority());
if (!add_smt.Run())
NOTREACHED() << "Could not add a cookie to the DB.";
break;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698