OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 const char* ProfileSyncService::kDevServerUrl = | 60 const char* ProfileSyncService::kDevServerUrl = |
61 "https://clients4.google.com/chrome-sync/dev"; | 61 "https://clients4.google.com/chrome-sync/dev"; |
62 | 62 |
63 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 63 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
64 | 64 |
65 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, | 65 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, |
66 Profile* profile, | 66 Profile* profile, |
67 const std::string& cros_user) | 67 const std::string& cros_user) |
68 : last_auth_error_(AuthError::None()), | 68 : last_auth_error_(AuthError::None()), |
| 69 tried_creating_explicit_passphrase_(false), |
| 70 tried_setting_explicit_passphrase_(false), |
69 observed_passphrase_required_(false), | 71 observed_passphrase_required_(false), |
70 passphrase_required_for_decryption_(false), | 72 passphrase_required_for_decryption_(false), |
71 factory_(factory), | 73 factory_(factory), |
72 profile_(profile), | 74 profile_(profile), |
73 cros_user_(cros_user), | 75 cros_user_(cros_user), |
74 sync_service_url_(kDevServerUrl), | 76 sync_service_url_(kDevServerUrl), |
75 backend_initialized_(false), | 77 backend_initialized_(false), |
76 is_auth_in_progress_(false), | 78 is_auth_in_progress_(false), |
77 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), | 79 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), |
78 unrecoverable_error_detected_(false), | 80 unrecoverable_error_detected_(false), |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 | 1014 |
1013 void ProfileSyncService::DeactivateDataType( | 1015 void ProfileSyncService::DeactivateDataType( |
1014 DataTypeController* data_type_controller, | 1016 DataTypeController* data_type_controller, |
1015 ChangeProcessor* change_processor) { | 1017 ChangeProcessor* change_processor) { |
1016 change_processor->Stop(); | 1018 change_processor->Stop(); |
1017 if (backend_.get()) | 1019 if (backend_.get()) |
1018 backend_->DeactivateDataType(data_type_controller, change_processor); | 1020 backend_->DeactivateDataType(data_type_controller, change_processor); |
1019 } | 1021 } |
1020 | 1022 |
1021 void ProfileSyncService::SetPassphrase(const std::string& passphrase, | 1023 void ProfileSyncService::SetPassphrase(const std::string& passphrase, |
1022 bool is_explicit) { | 1024 bool is_explicit, |
| 1025 bool is_creation) { |
1023 if (ShouldPushChanges() || observed_passphrase_required_) { | 1026 if (ShouldPushChanges() || observed_passphrase_required_) { |
1024 backend_->SetPassphrase(passphrase, is_explicit); | 1027 backend_->SetPassphrase(passphrase, is_explicit); |
1025 } else { | 1028 } else { |
1026 cached_passphrase_.value = passphrase; | 1029 cached_passphrase_.value = passphrase; |
1027 cached_passphrase_.is_explicit = is_explicit; | 1030 cached_passphrase_.is_explicit = is_explicit; |
| 1031 cached_passphrase_.is_creation = is_creation; |
1028 } | 1032 } |
| 1033 |
| 1034 if (is_explicit && is_creation) |
| 1035 tried_creating_explicit_passphrase_ = true; |
| 1036 else if (is_explicit) |
| 1037 tried_setting_explicit_passphrase_ = true; |
1029 } | 1038 } |
1030 | 1039 |
1031 void ProfileSyncService::Observe(NotificationType type, | 1040 void ProfileSyncService::Observe(NotificationType type, |
1032 const NotificationSource& source, | 1041 const NotificationSource& source, |
1033 const NotificationDetails& details) { | 1042 const NotificationDetails& details) { |
1034 switch (type.value) { | 1043 switch (type.value) { |
1035 case NotificationType::SYNC_CONFIGURE_START: { | 1044 case NotificationType::SYNC_CONFIGURE_START: { |
1036 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1045 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
1037 // TODO(sync): Maybe toast? | 1046 // TODO(sync): Maybe toast? |
1038 break; | 1047 break; |
1039 } | 1048 } |
1040 case NotificationType::SYNC_CONFIGURE_DONE: { | 1049 case NotificationType::SYNC_CONFIGURE_DONE: { |
1041 DataTypeManager::ConfigureResult result = | 1050 DataTypeManager::ConfigureResult result = |
1042 *(Details<DataTypeManager::ConfigureResult>(details).ptr()); | 1051 *(Details<DataTypeManager::ConfigureResult>(details).ptr()); |
1043 if (result == DataTypeManager::ABORTED && | 1052 if (result == DataTypeManager::ABORTED && |
1044 expect_sync_configuration_aborted_) { | 1053 expect_sync_configuration_aborted_) { |
1045 expect_sync_configuration_aborted_ = false; | 1054 expect_sync_configuration_aborted_ = false; |
1046 return; | 1055 return; |
1047 } | 1056 } |
1048 if (result != DataTypeManager::OK) { | 1057 if (result != DataTypeManager::OK) { |
1049 OnUnrecoverableError(FROM_HERE, "Sync Configuration failed."); | 1058 OnUnrecoverableError(FROM_HERE, "Sync Configuration failed."); |
1050 return; | 1059 return; |
1051 } | 1060 } |
1052 | 1061 |
1053 if (!cached_passphrase_.value.empty()) { | 1062 if (!cached_passphrase_.value.empty()) { |
1054 // Don't hold on to the passphrase in raw form longer than needed. | 1063 // Don't hold on to the passphrase in raw form longer than needed. |
1055 SetPassphrase(cached_passphrase_.value, | 1064 SetPassphrase(cached_passphrase_.value, |
1056 cached_passphrase_.is_explicit); | 1065 cached_passphrase_.is_explicit, |
| 1066 cached_passphrase_.is_creation); |
1057 cached_passphrase_ = CachedPassphrase(); | 1067 cached_passphrase_ = CachedPassphrase(); |
1058 } | 1068 } |
1059 | 1069 |
1060 // TODO(sync): Less wizard, more toast. | 1070 // TODO(sync): Less wizard, more toast. |
1061 if (!observed_passphrase_required_) | 1071 if (!observed_passphrase_required_) |
1062 wizard_.Step(SyncSetupWizard::DONE); | 1072 wizard_.Step(SyncSetupWizard::DONE); |
1063 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1073 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
1064 | 1074 |
1065 break; | 1075 break; |
1066 } | 1076 } |
1067 case NotificationType::SYNC_PASSPHRASE_REQUIRED: { | 1077 case NotificationType::SYNC_PASSPHRASE_REQUIRED: { |
1068 DCHECK(backend_.get()); | 1078 DCHECK(backend_.get()); |
1069 DCHECK(backend_->IsNigoriEnabled()); | 1079 DCHECK(backend_->IsNigoriEnabled()); |
1070 observed_passphrase_required_ = true; | 1080 observed_passphrase_required_ = true; |
1071 passphrase_required_for_decryption_ = *(Details<bool>(details).ptr()); | 1081 passphrase_required_for_decryption_ = *(Details<bool>(details).ptr()); |
1072 | 1082 |
1073 if (!cached_passphrase_.value.empty()) { | 1083 if (!cached_passphrase_.value.empty()) { |
1074 SetPassphrase(cached_passphrase_.value, | 1084 SetPassphrase(cached_passphrase_.value, |
1075 cached_passphrase_.is_explicit); | 1085 cached_passphrase_.is_explicit, |
| 1086 cached_passphrase_.is_creation); |
1076 cached_passphrase_ = CachedPassphrase(); | 1087 cached_passphrase_ = CachedPassphrase(); |
1077 break; | 1088 break; |
1078 } | 1089 } |
1079 | 1090 |
1080 if (WizardIsVisible()) { | 1091 if (WizardIsVisible()) { |
1081 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); | 1092 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); |
1082 } | 1093 } |
1083 | 1094 |
1084 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1095 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
1085 break; | 1096 break; |
1086 } | 1097 } |
1087 case NotificationType::SYNC_DATA_TYPES_UPDATED: { | 1098 case NotificationType::SYNC_DATA_TYPES_UPDATED: { |
1088 if (!HasSyncSetupCompleted()) break; | 1099 if (!HasSyncSetupCompleted()) break; |
1089 | 1100 |
1090 syncable::ModelTypeSet types; | 1101 syncable::ModelTypeSet types; |
1091 GetPreferredDataTypes(&types); | 1102 GetPreferredDataTypes(&types); |
1092 OnUserChoseDatatypes(false, types); | 1103 OnUserChoseDatatypes(false, types); |
1093 break; | 1104 break; |
1094 } | 1105 } |
1095 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { | 1106 case NotificationType::SYNC_PASSPHRASE_ACCEPTED: { |
1096 // Make sure the data types that depend on the passphrase are started at | 1107 // Make sure the data types that depend on the passphrase are started at |
1097 // this time. | 1108 // this time. |
1098 syncable::ModelTypeSet types; | 1109 syncable::ModelTypeSet types; |
1099 GetPreferredDataTypes(&types); | 1110 GetPreferredDataTypes(&types); |
1100 data_type_manager_->Configure(types); | 1111 data_type_manager_->Configure(types); |
1101 | 1112 |
1102 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1113 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
1103 observed_passphrase_required_ = false; | 1114 observed_passphrase_required_ = false; |
| 1115 tried_setting_explicit_passphrase_ = false; |
| 1116 tried_creating_explicit_passphrase_ = false; |
1104 | 1117 |
1105 wizard_.Step(SyncSetupWizard::DONE); | 1118 wizard_.Step(SyncSetupWizard::DONE); |
1106 break; | 1119 break; |
1107 } | 1120 } |
1108 case NotificationType::PREF_CHANGED: { | 1121 case NotificationType::PREF_CHANGED: { |
1109 std::string* pref_name = Details<std::string>(details).ptr(); | 1122 std::string* pref_name = Details<std::string>(details).ptr(); |
1110 if (*pref_name == prefs::kSyncManaged) { | 1123 if (*pref_name == prefs::kSyncManaged) { |
1111 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 1124 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
1112 if (*pref_sync_managed_) { | 1125 if (*pref_sync_managed_) { |
1113 DisableForUser(); | 1126 DisableForUser(); |
1114 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1127 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
1115 StartUp(); | 1128 StartUp(); |
1116 } | 1129 } |
1117 } | 1130 } |
1118 break; | 1131 break; |
1119 } | 1132 } |
1120 case NotificationType::GOOGLE_SIGNIN_SUCCESSFUL: { | 1133 case NotificationType::GOOGLE_SIGNIN_SUCCESSFUL: { |
1121 const GoogleServiceSigninSuccessDetails* successful = | 1134 const GoogleServiceSigninSuccessDetails* successful = |
1122 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); | 1135 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); |
1123 // We pass 'false' to SetPassphrase to denote that this is an implicit | 1136 // We pass 'false' to SetPassphrase to denote that this is an implicit |
1124 // request and shouldn't override an explicit one. Thus, we either | 1137 // request and shouldn't override an explicit one. Thus, we either |
1125 // update the implicit passphrase (idempotent if the passphrase didn't | 1138 // update the implicit passphrase (idempotent if the passphrase didn't |
1126 // actually change), or the user has an explicit passphrase set so this | 1139 // actually change), or the user has an explicit passphrase set so this |
1127 // becomes a no-op. | 1140 // becomes a no-op. |
1128 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; | 1141 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; |
1129 SetPassphrase(successful->password, false); | 1142 SetPassphrase(successful->password, false, true); |
1130 break; | 1143 break; |
1131 } | 1144 } |
1132 case NotificationType::GOOGLE_SIGNIN_FAILED: { | 1145 case NotificationType::GOOGLE_SIGNIN_FAILED: { |
1133 GoogleServiceAuthError error = | 1146 GoogleServiceAuthError error = |
1134 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1147 *(Details<const GoogleServiceAuthError>(details).ptr()); |
1135 UpdateAuthErrorState(error); | 1148 UpdateAuthErrorState(error); |
1136 break; | 1149 break; |
1137 } | 1150 } |
1138 case NotificationType::TOKEN_AVAILABLE: { | 1151 case NotificationType::TOKEN_AVAILABLE: { |
1139 if (AreCredentialsAvailable()) { | 1152 if (AreCredentialsAvailable()) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 // is initialized, all enabled data types are consistent with one | 1229 // is initialized, all enabled data types are consistent with one |
1217 // another, and no unrecoverable error has transpired. | 1230 // another, and no unrecoverable error has transpired. |
1218 if (unrecoverable_error_detected_) | 1231 if (unrecoverable_error_detected_) |
1219 return false; | 1232 return false; |
1220 | 1233 |
1221 if (!data_type_manager_.get()) | 1234 if (!data_type_manager_.get()) |
1222 return false; | 1235 return false; |
1223 | 1236 |
1224 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1237 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1225 } | 1238 } |
OLD | NEW |