summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorbrettw <brettw@chromium.org>2015-02-26 15:21:37 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-26 23:22:19 +0000
commitf4d16c2ed4b740ae78496519982012c7849aa616 (patch)
tree1031c380f67506f6a8ed5e1cd634d3630ec42fd7 /components
parentd1f5eb0865c89d9413fa6982fa49a1853325556e (diff)
downloadchromium_src-f4d16c2ed4b740ae78496519982012c7849aa616.zip
chromium_src-f4d16c2ed4b740ae78496519982012c7849aa616.tar.gz
chromium_src-f4d16c2ed4b740ae78496519982012c7849aa616.tar.bz2
Implement incremental syncing to wallet data.
Previously we only got updates on restart. This just hooks up the sync data changed notification. Since the amount of data is normally very small, it just re-gets the full list of data from the sync engine each time this happens, making the logic the same as the initialization case. Review URL: https://codereview.chromium.org/921303002 Cr-Commit-Position: refs/heads/master@{#318345}
Diffstat (limited to 'components')
-rw-r--r--components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc118
-rw-r--r--components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h4
2 files changed, 73 insertions, 49 deletions
diff --git a/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc b/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc
index 2cd0909..a99b375 100644
--- a/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc
+++ b/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.cc
@@ -118,15 +118,18 @@ template<class Data> struct AutofillDataPtrLessThan {
// corresponding data type, and expects the types to implement a server_id()
// and a Compare function.
//
-// Returns the previous number of items in the table (for sync tracking).
+// Returns true if anything changed. The previous number of items in the table
+// (for sync tracking) will be placed into *prev_item_count.
template<class Data>
-size_t SetDataIfChanged(
+bool SetDataIfChanged(
AutofillTable* table,
const std::vector<Data>& data,
bool (AutofillTable::*getter)(std::vector<Data*>*),
- void (AutofillTable::*setter)(const std::vector<Data>&)) {
+ void (AutofillTable::*setter)(const std::vector<Data>&),
+ size_t* prev_item_count) {
ScopedVector<Data> existing_data;
(table->*getter)(&existing_data.get());
+ *prev_item_count = existing_data.size();
bool difference_found = true;
if (existing_data.size() == data.size()) {
@@ -146,10 +149,11 @@ size_t SetDataIfChanged(
}
}
- if (difference_found)
+ if (difference_found) {
(table->*setter)(data);
-
- return existing_data.size();
+ return true;
+ }
+ return false;
}
} // namespace
@@ -170,47 +174,8 @@ AutofillWalletSyncableService::MergeDataAndStartSyncing(
scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
DCHECK(thread_checker_.CalledOnValidThread());
-
- std::vector<CreditCard> wallet_cards;
- std::vector<AutofillProfile> wallet_addresses;
-
- for (const syncer::SyncData& data : initial_sync_data) {
- DCHECK_EQ(syncer::AUTOFILL_WALLET_DATA, data.GetDataType());
- const sync_pb::AutofillWalletSpecifics& autofill_specifics =
- data.GetSpecifics().autofill_wallet();
- if (autofill_specifics.type() ==
- sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
- wallet_cards.push_back(
- CardFromSpecifics(autofill_specifics.masked_card()));
- } else {
- DCHECK_EQ(sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS,
- autofill_specifics.type());
- wallet_addresses.push_back(
- ProfileFromSpecifics(autofill_specifics.address()));
- }
- }
-
- // In the common case, the database won't have changed. Committing an update
- // to the database will require at least one DB page write and will schedule
- // a fsync. To avoid this I/O, it should be more efficient to do a read and
- // only do the writes if something changed.
- AutofillTable* table =
- AutofillTable::FromWebDatabase(webdata_backend_->GetDatabase());
- size_t prev_card_count =
- SetDataIfChanged(table, wallet_cards,
- &AutofillTable::GetServerCreditCards,
- &AutofillTable::SetServerCreditCards);
- size_t prev_address_count =
- SetDataIfChanged(table, wallet_addresses,
- &AutofillTable::GetAutofillServerProfiles,
- &AutofillTable::SetAutofillServerProfiles);
-
- syncer::SyncMergeResult merge_result(type);
- merge_result.set_num_items_before_association(
- static_cast<int>(prev_card_count + prev_address_count));
- merge_result.set_num_items_after_association(
- static_cast<int>(wallet_cards.size() + wallet_addresses.size()));
- return merge_result;
+ sync_processor_ = sync_processor.Pass();
+ return SetSyncData(initial_sync_data);
}
void AutofillWalletSyncableService::StopSyncing(syncer::ModelType type) {
@@ -221,6 +186,7 @@ void AutofillWalletSyncableService::StopSyncing(syncer::ModelType type) {
syncer::SyncDataList AutofillWalletSyncableService::GetAllSyncData(
syncer::ModelType type) const {
DCHECK(thread_checker_.CalledOnValidThread());
+ // This data type is never synced "up" so we don't need to implement this.
syncer::SyncDataList current_data;
return current_data;
}
@@ -229,7 +195,9 @@ syncer::SyncError AutofillWalletSyncableService::ProcessSyncChanges(
const tracked_objects::Location& from_here,
const syncer::SyncChangeList& change_list) {
DCHECK(thread_checker_.CalledOnValidThread());
- // TODO(brettw) handle incremental updates while Chrome is running.
+ // Don't bother handling incremental updates. Wallet data changes very rarely
+ // and has few items. Instead, just get all the current data and save it.
+ SetSyncData(sync_processor_->GetAllSyncData(syncer::AUTOFILL_WALLET_DATA));
return syncer::SyncError();
}
@@ -256,4 +224,56 @@ void AutofillWalletSyncableService::InjectStartSyncFlare(
flare_ = flare;
}
-} // namespace autofill
+syncer::SyncMergeResult AutofillWalletSyncableService::SetSyncData(
+ const syncer::SyncDataList& data_list) {
+ std::vector<CreditCard> wallet_cards;
+ std::vector<AutofillProfile> wallet_addresses;
+
+ for (const syncer::SyncData& data : data_list) {
+ DCHECK_EQ(syncer::AUTOFILL_WALLET_DATA, data.GetDataType());
+ const sync_pb::AutofillWalletSpecifics& autofill_specifics =
+ data.GetSpecifics().autofill_wallet();
+ if (autofill_specifics.type() ==
+ sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
+ wallet_cards.push_back(
+ CardFromSpecifics(autofill_specifics.masked_card()));
+ } else {
+ DCHECK_EQ(sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS,
+ autofill_specifics.type());
+ wallet_addresses.push_back(
+ ProfileFromSpecifics(autofill_specifics.address()));
+ }
+ }
+
+ // In the common case, the database won't have changed. Committing an update
+ // to the database will require at least one DB page write and will schedule
+ // a fsync. To avoid this I/O, it should be more efficient to do a read and
+ // only do the writes if something changed.
+ AutofillTable* table =
+ AutofillTable::FromWebDatabase(webdata_backend_->GetDatabase());
+ size_t prev_card_count = 0;
+ size_t prev_address_count = 0;
+ bool changed_cards = SetDataIfChanged(
+ table, wallet_cards,
+ &AutofillTable::GetServerCreditCards,
+ &AutofillTable::SetServerCreditCards,
+ &prev_card_count);
+ bool changed_addresses = SetDataIfChanged(
+ table, wallet_addresses,
+ &AutofillTable::GetAutofillServerProfiles,
+ &AutofillTable::SetAutofillServerProfiles,
+ &prev_address_count);
+
+ syncer::SyncMergeResult merge_result(syncer::AUTOFILL_WALLET_DATA);
+ merge_result.set_num_items_before_association(
+ static_cast<int>(prev_card_count + prev_address_count));
+ merge_result.set_num_items_after_association(
+ static_cast<int>(wallet_cards.size() + wallet_addresses.size()));
+
+ if (webdata_backend_ && (changed_cards || changed_addresses))
+ webdata_backend_->NotifyOfMultipleAutofillChanges();
+
+ return merge_result;
+}
+
+} // namespace autofil
diff --git a/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h b/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h
index fd32bae..1939564 100644
--- a/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h
+++ b/components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h
@@ -58,10 +58,14 @@ class AutofillWalletSyncableService
const std::string& app_locale);
private:
+ syncer::SyncMergeResult SetSyncData(const syncer::SyncDataList& data_list);
+
base::ThreadChecker thread_checker_;
AutofillWebDataBackend* webdata_backend_; // Weak ref.
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
+
syncer::SyncableService::StartSyncFlare flare_;
DISALLOW_COPY_AND_ASSIGN(AutofillWalletSyncableService);