OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/engine/syncer_util.h" | 5 #include "chrome/browser/sync/engine/syncer_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // of the first client and commit the set of merged encryption keys. Until the | 274 // of the first client and commit the set of merged encryption keys. Until the |
275 // second client provides the pending passphrase, the cryptographer will | 275 // second client provides the pending passphrase, the cryptographer will |
276 // preserve the encryption keys based on the local passphrase, while the | 276 // preserve the encryption keys based on the local passphrase, while the |
277 // nigori node will preserve the server encryption keys. | 277 // nigori node will preserve the server encryption keys. |
278 // | 278 // |
279 // If non-encryption changes are made to the nigori node, they will be | 279 // If non-encryption changes are made to the nigori node, they will be |
280 // lost as part of conflict resolution. This is intended, as we place a higher | 280 // lost as part of conflict resolution. This is intended, as we place a higher |
281 // priority on preserving the server's passphrase change to preserving local | 281 // priority on preserving the server's passphrase change to preserving local |
282 // non-encryption changes. Next time the non-encryption changes are made to | 282 // non-encryption changes. Next time the non-encryption changes are made to |
283 // the nigori node (e.g. on restart), they will commit without issue. | 283 // the nigori node (e.g. on restart), they will commit without issue. |
284 if (specifics.HasExtension(sync_pb::nigori)) { | 284 if (specifics.has_nigori()) { |
285 const sync_pb::NigoriSpecifics& nigori = | 285 const sync_pb::NigoriSpecifics& nigori = specifics.nigori(); |
286 specifics.GetExtension(sync_pb::nigori); | |
287 cryptographer->Update(nigori); | 286 cryptographer->Update(nigori); |
288 | 287 |
289 // Make sure any unsynced changes are properly encrypted as necessary. | 288 // Make sure any unsynced changes are properly encrypted as necessary. |
290 // We only perform this if the cryptographer is ready. If not, these are | 289 // We only perform this if the cryptographer is ready. If not, these are |
291 // re-encrypted at SetPassphrase time (via ReEncryptEverything). This logic | 290 // re-encrypted at SetPassphrase time (via ReEncryptEverything). This logic |
292 // covers the case where the nigori updated marked new datatypes for | 291 // covers the case where the nigori updated marked new datatypes for |
293 // encryption, but didn't change the passphrase. | 292 // encryption, but didn't change the passphrase. |
294 if (cryptographer->is_ready()) { | 293 if (cryptographer->is_ready()) { |
295 // Note that we don't bother to encrypt any data for which IS_UNSYNCED | 294 // Note that we don't bother to encrypt any data for which IS_UNSYNCED |
296 // == false here. The machine that turned on encryption should know about | 295 // == false here. The machine that turned on encryption should know about |
(...skipping 17 matching lines...) Expand all Loading... |
314 // treated as an unresolvable conflict. See the description in syncer_types.h. | 313 // treated as an unresolvable conflict. See the description in syncer_types.h. |
315 // This prevents any unsynced changes from commiting and postpones conflict | 314 // This prevents any unsynced changes from commiting and postpones conflict |
316 // resolution until all data can be decrypted. | 315 // resolution until all data can be decrypted. |
317 if (specifics.has_encrypted() && | 316 if (specifics.has_encrypted() && |
318 !cryptographer->CanDecrypt(specifics.encrypted())) { | 317 !cryptographer->CanDecrypt(specifics.encrypted())) { |
319 // We can't decrypt this node yet. | 318 // We can't decrypt this node yet. |
320 DVLOG(1) << "Received an undecryptable " | 319 DVLOG(1) << "Received an undecryptable " |
321 << syncable::ModelTypeToString(entry->GetServerModelType()) | 320 << syncable::ModelTypeToString(entry->GetServerModelType()) |
322 << " update, returning encryption_conflict."; | 321 << " update, returning encryption_conflict."; |
323 return CONFLICT_ENCRYPTION; | 322 return CONFLICT_ENCRYPTION; |
324 } else if (specifics.HasExtension(sync_pb::password) && | 323 } else if (specifics.has_password() && |
325 entry->Get(UNIQUE_SERVER_TAG).empty()) { | 324 entry->Get(UNIQUE_SERVER_TAG).empty()) { |
326 // Passwords use their own legacy encryption scheme. | 325 // Passwords use their own legacy encryption scheme. |
327 const sync_pb::PasswordSpecifics& password = | 326 const sync_pb::PasswordSpecifics& password = specifics.password(); |
328 specifics.GetExtension(sync_pb::password); | |
329 if (!cryptographer->CanDecrypt(password.encrypted())) { | 327 if (!cryptographer->CanDecrypt(password.encrypted())) { |
330 DVLOG(1) << "Received an undecryptable password update, returning " | 328 DVLOG(1) << "Received an undecryptable password update, returning " |
331 << "encryption_conflict."; | 329 << "encryption_conflict."; |
332 return CONFLICT_ENCRYPTION; | 330 return CONFLICT_ENCRYPTION; |
333 } | 331 } |
334 } | 332 } |
335 | 333 |
336 if (!entry->Get(SERVER_IS_DEL)) { | 334 if (!entry->Get(SERVER_IS_DEL)) { |
337 syncable::Id new_parent = entry->Get(SERVER_PARENT_ID); | 335 syncable::Id new_parent = entry->Get(SERVER_PARENT_ID); |
338 Entry parent(trans, GET_BY_ID, new_parent); | 336 Entry parent(trans, GET_BY_ID, new_parent); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // protocol. | 388 // protocol. |
391 void UpdateBookmarkSpecifics(const std::string& singleton_tag, | 389 void UpdateBookmarkSpecifics(const std::string& singleton_tag, |
392 const std::string& url, | 390 const std::string& url, |
393 const std::string& favicon_bytes, | 391 const std::string& favicon_bytes, |
394 MutableEntry* local_entry) { | 392 MutableEntry* local_entry) { |
395 // In the new-style protocol, the server no longer sends bookmark info for | 393 // In the new-style protocol, the server no longer sends bookmark info for |
396 // the "google_chrome" folder. Mimic that here. | 394 // the "google_chrome" folder. Mimic that here. |
397 if (singleton_tag == "google_chrome") | 395 if (singleton_tag == "google_chrome") |
398 return; | 396 return; |
399 sync_pb::EntitySpecifics pb; | 397 sync_pb::EntitySpecifics pb; |
400 sync_pb::BookmarkSpecifics* bookmark = pb.MutableExtension(sync_pb::bookmark); | 398 sync_pb::BookmarkSpecifics* bookmark = pb.mutable_bookmark(); |
401 if (!url.empty()) | 399 if (!url.empty()) |
402 bookmark->set_url(url); | 400 bookmark->set_url(url); |
403 if (!favicon_bytes.empty()) | 401 if (!favicon_bytes.empty()) |
404 bookmark->set_favicon(favicon_bytes); | 402 bookmark->set_favicon(favicon_bytes); |
405 local_entry->Put(SERVER_SPECIFICS, pb); | 403 local_entry->Put(SERVER_SPECIFICS, pb); |
406 } | 404 } |
407 | 405 |
408 } // namespace | 406 } // namespace |
409 | 407 |
410 // Pass in name and checksum because of UTF8 conversion. | 408 // Pass in name and checksum because of UTF8 conversion. |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 if (update.version() < target->Get(SERVER_VERSION)) { | 770 if (update.version() < target->Get(SERVER_VERSION)) { |
773 LOG(WARNING) << "Update older than current server version for " | 771 LOG(WARNING) << "Update older than current server version for " |
774 << *target << " Update:" | 772 << *target << " Update:" |
775 << SyncerProtoUtil::SyncEntityDebugString(update); | 773 << SyncerProtoUtil::SyncEntityDebugString(update); |
776 return VERIFY_SUCCESS; // Expected in new sync protocol. | 774 return VERIFY_SUCCESS; // Expected in new sync protocol. |
777 } | 775 } |
778 return VERIFY_UNDECIDED; | 776 return VERIFY_UNDECIDED; |
779 } | 777 } |
780 | 778 |
781 } // namespace browser_sync | 779 } // namespace browser_sync |
OLD | NEW |