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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 const char* ProfileSyncService::kDevServerUrl = | 62 const char* ProfileSyncService::kDevServerUrl = |
| 63 "https://clients4.google.com/chrome-sync/dev"; | 63 "https://clients4.google.com/chrome-sync/dev"; |
| 64 | 64 |
| 65 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 65 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
| 66 | 66 |
| 67 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, | 67 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, |
| 68 Profile* profile, | 68 Profile* profile, |
| 69 const std::string& cros_user) | 69 const std::string& cros_user) |
| 70 : last_auth_error_(AuthError::None()), | 70 : last_auth_error_(AuthError::None()), |
| 71 observed_passphrase_required_(false), | 71 observed_passphrase_required_(false), |
| 72 passphrase_required_for_decryption_(false), | 72 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.
| |
| 73 passphrase_migration_in_progress_(false), | 73 passphrase_migration_in_progress_(false), |
| 74 factory_(factory), | 74 factory_(factory), |
| 75 profile_(profile), | 75 profile_(profile), |
| 76 cros_user_(cros_user), | 76 cros_user_(cros_user), |
| 77 sync_service_url_(kDevServerUrl), | 77 sync_service_url_(kDevServerUrl), |
| 78 backend_initialized_(false), | 78 backend_initialized_(false), |
| 79 is_auth_in_progress_(false), | 79 is_auth_in_progress_(false), |
| 80 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 80 wizard_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 81 unrecoverable_error_detected_(false), | 81 unrecoverable_error_detected_(false), |
| 82 scoped_runnable_method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 82 scoped_runnable_method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 clear_server_data_timer_.Stop(); | 585 clear_server_data_timer_.Stop(); |
| 586 | 586 |
| 587 // Even if the timout fired, we still transition to the succeeded state as | 587 // Even if the timout fired, we still transition to the succeeded state as |
| 588 // we want UI to update itself and no longer allow the user to press "clear" | 588 // we want UI to update itself and no longer allow the user to press "clear" |
| 589 if (clear_server_data_state_ != CLEAR_SUCCEEDED) { | 589 if (clear_server_data_state_ != CLEAR_SUCCEEDED) { |
| 590 clear_server_data_state_ = CLEAR_SUCCEEDED; | 590 clear_server_data_state_ = CLEAR_SUCCEEDED; |
| 591 NotifyObservers(); | 591 NotifyObservers(); |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 void ProfileSyncService::OnPassphraseRequired(bool for_decryption) { | 595 void ProfileSyncService::OnPassphraseRequired( |
| 596 sync_api::PassphraseRequiredReason reason) { | |
| 596 DCHECK(backend_.get()); | 597 DCHECK(backend_.get()); |
| 597 DCHECK(backend_->IsNigoriEnabled()); | 598 DCHECK(backend_->IsNigoriEnabled()); |
| 598 | 599 |
| 599 // TODO(lipalani) : add this check to other locations as well. | 600 // TODO(lipalani) : add this check to other locations as well. |
| 600 if (unrecoverable_error_detected_) { | 601 if (unrecoverable_error_detected_) { |
| 601 // When unrecoverable error is detected we post a task to shutdown the | 602 // When unrecoverable error is detected we post a task to shutdown the |
| 602 // backend. The task might not have executed yet. | 603 // backend. The task might not have executed yet. |
| 603 return; | 604 return; |
| 604 } | 605 } |
| 605 observed_passphrase_required_ = true; | 606 observed_passphrase_required_ = true; |
| 606 passphrase_required_for_decryption_ = for_decryption; | 607 |
| 608 // Set passphrase_required_reason_ based on whether the passphrase is required | |
| 609 // for encryption or for decryption with a cached passphrase. If decryption | |
| 610 // failed and a new passphrase is required, the flag will already be set to | |
| 611 // DECRYPTION_FAILED. | |
| 612 passphrase_required_reason_ = reason; | |
| 607 | 613 |
| 608 if (!cached_passphrase_.value.empty()) { | 614 if (!cached_passphrase_.value.empty()) { |
| 609 SetPassphrase(cached_passphrase_.value, | 615 SetPassphrase(cached_passphrase_.value, |
| 610 cached_passphrase_.is_explicit, | 616 cached_passphrase_.is_explicit, |
| 611 cached_passphrase_.is_creation); | 617 cached_passphrase_.is_creation); |
| 612 cached_passphrase_ = CachedPassphrase(); | 618 cached_passphrase_ = CachedPassphrase(); |
| 613 return; | 619 return; |
| 614 } | 620 } |
| 615 | 621 |
| 616 // We will skip the passphrase prompt and suppress the warning | 622 // We will skip the passphrase prompt and suppress the warning if the |
| 617 // if the passphrase is needed for decryption but the user is | 623 // passphrase is needed for decryption but the user is not syncing an |
| 618 // not syncing an encrypted data type on this machine. | 624 // encrypted data type on this machine. Otherwise we prompt. |
| 619 // Otherwise we prompt. | 625 if (!IsEncryptedDatatypeEnabled() && |
| 620 if (!IsEncryptedDatatypeEnabled() && for_decryption) { | 626 reason == sync_api::DECRYPTION || reason == sync_api::DECRYPTION_FAILED) { |
| 621 OnPassphraseAccepted(); | 627 OnPassphraseAccepted(); |
| 622 return; | 628 return; |
| 623 } | 629 } |
| 624 | 630 |
| 625 if (WizardIsVisible() && for_decryption) { | 631 if (WizardIsVisible() && |
| 632 reason == sync_api::DECRYPTION || reason == sync_api::DECRYPTION_FAILED) { | |
| 626 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); | 633 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); |
| 627 } | 634 } |
| 628 | 635 |
| 629 NotifyObservers(); | 636 NotifyObservers(); |
| 630 } | 637 } |
| 631 | 638 |
| 632 void ProfileSyncService::OnPassphraseAccepted() { | 639 void ProfileSyncService::OnPassphraseAccepted() { |
| 633 // Make sure the data types that depend on the passphrase are started at | 640 // Make sure the data types that depend on the passphrase are started at |
| 634 // this time. | 641 // this time. |
| 635 syncable::ModelTypeSet types; | 642 syncable::ModelTypeSet types; |
| 636 GetPreferredDataTypes(&types); | 643 GetPreferredDataTypes(&types); |
| 637 // Reset "passphrase_required" flag before configuring the DataTypeManager | 644 |
| 638 // since we know we no longer require the passphrase. | 645 // Reset passphrase flags before configuring the DataTypeManager since we know |
| 646 // we no longer require the passphrase. | |
| 639 observed_passphrase_required_ = false; | 647 observed_passphrase_required_ = false; |
| 648 passphrase_required_reason_ = sync_api::UNKNOWN; | |
| 649 | |
| 640 if (data_type_manager_.get()) | 650 if (data_type_manager_.get()) |
| 641 data_type_manager_->Configure(types); | 651 data_type_manager_->Configure(types); |
| 642 | 652 |
| 643 NotifyObservers(); | 653 NotifyObservers(); |
| 644 | 654 |
| 645 wizard_.Step(SyncSetupWizard::DONE); | 655 wizard_.Step(SyncSetupWizard::DONE); |
| 646 } | 656 } |
| 647 | 657 |
| 648 void ProfileSyncService::OnEncryptionComplete( | 658 void ProfileSyncService::OnEncryptionComplete( |
| 649 const syncable::ModelTypeSet& encrypted_types) { | 659 const syncable::ModelTypeSet& encrypted_types) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 syncable::ModelTypeSet types; | 984 syncable::ModelTypeSet types; |
| 975 GetPreferredDataTypes(&types); | 985 GetPreferredDataTypes(&types); |
| 976 // We set this special case here since it's the only datatype whose encryption | 986 // We set this special case here since it's the only datatype whose encryption |
| 977 // status we already know. All others are set after the initial sync | 987 // status we already know. All others are set after the initial sync |
| 978 // completes (for now). | 988 // completes (for now). |
| 979 // TODO(zea): Implement a better way that uses preferences for which types | 989 // TODO(zea): Implement a better way that uses preferences for which types |
| 980 // need encryption. | 990 // need encryption. |
| 981 encrypted_types_.clear(); | 991 encrypted_types_.clear(); |
| 982 if (types.count(syncable::PASSWORDS) > 0) | 992 if (types.count(syncable::PASSWORDS) > 0) |
| 983 encrypted_types_.insert(syncable::PASSWORDS); | 993 encrypted_types_.insert(syncable::PASSWORDS); |
| 984 if (observed_passphrase_required_ && passphrase_required_for_decryption_) { | 994 if (observed_passphrase_required_ && |
| 995 (passphrase_required_reason_ == sync_api::DECRYPTION || | |
| 996 passphrase_required_reason_ == sync_api::DECRYPTION_FAILED)) { | |
| 985 if (IsEncryptedDatatypeEnabled()) { | 997 if (IsEncryptedDatatypeEnabled()) { |
| 986 // We need a passphrase still. Prompt the user for a passphrase, and | 998 // We need a passphrase still. Prompt the user for a passphrase, and |
| 987 // DataTypeManager::Configure() will get called once the passphrase is | 999 // DataTypeManager::Configure() will get called once the passphrase is |
| 988 // accepted. | 1000 // accepted. |
| 989 OnPassphraseRequired(true); | 1001 OnPassphraseRequired(passphrase_required_reason_); |
| 990 return; | 1002 return; |
| 991 } else { | 1003 } else { |
| 992 // We've been informed that a passphrase is required for decryption, but | 1004 // We've been informed that a passphrase is required for decryption, but |
| 993 // now there are no encrypted data types enabled, so clear the flag | 1005 // now there are no encrypted data types enabled, so clear the flag |
| 994 // (NotifyObservers() will be called when configuration completes). | 1006 // (NotifyObservers() will be called when configuration completes). |
| 995 observed_passphrase_required_ = false; | 1007 observed_passphrase_required_ = false; |
| 996 } | 1008 } |
| 997 } | 1009 } |
| 998 data_type_manager_->Configure(types); | 1010 data_type_manager_->Configure(types); |
| 999 } | 1011 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1148 // Don't hold on to the passphrase in raw form longer than needed. | 1160 // Don't hold on to the passphrase in raw form longer than needed. |
| 1149 SetPassphrase(cached_passphrase_.value, | 1161 SetPassphrase(cached_passphrase_.value, |
| 1150 cached_passphrase_.is_explicit, | 1162 cached_passphrase_.is_explicit, |
| 1151 cached_passphrase_.is_creation); | 1163 cached_passphrase_.is_creation); |
| 1152 cached_passphrase_ = CachedPassphrase(); | 1164 cached_passphrase_ = CachedPassphrase(); |
| 1153 } | 1165 } |
| 1154 | 1166 |
| 1155 // We should never get in a state where we have no encrypted datatypes | 1167 // We should never get in a state where we have no encrypted datatypes |
| 1156 // enabled, and yet we still think we require a passphrase. | 1168 // enabled, and yet we still think we require a passphrase. |
| 1157 DCHECK(!(observed_passphrase_required_ && | 1169 DCHECK(!(observed_passphrase_required_ && |
| 1158 passphrase_required_for_decryption_ && | 1170 (passphrase_required_reason_ == sync_api::DECRYPTION || |
| 1171 passphrase_required_reason_ == sync_api::DECRYPTION_FAILED) && | |
| 1159 !IsEncryptedDatatypeEnabled())); | 1172 !IsEncryptedDatatypeEnabled())); |
| 1160 | 1173 |
| 1161 // TODO(sync): Less wizard, more toast. | 1174 // TODO(sync): Less wizard, more toast. |
| 1162 wizard_.Step(SyncSetupWizard::DONE); | 1175 wizard_.Step(SyncSetupWizard::DONE); |
| 1163 NotifyObservers(); | 1176 NotifyObservers(); |
| 1164 | 1177 |
| 1165 // In the old world, this would be a no-op. With new syncer thread, | 1178 // In the old world, this would be a no-op. With new syncer thread, |
| 1166 // this is the point where it is safe to switch from config-mode to | 1179 // this is the point where it is safe to switch from config-mode to |
| 1167 // normal operation. | 1180 // normal operation. |
| 1168 backend_->StartSyncingWithServer(); | 1181 backend_->StartSyncingWithServer(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1195 // request and shouldn't override an explicit one. Thus, we either | 1208 // request and shouldn't override an explicit one. Thus, we either |
| 1196 // update the implicit passphrase (idempotent if the passphrase didn't | 1209 // update the implicit passphrase (idempotent if the passphrase didn't |
| 1197 // actually change), or the user has an explicit passphrase set so this | 1210 // actually change), or the user has an explicit passphrase set so this |
| 1198 // becomes a no-op. | 1211 // becomes a no-op. |
| 1199 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; | 1212 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; |
| 1200 SetPassphrase(successful->password, false, true); | 1213 SetPassphrase(successful->password, false, true); |
| 1201 | 1214 |
| 1202 // If this signin was to initiate a passphrase migration (on the | 1215 // If this signin was to initiate a passphrase migration (on the |
| 1203 // first computer, thus not for decryption), continue the migration. | 1216 // first computer, thus not for decryption), continue the migration. |
| 1204 if (passphrase_migration_in_progress_ && | 1217 if (passphrase_migration_in_progress_ && |
| 1205 !passphrase_required_for_decryption_) { | 1218 passphrase_required_reason_ != sync_api::DECRYPTION && |
| 1219 passphrase_required_reason_ != sync_api::DECRYPTION_FAILED) { | |
| 1206 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); | 1220 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); |
| 1207 passphrase_migration_in_progress_ = false; | 1221 passphrase_migration_in_progress_ = false; |
| 1208 } | 1222 } |
| 1209 | 1223 |
| 1210 break; | 1224 break; |
| 1211 } | 1225 } |
| 1212 case NotificationType::GOOGLE_SIGNIN_FAILED: { | 1226 case NotificationType::GOOGLE_SIGNIN_FAILED: { |
| 1213 GoogleServiceAuthError error = | 1227 GoogleServiceAuthError error = |
| 1214 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1228 *(Details<const GoogleServiceAuthError>(details).ptr()); |
| 1215 UpdateAuthErrorState(error); | 1229 UpdateAuthErrorState(error); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 // is initialized, all enabled data types are consistent with one | 1293 // is initialized, all enabled data types are consistent with one |
| 1280 // another, and no unrecoverable error has transpired. | 1294 // another, and no unrecoverable error has transpired. |
| 1281 if (unrecoverable_error_detected_) | 1295 if (unrecoverable_error_detected_) |
| 1282 return false; | 1296 return false; |
| 1283 | 1297 |
| 1284 if (!data_type_manager_.get()) | 1298 if (!data_type_manager_.get()) |
| 1285 return false; | 1299 return false; |
| 1286 | 1300 |
| 1287 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1301 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1288 } | 1302 } |
| OLD | NEW |