summaryrefslogtreecommitdiffstats
path: root/chrome/common/net
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 16:55:54 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 16:55:54 +0000
commit8d66f419e531fc1362b698769e7bd0cee31bd874 (patch)
treedb3b7315b285dea6fa6b95a3b556a4d6b87b2498 /chrome/common/net
parentfde5d9b56e852fd5e78ad835fc8abc3892c7eba7 (diff)
downloadchromium_src-8d66f419e531fc1362b698769e7bd0cee31bd874.zip
chromium_src-8d66f419e531fc1362b698769e7bd0cee31bd874.tar.gz
chromium_src-8d66f419e531fc1362b698769e7bd0cee31bd874.tar.bz2
Migrate cookies for the time epoch change.
Review URL: http://codereview.chromium.org/183021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/net')
-rw-r--r--chrome/common/net/cookie_monster_sqlite.cc48
1 files changed, 46 insertions, 2 deletions
diff --git a/chrome/common/net/cookie_monster_sqlite.cc b/chrome/common/net/cookie_monster_sqlite.cc
index 378ad0f..a292463 100644
--- a/chrome/common/net/cookie_monster_sqlite.cc
+++ b/chrome/common/net/cookie_monster_sqlite.cc
@@ -271,8 +271,15 @@ SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
}
}
-// Version number of the database.
-static const int kCurrentVersionNumber = 3;
+// Version number of the database. In version 4, we migrated the time epoch.
+// If you open the DB with an older version on Mac or Linux, the times will
+// look wonky, but the file will likely be usable. On Windows version 3 and 4
+// are the same.
+//
+// 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 = 4;
static const int kCompatibleVersionNumber = 3;
namespace {
@@ -393,6 +400,43 @@ bool SQLitePersistentCookieStore::EnsureDatabaseVersion(sqlite3* db) {
transaction.Commit();
}
+ if (cur_version == 3) {
+ // The time epoch changed for Mac & Linux in this version to match Windows.
+ // This patch came after the main epoch change happened, so some
+ // developers have "good" times for cookies added by the more recent
+ // versions. So we have to be careful to only update times that are under
+ // the old system (which will appear to be from before 1970 in the new
+ // system). The magic number used below is 1970 in our time units.
+ SQLTransaction transaction(db);
+ transaction.Begin();
+#if !defined(OS_WIN)
+ sqlite3_exec(db,
+ "UPDATE cookies "
+ "SET creation_utc = creation_utc + 11644473600000000 "
+ "WHERE rowid IN "
+ "(SELECT rowid FROM cookies WHERE "
+ "creation_utc > 0 AND creation_utc < 11644473600000000)",
+ NULL, NULL, NULL);
+ sqlite3_exec(db,
+ "UPDATE cookies "
+ "SET expires_utc = expires_utc + 11644473600000000 "
+ "WHERE rowid IN "
+ "(SELECT rowid FROM cookies WHERE "
+ "expires_utc > 0 AND expires_utc < 11644473600000000)",
+ NULL, NULL, NULL);
+ sqlite3_exec(db,
+ "UPDATE cookies "
+ "SET last_access_utc = last_access_utc + 11644473600000000 "
+ "WHERE rowid IN "
+ "(SELECT rowid FROM cookies WHERE "
+ "last_access_utc > 0 AND last_access_utc < 11644473600000000)",
+ NULL, NULL, NULL);
+#endif
+ ++cur_version;
+ meta_table_.SetVersionNumber(cur_version);
+ transaction.Commit();
+ }
+
// Put future migration cases here.
// When the version is too old, we just try to continue anyway, there should