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

Unified Diff: chrome/browser/sync/internal_api/write_node.cc

Issue 9315048: [Sync] Fix idempotency check for passwords datatype. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 11 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 | « chrome/browser/sync/internal_api/syncapi_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/internal_api/write_node.cc
diff --git a/chrome/browser/sync/internal_api/write_node.cc b/chrome/browser/sync/internal_api/write_node.cc
index 7f5869052cecc716e380b43a0f81b8750b3a5ffc..023061a2511c6ec1e42dd281bbb2e181af0afc82 100644
--- a/chrome/browser/sync/internal_api/write_node.cc
+++ b/chrome/browser/sync/internal_api/write_node.cc
@@ -195,15 +195,28 @@ void WriteNode::SetPasswordSpecifics(
Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
- sync_pb::PasswordSpecifics new_value;
- if (!cryptographer->Encrypt(data, new_value.mutable_encrypted())) {
+ // We have to do the idempotency check here (vs in UpdateEntryWithEncryption)
+ // because Passwords have their encrypted data within the PasswordSpecifics,
+ // vs within the EntitySpecifics like all the other types.
+ const sync_pb::EntitySpecifics& old_specifics = GetEntry()->Get(SPECIFICS);
+ sync_pb::EntitySpecifics entity_specifics;
+ // Copy over the old specifics if they exist.
+ if (syncable::GetModelTypeFromSpecifics(old_specifics) ==
+ syncable::PASSWORDS) {
+ entity_specifics.CopyFrom(old_specifics);
+ } else {
+ syncable::AddDefaultExtensionValue(syncable::PASSWORDS,
+ &entity_specifics);
+ }
+ sync_pb::PasswordSpecifics* password_specifics =
+ entity_specifics.MutableExtension(sync_pb::password);
+ // This will only update password_specifics if the underlying unencrypted blob
+ // was different from |data| or was not encrypted with the proper passphrase.
+ if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) {
NOTREACHED() << "Failed to encrypt password, possibly due to sync node "
<< "corruption";
return;
}
-
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value);
SetEntitySpecifics(entity_specifics);
}
« no previous file with comments | « chrome/browser/sync/internal_api/syncapi_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698