| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/syncable/directory_backing_store.h" | 5 #include "sync/syncable/directory_backing_store.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 return true; | 156 return true; |
| 157 | 157 |
| 158 sql::Statement statement(db_->GetCachedStatement( | 158 sql::Statement statement(db_->GetCachedStatement( |
| 159 SQL_FROM_HERE, "DELETE FROM metas WHERE metahandle = ?")); | 159 SQL_FROM_HERE, "DELETE FROM metas WHERE metahandle = ?")); |
| 160 | 160 |
| 161 for (MetahandleSet::const_iterator i = handles.begin(); i != handles.end(); | 161 for (MetahandleSet::const_iterator i = handles.begin(); i != handles.end(); |
| 162 ++i) { | 162 ++i) { |
| 163 statement.BindInt64(0, *i); | 163 statement.BindInt64(0, *i); |
| 164 if (!statement.Run()) | 164 if (!statement.Run()) |
| 165 return false; | 165 return false; |
| 166 statement.Reset(); | 166 statement.Reset(true); |
| 167 } | 167 } |
| 168 return true; | 168 return true; |
| 169 } | 169 } |
| 170 | 170 |
| 171 bool DirectoryBackingStore::SaveChanges( | 171 bool DirectoryBackingStore::SaveChanges( |
| 172 const Directory::SaveChangesSnapshot& snapshot) { | 172 const Directory::SaveChangesSnapshot& snapshot) { |
| 173 DCHECK(CalledOnValidThread()); | 173 DCHECK(CalledOnValidThread()); |
| 174 DCHECK(db_->is_open()); | 174 DCHECK(db_->is_open()); |
| 175 | 175 |
| 176 // Back out early if there is nothing to write. | 176 // Back out early if there is nothing to write. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // We persist not ModelType but rather a protobuf-derived ID. | 220 // We persist not ModelType but rather a protobuf-derived ID. |
| 221 string model_id = ModelTypeEnumToModelId(ModelTypeFromInt(i)); | 221 string model_id = ModelTypeEnumToModelId(ModelTypeFromInt(i)); |
| 222 string progress_marker; | 222 string progress_marker; |
| 223 info.download_progress[i].SerializeToString(&progress_marker); | 223 info.download_progress[i].SerializeToString(&progress_marker); |
| 224 s2.BindBlob(0, model_id.data(), model_id.length()); | 224 s2.BindBlob(0, model_id.data(), model_id.length()); |
| 225 s2.BindBlob(1, progress_marker.data(), progress_marker.length()); | 225 s2.BindBlob(1, progress_marker.data(), progress_marker.length()); |
| 226 s2.BindBool(2, info.initial_sync_ended.Has(ModelTypeFromInt(i))); | 226 s2.BindBool(2, info.initial_sync_ended.Has(ModelTypeFromInt(i))); |
| 227 if (!s2.Run()) | 227 if (!s2.Run()) |
| 228 return false; | 228 return false; |
| 229 DCHECK_EQ(db_->GetLastChangeCount(), 1); | 229 DCHECK_EQ(db_->GetLastChangeCount(), 1); |
| 230 s2.Reset(); | 230 s2.Reset(true); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 return transaction.Commit(); | 234 return transaction.Commit(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool DirectoryBackingStore::InitializeTables() { | 237 bool DirectoryBackingStore::InitializeTables() { |
| 238 sql::Transaction transaction(db_.get()); | 238 sql::Transaction transaction(db_.get()); |
| 239 if (!transaction.Begin()) | 239 if (!transaction.Begin()) |
| 240 return false; | 240 return false; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 query.append(ColumnName(i)); | 492 query.append(ColumnName(i)); |
| 493 values.append("?"); | 493 values.append("?"); |
| 494 } | 494 } |
| 495 query.append(" ) "); | 495 query.append(" ) "); |
| 496 values.append(" )"); | 496 values.append(" )"); |
| 497 query.append(values); | 497 query.append(values); |
| 498 | 498 |
| 499 save_entry_statement_.Assign( | 499 save_entry_statement_.Assign( |
| 500 db_->GetUniqueStatement(query.c_str())); | 500 db_->GetUniqueStatement(query.c_str())); |
| 501 } else { | 501 } else { |
| 502 save_entry_statement_.Reset(); | 502 save_entry_statement_.Reset(true); |
| 503 } | 503 } |
| 504 | 504 |
| 505 BindFields(entry, &save_entry_statement_); | 505 BindFields(entry, &save_entry_statement_); |
| 506 return save_entry_statement_.Run(); | 506 return save_entry_statement_.Run(); |
| 507 } | 507 } |
| 508 | 508 |
| 509 bool DirectoryBackingStore::DropDeletedEntries() { | 509 bool DirectoryBackingStore::DropDeletedEntries() { |
| 510 return db_->Execute("DELETE FROM metas " | 510 return db_->Execute("DELETE FROM metas " |
| 511 "WHERE is_del > 0 " | 511 "WHERE is_del > 0 " |
| 512 "AND is_unsynced < 1 " | 512 "AND is_unsynced < 1 " |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 query.ColumnBlobAsString(1, &new_value_bytes); | 576 query.ColumnBlobAsString(1, &new_value_bytes); |
| 577 sync_pb::EntitySpecifics new_value; | 577 sync_pb::EntitySpecifics new_value; |
| 578 new_value.ParseFromString(new_value_bytes); | 578 new_value.ParseFromString(new_value_bytes); |
| 579 handler_function(&query, 2, &new_value); | 579 handler_function(&query, 2, &new_value); |
| 580 new_value.SerializeToString(&new_value_bytes); | 580 new_value.SerializeToString(&new_value_bytes); |
| 581 | 581 |
| 582 update.BindBlob(0, new_value_bytes.data(), new_value_bytes.length()); | 582 update.BindBlob(0, new_value_bytes.data(), new_value_bytes.length()); |
| 583 update.BindInt64(1, metahandle); | 583 update.BindInt64(1, metahandle); |
| 584 if (!update.Run()) | 584 if (!update.Run()) |
| 585 return false; | 585 return false; |
| 586 update.Reset(); | 586 update.Reset(true); |
| 587 } | 587 } |
| 588 return query.Succeeded(); | 588 return query.Succeeded(); |
| 589 } | 589 } |
| 590 | 590 |
| 591 bool DirectoryBackingStore::SetVersion(int version) { | 591 bool DirectoryBackingStore::SetVersion(int version) { |
| 592 sql::Statement s(db_->GetCachedStatement( | 592 sql::Statement s(db_->GetCachedStatement( |
| 593 SQL_FROM_HERE, "UPDATE share_version SET data = ?")); | 593 SQL_FROM_HERE, "UPDATE share_version SET data = ?")); |
| 594 s.BindInt(0, version); | 594 s.BindInt(0, version); |
| 595 | 595 |
| 596 return s.Run(); | 596 return s.Run(); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 GetSpecificsFieldNumberFromModelType(type)); | 861 GetSpecificsFieldNumberFromModelType(type)); |
| 862 progress_marker.set_timestamp_token_for_migration(query.ColumnInt64(1)); | 862 progress_marker.set_timestamp_token_for_migration(query.ColumnInt64(1)); |
| 863 std::string progress_blob; | 863 std::string progress_blob; |
| 864 progress_marker.SerializeToString(&progress_blob); | 864 progress_marker.SerializeToString(&progress_blob); |
| 865 | 865 |
| 866 update.BindBlob(0, query.ColumnBlob(0), query.ColumnByteLength(0)); | 866 update.BindBlob(0, query.ColumnBlob(0), query.ColumnByteLength(0)); |
| 867 update.BindBlob(1, progress_blob.data(), progress_blob.length()); | 867 update.BindBlob(1, progress_blob.data(), progress_blob.length()); |
| 868 update.BindBool(2, query.ColumnBool(2)); | 868 update.BindBool(2, query.ColumnBool(2)); |
| 869 if (!update.Run()) | 869 if (!update.Run()) |
| 870 return false; | 870 return false; |
| 871 update.Reset(); | 871 update.Reset(true); |
| 872 } | 872 } |
| 873 } | 873 } |
| 874 if (!query.Succeeded()) | 874 if (!query.Succeeded()) |
| 875 return false; | 875 return false; |
| 876 | 876 |
| 877 // Drop the old table. | 877 // Drop the old table. |
| 878 SafeDropTable("temp_models"); | 878 SafeDropTable("temp_models"); |
| 879 | 879 |
| 880 SetVersion(75); | 880 SetVersion(75); |
| 881 return true; | 881 return true; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 "name TEXT, " | 1069 "name TEXT, " |
| 1070 "store_birthday TEXT, " | 1070 "store_birthday TEXT, " |
| 1071 "db_create_version TEXT, " | 1071 "db_create_version TEXT, " |
| 1072 "db_create_time INT, " | 1072 "db_create_time INT, " |
| 1073 "next_id INT default -2, " | 1073 "next_id INT default -2, " |
| 1074 "cache_guid TEXT )"); | 1074 "cache_guid TEXT )"); |
| 1075 return db_->Execute(query.c_str()); | 1075 return db_->Execute(query.c_str()); |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 } // namespace syncable | 1078 } // namespace syncable |
| OLD | NEW |