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

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

Issue 5159001: Rest of the autofill work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Couple of lint errors sneaked into my previous patch. This is clean of lint errors. Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/sync/syncable/directory_backing_store.h" 5 #include "chrome/browser/sync/syncable/directory_backing_store.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_MACOSX) 9 #if defined(OS_MACOSX)
10 #include <CoreFoundation/CoreFoundation.h> 10 #include <CoreFoundation/CoreFoundation.h>
(...skipping 26 matching lines...) Expand all
37 using std::string; 37 using std::string;
38 38
39 namespace syncable { 39 namespace syncable {
40 40
41 // This just has to be big enough to hold an UPDATE or INSERT statement that 41 // This just has to be big enough to hold an UPDATE or INSERT statement that
42 // modifies all the columns in the entry table. 42 // modifies all the columns in the entry table.
43 static const string::size_type kUpdateStatementBufferSize = 2048; 43 static const string::size_type kUpdateStatementBufferSize = 2048;
44 44
45 // Increment this version whenever updating DB tables. 45 // Increment this version whenever updating DB tables.
46 extern const int32 kCurrentDBVersion; // Global visibility for our unittest. 46 extern const int32 kCurrentDBVersion; // Global visibility for our unittest.
47 const int32 kCurrentDBVersion = 73; 47 const int32 kCurrentDBVersion = 74;
48 48
49 namespace { 49 namespace {
50 50
51 int ExecQuery(sqlite3* dbhandle, const char* query) { 51 int ExecQuery(sqlite3* dbhandle, const char* query) {
52 SQLStatement statement; 52 SQLStatement statement;
53 int result = statement.prepare(dbhandle, query); 53 int result = statement.prepare(dbhandle, query);
54 if (SQLITE_OK != result) 54 if (SQLITE_OK != result)
55 return result; 55 return result;
56 do { 56 do {
57 result = statement.step(); 57 result = statement.step();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 if (!DeleteEntries(snapshot.metahandles_to_purge)) 373 if (!DeleteEntries(snapshot.metahandles_to_purge))
374 return false; 374 return false;
375 375
376 if (save_info) { 376 if (save_info) {
377 const Directory::PersistedKernelInfo& info = snapshot.kernel_info; 377 const Directory::PersistedKernelInfo& info = snapshot.kernel_info;
378 SQLStatement update; 378 SQLStatement update;
379 update.prepare(dbhandle, "UPDATE share_info " 379 update.prepare(dbhandle, "UPDATE share_info "
380 "SET store_birthday = ?, " 380 "SET store_birthday = ?, "
381 "next_id = ?, " 381 "next_id = ?, "
382 "notification_state = ?"); 382 "notification_state = ?, "
383 "autofill_migration_state = ?, "
384 "bookmarks_added_during_autofill_migration = ?, "
385 "autofill_migration_time = ?, "
386 "autofill_entries_added_during_migration = ?, "
387 "autofill_profiles_added_during_migration = ? ");
388
389 syncable::AutofillMigrationDebugInfo& debug_info =
390 info.autofill_migration_debug_info;
tim (not reviewing) 2010/12/13 19:24:33 indent 4 spaces
lipalani 2010/12/14 21:05:57 Done.
383 update.bind_string(0, info.store_birthday); 391 update.bind_string(0, info.store_birthday);
384 update.bind_int64(1, info.next_id); 392 update.bind_int64(1, info.next_id);
385 update.bind_blob(2, info.notification_state.data(), 393 update.bind_blob(2, info.notification_state.data(),
386 info.notification_state.size()); 394 info.notification_state.size());
395 update.bind_int(3, info.autofill_migration_state);
396 update.bind_int(4,
397 debug_info.bookmarks_added_during_migration);
398 update.bind_int64(5,
399 debug_info.autofill_migration_time);
400 update.bind_int(6,
401 debug_info.autofill_entries_added_during_migration);
402 update.bind_int(7,
403 debug_info.autofill_profile_added_during_migration);
387 404
388 if (!(SQLITE_DONE == update.step() && 405 if (!(SQLITE_DONE == update.step() &&
389 SQLITE_OK == update.reset() && 406 SQLITE_OK == update.reset() &&
390 1 == update.changes())) { 407 1 == update.changes())) {
391 return false; 408 return false;
392 } 409 }
393 410
394 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 411 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
395 SQLStatement op; 412 SQLStatement op;
396 op.prepare(dbhandle, "INSERT OR REPLACE INTO models (model_id, " 413 op.prepare(dbhandle, "INSERT OR REPLACE INTO models (model_id, "
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if (MigrateVersion71To72()) 466 if (MigrateVersion71To72())
450 version_on_disk = 72; 467 version_on_disk = 72;
451 } 468 }
452 469
453 // Version 73 added a field for notification state. 470 // Version 73 added a field for notification state.
454 if (version_on_disk == 72) { 471 if (version_on_disk == 72) {
455 if (MigrateVersion72To73()) 472 if (MigrateVersion72To73())
456 version_on_disk = 73; 473 version_on_disk = 73;
457 } 474 }
458 475
476 if (version_on_disk == 73) {
477 if (MigrateVersion73To74())
478 version_on_disk = 74;
479 }
480
459 // If one of the migrations requested it, drop columns that aren't current. 481 // If one of the migrations requested it, drop columns that aren't current.
460 // It's only safe to do this after migrating all the way to the current 482 // It's only safe to do this after migrating all the way to the current
461 // version. 483 // version.
462 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { 484 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) {
463 if (!RefreshColumns()) 485 if (!RefreshColumns())
464 version_on_disk = 0; 486 version_on_disk = 0;
465 } 487 }
466 488
467 // A final, alternative catch-all migration to simply re-sync everything. 489 // A final, alternative catch-all migration to simply re-sync everything.
468 if (version_on_disk != kCurrentDBVersion) { 490 if (version_on_disk != kCurrentDBVersion) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 entry_bucket->insert(kernel); 571 entry_bucket->insert(kernel);
550 } 572 }
551 return SQLITE_DONE == query_result; 573 return SQLITE_DONE == query_result;
552 } 574 }
553 575
554 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { 576 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) {
555 { 577 {
556 SQLStatement query; 578 SQLStatement query;
557 query.prepare(load_dbhandle_, 579 query.prepare(load_dbhandle_,
558 "SELECT store_birthday, next_id, cache_guid, " 580 "SELECT store_birthday, next_id, cache_guid, "
559 "notification_state FROM share_info"); 581 "notification_state, autofill_migration_state, "
582 "bookmarks_added_during_autofill_migration, "
583 "autofill_migration_time, "
584 "autofill_entries_added_during_migration, "
585 "autofill_profiles_added_during_migration "
586 "FROM share_info");
560 if (SQLITE_ROW != query.step()) 587 if (SQLITE_ROW != query.step())
561 return false; 588 return false;
562 info->kernel_info.store_birthday = query.column_string(0); 589 info->kernel_info.store_birthday = query.column_string(0);
563 info->kernel_info.next_id = query.column_int64(1); 590 info->kernel_info.next_id = query.column_int64(1);
564 info->cache_guid = query.column_string(2); 591 info->cache_guid = query.column_string(2);
565 query.column_blob_as_string(3, &info->kernel_info.notification_state); 592 query.column_blob_as_string(3, &info->kernel_info.notification_state);
593 info->kernel_info.autofill_migration_state =
594 static_cast<AutofillMigrationState> (query.column_int(4));
tim (not reviewing) 2010/12/13 19:24:33 indent 4 spaces. would be nice to have dchecks on
lipalani 2010/12/15 09:08:33 Not sure how dchecks can be added. fixed the inden
595 syncable::AutofillMigrationDebugInfo& debug_info =
596 info->kernel_info.autofill_migration_debug_info;
597 debug_info.bookmarks_added_during_migration =
598 query.column_int(5);
599 debug_info.autofill_migration_time =
600 query.column_int64(6);
601 debug_info.autofill_entries_added_during_migration =
602 query.column_int(7);
603 debug_info.autofill_profile_added_during_migration =
604 query.column_int(8);
566 } 605 }
567 { 606 {
568 SQLStatement query; 607 SQLStatement query;
569 query.prepare(load_dbhandle_, 608 query.prepare(load_dbhandle_,
570 "SELECT model_id, last_download_timestamp, initial_sync_ended " 609 "SELECT model_id, last_download_timestamp, initial_sync_ended "
571 "FROM models"); 610 "FROM models");
572 while (SQLITE_ROW == query.step()) { 611 while (SQLITE_ROW == query.step()) {
573 string model_id; 612 string model_id;
574 query.column_blob_as_string(0, &model_id); 613 query.column_blob_as_string(0, &model_id);
575 ModelType type = ModelIdToModelTypeEnum(model_id); 614 ModelType type = ModelIdToModelTypeEnum(model_id);
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 bool DirectoryBackingStore::MigrateVersion72To73() { 958 bool DirectoryBackingStore::MigrateVersion72To73() {
920 int result = 959 int result =
921 ExecQuery(load_dbhandle_, 960 ExecQuery(load_dbhandle_,
922 "ALTER TABLE share_info ADD COLUMN notification_state BLOB"); 961 "ALTER TABLE share_info ADD COLUMN notification_state BLOB");
923 if (result != SQLITE_DONE) 962 if (result != SQLITE_DONE)
924 return false; 963 return false;
925 SetVersion(73); 964 SetVersion(73);
926 return true; 965 return true;
927 } 966 }
928 967
968 bool DirectoryBackingStore::MigrateVersion73To74() {
969 int result =
970 ExecQuery(load_dbhandle_,
971 "ALTER TABLE share_info ADD COLUMN autofill_migration_state "
972 "INT default 0");
973 if (result != SQLITE_DONE)
974 return false;
975
976 result =
977 ExecQuery(load_dbhandle_,
tim (not reviewing) 2010/12/13 19:24:33 prev line
lipalani 2010/12/14 21:05:57 Done.
978 "ALTER TABLE share_info ADD COLUMN "
979 "bookmarks_added_during_autofill_migration "
980 "INT default 0");
981
982 if (result != SQLITE_DONE)
983 return false;
984
985 result =
986 ExecQuery(load_dbhandle_,
tim (not reviewing) 2010/12/13 19:24:33 prev line
lipalani 2010/12/14 21:05:57 Done.
987 "ALTER TABLE share_info ADD COLUMN autofill_migration_time "
988 "INT default 0");
989
990 if (result != SQLITE_DONE)
991 return false;
992
993 result =
994 ExecQuery(load_dbhandle_,
tim (not reviewing) 2010/12/13 19:24:33 prev line
lipalani 2010/12/14 21:05:57 Done.
995 "ALTER TABLE share_info ADD COLUMN "
996 "autofill_entries_added_during_migration "
997 "INT default 0");
998
999 if (result != SQLITE_DONE)
1000 return false;
1001
1002 result =
1003 ExecQuery(load_dbhandle_,
tim (not reviewing) 2010/12/13 19:24:33 prev line
lipalani 2010/12/14 21:05:57 Done.
1004 "ALTER TABLE share_info ADD COLUMN "
1005 "autofill_profiles_added_during_migration "
1006 "INT default 0");
1007
1008 if (result != SQLITE_DONE)
1009 return false;
1010
1011 SetVersion(74);
1012 return true;
1013 }
1014
1015
929 int DirectoryBackingStore::CreateTables() { 1016 int DirectoryBackingStore::CreateTables() {
930 VLOG(1) << "First run, creating tables"; 1017 VLOG(1) << "First run, creating tables";
931 // Create two little tables share_version and share_info 1018 // Create two little tables share_version and share_info
932 int result = ExecQuery(load_dbhandle_, 1019 int result = ExecQuery(load_dbhandle_,
933 "CREATE TABLE share_version (" 1020 "CREATE TABLE share_version ("
934 "id VARCHAR(128) primary key, data INT)"); 1021 "id VARCHAR(128) primary key, data INT)");
935 if (result != SQLITE_DONE) 1022 if (result != SQLITE_DONE)
936 return result; 1023 return result;
937 { 1024 {
938 SQLStatement statement; 1025 SQLStatement statement;
(...skipping 14 matching lines...) Expand all
953 { 1040 {
954 SQLStatement statement; 1041 SQLStatement statement;
955 statement.prepare(load_dbhandle_, "INSERT INTO share_info VALUES" 1042 statement.prepare(load_dbhandle_, "INSERT INTO share_info VALUES"
956 "(?, " // id 1043 "(?, " // id
957 "?, " // name 1044 "?, " // name
958 "?, " // store_birthday 1045 "?, " // store_birthday
959 "?, " // db_create_version 1046 "?, " // db_create_version
960 "?, " // db_create_time 1047 "?, " // db_create_time
961 "-2, " // next_id 1048 "-2, " // next_id
962 "?, " // cache_guid 1049 "?, " // cache_guid
1050 "?, " // autofill_migration_state
1051 "?, " // bookmarks_added
1052 // _during_autofill_migration
1053 "?, " // autofill_migration_time
1054 "?, " // autofill_entries
1055 // _added_during_migration
1056 "?, " // autofill_profiles_added
1057 // _during_migration
963 "?);"); // notification_state 1058 "?);"); // notification_state
964 statement.bind_string(0, dir_name_); // id 1059 statement.bind_string(0, dir_name_); // id
965 statement.bind_string(1, dir_name_); // name 1060 statement.bind_string(1, dir_name_); // name
966 statement.bind_string(2, ""); // store_birthday 1061 statement.bind_string(2, ""); // store_birthday
967 statement.bind_string(3, SYNC_ENGINE_VERSION_STRING); // db_create_version 1062 statement.bind_string(3, SYNC_ENGINE_VERSION_STRING); // db_create_version
968 statement.bind_int(4, static_cast<int32>(time(0))); // db_create_time 1063 statement.bind_int(4, static_cast<int32>(time(0))); // db_create_time
969 statement.bind_string(5, GenerateCacheGUID()); // cache_guid 1064 statement.bind_string(5, GenerateCacheGUID()); // cache_guid
970 statement.bind_blob(6, NULL, 0); // notification_state 1065 statement.bind_int(6, 0); // autofill_migration_state
1066 statement.bind_int(7, 0); // autofill_migration_time
1067 statement.bind_int(8, 0); // bookmarks_added_during_autofill_migration
1068 statement.bind_int(9, 0); // autofill_entries_added_during_migration
1069 statement.bind_int(10, 0); // autofill_profiles_added_during_migration
1070 statement.bind_blob(11, NULL, 0); // notification_state
971 result = statement.step(); 1071 result = statement.step();
972 } 1072 }
973 if (result != SQLITE_DONE) 1073 if (result != SQLITE_DONE)
974 return result; 1074 return result;
975 1075
976 result = CreateModelsTable(); 1076 result = CreateModelsTable();
977 if (result != SQLITE_DONE) 1077 if (result != SQLITE_DONE)
978 return result; 1078 return result;
979 // Create the big metas table. 1079 // Create the big metas table.
980 result = CreateMetasTable(false); 1080 result = CreateMetasTable(false);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 // This is the current schema for the ShareInfo table, from version 71 1133 // This is the current schema for the ShareInfo table, from version 71
1034 // onward. If you change the schema, you'll probably want to double-check 1134 // onward. If you change the schema, you'll probably want to double-check
1035 // the use of this function in the v70-v71 migration. 1135 // the use of this function in the v70-v71 migration.
1036 query.append(" (" 1136 query.append(" ("
1037 "id TEXT primary key, " 1137 "id TEXT primary key, "
1038 "name TEXT, " 1138 "name TEXT, "
1039 "store_birthday TEXT, " 1139 "store_birthday TEXT, "
1040 "db_create_version TEXT, " 1140 "db_create_version TEXT, "
1041 "db_create_time INT, " 1141 "db_create_time INT, "
1042 "next_id INT default -2, " 1142 "next_id INT default -2, "
1043 "cache_guid TEXT"); 1143 "cache_guid TEXT, "
1144 "autofill_migration_state INT default 0, "
1145 "bookmarks_added_during_autofill_migration INT default 0, "
1146 "autofill_migration_time INT default 0, "
1147 "autofill_entries_added_during_migration INT default 0, "
1148 "autofill_profiles_added_during_migration INT default 0 ");
1044 if (with_notification_state) { 1149 if (with_notification_state) {
1045 query.append(", notification_state BLOB"); 1150 query.append(", notification_state BLOB");
1046 } 1151 }
1047 query.append(")"); 1152 query.append(")");
1048 return ExecQuery(load_dbhandle_, query.c_str()); 1153 return ExecQuery(load_dbhandle_, query.c_str());
1049 } 1154 }
1050 1155
1051 } // namespace syncable 1156 } // namespace syncable
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698