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

Unified Diff: chrome/common/net/cookie_monster_sqlite.cc

Issue 183021: Migrate cookies for the time epoch change. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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: chrome/common/net/cookie_monster_sqlite.cc
===================================================================
--- chrome/common/net/cookie_monster_sqlite.cc (revision 24867)
+++ chrome/common/net/cookie_monster_sqlite.cc (working copy)
@@ -271,8 +271,11 @@
}
}
-// 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.
+static const int kCurrentVersionNumber = 4;
static const int kCompatibleVersionNumber = 3;
Evan Martin 2009/09/01 00:04:14 Can you doc this too? (I checked the code and it
namespace {
@@ -393,6 +396,43 @@
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
« 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