| 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 "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 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 284 |
| 285 if (!DeleteEntries(DELETE_JOURNAL_TABLE, snapshot.delete_journals_to_purge)) | 285 if (!DeleteEntries(DELETE_JOURNAL_TABLE, snapshot.delete_journals_to_purge)) |
| 286 return false; | 286 return false; |
| 287 | 287 |
| 288 if (save_info) { | 288 if (save_info) { |
| 289 const Directory::PersistedKernelInfo& info = snapshot.kernel_info; | 289 const Directory::PersistedKernelInfo& info = snapshot.kernel_info; |
| 290 sql::Statement s1(db_->GetCachedStatement( | 290 sql::Statement s1(db_->GetCachedStatement( |
| 291 SQL_FROM_HERE, | 291 SQL_FROM_HERE, |
| 292 "UPDATE share_info " | 292 "UPDATE share_info " |
| 293 "SET store_birthday = ?, " | 293 "SET store_birthday = ?, " |
| 294 "next_id = ?, " | |
| 295 "bag_of_chips = ?")); | 294 "bag_of_chips = ?")); |
| 296 s1.BindString(0, info.store_birthday); | 295 s1.BindString(0, info.store_birthday); |
| 297 s1.BindInt64(1, info.next_id); | 296 s1.BindBlob(1, info.bag_of_chips.data(), info.bag_of_chips.size()); |
| 298 s1.BindBlob(2, info.bag_of_chips.data(), info.bag_of_chips.size()); | |
| 299 | 297 |
| 300 if (!s1.Run()) | 298 if (!s1.Run()) |
| 301 return false; | 299 return false; |
| 302 DCHECK_EQ(db_->GetLastChangeCount(), 1); | 300 DCHECK_EQ(db_->GetLastChangeCount(), 1); |
| 303 | 301 |
| 304 sql::Statement s2(db_->GetCachedStatement( | 302 sql::Statement s2(db_->GetCachedStatement( |
| 305 SQL_FROM_HERE, | 303 SQL_FROM_HERE, |
| 306 "INSERT OR REPLACE " | 304 "INSERT OR REPLACE " |
| 307 "INTO models (model_id, " | 305 "INTO models (model_id, " |
| 308 "progress_marker, " | 306 "progress_marker, " |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 // A null kernel is evidence of external data corruption. | 637 // A null kernel is evidence of external data corruption. |
| 640 if (!kernel) | 638 if (!kernel) |
| 641 return false; | 639 return false; |
| 642 delete_journals->insert(kernel.release()); | 640 delete_journals->insert(kernel.release()); |
| 643 } | 641 } |
| 644 return s.Succeeded(); | 642 return s.Succeeded(); |
| 645 } | 643 } |
| 646 | 644 |
| 647 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { | 645 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { |
| 648 { | 646 { |
| 649 sql::Statement s( | 647 sql::Statement s(db_->GetUniqueStatement( |
| 650 db_->GetUniqueStatement( | 648 "SELECT store_birthday, cache_guid, bag_of_chips " |
| 651 "SELECT store_birthday, next_id, cache_guid, bag_of_chips " | 649 "FROM share_info")); |
| 652 "FROM share_info")); | |
| 653 if (!s.Step()) | 650 if (!s.Step()) |
| 654 return false; | 651 return false; |
| 655 | 652 |
| 656 info->kernel_info.store_birthday = s.ColumnString(0); | 653 info->kernel_info.store_birthday = s.ColumnString(0); |
| 657 info->kernel_info.next_id = s.ColumnInt64(1); | 654 info->cache_guid = s.ColumnString(1); |
| 658 info->cache_guid = s.ColumnString(2); | 655 s.ColumnBlobAsString(2, &(info->kernel_info.bag_of_chips)); |
| 659 s.ColumnBlobAsString(3, &(info->kernel_info.bag_of_chips)); | |
| 660 | 656 |
| 661 // Verify there was only one row returned. | 657 // Verify there was only one row returned. |
| 662 DCHECK(!s.Step()); | 658 DCHECK(!s.Step()); |
| 663 DCHECK(s.Succeeded()); | 659 DCHECK(s.Succeeded()); |
| 664 } | 660 } |
| 665 | 661 |
| 666 { | 662 { |
| 667 sql::Statement s( | 663 sql::Statement s( |
| 668 db_->GetUniqueStatement( | 664 db_->GetUniqueStatement( |
| 669 "SELECT model_id, progress_marker, " | 665 "SELECT model_id, progress_marker, " |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 DCHECK(CalledOnValidThread()); | 1673 DCHECK(CalledOnValidThread()); |
| 1678 DCHECK(!catastrophic_error_handler.is_null()); | 1674 DCHECK(!catastrophic_error_handler.is_null()); |
| 1679 catastrophic_error_handler_ = catastrophic_error_handler; | 1675 catastrophic_error_handler_ = catastrophic_error_handler; |
| 1680 sql::Connection::ErrorCallback error_callback = | 1676 sql::Connection::ErrorCallback error_callback = |
| 1681 base::Bind(&OnSqliteError, catastrophic_error_handler_); | 1677 base::Bind(&OnSqliteError, catastrophic_error_handler_); |
| 1682 db_->set_error_callback(error_callback); | 1678 db_->set_error_callback(error_callback); |
| 1683 } | 1679 } |
| 1684 | 1680 |
| 1685 } // namespace syncable | 1681 } // namespace syncable |
| 1686 } // namespace syncer | 1682 } // namespace syncer |
| OLD | NEW |