Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table.cc

Issue 2660673002: [Sync] Not having an autocomplete ModelTypeState is valid. (Closed)
Patch Set: Update AutocompleteSyncBridge unittests to not rely on initial metadata. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <limits> 11 #include <limits>
12 #include <map> 12 #include <map>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <utility>
15 #include <vector>
16 15
17 #include "base/command_line.h" 16 #include "base/command_line.h"
18 #include "base/guid.h" 17 #include "base/guid.h"
19 #include "base/i18n/case_conversion.h" 18 #include "base/i18n/case_conversion.h"
20 #include "base/logging.h" 19 #include "base/logging.h"
21 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
22 #include "base/numerics/safe_conversions.h" 21 #include "base/numerics/safe_conversions.h"
23 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
26 #include "base/time/time.h" 25 #include "base/time/time.h"
27 #include "components/autofill/core/browser/autofill_country.h" 26 #include "components/autofill/core/browser/autofill_country.h"
28 #include "components/autofill/core/browser/autofill_profile.h" 27 #include "components/autofill/core/browser/autofill_profile.h"
29 #include "components/autofill/core/browser/autofill_type.h" 28 #include "components/autofill/core/browser/autofill_type.h"
30 #include "components/autofill/core/browser/credit_card.h" 29 #include "components/autofill/core/browser/credit_card.h"
31 #include "components/autofill/core/browser/personal_data_manager.h" 30 #include "components/autofill/core/browser/personal_data_manager.h"
32 #include "components/autofill/core/browser/webdata/autofill_change.h" 31 #include "components/autofill/core/browser/webdata/autofill_change.h"
33 #include "components/autofill/core/browser/webdata/autofill_entry.h" 32 #include "components/autofill/core/browser/webdata/autofill_entry.h"
34 #include "components/autofill/core/common/autofill_switches.h" 33 #include "components/autofill/core/common/autofill_switches.h"
35 #include "components/autofill/core/common/autofill_util.h" 34 #include "components/autofill/core/common/autofill_util.h"
36 #include "components/autofill/core/common/form_field_data.h" 35 #include "components/autofill/core/common/form_field_data.h"
37 #include "components/os_crypt/os_crypt.h" 36 #include "components/os_crypt/os_crypt.h"
38 #include "components/sync/base/model_type.h" 37 #include "components/sync/base/model_type.h"
39 #include "components/sync/model/metadata_batch.h"
40 #include "components/sync/protocol/entity_metadata.pb.h" 38 #include "components/sync/protocol/entity_metadata.pb.h"
41 #include "components/sync/protocol/model_type_state.pb.h" 39 #include "components/sync/protocol/model_type_state.pb.h"
42 #include "components/webdata/common/web_database.h" 40 #include "components/webdata/common/web_database.h"
43 #include "sql/statement.h" 41 #include "sql/statement.h"
44 #include "sql/transaction.h" 42 #include "sql/transaction.h"
45 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
46 #include "url/gurl.h" 44 #include "url/gurl.h"
47 45
48 using base::ASCIIToUTF16; 46 using base::ASCIIToUTF16;
49 using base::Time; 47 using base::Time;
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 return s.Step(); 1677 return s.Step();
1680 } 1678 }
1681 1679
1682 bool AutofillTable::GetAllSyncMetadata(syncer::ModelType model_type, 1680 bool AutofillTable::GetAllSyncMetadata(syncer::ModelType model_type,
1683 syncer::MetadataBatch* metadata_batch) { 1681 syncer::MetadataBatch* metadata_batch) {
1684 DCHECK_EQ(model_type, syncer::AUTOFILL) 1682 DCHECK_EQ(model_type, syncer::AUTOFILL)
1685 << "Only the AUTOFILL model type is supported"; 1683 << "Only the AUTOFILL model type is supported";
1686 syncer::EntityMetadataMap metadata_records; 1684 syncer::EntityMetadataMap metadata_records;
1687 if (GetAllSyncEntityMetadata(model_type, &metadata_records)) { 1685 if (GetAllSyncEntityMetadata(model_type, &metadata_records)) {
1688 for (const auto& pair : metadata_records) { 1686 for (const auto& pair : metadata_records) {
1689 // todo(pnoland): add batch transfer of metadata map 1687 // TODO(pnoland): Add batch transfer of metadata map.
1690 metadata_batch->AddMetadata(pair.first, pair.second); 1688 metadata_batch->AddMetadata(pair.first, pair.second);
1691 } 1689 }
1692 } else { 1690 } else {
1693 return false; 1691 return false;
1694 } 1692 }
1695 1693
1696 sync_pb::ModelTypeState model_type_state; 1694 sync_pb::ModelTypeState model_type_state;
1697 if (GetModelTypeState(model_type, &model_type_state)) { 1695 if (GetModelTypeState(model_type, &model_type_state)) {
1698 metadata_batch->SetModelTypeState(model_type_state); 1696 metadata_batch->SetModelTypeState(model_type_state);
1699 } else { 1697 } else {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 1753
1756 bool AutofillTable::GetModelTypeState(syncer::ModelType model_type, 1754 bool AutofillTable::GetModelTypeState(syncer::ModelType model_type,
1757 sync_pb::ModelTypeState* state) { 1755 sync_pb::ModelTypeState* state) {
1758 DCHECK_EQ(model_type, syncer::AUTOFILL) 1756 DCHECK_EQ(model_type, syncer::AUTOFILL)
1759 << "Only the AUTOFILL model type is supported"; 1757 << "Only the AUTOFILL model type is supported";
1760 1758
1761 sql::Statement s(db_->GetUniqueStatement( 1759 sql::Statement s(db_->GetUniqueStatement(
1762 "SELECT value FROM autofill_model_type_state WHERE id=1")); 1760 "SELECT value FROM autofill_model_type_state WHERE id=1"));
1763 1761
1764 if (!s.Step()) { 1762 if (!s.Step()) {
1765 return false; 1763 return true;
1766 } 1764 }
1767 1765
1768 std::string serialized_state = s.ColumnString(0); 1766 std::string serialized_state = s.ColumnString(0);
1769 return state->ParseFromString(serialized_state); 1767 return state->ParseFromString(serialized_state);
1770 } 1768 }
1771 1769
1772 bool AutofillTable::UpdateModelTypeState( 1770 bool AutofillTable::UpdateModelTypeState(
1773 syncer::ModelType model_type, 1771 syncer::ModelType model_type,
1774 const sync_pb::ModelTypeState& model_type_state) { 1772 const sync_pb::ModelTypeState& model_type_state) {
1775 DCHECK_EQ(model_type, syncer::AUTOFILL) 1773 DCHECK_EQ(model_type, syncer::AUTOFILL)
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 // temporary table. 2518 // temporary table.
2521 if (!db_->Execute("DROP TABLE masked_credit_cards") || 2519 if (!db_->Execute("DROP TABLE masked_credit_cards") ||
2522 !db_->Execute("ALTER TABLE masked_credit_cards_temp " 2520 !db_->Execute("ALTER TABLE masked_credit_cards_temp "
2523 "RENAME TO masked_credit_cards")) { 2521 "RENAME TO masked_credit_cards")) {
2524 return false; 2522 return false;
2525 } 2523 }
2526 2524
2527 return transaction.Commit(); 2525 return transaction.Commit();
2528 } 2526 }
2529 2527
2530 } // namespace autofill 2528 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698