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

Unified Diff: components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.cc

Issue 2759183003: [Merge-58] Preserve use stats of existing Wallet cards when syncing. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.cc
diff --git a/components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.cc b/components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.cc
index f2305124934329ff30caac4ebac3e1dcf92cdecf..021b91abd5034ce35cb281ca91e06b6d858b3d6e 100644
--- a/components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.cc
+++ b/components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.cc
@@ -167,20 +167,40 @@ void MergeCommonMetadata(
bool* is_local_modified) {
size_t remote_use_count =
base::checked_cast<size_t>(remote_metadata.use_count());
- if (local_model->use_count() < remote_use_count) {
- local_model->set_use_count(remote_use_count);
- *is_local_modified = true;
- } else if (local_model->use_count() > remote_use_count) {
- *is_remote_outdated = true;
- }
-
base::Time remote_use_date =
base::Time::FromInternalValue(remote_metadata.use_date());
- if (local_model->use_date() < remote_use_date) {
+
+ // If the two models have the same metadata, do nothing.
+ if (local_model->use_count() == remote_use_count &&
+ local_model->use_date() == remote_use_date) {
+ return;
+ }
+
+ // Special case for local models with a use_count of one. This means the local
+ // model was only created, never used. The remote model should always be
+ // preferred.
+ // This situation can happen for new Chromium instances where there is no data
+ // yet on disk, making the use_date artifically high. Once the metadata sync
+ // kicks in, we should use that value.
+ if (local_model->use_count() == 1) {
local_model->set_use_date(remote_use_date);
+ local_model->set_use_count(remote_use_count);
*is_local_modified = true;
- } else if (local_model->use_date() > remote_use_date) {
- *is_remote_outdated = true;
+ } else {
+ // Otherwise, just keep the most recent use date and biggest use count.
+ if (local_model->use_date() < remote_use_date) {
+ local_model->set_use_date(remote_use_date);
+ *is_local_modified = true;
+ } else if (local_model->use_date() > remote_use_date) {
+ *is_remote_outdated = true;
+ }
+
+ if (local_model->use_count() < remote_use_count) {
+ local_model->set_use_count(remote_use_count);
+ *is_local_modified = true;
+ } else if (local_model->use_count() > remote_use_count) {
+ *is_remote_outdated = true;
+ }
}
}
« no previous file with comments | « no previous file | components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698