| 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-inl.h" | |
| 30 #include "components/sync/syncable/syncable_columns.h" | 29 #include "components/sync/syncable/syncable_columns.h" |
| 31 #include "components/sync/syncable/syncable_util.h" | 30 #include "components/sync/syncable/syncable_util.h" |
| 32 #include "sql/connection.h" | 31 #include "sql/connection.h" |
| 33 #include "sql/error_delegate_util.h" | 32 #include "sql/error_delegate_util.h" |
| 34 #include "sql/statement.h" | 33 #include "sql/statement.h" |
| 35 #include "sql/transaction.h" | 34 #include "sql/transaction.h" |
| 36 | 35 |
| 37 using std::string; | 36 using std::string; |
| 38 | 37 |
| 39 namespace syncer { | 38 namespace syncer { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 (Directory::KERNEL_SHARE_INFO_DIRTY == snapshot.kernel_info_status); | 323 (Directory::KERNEL_SHARE_INFO_DIRTY == snapshot.kernel_info_status); |
| 325 if (!snapshot.HasUnsavedMetahandleChanges() && !save_info) { | 324 if (!snapshot.HasUnsavedMetahandleChanges() && !save_info) { |
| 326 return true; | 325 return true; |
| 327 } | 326 } |
| 328 | 327 |
| 329 sql::Transaction transaction(db_.get()); | 328 sql::Transaction transaction(db_.get()); |
| 330 if (!transaction.Begin()) | 329 if (!transaction.Begin()) |
| 331 return false; | 330 return false; |
| 332 | 331 |
| 333 PrepareSaveEntryStatement(METAS_TABLE, &save_meta_statement_); | 332 PrepareSaveEntryStatement(METAS_TABLE, &save_meta_statement_); |
| 334 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); | 333 for (auto i = snapshot.dirty_metas.begin(); i != snapshot.dirty_metas.end(); |
| 335 i != snapshot.dirty_metas.end(); ++i) { | 334 ++i) { |
| 336 DCHECK((*i)->is_dirty()); | 335 DCHECK((*i)->is_dirty()); |
| 337 if (!SaveEntryToDB(&save_meta_statement_, **i)) | 336 if (!SaveEntryToDB(&save_meta_statement_, **i)) |
| 338 return false; | 337 return false; |
| 339 } | 338 } |
| 340 | 339 |
| 341 if (!DeleteEntries(METAS_TABLE, snapshot.metahandles_to_purge)) | 340 if (!DeleteEntries(METAS_TABLE, snapshot.metahandles_to_purge)) |
| 342 return false; | 341 return false; |
| 343 | 342 |
| 344 PrepareSaveEntryStatement(DELETE_JOURNAL_TABLE, | 343 PrepareSaveEntryStatement(DELETE_JOURNAL_TABLE, |
| 345 &save_delete_journal_statement_); | 344 &save_delete_journal_statement_); |
| 346 for (EntryKernelSet::const_iterator i = snapshot.delete_journals.begin(); | 345 for (auto i = snapshot.delete_journals.begin(); |
| 347 i != snapshot.delete_journals.end(); ++i) { | 346 i != snapshot.delete_journals.end(); ++i) { |
| 348 if (!SaveEntryToDB(&save_delete_journal_statement_, **i)) | 347 if (!SaveEntryToDB(&save_delete_journal_statement_, **i)) |
| 349 return false; | 348 return false; |
| 350 } | 349 } |
| 351 | 350 |
| 352 if (!DeleteEntries(DELETE_JOURNAL_TABLE, snapshot.delete_journals_to_purge)) | 351 if (!DeleteEntries(DELETE_JOURNAL_TABLE, snapshot.delete_journals_to_purge)) |
| 353 return false; | 352 return false; |
| 354 | 353 |
| 355 if (save_info) { | 354 if (save_info) { |
| 356 const Directory::PersistedKernelInfo& info = snapshot.kernel_info; | 355 const Directory::PersistedKernelInfo& info = snapshot.kernel_info; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 const EntryKernel& entry) const { | 693 const EntryKernel& entry) const { |
| 695 if (entry.ref(IS_DEL)) { | 694 if (entry.ref(IS_DEL)) { |
| 696 if (!entry.ref(IS_UNSYNCED) && !entry.ref(IS_UNAPPLIED_UPDATE)) | 695 if (!entry.ref(IS_UNSYNCED) && !entry.ref(IS_UNAPPLIED_UPDATE)) |
| 697 return true; | 696 return true; |
| 698 else if (!entry.ref(ID).ServerKnows()) | 697 else if (!entry.ref(ID).ServerKnows()) |
| 699 return true; | 698 return true; |
| 700 } | 699 } |
| 701 return false; | 700 return false; |
| 702 } | 701 } |
| 703 | 702 |
| 704 bool DirectoryBackingStore::LoadDeleteJournals( | 703 bool DirectoryBackingStore::LoadDeleteJournals(JournalIndex* delete_journals) { |
| 705 JournalIndex* delete_journals) { | |
| 706 string select; | 704 string select; |
| 707 select.reserve(kUpdateStatementBufferSize); | 705 select.reserve(kUpdateStatementBufferSize); |
| 708 select.append("SELECT "); | 706 select.append("SELECT "); |
| 709 AppendColumnList(&select); | 707 AppendColumnList(&select); |
| 710 select.append(" FROM deleted_metas"); | 708 select.append(" FROM deleted_metas"); |
| 711 | 709 |
| 712 sql::Statement s(db_->GetUniqueStatement(select.c_str())); | 710 sql::Statement s(db_->GetUniqueStatement(select.c_str())); |
| 713 | 711 |
| 714 while (s.Step()) { | 712 while (s.Step()) { |
| 715 int total_entry_copies; | 713 int total_entry_copies; |
| 716 std::unique_ptr<EntryKernel> kernel = UnpackEntry(&s, &total_entry_copies); | 714 std::unique_ptr<EntryKernel> kernel_ptr = |
| 715 UnpackEntry(&s, &total_entry_copies); |
| 717 // A null kernel is evidence of external data corruption. | 716 // A null kernel is evidence of external data corruption. |
| 718 if (!kernel) | 717 if (!kernel_ptr) |
| 719 return false; | 718 return false; |
| 720 delete_journals->insert(kernel.release()); | 719 EntryKernel* kernel = kernel_ptr.get(); |
| 720 (*delete_journals)[kernel] = std::move(kernel_ptr); |
| 721 } | 721 } |
| 722 return s.Succeeded(); | 722 return s.Succeeded(); |
| 723 } | 723 } |
| 724 | 724 |
| 725 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { | 725 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { |
| 726 { | 726 { |
| 727 sql::Statement s(db_->GetUniqueStatement( | 727 sql::Statement s(db_->GetUniqueStatement( |
| 728 "SELECT store_birthday, cache_guid, bag_of_chips " | 728 "SELECT store_birthday, cache_guid, bag_of_chips " |
| 729 "FROM share_info")); | 729 "FROM share_info")); |
| 730 if (!s.Step()) | 730 if (!s.Step()) |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 DCHECK(CalledOnValidThread()); | 1759 DCHECK(CalledOnValidThread()); |
| 1760 DCHECK(!catastrophic_error_handler.is_null()); | 1760 DCHECK(!catastrophic_error_handler.is_null()); |
| 1761 catastrophic_error_handler_ = catastrophic_error_handler; | 1761 catastrophic_error_handler_ = catastrophic_error_handler; |
| 1762 sql::Connection::ErrorCallback error_callback = | 1762 sql::Connection::ErrorCallback error_callback = |
| 1763 base::Bind(&OnSqliteError, catastrophic_error_handler_); | 1763 base::Bind(&OnSqliteError, catastrophic_error_handler_); |
| 1764 db_->set_error_callback(error_callback); | 1764 db_->set_error_callback(error_callback); |
| 1765 } | 1765 } |
| 1766 | 1766 |
| 1767 } // namespace syncable | 1767 } // namespace syncable |
| 1768 } // namespace syncer | 1768 } // namespace syncer |
| OLD | NEW |