Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "components/sync/syncable/directory_backing_store.h" | 5 #include "components/sync/syncable/directory_backing_store.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1635 "store_birthday TEXT, " | 1635 "store_birthday TEXT, " |
| 1636 "db_create_version TEXT, " | 1636 "db_create_version TEXT, " |
| 1637 "db_create_time INT, " | 1637 "db_create_time INT, " |
| 1638 "next_id INT default -2, " | 1638 "next_id INT default -2, " |
| 1639 "cache_guid TEXT )"); | 1639 "cache_guid TEXT )"); |
| 1640 return db_->Execute(query.c_str()); | 1640 return db_->Execute(query.c_str()); |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 // This function checks to see if the given list of Metahandles has any nodes | 1643 // This function checks to see if the given list of Metahandles has any nodes |
| 1644 // whose PARENT_ID values refer to ID values that do not actually exist. | 1644 // whose PARENT_ID values refer to ID values that do not actually exist. |
| 1645 // This function also checks that the root node exists in the set. | |
|
pavely
2016/09/15 22:50:15
I would say "that root node with correct id exists
| |
| 1645 // Returns true on success. | 1646 // Returns true on success. |
| 1646 bool DirectoryBackingStore::VerifyReferenceIntegrity( | 1647 bool DirectoryBackingStore::VerifyReferenceIntegrity( |
| 1647 const Directory::MetahandlesMap* handles_map) { | 1648 const Directory::MetahandlesMap* handles_map) { |
| 1648 TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck"); | 1649 TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck"); |
| 1649 typedef std::unordered_set<std::string> IdsSet; | 1650 typedef std::unordered_set<std::string> IdsSet; |
| 1650 | 1651 |
| 1651 IdsSet ids_set; | 1652 IdsSet ids_set; |
| 1652 bool is_ok = true; | 1653 bool is_ok = true; |
| 1653 | 1654 |
| 1654 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { | 1655 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { |
| 1655 EntryKernel* entry = it->second.get(); | 1656 EntryKernel* entry = it->second.get(); |
| 1656 bool is_duplicate_id = !(ids_set.insert(entry->ref(ID).value()).second); | 1657 bool is_duplicate_id = !(ids_set.insert(entry->ref(ID).value()).second); |
| 1657 is_ok = is_ok && !is_duplicate_id; | 1658 is_ok = is_ok && !is_duplicate_id; |
| 1658 } | 1659 } |
| 1659 | 1660 |
| 1660 IdsSet::iterator end = ids_set.end(); | 1661 IdsSet::iterator end = ids_set.end(); |
| 1661 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { | 1662 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { |
| 1662 EntryKernel* entry = it->second.get(); | 1663 EntryKernel* entry = it->second.get(); |
| 1663 if (!entry->ref(PARENT_ID).IsNull()) { | 1664 if (!entry->ref(PARENT_ID).IsNull()) { |
| 1664 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); | 1665 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); |
| 1665 if (!parent_exists) { | 1666 if (!parent_exists) { |
| 1666 return false; | 1667 return false; |
| 1667 } | 1668 } |
| 1668 } | 1669 } |
| 1669 } | 1670 } |
| 1671 if (ids_set.find(Id::GetRoot().value()) == ids_set.end()) { | |
|
pavely
2016/09/15 22:50:15
nit: Since you are using Id class directly could y
| |
| 1672 return false; | |
| 1673 } | |
| 1670 return is_ok; | 1674 return is_ok; |
| 1671 } | 1675 } |
| 1672 | 1676 |
| 1673 void DirectoryBackingStore::PrepareSaveEntryStatement( | 1677 void DirectoryBackingStore::PrepareSaveEntryStatement( |
| 1674 EntryTable table, sql::Statement* save_statement) { | 1678 EntryTable table, sql::Statement* save_statement) { |
| 1675 if (save_statement->is_valid()) | 1679 if (save_statement->is_valid()) |
| 1676 return; | 1680 return; |
| 1677 | 1681 |
| 1678 string query; | 1682 string query; |
| 1679 query.reserve(kUpdateStatementBufferSize); | 1683 query.reserve(kUpdateStatementBufferSize); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1759 DCHECK(CalledOnValidThread()); | 1763 DCHECK(CalledOnValidThread()); |
| 1760 DCHECK(!catastrophic_error_handler.is_null()); | 1764 DCHECK(!catastrophic_error_handler.is_null()); |
| 1761 catastrophic_error_handler_ = catastrophic_error_handler; | 1765 catastrophic_error_handler_ = catastrophic_error_handler; |
| 1762 sql::Connection::ErrorCallback error_callback = | 1766 sql::Connection::ErrorCallback error_callback = |
| 1763 base::Bind(&OnSqliteError, catastrophic_error_handler_); | 1767 base::Bind(&OnSqliteError, catastrophic_error_handler_); |
| 1764 db_->set_error_callback(error_callback); | 1768 db_->set_error_callback(error_callback); |
| 1765 } | 1769 } |
| 1766 | 1770 |
| 1767 } // namespace syncable | 1771 } // namespace syncable |
| 1768 } // namespace syncer | 1772 } // namespace syncer |
| OLD | NEW |