| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/autofill/core/browser/webdata/autofill_table.h" | 5 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 "WHERE guid = ?")); | 1693 "WHERE guid = ?")); |
| 1694 s.BindString(0, guid); | 1694 s.BindString(0, guid); |
| 1695 | 1695 |
| 1696 return s.Step(); | 1696 return s.Step(); |
| 1697 } | 1697 } |
| 1698 | 1698 |
| 1699 bool AutofillTable::GetAllSyncMetadata(syncer::ModelType model_type, | 1699 bool AutofillTable::GetAllSyncMetadata(syncer::ModelType model_type, |
| 1700 syncer::MetadataBatch* metadata_batch) { | 1700 syncer::MetadataBatch* metadata_batch) { |
| 1701 DCHECK_EQ(model_type, syncer::AUTOFILL) | 1701 DCHECK_EQ(model_type, syncer::AUTOFILL) |
| 1702 << "Only the AUTOFILL model type is supported"; | 1702 << "Only the AUTOFILL model type is supported"; |
| 1703 syncer::EntityMetadataMap metadata_records; | 1703 DCHECK(metadata_batch); |
| 1704 if (GetAllSyncEntityMetadata(model_type, &metadata_records)) { | 1704 if (!GetAllSyncEntityMetadata(model_type, metadata_batch)) { |
| 1705 for (const auto& pair : metadata_records) { | |
| 1706 // TODO(pnoland): Add batch transfer of metadata map. | |
| 1707 metadata_batch->AddMetadata(pair.first, pair.second); | |
| 1708 } | |
| 1709 } else { | |
| 1710 return false; | 1705 return false; |
| 1711 } | 1706 } |
| 1712 | 1707 |
| 1713 sync_pb::ModelTypeState model_type_state; | 1708 sync_pb::ModelTypeState model_type_state; |
| 1714 if (GetModelTypeState(model_type, &model_type_state)) { | 1709 if (GetModelTypeState(model_type, &model_type_state)) { |
| 1715 metadata_batch->SetModelTypeState(model_type_state); | 1710 metadata_batch->SetModelTypeState(model_type_state); |
| 1716 } else { | 1711 } else { |
| 1717 return false; | 1712 return false; |
| 1718 } | 1713 } |
| 1719 | 1714 |
| 1720 return true; | 1715 return true; |
| 1721 } | 1716 } |
| 1722 | 1717 |
| 1723 bool AutofillTable::GetAllSyncEntityMetadata( | 1718 bool AutofillTable::GetAllSyncEntityMetadata( |
| 1724 syncer::ModelType model_type, | 1719 syncer::ModelType model_type, |
| 1725 syncer::EntityMetadataMap* metadata_records) { | 1720 syncer::MetadataBatch* metadata_batch) { |
| 1726 DCHECK_EQ(model_type, syncer::AUTOFILL) | 1721 DCHECK_EQ(model_type, syncer::AUTOFILL) |
| 1727 << "Only the AUTOFILL model type is supported"; | 1722 << "Only the AUTOFILL model type is supported"; |
| 1723 DCHECK(metadata_batch); |
| 1728 | 1724 |
| 1729 sql::Statement s(db_->GetUniqueStatement( | 1725 sql::Statement s(db_->GetUniqueStatement( |
| 1730 "SELECT storage_key, value FROM autofill_sync_metadata")); | 1726 "SELECT storage_key, value FROM autofill_sync_metadata")); |
| 1731 | 1727 |
| 1732 while (s.Step()) { | 1728 while (s.Step()) { |
| 1733 std::string storage_key = s.ColumnString(0); | 1729 std::string storage_key = s.ColumnString(0); |
| 1734 std::string serialized_metadata = s.ColumnString(1); | 1730 std::string serialized_metadata = s.ColumnString(1); |
| 1735 sync_pb::EntityMetadata metadata_record; | 1731 sync_pb::EntityMetadata entity_metadata; |
| 1736 if (metadata_record.ParseFromString(serialized_metadata)) { | 1732 if (entity_metadata.ParseFromString(serialized_metadata)) { |
| 1737 metadata_records->insert(std::make_pair(storage_key, metadata_record)); | 1733 metadata_batch->AddMetadata(storage_key, entity_metadata); |
| 1738 } else { | 1734 } else { |
| 1735 DLOG(WARNING) << "Failed to deserialize AUTOFILL model type " |
| 1736 "sync_pb::EntityMetadata."; |
| 1739 return false; | 1737 return false; |
| 1740 } | 1738 } |
| 1741 } | 1739 } |
| 1742 return true; | 1740 return true; |
| 1743 } | 1741 } |
| 1744 | 1742 |
| 1745 bool AutofillTable::UpdateSyncMetadata( | 1743 bool AutofillTable::UpdateSyncMetadata( |
| 1746 syncer::ModelType model_type, | 1744 syncer::ModelType model_type, |
| 1747 const std::string& storage_key, | 1745 const std::string& storage_key, |
| 1748 const sync_pb::EntityMetadata& metadata) { | 1746 const sync_pb::EntityMetadata& metadata) { |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 if (!db_->Execute("DROP TABLE masked_credit_cards") || | 2536 if (!db_->Execute("DROP TABLE masked_credit_cards") || |
| 2539 !db_->Execute("ALTER TABLE masked_credit_cards_temp " | 2537 !db_->Execute("ALTER TABLE masked_credit_cards_temp " |
| 2540 "RENAME TO masked_credit_cards")) { | 2538 "RENAME TO masked_credit_cards")) { |
| 2541 return false; | 2539 return false; |
| 2542 } | 2540 } |
| 2543 | 2541 |
| 2544 return transaction.Commit(); | 2542 return transaction.Commit(); |
| 2545 } | 2543 } |
| 2546 | 2544 |
| 2547 } // namespace autofill | 2545 } // namespace autofill |
| OLD | NEW |