| Index: chrome/browser/sync/util/cryptographer.cc
|
| diff --git a/chrome/browser/sync/util/cryptographer.cc b/chrome/browser/sync/util/cryptographer.cc
|
| index a24e9cfd36d88d2bcf67cfa1f4141b7976e1291e..5d1e45009dac82da7320d3749196d16945cca5a6 100644
|
| --- a/chrome/browser/sync/util/cryptographer.cc
|
| +++ b/chrome/browser/sync/util/cryptographer.cc
|
| @@ -55,9 +55,11 @@ bool Cryptographer::CanDecryptUsingDefaultKey(
|
| return default_nigori_ && (data.key_name() == default_nigori_->first);
|
| }
|
|
|
| -bool Cryptographer::Encrypt(const ::google::protobuf::MessageLite& message,
|
| - sync_pb::EncryptedData* encrypted) const {
|
| - if (!encrypted || !default_nigori_) {
|
| +bool Cryptographer::Encrypt(
|
| + const ::google::protobuf::MessageLite& message,
|
| + sync_pb::EncryptedData* encrypted) const {
|
| + DCHECK(encrypted);
|
| + if (!default_nigori_) {
|
| LOG(ERROR) << "Cryptographer not ready, failed to encrypt.";
|
| return false;
|
| }
|
| @@ -68,6 +70,14 @@ bool Cryptographer::Encrypt(const ::google::protobuf::MessageLite& message,
|
| return false;
|
| }
|
|
|
| + if (CanDecryptUsingDefaultKey(*encrypted)) {
|
| + const std::string& original_serialized = DecryptToString(*encrypted);
|
| + if (original_serialized == serialized) {
|
| + DVLOG(2) << "Re-encryption unnecessary, encrypted data already matches.";
|
| + return true;
|
| + }
|
| + }
|
| +
|
| encrypted->set_key_name(default_nigori_->first);
|
| if (!default_nigori_->second->Encrypt(serialized,
|
| encrypted->mutable_blob())) {
|
|
|