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::REASON_PASSPHRASE_NOT_REQUIRED), |
| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); | 372 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); |
| 373 if (doomed_backend.get()) { | 373 if (doomed_backend.get()) { |
| 374 doomed_backend->Shutdown(sync_disabled); | 374 doomed_backend->Shutdown(sync_disabled); |
| 375 | 375 |
| 376 doomed_backend.reset(); | 376 doomed_backend.reset(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 // Clear various flags. | 379 // Clear various flags. |
| 380 is_auth_in_progress_ = false; | 380 is_auth_in_progress_ = false; |
| 381 backend_initialized_ = false; | 381 backend_initialized_ = false; |
| 382 observed_passphrase_required_ = false; | 382 observed_passphrase_required_ = false; |
|
Nicolas Zea
2011/04/29 22:59:30
Add clear of passphrase reason here too?
Raghu Simha
2011/04/30 00:43:06
Done.
| |
| 383 last_attempted_user_email_.clear(); | 383 last_attempted_user_email_.clear(); |
| 384 last_auth_error_ = GoogleServiceAuthError::None(); | 384 last_auth_error_ = GoogleServiceAuthError::None(); |
| 385 } | 385 } |
| 386 | 386 |
| 387 void ProfileSyncService::ClearServerData() { | 387 void ProfileSyncService::ClearServerData() { |
| 388 clear_server_data_state_ = CLEAR_CLEARING; | 388 clear_server_data_state_ = CLEAR_CLEARING; |
| 389 clear_server_data_timer_.Start( | 389 clear_server_data_timer_.Start( |
| 390 base::TimeDelta::FromSeconds(kSyncClearDataTimeoutInSeconds), this, | 390 base::TimeDelta::FromSeconds(kSyncClearDataTimeoutInSeconds), this, |
| 391 &ProfileSyncService::OnClearServerDataTimeout); | 391 &ProfileSyncService::OnClearServerDataTimeout); |
| 392 backend_->RequestClearServerData(); | 392 backend_->RequestClearServerData(); |
| (...skipping 192 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; |
|
tim (not reviewing)
2011/04/29 23:02:13
can we eliminate this and just check passphrase_re
Raghu Simha
2011/04/30 00:43:06
Done.
| |
| 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 // REASON_SET_PASSPHRASE_FAILED. | |
|
Nicolas Zea
2011/04/29 22:59:30
That's not true right? If the passphrase changes a
Raghu Simha
2011/04/30 00:43:06
The comment is outdated, misleading and probably u
| |
| 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::REASON_DECRYPTION || |
| 627 reason == sync_api::REASON_SET_PASSPHRASE_FAILED)) { | |
| 621 OnPassphraseAccepted(); | 628 OnPassphraseAccepted(); |
| 622 return; | 629 return; |
| 623 } | 630 } |
| 624 | 631 |
| 625 if (WizardIsVisible() && for_decryption) { | 632 if (WizardIsVisible() && |
| 633 (reason == sync_api::REASON_DECRYPTION || | |
| 634 reason == sync_api::REASON_SET_PASSPHRASE_FAILED)) { | |
| 626 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); | 635 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); |
| 627 } | 636 } |
| 628 | 637 |
| 629 NotifyObservers(); | 638 NotifyObservers(); |
| 630 } | 639 } |
| 631 | 640 |
| 632 void ProfileSyncService::OnPassphraseAccepted() { | 641 void ProfileSyncService::OnPassphraseAccepted() { |
| 633 // Make sure the data types that depend on the passphrase are started at | 642 // Make sure the data types that depend on the passphrase are started at |
| 634 // this time. | 643 // this time. |
| 635 syncable::ModelTypeSet types; | 644 syncable::ModelTypeSet types; |
| 636 GetPreferredDataTypes(&types); | 645 GetPreferredDataTypes(&types); |
| 637 // Reset "passphrase_required" flag before configuring the DataTypeManager | 646 |
| 638 // since we know we no longer require the passphrase. | 647 // Reset passphrase flags before configuring the DataTypeManager since we know |
| 648 // we no longer require the passphrase. | |
| 639 observed_passphrase_required_ = false; | 649 observed_passphrase_required_ = false; |
| 650 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; | |
| 651 | |
| 640 if (data_type_manager_.get()) | 652 if (data_type_manager_.get()) |
| 641 data_type_manager_->Configure(types); | 653 data_type_manager_->Configure(types); |
| 642 | 654 |
| 643 NotifyObservers(); | 655 NotifyObservers(); |
| 644 | 656 |
| 645 wizard_.Step(SyncSetupWizard::DONE); | 657 wizard_.Step(SyncSetupWizard::DONE); |
| 646 } | 658 } |
| 647 | 659 |
| 648 void ProfileSyncService::OnEncryptionComplete( | 660 void ProfileSyncService::OnEncryptionComplete( |
| 649 const syncable::ModelTypeSet& encrypted_types) { | 661 const syncable::ModelTypeSet& encrypted_types) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 syncable::ModelTypeSet types; | 986 syncable::ModelTypeSet types; |
| 975 GetPreferredDataTypes(&types); | 987 GetPreferredDataTypes(&types); |
| 976 // We set this special case here since it's the only datatype whose encryption | 988 // 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 | 989 // status we already know. All others are set after the initial sync |
| 978 // completes (for now). | 990 // completes (for now). |
| 979 // TODO(zea): Implement a better way that uses preferences for which types | 991 // TODO(zea): Implement a better way that uses preferences for which types |
| 980 // need encryption. | 992 // need encryption. |
| 981 encrypted_types_.clear(); | 993 encrypted_types_.clear(); |
| 982 if (types.count(syncable::PASSWORDS) > 0) | 994 if (types.count(syncable::PASSWORDS) > 0) |
| 983 encrypted_types_.insert(syncable::PASSWORDS); | 995 encrypted_types_.insert(syncable::PASSWORDS); |
| 984 if (observed_passphrase_required_ && passphrase_required_for_decryption_) { | 996 if (observed_passphrase_required_ && |
| 997 (passphrase_required_reason_ == sync_api::REASON_DECRYPTION || | |
| 998 passphrase_required_reason_ == sync_api::REASON_SET_PASSPHRASE_FAILED)) { | |
| 985 if (IsEncryptedDatatypeEnabled()) { | 999 if (IsEncryptedDatatypeEnabled()) { |
| 986 // We need a passphrase still. Prompt the user for a passphrase, and | 1000 // We need a passphrase still. Prompt the user for a passphrase, and |
| 987 // DataTypeManager::Configure() will get called once the passphrase is | 1001 // DataTypeManager::Configure() will get called once the passphrase is |
| 988 // accepted. | 1002 // accepted. |
| 989 OnPassphraseRequired(true); | 1003 OnPassphraseRequired(passphrase_required_reason_); |
| 990 return; | 1004 return; |
| 991 } else { | 1005 } else { |
| 992 // We've been informed that a passphrase is required for decryption, but | 1006 // 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 | 1007 // now there are no encrypted data types enabled, so clear the flag |
| 994 // (NotifyObservers() will be called when configuration completes). | 1008 // (NotifyObservers() will be called when configuration completes). |
| 995 observed_passphrase_required_ = false; | 1009 observed_passphrase_required_ = false; |
| 996 } | 1010 } |
| 997 } | 1011 } |
| 998 data_type_manager_->Configure(types); | 1012 data_type_manager_->Configure(types); |
| 999 } | 1013 } |
| (...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. | 1162 // Don't hold on to the passphrase in raw form longer than needed. |
| 1149 SetPassphrase(cached_passphrase_.value, | 1163 SetPassphrase(cached_passphrase_.value, |
| 1150 cached_passphrase_.is_explicit, | 1164 cached_passphrase_.is_explicit, |
| 1151 cached_passphrase_.is_creation); | 1165 cached_passphrase_.is_creation); |
| 1152 cached_passphrase_ = CachedPassphrase(); | 1166 cached_passphrase_ = CachedPassphrase(); |
| 1153 } | 1167 } |
| 1154 | 1168 |
| 1155 // We should never get in a state where we have no encrypted datatypes | 1169 // We should never get in a state where we have no encrypted datatypes |
| 1156 // enabled, and yet we still think we require a passphrase. | 1170 // enabled, and yet we still think we require a passphrase. |
| 1157 DCHECK(!(observed_passphrase_required_ && | 1171 DCHECK(!(observed_passphrase_required_ && |
| 1158 passphrase_required_for_decryption_ && | 1172 (passphrase_required_reason_ == sync_api::REASON_DECRYPTION || |
| 1173 passphrase_required_reason_ == | |
| 1174 sync_api::REASON_SET_PASSPHRASE_FAILED) && | |
| 1159 !IsEncryptedDatatypeEnabled())); | 1175 !IsEncryptedDatatypeEnabled())); |
| 1160 | 1176 |
| 1161 // TODO(sync): Less wizard, more toast. | 1177 // TODO(sync): Less wizard, more toast. |
| 1162 wizard_.Step(SyncSetupWizard::DONE); | 1178 wizard_.Step(SyncSetupWizard::DONE); |
| 1163 NotifyObservers(); | 1179 NotifyObservers(); |
| 1164 | 1180 |
| 1165 // In the old world, this would be a no-op. With new syncer thread, | 1181 // 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 | 1182 // this is the point where it is safe to switch from config-mode to |
| 1167 // normal operation. | 1183 // normal operation. |
| 1168 backend_->StartSyncingWithServer(); | 1184 backend_->StartSyncingWithServer(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1195 // request and shouldn't override an explicit one. Thus, we either | 1211 // request and shouldn't override an explicit one. Thus, we either |
| 1196 // update the implicit passphrase (idempotent if the passphrase didn't | 1212 // update the implicit passphrase (idempotent if the passphrase didn't |
| 1197 // actually change), or the user has an explicit passphrase set so this | 1213 // actually change), or the user has an explicit passphrase set so this |
| 1198 // becomes a no-op. | 1214 // becomes a no-op. |
| 1199 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; | 1215 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; |
| 1200 SetPassphrase(successful->password, false, true); | 1216 SetPassphrase(successful->password, false, true); |
| 1201 | 1217 |
| 1202 // If this signin was to initiate a passphrase migration (on the | 1218 // If this signin was to initiate a passphrase migration (on the |
| 1203 // first computer, thus not for decryption), continue the migration. | 1219 // first computer, thus not for decryption), continue the migration. |
| 1204 if (passphrase_migration_in_progress_ && | 1220 if (passphrase_migration_in_progress_ && |
| 1205 !passphrase_required_for_decryption_) { | 1221 passphrase_required_reason_ != sync_api::REASON_DECRYPTION && |
| 1222 passphrase_required_reason_ != | |
| 1223 sync_api::REASON_SET_PASSPHRASE_FAILED) { | |
| 1206 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); | 1224 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); |
| 1207 passphrase_migration_in_progress_ = false; | 1225 passphrase_migration_in_progress_ = false; |
| 1208 } | 1226 } |
| 1209 | 1227 |
| 1210 break; | 1228 break; |
| 1211 } | 1229 } |
| 1212 case NotificationType::GOOGLE_SIGNIN_FAILED: { | 1230 case NotificationType::GOOGLE_SIGNIN_FAILED: { |
| 1213 GoogleServiceAuthError error = | 1231 GoogleServiceAuthError error = |
| 1214 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1232 *(Details<const GoogleServiceAuthError>(details).ptr()); |
| 1215 UpdateAuthErrorState(error); | 1233 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 | 1297 // is initialized, all enabled data types are consistent with one |
| 1280 // another, and no unrecoverable error has transpired. | 1298 // another, and no unrecoverable error has transpired. |
| 1281 if (unrecoverable_error_detected_) | 1299 if (unrecoverable_error_detected_) |
| 1282 return false; | 1300 return false; |
| 1283 | 1301 |
| 1284 if (!data_type_manager_.get()) | 1302 if (!data_type_manager_.get()) |
| 1285 return false; | 1303 return false; |
| 1286 | 1304 |
| 1287 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1305 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1288 } | 1306 } |
| OLD | NEW |