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 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/debug/trace_event.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
16 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
18 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
19 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
20 #include "base/time.h" | 21 #include "base/time.h" |
21 #include "sql/connection.h" | 22 #include "sql/connection.h" |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 "id TEXT primary key, " | 1077 "id TEXT primary key, " |
1077 "name TEXT, " | 1078 "name TEXT, " |
1078 "store_birthday TEXT, " | 1079 "store_birthday TEXT, " |
1079 "db_create_version TEXT, " | 1080 "db_create_version TEXT, " |
1080 "db_create_time INT, " | 1081 "db_create_time INT, " |
1081 "next_id INT default -2, " | 1082 "next_id INT default -2, " |
1082 "cache_guid TEXT )"); | 1083 "cache_guid TEXT )"); |
1083 return db_->Execute(query.c_str()); | 1084 return db_->Execute(query.c_str()); |
1084 } | 1085 } |
1085 | 1086 |
| 1087 // This function checks to see if the given list of Metahandles has any nodes |
| 1088 // whose PREV_ID, PARENT_ID or NEXT_ID values refer to ID values that do not |
| 1089 // actually exist. Returns true on success. |
| 1090 bool DirectoryBackingStore::VerifyReferenceIntegrity( |
| 1091 const syncable::MetahandlesIndex &index) { |
| 1092 TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck"); |
| 1093 using namespace syncable; |
| 1094 typedef base::hash_set<std::string> IdsSet; |
| 1095 |
| 1096 IdsSet ids_set; |
| 1097 bool is_ok = true; |
| 1098 |
| 1099 for (MetahandlesIndex::const_iterator it = index.begin(); |
| 1100 it != index.end(); ++it) { |
| 1101 EntryKernel* entry = *it; |
| 1102 bool is_duplicate_id = !(ids_set.insert(entry->ref(ID).value()).second); |
| 1103 is_ok = is_ok && !is_duplicate_id; |
| 1104 } |
| 1105 |
| 1106 IdsSet::iterator end = ids_set.end(); |
| 1107 for (MetahandlesIndex::const_iterator it = index.begin(); |
| 1108 it != index.end(); ++it) { |
| 1109 EntryKernel* entry = *it; |
| 1110 bool prev_exists = (ids_set.find(entry->ref(PREV_ID).value()) != end); |
| 1111 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); |
| 1112 bool next_exists = (ids_set.find(entry->ref(NEXT_ID).value()) != end); |
| 1113 is_ok = is_ok && prev_exists && parent_exists && next_exists; |
| 1114 } |
| 1115 return is_ok; |
| 1116 } |
| 1117 |
1086 } // namespace syncable | 1118 } // namespace syncable |
1087 } // namespace syncer | 1119 } // namespace syncer |
OLD | NEW |