| Index: sync/syncable/directory_backing_store.cc
|
| diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc
|
| index f1bfe8c4190d9a3856bac6be9f20ebe398e75d4e..f7acdf8ce6b50e2dea355386122c66e43901db71 100644
|
| --- a/sync/syncable/directory_backing_store.cc
|
| +++ b/sync/syncable/directory_backing_store.cc
|
| @@ -9,6 +9,7 @@
|
| #include <limits>
|
|
|
| #include "base/base64.h"
|
| +#include "base/debug/trace_event.h"
|
| #include "base/file_util.h"
|
| #include "base/hash_tables.h"
|
| #include "base/logging.h"
|
| @@ -1083,5 +1084,36 @@ bool DirectoryBackingStore::CreateShareInfoTableVersion71(
|
| return db_->Execute(query.c_str());
|
| }
|
|
|
| +// This function checks to see if the given list of Metahandles has any nodes
|
| +// whose PREV_ID, PARENT_ID or NEXT_ID values refer to ID values that do not
|
| +// actually exist. Returns true on success.
|
| +bool DirectoryBackingStore::VerifyReferenceIntegrity(
|
| + const syncable::MetahandlesIndex &index) {
|
| + TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck");
|
| + using namespace syncable;
|
| + typedef base::hash_set<std::string> IdsSet;
|
| +
|
| + IdsSet ids_set;
|
| + bool is_ok = true;
|
| +
|
| + for (MetahandlesIndex::const_iterator it = index.begin();
|
| + it != index.end(); ++it) {
|
| + EntryKernel* entry = *it;
|
| + bool is_duplicate_id = !(ids_set.insert(entry->ref(ID).value()).second);
|
| + is_ok = is_ok && !is_duplicate_id;
|
| + }
|
| +
|
| + IdsSet::iterator end = ids_set.end();
|
| + for (MetahandlesIndex::const_iterator it = index.begin();
|
| + it != index.end(); ++it) {
|
| + EntryKernel* entry = *it;
|
| + bool prev_exists = (ids_set.find(entry->ref(PREV_ID).value()) != end);
|
| + bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end);
|
| + bool next_exists = (ids_set.find(entry->ref(NEXT_ID).value()) != end);
|
| + is_ok = is_ok && prev_exists && parent_exists && next_exists;
|
| + }
|
| + return is_ok;
|
| +}
|
| +
|
| } // namespace syncable
|
| } // namespace syncer
|
|
|