| 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> |
| 11 #include <unordered_set> | 11 #include <unordered_set> |
| 12 | 12 |
| 13 #include "base/base64.h" | 13 #include "base/base64.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "components/sync/base/node_ordinal.h" | 25 #include "components/sync/base/node_ordinal.h" |
| 26 #include "components/sync/base/time.h" | 26 #include "components/sync/base/time.h" |
| 27 #include "components/sync/protocol/bookmark_specifics.pb.h" | 27 #include "components/sync/protocol/bookmark_specifics.pb.h" |
| 28 #include "components/sync/protocol/sync.pb.h" | 28 #include "components/sync/protocol/sync.pb.h" |
| 29 #include "components/sync/syncable/syncable_columns.h" | 29 #include "components/sync/syncable/syncable_columns.h" |
| 30 #include "components/sync/syncable/syncable_id.h" |
| 30 #include "components/sync/syncable/syncable_util.h" | 31 #include "components/sync/syncable/syncable_util.h" |
| 31 #include "sql/connection.h" | 32 #include "sql/connection.h" |
| 32 #include "sql/error_delegate_util.h" | 33 #include "sql/error_delegate_util.h" |
| 33 #include "sql/statement.h" | 34 #include "sql/statement.h" |
| 34 #include "sql/transaction.h" | 35 #include "sql/transaction.h" |
| 35 | 36 |
| 36 using std::string; | 37 using std::string; |
| 37 | 38 |
| 38 namespace syncer { | 39 namespace syncer { |
| 39 namespace syncable { | 40 namespace syncable { |
| (...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 "store_birthday TEXT, " | 1636 "store_birthday TEXT, " |
| 1636 "db_create_version TEXT, " | 1637 "db_create_version TEXT, " |
| 1637 "db_create_time INT, " | 1638 "db_create_time INT, " |
| 1638 "next_id INT default -2, " | 1639 "next_id INT default -2, " |
| 1639 "cache_guid TEXT )"); | 1640 "cache_guid TEXT )"); |
| 1640 return db_->Execute(query.c_str()); | 1641 return db_->Execute(query.c_str()); |
| 1641 } | 1642 } |
| 1642 | 1643 |
| 1643 // This function checks to see if the given list of Metahandles has any nodes | 1644 // 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. | 1645 // whose PARENT_ID values refer to ID values that do not actually exist. |
| 1646 // This function also checks that a root node with the correct id exists in the |
| 1647 // set. |
| 1645 // Returns true on success. | 1648 // Returns true on success. |
| 1646 bool DirectoryBackingStore::VerifyReferenceIntegrity( | 1649 bool DirectoryBackingStore::VerifyReferenceIntegrity( |
| 1647 const Directory::MetahandlesMap* handles_map) { | 1650 const Directory::MetahandlesMap* handles_map) { |
| 1648 TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck"); | 1651 TRACE_EVENT0("sync", "SyncDatabaseIntegrityCheck"); |
| 1649 typedef std::unordered_set<std::string> IdsSet; | 1652 typedef std::unordered_set<std::string> IdsSet; |
| 1650 | 1653 |
| 1651 IdsSet ids_set; | 1654 IdsSet ids_set; |
| 1652 bool is_ok = true; | 1655 bool is_ok = true; |
| 1653 | 1656 |
| 1654 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { | 1657 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { |
| 1655 EntryKernel* entry = it->second.get(); | 1658 EntryKernel* entry = it->second.get(); |
| 1656 bool is_duplicate_id = !(ids_set.insert(entry->ref(ID).value()).second); | 1659 bool is_duplicate_id = !(ids_set.insert(entry->ref(ID).value()).second); |
| 1657 is_ok = is_ok && !is_duplicate_id; | 1660 is_ok = is_ok && !is_duplicate_id; |
| 1658 } | 1661 } |
| 1659 | 1662 |
| 1660 IdsSet::iterator end = ids_set.end(); | 1663 IdsSet::iterator end = ids_set.end(); |
| 1661 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { | 1664 for (auto it = handles_map->begin(); it != handles_map->end(); ++it) { |
| 1662 EntryKernel* entry = it->second.get(); | 1665 EntryKernel* entry = it->second.get(); |
| 1663 if (!entry->ref(PARENT_ID).IsNull()) { | 1666 if (!entry->ref(PARENT_ID).IsNull()) { |
| 1664 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); | 1667 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); |
| 1665 if (!parent_exists) { | 1668 if (!parent_exists) { |
| 1666 return false; | 1669 return false; |
| 1667 } | 1670 } |
| 1668 } | 1671 } |
| 1669 } | 1672 } |
| 1673 if (ids_set.find(Id::GetRoot().value()) == ids_set.end()) { |
| 1674 return false; |
| 1675 } |
| 1670 return is_ok; | 1676 return is_ok; |
| 1671 } | 1677 } |
| 1672 | 1678 |
| 1673 void DirectoryBackingStore::PrepareSaveEntryStatement( | 1679 void DirectoryBackingStore::PrepareSaveEntryStatement( |
| 1674 EntryTable table, sql::Statement* save_statement) { | 1680 EntryTable table, sql::Statement* save_statement) { |
| 1675 if (save_statement->is_valid()) | 1681 if (save_statement->is_valid()) |
| 1676 return; | 1682 return; |
| 1677 | 1683 |
| 1678 string query; | 1684 string query; |
| 1679 query.reserve(kUpdateStatementBufferSize); | 1685 query.reserve(kUpdateStatementBufferSize); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 DCHECK(CalledOnValidThread()); | 1765 DCHECK(CalledOnValidThread()); |
| 1760 DCHECK(!catastrophic_error_handler.is_null()); | 1766 DCHECK(!catastrophic_error_handler.is_null()); |
| 1761 catastrophic_error_handler_ = catastrophic_error_handler; | 1767 catastrophic_error_handler_ = catastrophic_error_handler; |
| 1762 sql::Connection::ErrorCallback error_callback = | 1768 sql::Connection::ErrorCallback error_callback = |
| 1763 base::Bind(&OnSqliteError, catastrophic_error_handler_); | 1769 base::Bind(&OnSqliteError, catastrophic_error_handler_); |
| 1764 db_->set_error_callback(error_callback); | 1770 db_->set_error_callback(error_callback); |
| 1765 } | 1771 } |
| 1766 | 1772 |
| 1767 } // namespace syncable | 1773 } // namespace syncable |
| 1768 } // namespace syncer | 1774 } // namespace syncer |
| OLD | NEW |