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

Side by Side Diff: sync/syncable/directory_backing_store.cc

Issue 211523002: Add AttachmentMetadata to Sync's EntryKernel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 17 matching lines...) Expand all
28 using std::string; 28 using std::string;
29 29
30 namespace syncer { 30 namespace syncer {
31 namespace syncable { 31 namespace syncable {
32 32
33 // This just has to be big enough to hold an UPDATE or INSERT statement that 33 // This just has to be big enough to hold an UPDATE or INSERT statement that
34 // modifies all the columns in the entry table. 34 // modifies all the columns in the entry table.
35 static const string::size_type kUpdateStatementBufferSize = 2048; 35 static const string::size_type kUpdateStatementBufferSize = 2048;
36 36
37 // Increment this version whenever updating DB tables. 37 // Increment this version whenever updating DB tables.
38 const int32 kCurrentDBVersion = 86; 38 const int32 kCurrentDBVersion = 87;
39 39
40 // Iterate over the fields of |entry| and bind each to |statement| for 40 // Iterate over the fields of |entry| and bind each to |statement| for
41 // updating. Returns the number of args bound. 41 // updating. Returns the number of args bound.
42 void BindFields(const EntryKernel& entry, 42 void BindFields(const EntryKernel& entry,
43 sql::Statement* statement) { 43 sql::Statement* statement) {
44 int index = 0; 44 int index = 0;
45 int i = 0; 45 int i = 0;
46 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { 46 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) {
47 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); 47 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i)));
48 } 48 }
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 version_on_disk = 85; 399 version_on_disk = 85;
400 } 400 }
401 401
402 // Version 86 migration converts bookmarks to the unique positioning system. 402 // Version 86 migration converts bookmarks to the unique positioning system.
403 // It also introduces a new field to store a unique ID for each bookmark. 403 // It also introduces a new field to store a unique ID for each bookmark.
404 if (version_on_disk == 85) { 404 if (version_on_disk == 85) {
405 if (MigrateVersion85To86()) 405 if (MigrateVersion85To86())
406 version_on_disk = 86; 406 version_on_disk = 86;
407 } 407 }
408 408
409 // Version 87 migration adds a collection of attachment ids per sync entry.
410 if (version_on_disk == 86) {
411 if (MigrateVersion86To87())
412 version_on_disk = 87;
413 }
414
409 // If one of the migrations requested it, drop columns that aren't current. 415 // If one of the migrations requested it, drop columns that aren't current.
410 // It's only safe to do this after migrating all the way to the current 416 // It's only safe to do this after migrating all the way to the current
411 // version. 417 // version.
412 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { 418 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) {
413 if (!RefreshColumns()) 419 if (!RefreshColumns())
414 version_on_disk = 0; 420 version_on_disk = 0;
415 } 421 }
416 422
417 // A final, alternative catch-all migration to simply re-sync everything. 423 // A final, alternative catch-all migration to simply re-sync everything.
418 if (version_on_disk != kCurrentDBVersion) { 424 if (version_on_disk != kCurrentDBVersion) {
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 if (!put.Run()) 1265 if (!put.Run())
1260 return false; 1266 return false;
1261 put.Reset(true); 1267 put.Reset(true);
1262 } 1268 }
1263 1269
1264 SetVersion(86); 1270 SetVersion(86);
1265 needs_column_refresh_ = true; 1271 needs_column_refresh_ = true;
1266 return true; 1272 return true;
1267 } 1273 }
1268 1274
1275 bool DirectoryBackingStore::MigrateVersion86To87() {
1276 // Version 87 adds AttachmentMetadata proto.
1277 if (!db_->Execute(
1278 "ALTER TABLE metas ADD COLUMN "
1279 "attachment_metadata BLOB")) {
1280 return false;
1281 }
1282 SetVersion(87);
1283 needs_column_refresh_ = true;
1284 return true;
1285 }
1286
1269 bool DirectoryBackingStore::CreateTables() { 1287 bool DirectoryBackingStore::CreateTables() {
1270 DVLOG(1) << "First run, creating tables"; 1288 DVLOG(1) << "First run, creating tables";
1271 // Create two little tables share_version and share_info 1289 // Create two little tables share_version and share_info
1272 if (!db_->Execute( 1290 if (!db_->Execute(
1273 "CREATE TABLE share_version (" 1291 "CREATE TABLE share_version ("
1274 "id VARCHAR(128) primary key, data INT)")) { 1292 "id VARCHAR(128) primary key, data INT)")) {
1275 return false; 1293 return false;
1276 } 1294 }
1277 1295
1278 { 1296 {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 } 1513 }
1496 query.append(" ) "); 1514 query.append(" ) ");
1497 values.append(" )"); 1515 values.append(" )");
1498 query.append(values); 1516 query.append(values);
1499 save_statement->Assign(db_->GetUniqueStatement( 1517 save_statement->Assign(db_->GetUniqueStatement(
1500 base::StringPrintf(query.c_str(), "metas").c_str())); 1518 base::StringPrintf(query.c_str(), "metas").c_str()));
1501 } 1519 }
1502 1520
1503 } // namespace syncable 1521 } // namespace syncable
1504 } // namespace syncer 1522 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698