Chromium Code Reviews| 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..ba6ae1b8f6d4cb2a0e4f095989ea052a455b771a 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 deleted in order to meet domain cookie limits. |
|
huangs
2013/04/16 18:25:55
s/deleted/evicted/g to conform with terminology.
Roger McFarlane (Chromium)
2013/04/16 19:17:25
Done.
|
| +// |
| // 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 { |
| @@ -370,7 +373,8 @@ bool InitTable(sql::Connection* db) { |
| "httponly INTEGER NOT NULL," |
| "last_access_utc INTEGER NOT NULL, " |
| "has_expires INTEGER NOT NULL DEFAULT 1, " |
| - "persistent INTEGER NOT NULL DEFAULT 1)")) |
| + "persistent INTEGER NOT NULL DEFAULT 1," |
| + "priority INTEGER NOT NULL DEFAULT 1")) |
|
huangs
2013/04/16 18:25:55
1 == net::PRIORITY_DEFAULT. While it's messy to i
Roger McFarlane (Chromium)
2013/04/16 19:17:25
Done.
|
| return false; |
| } |
| @@ -659,13 +663,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 +696,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 +798,25 @@ 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; |
| + if (!db_->Execute("ALTER TABLE cookies " |
| + "ADD COLUMN priority INTEGER DEFAULT 1")) { |
|
huangs
2013/04/16 18:25:55
Add comment that we set 1 == net::PRIORITY_DEFAULT
Roger McFarlane (Chromium)
2013/04/16 19:17:25
Done.
|
| + 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 +903,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 +942,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; |