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

Unified Diff: sync/syncable/directory_backing_store.cc

Issue 11474036: Remove initial_sync_ended bits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add another test Created 8 years 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 | « sync/syncable/directory_backing_store.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/syncable/directory_backing_store.cc
diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc
index e9ba0acc57c0bd945b1010f3f230a288f64999cb..5d160836c3d5ef13202d63940d4b3d1cabbdf467 100644
--- a/sync/syncable/directory_backing_store.cc
+++ b/sync/syncable/directory_backing_store.cc
@@ -40,7 +40,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 = 83;
+const int32 kCurrentDBVersion = 84;
// Iterate over the fields of |entry| and bind each to |statement| for
// updating. Returns the number of args bound.
@@ -197,8 +197,11 @@ bool DirectoryBackingStore::SaveChanges(
// Back out early if there is nothing to write.
bool save_info =
(Directory::KERNEL_SHARE_INFO_DIRTY == snapshot.kernel_info_status);
- if (snapshot.dirty_metas.size() < 1 && !save_info)
+ if (snapshot.dirty_metas.empty()
+ && snapshot.metahandles_to_purge.empty()
+ && !save_info) {
return true;
+ }
sql::Transaction transaction(db_.get());
if (!transaction.Begin())
@@ -236,9 +239,8 @@ bool DirectoryBackingStore::SaveChanges(
sql::Statement s2(db_->GetCachedStatement(
SQL_FROM_HERE,
"INSERT OR REPLACE "
- "INTO models (model_id, progress_marker, initial_sync_ended, "
- " transaction_version) "
- "VALUES (?, ?, ?, ?)"));
+ "INTO models (model_id, progress_marker, transaction_version) "
+ "VALUES (?, ?, ?)"));
for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
// We persist not ModelType but rather a protobuf-derived ID.
@@ -247,8 +249,7 @@ bool DirectoryBackingStore::SaveChanges(
info.download_progress[i].SerializeToString(&progress_marker);
s2.BindBlob(0, model_id.data(), model_id.length());
s2.BindBlob(1, progress_marker.data(), progress_marker.length());
- s2.BindBool(2, info.initial_sync_ended.Has(ModelTypeFromInt(i)));
- s2.BindInt64(3, info.transaction_version[i]);
+ s2.BindInt64(2, info.transaction_version[i]);
if (!s2.Run())
return false;
DCHECK_EQ(db_->GetLastChangeCount(), 1);
@@ -364,6 +365,12 @@ bool DirectoryBackingStore::InitializeTables() {
version_on_disk = 83;
}
+ // Version 84 migration removes the initial_sync_ended bits.
+ if (version_on_disk == 83) {
+ if (MigrateVersion83To84())
+ version_on_disk = 84;
+ }
+
// 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.
@@ -502,7 +509,7 @@ bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) {
{
sql::Statement s(
db_->GetUniqueStatement(
- "SELECT model_id, progress_marker, initial_sync_ended, "
+ "SELECT model_id, progress_marker, "
"transaction_version FROM models"));
while (s.Step()) {
@@ -511,9 +518,7 @@ bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) {
if (type != UNSPECIFIED && type != TOP_LEVEL_FOLDER) {
info->kernel_info.download_progress[type].ParseFromArray(
s.ColumnBlob(1), s.ColumnByteLength(1));
- if (s.ColumnBool(2))
- info->kernel_info.initial_sync_ended.Put(type);
- info->kernel_info.transaction_version[type] = s.ColumnInt64(3);
+ info->kernel_info.transaction_version[type] = s.ColumnInt64(2);
}
}
if (!s.Succeeded())
@@ -908,7 +913,7 @@ bool DirectoryBackingStore::MigrateVersion74To75() {
// Move aside the old table and create a new empty one at the current schema.
if (!db_->Execute("ALTER TABLE models RENAME TO temp_models"))
return false;
- if (!CreateModelsTable())
+ if (!CreateV75ModelsTable())
return false;
sql::Statement query(db_->GetUniqueStatement(
@@ -1091,6 +1096,23 @@ bool DirectoryBackingStore::MigrateVersion82To83() {
return true;
}
+
+bool DirectoryBackingStore::MigrateVersion83To84() {
+ // Version 84 removes the initial_sync_ended flag.
+ if (!db_->Execute("ALTER TABLE models RENAME TO temp_models"))
+ return false;
+ if (!CreateModelsTable())
+ return false;
+ if (!db_->Execute("INSERT INTO models SELECT "
+ "model_id, progress_marker, transaction_version "
+ "FROM temp_models")) {
+ return false;
+ }
+ SafeDropTable("temp_models");
+ SetVersion(84);
+ return true;
+}
+
bool DirectoryBackingStore::CreateTables() {
DVLOG(1) << "First run, creating tables";
// Create two little tables share_version and share_info
@@ -1188,10 +1210,23 @@ bool DirectoryBackingStore::CreateV71ModelsTable() {
"initial_sync_ended BOOLEAN default 0)");
}
+bool DirectoryBackingStore::CreateV75ModelsTable() {
+ // This is an old schema for the Models table, used from versions 75 to 83.
+ return db_->Execute(
+ "CREATE TABLE models ("
+ "model_id BLOB primary key, "
+ "progress_marker BLOB, "
+ // Gets set if the syncer ever gets updates from the
+ // server and the server returns 0. Lets us detect the
+ // end of the initial sync.
+ "initial_sync_ended BOOLEAN default 0, "
+ "transaction_version BIGINT default 0)");
+}
+
bool DirectoryBackingStore::CreateModelsTable() {
// This is the current schema for the Models table, from version 81
// onward. If you change the schema, you'll probably want to double-check
- // the use of this function in the v74-v75 migration.
+ // the use of this function in the v83-v84 migration.
return db_->Execute(
"CREATE TABLE models ("
"model_id BLOB primary key, "
@@ -1199,7 +1234,6 @@ bool DirectoryBackingStore::CreateModelsTable() {
// Gets set if the syncer ever gets updates from the
// server and the server returns 0. Lets us detect the
// end of the initial sync.
- "initial_sync_ended BOOLEAN default 0, "
"transaction_version BIGINT default 0)");
}
« no previous file with comments | « sync/syncable/directory_backing_store.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698