OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
11 #endif | 11 #endif |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 | 14 |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/hash_tables.h" | 16 #include "base/hash_tables.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/stl_util-inl.h" | 19 #include "base/stl_util-inl.h" |
| 20 #include "base/stringprintf.h" |
20 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
21 #include "base/string_util.h" | |
22 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 22 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
23 #include "chrome/browser/sync/protocol/service_constants.h" | 23 #include "chrome/browser/sync/protocol/service_constants.h" |
24 #include "chrome/browser/sync/protocol/sync.pb.h" | 24 #include "chrome/browser/sync/protocol/sync.pb.h" |
25 #include "chrome/browser/sync/syncable/syncable-inl.h" | 25 #include "chrome/browser/sync/syncable/syncable-inl.h" |
26 #include "chrome/browser/sync/syncable/syncable_columns.h" | 26 #include "chrome/browser/sync/syncable/syncable_columns.h" |
27 #include "chrome/common/random.h" | 27 #include "chrome/common/random.h" |
28 #include "chrome/common/sqlite_utils.h" | 28 #include "chrome/common/sqlite_utils.h" |
29 #include "third_party/sqlite/sqlite3.h" | 29 #include "third_party/sqlite/sqlite3.h" |
30 | 30 |
31 // Sometimes threads contend on the DB lock itself, especially when one thread | 31 // Sometimes threads contend on the DB lock itself, especially when one thread |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 syncable::AddDefaultExtensionValue(model_type, &specifics); | 733 syncable::AddDefaultExtensionValue(model_type, &specifics); |
734 return specifics.SerializeAsString(); | 734 return specifics.SerializeAsString(); |
735 } | 735 } |
736 | 736 |
737 bool DirectoryBackingStore::MigrateToSpecifics( | 737 bool DirectoryBackingStore::MigrateToSpecifics( |
738 const char* old_columns, | 738 const char* old_columns, |
739 const char* specifics_column, | 739 const char* specifics_column, |
740 void (*handler_function)(SQLStatement* old_value_query, | 740 void (*handler_function)(SQLStatement* old_value_query, |
741 int old_value_column, | 741 int old_value_column, |
742 sync_pb::EntitySpecifics* mutable_new_value)) { | 742 sync_pb::EntitySpecifics* mutable_new_value)) { |
743 std::string query_sql = StringPrintf("SELECT metahandle, %s, %s FROM metas", | 743 std::string query_sql = base::StringPrintf( |
744 specifics_column, old_columns); | 744 "SELECT metahandle, %s, %s FROM metas", specifics_column, old_columns); |
745 std::string update_sql = StringPrintf( | 745 std::string update_sql = base::StringPrintf( |
746 "UPDATE metas SET %s = ? WHERE metahandle = ?", specifics_column); | 746 "UPDATE metas SET %s = ? WHERE metahandle = ?", specifics_column); |
747 SQLStatement query; | 747 SQLStatement query; |
748 query.prepare(load_dbhandle_, query_sql.c_str()); | 748 query.prepare(load_dbhandle_, query_sql.c_str()); |
749 while (query.step() == SQLITE_ROW) { | 749 while (query.step() == SQLITE_ROW) { |
750 int64 metahandle = query.column_int64(0); | 750 int64 metahandle = query.column_int64(0); |
751 std::string new_value_bytes; | 751 std::string new_value_bytes; |
752 query.column_blob_as_string(1, &new_value_bytes); | 752 query.column_blob_as_string(1, &new_value_bytes); |
753 sync_pb::EntitySpecifics new_value; | 753 sync_pb::EntitySpecifics new_value; |
754 new_value.ParseFromString(new_value_bytes); | 754 new_value.ParseFromString(new_value_bytes); |
755 handler_function(&query, 2, &new_value); | 755 handler_function(&query, 2, &new_value); |
756 new_value.SerializeToString(&new_value_bytes); | 756 new_value.SerializeToString(&new_value_bytes); |
757 | 757 |
758 SQLStatement update; | 758 SQLStatement update; |
759 update.prepare(load_dbhandle_, update_sql.data(), update_sql.length()); | 759 update.prepare(load_dbhandle_, update_sql.data(), update_sql.length()); |
760 update.bind_blob(0, new_value_bytes.data(), new_value_bytes.length()); | 760 update.bind_blob(0, new_value_bytes.data(), new_value_bytes.length()); |
761 update.bind_int64(1, metahandle); | 761 update.bind_int64(1, metahandle); |
762 if (update.step() != SQLITE_DONE) { | 762 if (update.step() != SQLITE_DONE) { |
763 NOTREACHED(); | 763 NOTREACHED(); |
764 return false; | 764 return false; |
765 } | 765 } |
766 } | 766 } |
767 return true; | 767 return true; |
768 } | 768 } |
769 | 769 |
770 bool DirectoryBackingStore::AddColumn(const ColumnSpec* column) { | 770 bool DirectoryBackingStore::AddColumn(const ColumnSpec* column) { |
771 SQLStatement add_column; | 771 SQLStatement add_column; |
772 std::string sql = StringPrintf("ALTER TABLE metas ADD COLUMN %s %s", | 772 std::string sql = base::StringPrintf( |
773 column->name, column->spec); | 773 "ALTER TABLE metas ADD COLUMN %s %s", column->name, column->spec); |
774 add_column.prepare(load_dbhandle_, sql.c_str()); | 774 add_column.prepare(load_dbhandle_, sql.c_str()); |
775 return add_column.step() == SQLITE_DONE; | 775 return add_column.step() == SQLITE_DONE; |
776 } | 776 } |
777 | 777 |
778 bool DirectoryBackingStore::SetVersion(int version) { | 778 bool DirectoryBackingStore::SetVersion(int version) { |
779 SQLStatement statement; | 779 SQLStatement statement; |
780 statement.prepare(load_dbhandle_, "UPDATE share_version SET data = ?"); | 780 statement.prepare(load_dbhandle_, "UPDATE share_version SET data = ?"); |
781 statement.bind_int(0, version); | 781 statement.bind_int(0, version); |
782 return statement.step() == SQLITE_DONE; | 782 return statement.step() == SQLITE_DONE; |
783 } | 783 } |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 "id TEXT primary key, " | 1237 "id TEXT primary key, " |
1238 "name TEXT, " | 1238 "name TEXT, " |
1239 "store_birthday TEXT, " | 1239 "store_birthday TEXT, " |
1240 "db_create_version TEXT, " | 1240 "db_create_version TEXT, " |
1241 "db_create_time INT, " | 1241 "db_create_time INT, " |
1242 "next_id INT default -2, " | 1242 "next_id INT default -2, " |
1243 "cache_guid TEXT )"); | 1243 "cache_guid TEXT )"); |
1244 return ExecQuery(load_dbhandle_, query.c_str()); | 1244 return ExecQuery(load_dbhandle_, query.c_str()); |
1245 } | 1245 } |
1246 } // namespace syncable | 1246 } // namespace syncable |
OLD | NEW |