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

Unified Diff: chrome/browser/sync/syncable/directory_backing_store.cc

Issue 7981006: [Sync] use base::Time in sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head, fix comment and lint Created 9 years, 3 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
Index: chrome/browser/sync/syncable/directory_backing_store.cc
diff --git a/chrome/browser/sync/syncable/directory_backing_store.cc b/chrome/browser/sync/syncable/directory_backing_store.cc
index be5791514e5bc18cd45b6d95aeedef2532d737d6..060b79041ae587f430976e2da9ab86877913ff85 100644
--- a/chrome/browser/sync/syncable/directory_backing_store.cc
+++ b/chrome/browser/sync/syncable/directory_backing_store.cc
@@ -6,10 +6,6 @@
#include "build/build_config.h"
-#if defined(OS_MACOSX)
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
#include <limits>
#include "base/file_util.h"
@@ -19,12 +15,14 @@
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
+#include "base/time.h"
#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
#include "chrome/browser/sync/protocol/service_constants.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/syncable/syncable-inl.h"
#include "chrome/browser/sync/syncable/syncable_columns.h"
#include "chrome/browser/sync/util/sqlite_utils.h"
+#include "chrome/browser/sync/util/time.h"
#include "chrome/common/random.h"
#include "third_party/sqlite/sqlite3.h"
@@ -44,7 +42,7 @@ static const string::size_type kUpdateStatementBufferSize = 2048;
// Increment this version whenever updating DB tables.
extern const int32 kCurrentDBVersion; // Global visibility for our unittest.
-const int32 kCurrentDBVersion = 76;
+const int32 kCurrentDBVersion = 77;
namespace {
@@ -76,6 +74,11 @@ int BindFields(const EntryKernel& entry,
for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) {
statement->bind_int64(index++, entry.ref(static_cast<Int64Field>(i)));
}
+ for ( ; i < TIME_FIELDS_END; ++i) {
+ statement->bind_int64(index++,
+ browser_sync::TimeToProtoTime(
+ entry.ref(static_cast<TimeField>(i))));
+ }
for ( ; i < ID_FIELDS_END; ++i) {
statement->bind_string(index++, entry.ref(static_cast<IdField>(i)).s_);
}
@@ -105,6 +108,11 @@ int UnpackEntry(sqlite_utils::SQLStatement* statement, EntryKernel** kernel) {
for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) {
(*kernel)->put(static_cast<Int64Field>(i), statement->column_int64(i));
}
+ for ( ; i < TIME_FIELDS_END; ++i) {
+ (*kernel)->put(static_cast<TimeField>(i),
+ browser_sync::ProtoTimeToTime(
+ statement->column_int64(i)));
+ }
for ( ; i < ID_FIELDS_END; ++i) {
(*kernel)->mutable_ref(static_cast<IdField>(i)).s_ =
statement->column_string(i);
@@ -478,6 +486,12 @@ DirOpenResult DirectoryBackingStore::InitializeTables() {
version_on_disk = 76;
}
+ // Version 77 standardized all time fields to Unix epoch times.
+ if (version_on_disk == 76) {
+ if (MigrateVersion76To77())
+ version_on_disk = 77;
+ }
+
// If one of the migrations requested it, drop columns that aren't current.
// It's only safe to do this after migrating all the way to the current
// version.
@@ -1089,6 +1103,34 @@ bool DirectoryBackingStore::MigrateVersion75To76() {
return true;
}
+bool DirectoryBackingStore::MigrateVersion76To77() {
+ sqlite_utils::SQLStatement update_timestamps;
+ // This change changes the format of stored timestamps to ms since
+ // the Unix epoch.
+#if defined(OS_WIN)
+// On Windows, we used to store timestamps in FILETIME format. Magic
Nicolas Zea 2011/09/21 18:09:12 may as well mention: (100's of ns since Jan 1 1601
akalin 2011/09/21 19:37:35 Done.
+// numbers taken from
+// http://stackoverflow.com/questions/5398557/java-library-for-dealing-with-win32-filetime .
+#define TO_UNIX_TIME_MS(x) #x " = " #x " / 10000 - 11644473600000"
+#else
+// On other platforms, we used to store timestamps in time_t format (s
+// since the Unix epoch).
+#define TO_UNIX_TIME_MS(x) #x " = " #x " * 1000"
+#endif
+ update_timestamps.prepare(
+ load_dbhandle_,
+ "UPDATE metas SET "
+ TO_UNIX_TIME_MS(mtime) ", "
+ TO_UNIX_TIME_MS(server_mtime) ", "
+ TO_UNIX_TIME_MS(ctime) ", "
+ TO_UNIX_TIME_MS(server_ctime));
+#undef TO_UNIX_TIME_MS
+ if (update_timestamps.step() != SQLITE_DONE)
+ return false;
+ SetVersion(77);
+ return true;
+}
+
int DirectoryBackingStore::CreateTables() {
VLOG(1) << "First run, creating tables";
// Create two little tables share_version and share_info
@@ -1143,7 +1185,7 @@ int DirectoryBackingStore::CreateTables() {
return result;
{
// Insert the entry for the root into the metas table.
- const int64 now = Now();
+ const int64 now = browser_sync::TimeToProtoTime(base::Time::Now());
sqlite_utils::SQLStatement statement;
statement.prepare(load_dbhandle_,
"INSERT INTO metas "

Powered by Google App Engine
This is Rietveld 408576698