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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 8356026: [Sync] Cache encrypted types info in ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments (retry) 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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 cros_user_(cros_user), 104 cros_user_(cros_user),
105 sync_service_url_(kDevServerUrl), 105 sync_service_url_(kDevServerUrl),
106 backend_initialized_(false), 106 backend_initialized_(false),
107 is_auth_in_progress_(false), 107 is_auth_in_progress_(false),
108 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 108 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
109 signin_(signin_manager), 109 signin_(signin_manager),
110 unrecoverable_error_detected_(false), 110 unrecoverable_error_detected_(false),
111 scoped_runnable_method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 111 scoped_runnable_method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
112 expect_sync_configuration_aborted_(false), 112 expect_sync_configuration_aborted_(false),
113 clear_server_data_state_(CLEAR_NOT_STARTED), 113 clear_server_data_state_(CLEAR_NOT_STARTED),
114 encrypted_types_(browser_sync::Cryptographer::SensitiveTypes()),
115 encrypt_everything_(false),
114 encryption_pending_(false), 116 encryption_pending_(false),
115 auto_start_enabled_(false), 117 auto_start_enabled_(false),
116 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 118 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
117 // By default, dev, canary, and unbranded Chromium users will go to the 119 // By default, dev, canary, and unbranded Chromium users will go to the
118 // development servers. Development servers have more features than standard 120 // development servers. Development servers have more features than standard
119 // sync servers. Users with officially-branded Chrome stable and beta builds 121 // sync servers. Users with officially-branded Chrome stable and beta builds
120 // will go to the standard sync servers. 122 // will go to the standard sync servers.
121 // 123 //
122 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 124 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
123 base::ThreadRestrictions::ScopedAllowIO allow_io; 125 base::ThreadRestrictions::ScopedAllowIO allow_io;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 418 }
417 419
418 scoped_runnable_method_factory_.RevokeAll(); 420 scoped_runnable_method_factory_.RevokeAll();
419 421
420 // Clear various flags. 422 // Clear various flags.
421 expect_sync_configuration_aborted_ = false; 423 expect_sync_configuration_aborted_ = false;
422 is_auth_in_progress_ = false; 424 is_auth_in_progress_ = false;
423 backend_initialized_ = false; 425 backend_initialized_ = false;
424 cached_passphrases_ = CachedPassphrases(); 426 cached_passphrases_ = CachedPassphrases();
425 encryption_pending_ = false; 427 encryption_pending_ = false;
428 encrypt_everything_ = false;
429 encrypted_types_ = browser_sync::Cryptographer::SensitiveTypes();
426 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; 430 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED;
427 last_attempted_user_email_.clear(); 431 last_attempted_user_email_.clear();
428 last_auth_error_ = GoogleServiceAuthError::None(); 432 last_auth_error_ = GoogleServiceAuthError::None();
429 433
430 if (sync_global_error_.get()) { 434 if (sync_global_error_.get()) {
431 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( 435 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
432 sync_global_error_.get()); 436 sync_global_error_.get());
433 RemoveObserver(sync_global_error_.get()); 437 RemoveObserver(sync_global_error_.get());
434 sync_global_error_.reset(NULL); 438 sync_global_error_.reset(NULL);
435 } 439 }
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // If No encryption is pending and our passphrase has been accepted, tell the 835 // If No encryption is pending and our passphrase has been accepted, tell the
832 // wizard we're done (no need to hang around waiting for the sync to 836 // wizard we're done (no need to hang around waiting for the sync to
833 // complete). If encryption is pending, its successful completion will trigger 837 // complete). If encryption is pending, its successful completion will trigger
834 // the done step. 838 // the done step.
835 if (WizardIsVisible() && !encryption_pending()) 839 if (WizardIsVisible() && !encryption_pending())
836 wizard_.Step(SyncSetupWizard::DONE); 840 wizard_.Step(SyncSetupWizard::DONE);
837 841
838 NotifyObservers(); 842 NotifyObservers();
839 } 843 }
840 844
841 void ProfileSyncService::OnEncryptionComplete( 845 void ProfileSyncService::OnEncryptedTypesChanged(
842 const syncable::ModelTypeSet& encrypted_types) { 846 const syncable::ModelTypeSet& encrypted_types,
843 if (encryption_pending_) { 847 bool encrypt_everything) {
844 syncable::ModelTypeSet registered_types; 848 encrypted_types_ = encrypted_types;
845 GetRegisteredDataTypes(&registered_types); 849 encrypt_everything_ = encrypt_everything;
846 bool encryption_complete = true; 850 VLOG(1) << "Encrypted types changed to "
847 for (syncable::ModelTypeSet::const_iterator it = registered_types.begin(); 851 << syncable::ModelTypeSetToString(encrypted_types_)
848 it != registered_types.end(); 852 << " (encrypt everything is set to "
849 ++it) { 853 << (encrypt_everything_ ? "true" : "false") << ")";
850 if (encrypted_types.count(*it) == 0) { 854 DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u);
851 // One of our types is not yet encrypted - keep waiting. 855 }
852 encryption_complete = false; 856
853 break; 857 void ProfileSyncService::OnEncryptionComplete() {
854 } 858 VLOG(1) << "Encryption complete";
855 } 859 if (encryption_pending_ && encrypt_everything_) {
856 if (encryption_complete) { 860 encryption_pending_ = false;
857 encryption_pending_ = false; 861 // The user had chosen to encrypt datatypes. This is the last thing to
858 // The user had chosen to encrypt datatypes. This is the last thing to 862 // complete, so now that we're done notify the UI.
859 // complete, so now that we're done notify the UI. 863 wizard_.Step(SyncSetupWizard::DONE);
860 wizard_.Step(SyncSetupWizard::DONE); 864 // This is to nudge the integration tests when encryption is
861 } 865 // finished.
866 NotifyObservers();
862 } 867 }
863 NotifyObservers();
864 } 868 }
865 869
866 void ProfileSyncService::OnMigrationNeededForTypes( 870 void ProfileSyncService::OnMigrationNeededForTypes(
867 const syncable::ModelTypeSet& types) { 871 const syncable::ModelTypeSet& types) {
868 DCHECK(backend_initialized_); 872 DCHECK(backend_initialized_);
869 DCHECK(data_type_manager_.get()); 873 DCHECK(data_type_manager_.get());
870 874
871 // Migrator must be valid, because we don't sync until it is created and this 875 // Migrator must be valid, because we don't sync until it is created and this
872 // callback originates from a sync cycle. 876 // callback originates from a sync cycle.
873 migrator_->MigrateTypes(types); 877 migrator_->MigrateTypes(types);
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 } else { 1321 } else {
1318 if (is_explicit) { 1322 if (is_explicit) {
1319 cached_passphrases_.explicit_passphrase = passphrase; 1323 cached_passphrases_.explicit_passphrase = passphrase;
1320 } else { 1324 } else {
1321 cached_passphrases_.gaia_passphrase = passphrase; 1325 cached_passphrases_.gaia_passphrase = passphrase;
1322 } 1326 }
1323 } 1327 }
1324 } 1328 }
1325 1329
1326 void ProfileSyncService::SetEncryptEverything(bool encrypt_everything) { 1330 void ProfileSyncService::SetEncryptEverything(bool encrypt_everything) {
1331 // Tests override sync_initialized() to always return true, so we
1332 // must check that instead of |backend_initialized_|.
1333 // TODO(akalin): Fix the above. :/
1334 DCHECK(sync_initialized());
1327 encryption_pending_ = encrypt_everything; 1335 encryption_pending_ = encrypt_everything;
1336 // Callers shouldn't try to disable encrypt everything once it has
1337 // already succeeded.
1338 DCHECK(!encrypt_everything_);
1328 } 1339 }
1329 1340
1330 bool ProfileSyncService::encryption_pending() const { 1341 bool ProfileSyncService::encryption_pending() const {
1342 // We may be called during the setup process before we're
1343 // initialized (via IsEncryptedDatatypeEnabled and
1344 // IsPassphraseRequiredForDecryption).
1331 return encryption_pending_; 1345 return encryption_pending_;
1332 } 1346 }
1333 1347
1334 bool ProfileSyncService::EncryptEverythingEnabled() const { 1348 bool ProfileSyncService::EncryptEverythingEnabled() const {
1335 if (!backend_.get() || !backend_initialized_) { 1349 DCHECK(backend_initialized_);
1336 NOTREACHED() << "Cannot check encryption without initialized backend."; 1350 return encrypt_everything_;
1337 return false;
1338 }
1339 return backend_->EncryptEverythingEnabled();
1340 } 1351 }
1341 1352
1342 // This will open a transaction to get the encrypted types. Do not call this
1343 // if you already have a transaction open.
1344 void ProfileSyncService::GetEncryptedDataTypes( 1353 void ProfileSyncService::GetEncryptedDataTypes(
1345 syncable::ModelTypeSet* encrypted_types) const { 1354 syncable::ModelTypeSet* encrypted_types) const {
1346 CHECK(encrypted_types); 1355 CHECK(encrypted_types);
1347 if (backend_.get()) { 1356 // We may be called during the setup process before we're
1348 *encrypted_types = backend_->GetEncryptedDataTypes(); 1357 // initialized. In this case, we default to the sensitive types.
1349 DCHECK(encrypted_types->count(syncable::PASSWORDS)); 1358 *encrypted_types = encrypted_types_;
1350 } else { 1359 DCHECK_GT(encrypted_types->count(syncable::PASSWORDS), 0u);
1351 // Either we are in an unrecoverable error or the sync is not yet done
1352 // initializing. In either case just return the sensitive types. During
1353 // sync initialization the UI might need to know what our encrypted
1354 // types are.
1355 *encrypted_types = browser_sync::Cryptographer::SensitiveTypes();
1356 DCHECK(encrypted_types->count(syncable::PASSWORDS));
1357 }
1358 } 1360 }
1359 1361
1360 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 1362 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
1361 NotifyObservers(); 1363 NotifyObservers();
1362 if (is_sync_managed) { 1364 if (is_sync_managed) {
1363 DisableForUser(); 1365 DisableForUser();
1364 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { 1366 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) {
1365 StartUp(); 1367 StartUp();
1366 } 1368 }
1367 } 1369 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 << "Unrecoverable error."; 1536 << "Unrecoverable error.";
1535 } else { 1537 } else {
1536 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " 1538 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not "
1537 << "initialized"; 1539 << "initialized";
1538 } 1540 }
1539 } 1541 }
1540 1542
1541 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { 1543 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() {
1542 return failed_datatypes_handler_; 1544 return failed_datatypes_handler_;
1543 } 1545 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_harness.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698