OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/internal_api/write_node.h" | 5 #include "chrome/browser/sync/internal_api/write_node.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/sync/engine/nigori_util.h" | 10 #include "chrome/browser/sync/engine/nigori_util.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 entity_specifics.MutableExtension(sync_pb::nigori)->CopyFrom(new_value); | 188 entity_specifics.MutableExtension(sync_pb::nigori)->CopyFrom(new_value); |
189 SetEntitySpecifics(entity_specifics); | 189 SetEntitySpecifics(entity_specifics); |
190 } | 190 } |
191 | 191 |
192 void WriteNode::SetPasswordSpecifics( | 192 void WriteNode::SetPasswordSpecifics( |
193 const sync_pb::PasswordSpecificsData& data) { | 193 const sync_pb::PasswordSpecificsData& data) { |
194 DCHECK_EQ(syncable::PASSWORDS, GetModelType()); | 194 DCHECK_EQ(syncable::PASSWORDS, GetModelType()); |
195 | 195 |
196 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); | 196 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); |
197 | 197 |
198 sync_pb::PasswordSpecifics new_value; | 198 // We have to do the idempotency check here (vs in UpdateEntryWithEncryption) |
199 if (!cryptographer->Encrypt(data, new_value.mutable_encrypted())) { | 199 // because Passwords have their encrypted data within the PasswordSpecifics, |
| 200 // vs within the EntitySpecifics like all the other types. |
| 201 const sync_pb::EntitySpecifics& old_specifics = GetEntry()->Get(SPECIFICS); |
| 202 sync_pb::EntitySpecifics entity_specifics; |
| 203 // Copy over the old specifics if they exist. |
| 204 if (syncable::GetModelTypeFromSpecifics(old_specifics) == |
| 205 syncable::PASSWORDS) { |
| 206 entity_specifics.CopyFrom(old_specifics); |
| 207 } else { |
| 208 syncable::AddDefaultExtensionValue(syncable::PASSWORDS, |
| 209 &entity_specifics); |
| 210 } |
| 211 sync_pb::PasswordSpecifics* password_specifics = |
| 212 entity_specifics.MutableExtension(sync_pb::password); |
| 213 // This will only update password_specifics if the underlying unencrypted blob |
| 214 // was different from |data| or was not encrypted with the proper passphrase. |
| 215 if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) { |
200 NOTREACHED() << "Failed to encrypt password, possibly due to sync node " | 216 NOTREACHED() << "Failed to encrypt password, possibly due to sync node " |
201 << "corruption"; | 217 << "corruption"; |
202 return; | 218 return; |
203 } | 219 } |
204 | |
205 sync_pb::EntitySpecifics entity_specifics; | |
206 entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value); | |
207 SetEntitySpecifics(entity_specifics); | 220 SetEntitySpecifics(entity_specifics); |
208 } | 221 } |
209 | 222 |
210 void WriteNode::SetThemeSpecifics( | 223 void WriteNode::SetThemeSpecifics( |
211 const sync_pb::ThemeSpecifics& new_value) { | 224 const sync_pb::ThemeSpecifics& new_value) { |
212 sync_pb::EntitySpecifics entity_specifics; | 225 sync_pb::EntitySpecifics entity_specifics; |
213 entity_specifics.MutableExtension(sync_pb::theme)->CopyFrom(new_value); | 226 entity_specifics.MutableExtension(sync_pb::theme)->CopyFrom(new_value); |
214 SetEntitySpecifics(entity_specifics); | 227 SetEntitySpecifics(entity_specifics); |
215 } | 228 } |
216 | 229 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); | 528 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); |
516 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); | 529 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); |
517 SetBookmarkSpecifics(new_value); | 530 SetBookmarkSpecifics(new_value); |
518 } | 531 } |
519 | 532 |
520 void WriteNode::MarkForSyncing() { | 533 void WriteNode::MarkForSyncing() { |
521 syncable::MarkForSyncing(entry_); | 534 syncable::MarkForSyncing(entry_); |
522 } | 535 } |
523 | 536 |
524 } // namespace sync_api | 537 } // namespace sync_api |
OLD | NEW |