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 |