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

Unified Diff: chrome/browser/sync/profile_sync_service.cc

Issue 6902101: Refactor sync passphrase setup flow and fix passphrase tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove OnPassphraseFailed; Plumb enum all the way through; Shave yak. Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/profile_sync_service.cc
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index d6347d85b9ffdac614afb43f20dda792dd20f129..41daff5574c9e780da84aaae7f5b54f72a74530a 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -69,7 +69,7 @@ ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory,
const std::string& cros_user)
: last_auth_error_(AuthError::None()),
observed_passphrase_required_(false),
- passphrase_required_for_decryption_(false),
+ passphrase_required_reason_(sync_api::UNKNOWN),
tim (not reviewing) 2011/04/29 01:21:48 i think I liked NO_REASON better
Raghu Simha 2011/04/29 18:59:14 Done.
passphrase_migration_in_progress_(false),
factory_(factory),
profile_(profile),
@@ -592,7 +592,8 @@ void ProfileSyncService::OnClearServerDataSucceeded() {
}
}
-void ProfileSyncService::OnPassphraseRequired(bool for_decryption) {
+void ProfileSyncService::OnPassphraseRequired(
+ sync_api::PassphraseRequiredReason reason) {
DCHECK(backend_.get());
DCHECK(backend_->IsNigoriEnabled());
@@ -603,7 +604,12 @@ void ProfileSyncService::OnPassphraseRequired(bool for_decryption) {
return;
}
observed_passphrase_required_ = true;
- passphrase_required_for_decryption_ = for_decryption;
+
+ // Set passphrase_required_reason_ based on whether the passphrase is required
+ // for encryption or for decryption with a cached passphrase. If decryption
+ // failed and a new passphrase is required, the flag will already be set to
+ // DECRYPTION_FAILED.
+ passphrase_required_reason_ = reason;
if (!cached_passphrase_.value.empty()) {
SetPassphrase(cached_passphrase_.value,
@@ -613,16 +619,17 @@ void ProfileSyncService::OnPassphraseRequired(bool for_decryption) {
return;
}
- // We will skip the passphrase prompt and suppress the warning
- // if the passphrase is needed for decryption but the user is
- // not syncing an encrypted data type on this machine.
- // Otherwise we prompt.
- if (!IsEncryptedDatatypeEnabled() && for_decryption) {
+ // We will skip the passphrase prompt and suppress the warning if the
+ // passphrase is needed for decryption but the user is not syncing an
+ // encrypted data type on this machine. Otherwise we prompt.
+ if (!IsEncryptedDatatypeEnabled() &&
+ reason == sync_api::DECRYPTION || reason == sync_api::DECRYPTION_FAILED) {
OnPassphraseAccepted();
return;
}
- if (WizardIsVisible() && for_decryption) {
+ if (WizardIsVisible() &&
+ reason == sync_api::DECRYPTION || reason == sync_api::DECRYPTION_FAILED) {
wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE);
}
@@ -634,9 +641,12 @@ void ProfileSyncService::OnPassphraseAccepted() {
// this time.
syncable::ModelTypeSet types;
GetPreferredDataTypes(&types);
- // Reset "passphrase_required" flag before configuring the DataTypeManager
- // since we know we no longer require the passphrase.
+
+ // Reset passphrase flags before configuring the DataTypeManager since we know
+ // we no longer require the passphrase.
observed_passphrase_required_ = false;
+ passphrase_required_reason_ = sync_api::UNKNOWN;
+
if (data_type_manager_.get())
data_type_manager_->Configure(types);
@@ -981,12 +991,14 @@ void ProfileSyncService::ConfigureDataTypeManager() {
encrypted_types_.clear();
if (types.count(syncable::PASSWORDS) > 0)
encrypted_types_.insert(syncable::PASSWORDS);
- if (observed_passphrase_required_ && passphrase_required_for_decryption_) {
+ if (observed_passphrase_required_ &&
+ (passphrase_required_reason_ == sync_api::DECRYPTION ||
+ passphrase_required_reason_ == sync_api::DECRYPTION_FAILED)) {
if (IsEncryptedDatatypeEnabled()) {
// We need a passphrase still. Prompt the user for a passphrase, and
// DataTypeManager::Configure() will get called once the passphrase is
// accepted.
- OnPassphraseRequired(true);
+ OnPassphraseRequired(passphrase_required_reason_);
return;
} else {
// We've been informed that a passphrase is required for decryption, but
@@ -1155,7 +1167,8 @@ void ProfileSyncService::Observe(NotificationType type,
// We should never get in a state where we have no encrypted datatypes
// enabled, and yet we still think we require a passphrase.
DCHECK(!(observed_passphrase_required_ &&
- passphrase_required_for_decryption_ &&
+ (passphrase_required_reason_ == sync_api::DECRYPTION ||
+ passphrase_required_reason_ == sync_api::DECRYPTION_FAILED) &&
!IsEncryptedDatatypeEnabled()));
// TODO(sync): Less wizard, more toast.
@@ -1202,7 +1215,8 @@ void ProfileSyncService::Observe(NotificationType type,
// If this signin was to initiate a passphrase migration (on the
// first computer, thus not for decryption), continue the migration.
if (passphrase_migration_in_progress_ &&
- !passphrase_required_for_decryption_) {
+ passphrase_required_reason_ != sync_api::DECRYPTION &&
+ passphrase_required_reason_ != sync_api::DECRYPTION_FAILED) {
wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION);
passphrase_migration_in_progress_ = false;
}

Powered by Google App Engine
This is Rietveld 408576698