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

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: fix linux compile errors 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..6a2c546f2d35fec03be6b278f09b55b8ea53b8fa 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_);
}
@@ -97,14 +100,18 @@ int BindFields(const EntryKernel& entry,
int UnpackEntry(sqlite_utils::SQLStatement* statement, EntryKernel** kernel) {
*kernel = NULL;
int query_result = statement->step();
- if (SQLITE_ROW == query_result) {
- *kernel = new EntryKernel;
- (*kernel)->clear_dirty(NULL);
- DCHECK(statement->column_count() == static_cast<int>(FIELD_COUNT));
+ if (query_result == SQLITE_ROW) {
+ *kernel = new EntryKernel();
+ DCHECK_EQ(statement->column_count(), static_cast<int>(FIELD_COUNT));
int i = 0;
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);
@@ -120,9 +127,8 @@ int UnpackEntry(sqlite_utils::SQLStatement* statement, EntryKernel** kernel) {
(*kernel)->mutable_ref(static_cast<ProtoField>(i)).ParseFromArray(
statement->column_blob(i), statement->column_bytes(i));
}
- ZeroFields((*kernel), i);
} else {
- DCHECK(SQLITE_DONE == query_result);
+ DCHECK_EQ(query_result, SQLITE_DONE);
(*kernel) = NULL;
}
return query_result;
@@ -478,6 +484,13 @@ DirOpenResult DirectoryBackingStore::InitializeTables() {
version_on_disk = 76;
}
+ // Version 77 standardized all time fields to ms since the Unix
+ // epoch.
+ 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 +1102,35 @@ 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 (100s of
+// ns since Jan 1, 1601). Magic 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