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

Side by Side Diff: chrome/browser/sync/util/cryptographer.cc

Issue 8564032: [Sync] The cryptographer should be able to handle empty or old nigori nodes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Fix diff Created 9 years, 1 month 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
OLDNEW
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 <algorithm>
6
5 #include "base/base64.h" 7 #include "base/base64.h"
6 #include "chrome/browser/sync/util/cryptographer.h" 8 #include "chrome/browser/sync/util/cryptographer.h"
7 #include "chrome/browser/password_manager/encryptor.h" 9 #include "chrome/browser/password_manager/encryptor.h"
8 10
9 namespace browser_sync { 11 namespace browser_sync {
10 12
11 const char kNigoriTag[] = "google_chrome_nigori"; 13 const char kNigoriTag[] = "google_chrome_nigori";
12 14
13 // We name a particular Nigori instance (ie. a triplet consisting of a hostname, 15 // We name a particular Nigori instance (ie. a triplet consisting of a hostname,
14 // a username, and a password) by calling Permute on this string. Since the 16 // a username, and a password) by calling Permute on this string. Since the
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 321
320 // Note: the initial version with encryption did not support the 322 // Note: the initial version with encryption did not support the
321 // encrypt_everything field. If anything more than the sensitive types were 323 // encrypt_everything field. If anything more than the sensitive types were
322 // encrypted, it meant we were encrypting everything. 324 // encrypted, it meant we were encrypting everything.
323 if (!nigori.has_encrypt_everything() && 325 if (!nigori.has_encrypt_everything() &&
324 encrypted_types.size() > SensitiveTypes().size()) { 326 encrypted_types.size() > SensitiveTypes().size()) {
325 set_encrypt_everything(); 327 set_encrypt_everything();
326 return; 328 return;
327 } 329 }
328 330
329 SetEncryptedTypes(encrypted_types); 331 MergeEncryptedTypes(encrypted_types);
330 } 332 }
331 333
332 void Cryptographer::UpdateNigoriFromEncryptedTypes( 334 void Cryptographer::UpdateNigoriFromEncryptedTypes(
333 sync_pb::NigoriSpecifics* nigori) const { 335 sync_pb::NigoriSpecifics* nigori) const {
334 nigori->set_encrypt_everything(encrypt_everything_); 336 nigori->set_encrypt_everything(encrypt_everything_);
335 nigori->set_encrypt_bookmarks( 337 nigori->set_encrypt_bookmarks(
336 encrypted_types_.count(syncable::BOOKMARKS) > 0); 338 encrypted_types_.count(syncable::BOOKMARKS) > 0);
337 nigori->set_encrypt_preferences( 339 nigori->set_encrypt_preferences(
338 encrypted_types_.count(syncable::PREFERENCES) > 0); 340 encrypted_types_.count(syncable::PREFERENCES) > 0);
339 nigori->set_encrypt_autofill_profile( 341 nigori->set_encrypt_autofill_profile(
(...skipping 29 matching lines...) Expand all
369 } 371 }
370 372
371 bool Cryptographer::encrypt_everything() const { 373 bool Cryptographer::encrypt_everything() const {
372 return encrypt_everything_; 374 return encrypt_everything_;
373 } 375 }
374 376
375 syncable::ModelTypeSet Cryptographer::GetEncryptedTypes() const { 377 syncable::ModelTypeSet Cryptographer::GetEncryptedTypes() const {
376 return encrypted_types_; 378 return encrypted_types_;
377 } 379 }
378 380
379 void Cryptographer::SetEncryptedTypesForTest( 381 void Cryptographer::MergeEncryptedTypesForTest(
380 const syncable::ModelTypeSet& encrypted_types) { 382 const syncable::ModelTypeSet& encrypted_types) {
381 SetEncryptedTypes(encrypted_types); 383 MergeEncryptedTypes(encrypted_types);
382 } 384 }
383 385
384 void Cryptographer::SetEncryptedTypes( 386 void Cryptographer::MergeEncryptedTypes(
385 const syncable::ModelTypeSet& encrypted_types) { 387 const syncable::ModelTypeSet& encrypted_types) {
386 if (encrypted_types_ == encrypted_types) { 388 if (std::includes(encrypted_types_.begin(), encrypted_types_.end(),
389 encrypted_types.begin(), encrypted_types.end())) {
387 return; 390 return;
388 } 391 }
389 encrypted_types_ = encrypted_types; 392 encrypted_types_ = encrypted_types;
390 EmitEncryptedTypesChangedNotification(); 393 EmitEncryptedTypesChangedNotification();
391 } 394 }
392 395
393 void Cryptographer::EmitEncryptedTypesChangedNotification() { 396 void Cryptographer::EmitEncryptedTypesChangedNotification() {
394 FOR_EACH_OBSERVER( 397 FOR_EACH_OBSERVER(
395 Observer, observers_, 398 Observer, observers_,
396 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_)); 399 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_));
(...skipping 14 matching lines...) Expand all
411 continue; 414 continue;
412 } 415 }
413 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); 416 nigoris_[key.name()] = make_linked_ptr(new_nigori.release());
414 } 417 }
415 } 418 }
416 DCHECK(nigoris_.end() != nigoris_.find(default_key_name)); 419 DCHECK(nigoris_.end() != nigoris_.find(default_key_name));
417 default_nigori_ = &*nigoris_.find(default_key_name); 420 default_nigori_ = &*nigoris_.find(default_key_name);
418 } 421 }
419 422
420 } // namespace browser_sync 423 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/cryptographer.h ('k') | chrome/browser/sync/util/cryptographer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698