Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 // If No encryption is pending and our passphrase has been accepted, tell the | 831 // If No encryption is pending and our passphrase has been accepted, tell the |
| 828 // wizard we're done (no need to hang around waiting for the sync to | 832 // wizard we're done (no need to hang around waiting for the sync to |
| 829 // complete). If encryption is pending, its successful completion will trigger | 833 // complete). If encryption is pending, its successful completion will trigger |
| 830 // the done step. | 834 // the done step. |
| 831 if (WizardIsVisible() && !encryption_pending()) | 835 if (WizardIsVisible() && !encryption_pending()) |
| 832 wizard_.Step(SyncSetupWizard::DONE); | 836 wizard_.Step(SyncSetupWizard::DONE); |
| 833 | 837 |
| 834 NotifyObservers(); | 838 NotifyObservers(); |
| 835 } | 839 } |
| 836 | 840 |
| 837 void ProfileSyncService::OnEncryptionComplete( | 841 void ProfileSyncService::OnEncryptedTypesChanged( |
| 838 const syncable::ModelTypeSet& encrypted_types) { | 842 const syncable::ModelTypeSet& encrypted_types, |
| 843 bool encrypt_everything) { | |
| 844 encrypted_types_ = encrypted_types; | |
| 845 encrypt_everything_ = encrypt_everything; | |
| 846 VLOG(2) << "Encrypted types changed to " | |
|
Nicolas Zea
2011/10/21 14:29:07
Since these now happen relatively rarely, I'd pref
akalin
2011/10/22 03:28:38
Done.
| |
| 847 << syncable::ModelTypeSetToString(encrypted_types_) | |
| 848 << " (encrypt everything is set to " | |
| 849 << (encrypt_everything_ ? "true" : "false") << ")"; | |
| 850 DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u); | |
| 851 } | |
| 852 | |
| 853 void ProfileSyncService::OnEncryptionComplete() { | |
| 854 VLOG(2) << "Encryption complete for " | |
| 855 << syncable::ModelTypeSetToString(encrypted_types_); | |
| 856 DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u); | |
| 839 if (encryption_pending_) { | 857 if (encryption_pending_) { |
| 840 syncable::ModelTypeSet registered_types; | 858 syncable::ModelTypeSet registered_types; |
| 841 GetRegisteredDataTypes(®istered_types); | 859 GetRegisteredDataTypes(®istered_types); |
| 842 bool encryption_complete = true; | 860 bool encryption_complete = true; |
| 843 for (syncable::ModelTypeSet::const_iterator it = registered_types.begin(); | 861 for (syncable::ModelTypeSet::const_iterator it = registered_types.begin(); |
|
Nicolas Zea
2011/10/21 14:29:07
I think now that we're receiving the encrypt_every
akalin
2011/10/22 03:28:38
Yeah. But we still need to wait for encryption to
| |
| 844 it != registered_types.end(); | 862 it != registered_types.end(); |
| 845 ++it) { | 863 ++it) { |
| 846 if (encrypted_types.count(*it) == 0) { | 864 if (encrypted_types_.count(*it) == 0) { |
| 847 // One of our types is not yet encrypted - keep waiting. | 865 // One of our types is not yet encrypted - keep waiting. |
| 848 encryption_complete = false; | 866 encryption_complete = false; |
| 849 break; | 867 break; |
| 850 } | 868 } |
| 851 } | 869 } |
| 852 if (encryption_complete) { | 870 if (encryption_complete) { |
| 853 encryption_pending_ = false; | 871 encryption_pending_ = false; |
| 854 // The user had chosen to encrypt datatypes. This is the last thing to | 872 // The user had chosen to encrypt datatypes. This is the last thing to |
| 855 // complete, so now that we're done notify the UI. | 873 // complete, so now that we're done notify the UI. |
| 856 wizard_.Step(SyncSetupWizard::DONE); | 874 wizard_.Step(SyncSetupWizard::DONE); |
| 875 // This is to nudge the integration tests when encryption is | |
| 876 // finished. | |
| 877 NotifyObservers(); | |
| 857 } | 878 } |
| 858 } | 879 } |
| 859 NotifyObservers(); | |
| 860 } | 880 } |
| 861 | 881 |
| 862 void ProfileSyncService::OnMigrationNeededForTypes( | 882 void ProfileSyncService::OnMigrationNeededForTypes( |
| 863 const syncable::ModelTypeSet& types) { | 883 const syncable::ModelTypeSet& types) { |
| 864 DCHECK(backend_initialized_); | 884 DCHECK(backend_initialized_); |
| 865 DCHECK(data_type_manager_.get()); | 885 DCHECK(data_type_manager_.get()); |
| 866 | 886 |
| 867 // Migrator must be valid, because we don't sync until it is created and this | 887 // Migrator must be valid, because we don't sync until it is created and this |
| 868 // callback originates from a sync cycle. | 888 // callback originates from a sync cycle. |
| 869 migrator_->MigrateTypes(types); | 889 migrator_->MigrateTypes(types); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1313 } else { | 1333 } else { |
| 1314 if (is_explicit) { | 1334 if (is_explicit) { |
| 1315 cached_passphrases_.explicit_passphrase = passphrase; | 1335 cached_passphrases_.explicit_passphrase = passphrase; |
| 1316 } else { | 1336 } else { |
| 1317 cached_passphrases_.gaia_passphrase = passphrase; | 1337 cached_passphrases_.gaia_passphrase = passphrase; |
| 1318 } | 1338 } |
| 1319 } | 1339 } |
| 1320 } | 1340 } |
| 1321 | 1341 |
| 1322 void ProfileSyncService::SetEncryptEverything(bool encrypt_everything) { | 1342 void ProfileSyncService::SetEncryptEverything(bool encrypt_everything) { |
| 1343 // We may be called during the setup process before we're | |
|
Nicolas Zea
2011/10/21 14:29:07
I understand GetEncryptedTypes being called by the
akalin
2011/10/22 03:28:38
Called by some unittests; see comment. :/
| |
| 1344 // initialized. | |
| 1323 encryption_pending_ = encrypt_everything; | 1345 encryption_pending_ = encrypt_everything; |
| 1346 // Callers shouldn't try to disable encrypt everything once it has | |
| 1347 // already succeeded. | |
| 1348 DCHECK(!encrypt_everything_); | |
| 1324 } | 1349 } |
| 1325 | 1350 |
| 1326 bool ProfileSyncService::encryption_pending() const { | 1351 bool ProfileSyncService::encryption_pending() const { |
| 1352 // We may be called during the setup process before we're | |
| 1353 // initialized. | |
|
Nicolas Zea
2011/10/21 14:29:07
Comment that this is because it's used by IsEncryp
akalin
2011/10/22 03:28:38
Done.
| |
| 1327 return encryption_pending_; | 1354 return encryption_pending_; |
| 1328 } | 1355 } |
| 1329 | 1356 |
| 1330 bool ProfileSyncService::EncryptEverythingEnabled() const { | 1357 bool ProfileSyncService::EncryptEverythingEnabled() const { |
| 1331 if (!backend_.get() || !backend_initialized_) { | 1358 DCHECK(backend_initialized_); |
| 1332 NOTREACHED() << "Cannot check encryption without initialized backend."; | 1359 return encrypt_everything_; |
| 1333 return false; | |
| 1334 } | |
| 1335 return backend_->EncryptEverythingEnabled(); | |
| 1336 } | 1360 } |
| 1337 | 1361 |
| 1338 // This will open a transaction to get the encrypted types. Do not call this | |
| 1339 // if you already have a transaction open. | |
| 1340 void ProfileSyncService::GetEncryptedDataTypes( | 1362 void ProfileSyncService::GetEncryptedDataTypes( |
| 1341 syncable::ModelTypeSet* encrypted_types) const { | 1363 syncable::ModelTypeSet* encrypted_types) const { |
| 1342 CHECK(encrypted_types); | 1364 CHECK(encrypted_types); |
| 1343 if (backend_.get()) { | 1365 // We may be called during the setup process before we're |
| 1344 *encrypted_types = backend_->GetEncryptedDataTypes(); | 1366 // initialized. |
|
Nicolas Zea
2011/10/21 14:29:07
Add something like "In this case, we'll default to
akalin
2011/10/22 03:28:38
Done.
| |
| 1345 DCHECK(encrypted_types->count(syncable::PASSWORDS)); | 1367 *encrypted_types = encrypted_types_; |
| 1346 } else { | 1368 DCHECK_GT(encrypted_types->count(syncable::PASSWORDS), 0u); |
| 1347 // Either we are in an unrecoverable error or the sync is not yet done | |
| 1348 // initializing. In either case just return the sensitive types. During | |
| 1349 // sync initialization the UI might need to know what our encrypted | |
| 1350 // types are. | |
| 1351 *encrypted_types = browser_sync::Cryptographer::SensitiveTypes(); | |
| 1352 DCHECK(encrypted_types->count(syncable::PASSWORDS)); | |
| 1353 } | |
| 1354 } | 1369 } |
| 1355 | 1370 |
| 1356 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { | 1371 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { |
| 1357 NotifyObservers(); | 1372 NotifyObservers(); |
| 1358 if (is_sync_managed) { | 1373 if (is_sync_managed) { |
| 1359 DisableForUser(); | 1374 DisableForUser(); |
| 1360 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1375 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
| 1361 StartUp(); | 1376 StartUp(); |
| 1362 } | 1377 } |
| 1363 } | 1378 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1530 << "Unrecoverable error."; | 1545 << "Unrecoverable error."; |
| 1531 } else { | 1546 } else { |
| 1532 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1547 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
| 1533 << "initialized"; | 1548 << "initialized"; |
| 1534 } | 1549 } |
| 1535 } | 1550 } |
| 1536 | 1551 |
| 1537 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1552 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
| 1538 return failed_datatypes_handler_; | 1553 return failed_datatypes_handler_; |
| 1539 } | 1554 } |
| OLD | NEW |