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

Side by Side Diff: sync/engine/syncer_util.cc

Issue 10844005: [Sync] Refactor GetEncryptedTypes usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + add dcheck Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/syncer_unittest.cc ('k') | sync/internal_api/base_transaction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sync/engine/syncer_util.h" 5 #include "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>
11 11
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "sync/engine/conflict_resolver.h" 14 #include "sync/engine/conflict_resolver.h"
15 #include "sync/engine/syncer_proto_util.h" 15 #include "sync/engine/syncer_proto_util.h"
16 #include "sync/engine/syncer_types.h" 16 #include "sync/engine/syncer_types.h"
17 #include "sync/internal_api/public/base/model_type.h" 17 #include "sync/internal_api/public/base/model_type.h"
18 #include "sync/protocol/bookmark_specifics.pb.h" 18 #include "sync/protocol/bookmark_specifics.pb.h"
19 #include "sync/protocol/nigori_specifics.pb.h" 19 #include "sync/protocol/nigori_specifics.pb.h"
20 #include "sync/protocol/password_specifics.pb.h" 20 #include "sync/protocol/password_specifics.pb.h"
21 #include "sync/protocol/sync.pb.h" 21 #include "sync/protocol/sync.pb.h"
22 #include "sync/syncable/directory.h" 22 #include "sync/syncable/directory.h"
23 #include "sync/syncable/entry.h" 23 #include "sync/syncable/entry.h"
24 #include "sync/syncable/mutable_entry.h" 24 #include "sync/syncable/mutable_entry.h"
25 #include "sync/syncable/nigori_handler.h"
25 #include "sync/syncable/nigori_util.h" 26 #include "sync/syncable/nigori_util.h"
26 #include "sync/syncable/read_transaction.h" 27 #include "sync/syncable/read_transaction.h"
27 #include "sync/syncable/syncable_changes_version.h" 28 #include "sync/syncable/syncable_changes_version.h"
28 #include "sync/syncable/syncable_proto_util.h" 29 #include "sync/syncable/syncable_proto_util.h"
29 #include "sync/syncable/syncable_util.h" 30 #include "sync/syncable/syncable_util.h"
30 #include "sync/syncable/write_transaction.h" 31 #include "sync/syncable/write_transaction.h"
31 #include "sync/util/cryptographer.h" 32 #include "sync/util/cryptographer.h"
32 #include "sync/util/time.h" 33 #include "sync/util/time.h"
33 34
34 namespace syncer { 35 namespace syncer {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // preserve the encryption keys based on the local passphrase, while the 211 // preserve the encryption keys based on the local passphrase, while the
211 // nigori node will preserve the server encryption keys. 212 // nigori node will preserve the server encryption keys.
212 // 213 //
213 // If non-encryption changes are made to the nigori node, they will be 214 // If non-encryption changes are made to the nigori node, they will be
214 // lost as part of conflict resolution. This is intended, as we place a higher 215 // lost as part of conflict resolution. This is intended, as we place a higher
215 // priority on preserving the server's passphrase change to preserving local 216 // priority on preserving the server's passphrase change to preserving local
216 // non-encryption changes. Next time the non-encryption changes are made to 217 // non-encryption changes. Next time the non-encryption changes are made to
217 // the nigori node (e.g. on restart), they will commit without issue. 218 // the nigori node (e.g. on restart), they will commit without issue.
218 if (specifics.has_nigori()) { 219 if (specifics.has_nigori()) {
219 const sync_pb::NigoriSpecifics& nigori = specifics.nigori(); 220 const sync_pb::NigoriSpecifics& nigori = specifics.nigori();
220 cryptographer->ApplyNigoriUpdate(nigori, trans); 221 trans->directory()->GetNigoriHandler()->ApplyNigoriUpdate(nigori, trans);
221 222
222 // Make sure any unsynced changes are properly encrypted as necessary. 223 // Make sure any unsynced changes are properly encrypted as necessary.
223 // We only perform this if the cryptographer is ready. If not, these are 224 // We only perform this if the cryptographer is ready. If not, these are
224 // re-encrypted at SetDecryptionPassphrase time (via ReEncryptEverything). 225 // re-encrypted at SetDecryptionPassphrase time (via ReEncryptEverything).
225 // This logic covers the case where the nigori update marked new datatypes 226 // This logic covers the case where the nigori update marked new datatypes
226 // for encryption, but didn't change the passphrase. 227 // for encryption, but didn't change the passphrase.
227 if (cryptographer->is_ready()) { 228 if (cryptographer->is_ready()) {
228 // Note that we don't bother to encrypt any data for which IS_UNSYNCED 229 // Note that we don't bother to encrypt any data for which IS_UNSYNCED
229 // == false here. The machine that turned on encryption should know about 230 // == false here. The machine that turned on encryption should know about
230 // and re-encrypt all synced data. It's possible it could get interrupted 231 // and re-encrypt all synced data. It's possible it could get interrupted
231 // during this process, but we currently reencrypt everything at startup 232 // during this process, but we currently reencrypt everything at startup
232 // as well, so as soon as a client is restarted with this datatype marked 233 // as well, so as soon as a client is restarted with this datatype marked
233 // for encryption, all the data should be updated as necessary. 234 // for encryption, all the data should be updated as necessary.
234 235
235 // If this fails, something is wrong with the cryptographer, but there's 236 // If this fails, something is wrong with the cryptographer, but there's
236 // nothing we can do about it here. 237 // nothing we can do about it here.
237 DVLOG(1) << "Received new nigori, encrypting unsynced changes."; 238 DVLOG(1) << "Received new nigori, encrypting unsynced changes.";
238 syncable::ProcessUnsyncedChangesForEncryption(trans, cryptographer); 239 syncable::ProcessUnsyncedChangesForEncryption(trans);
239 } 240 }
240 } 241 }
241 242
242 // Only apply updates that we can decrypt. If we can't decrypt the update, it 243 // Only apply updates that we can decrypt. If we can't decrypt the update, it
243 // is likely because the passphrase has not arrived yet. Because the 244 // is likely because the passphrase has not arrived yet. Because the
244 // passphrase may not arrive within this GetUpdates, we can't just return 245 // passphrase may not arrive within this GetUpdates, we can't just return
245 // conflict, else we try to perform normal conflict resolution prematurely or 246 // conflict, else we try to perform normal conflict resolution prematurely or
246 // the syncer may get stuck. As such, we return CONFLICT_ENCRYPTION, which is 247 // the syncer may get stuck. As such, we return CONFLICT_ENCRYPTION, which is
247 // treated as an unresolvable conflict. See the description in syncer_types.h. 248 // treated as an unresolvable conflict. See the description in syncer_types.h.
248 // This prevents any unsynced changes from commiting and postpones conflict 249 // This prevents any unsynced changes from commiting and postpones conflict
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (update.version() < target->Get(SERVER_VERSION)) { 693 if (update.version() < target->Get(SERVER_VERSION)) {
693 LOG(WARNING) << "Update older than current server version for " 694 LOG(WARNING) << "Update older than current server version for "
694 << *target << " Update:" 695 << *target << " Update:"
695 << SyncerProtoUtil::SyncEntityDebugString(update); 696 << SyncerProtoUtil::SyncEntityDebugString(update);
696 return VERIFY_SUCCESS; // Expected in new sync protocol. 697 return VERIFY_SUCCESS; // Expected in new sync protocol.
697 } 698 }
698 return VERIFY_UNDECIDED; 699 return VERIFY_UNDECIDED;
699 } 700 }
700 701
701 } // namespace syncer 702 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer_unittest.cc ('k') | sync/internal_api/base_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698