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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 | 111 |
112 bool ProfileSyncService::AreCredentialsAvailable() { | 112 bool ProfileSyncService::AreCredentialsAvailable() { |
113 if (IsManaged()) { | 113 if (IsManaged()) { |
114 return false; | 114 return false; |
115 } | 115 } |
116 | 116 |
117 // CrOS user is always logged in. Chrome uses signin_ to check logged in. | 117 // CrOS user is always logged in. Chrome uses signin_ to check logged in. |
118 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { | 118 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { |
119 // TODO(chron): Verify CrOS unit test behavior. | 119 // TODO(chron): Verify CrOS unit test behavior. |
120 if (profile()->GetTokenService() && | 120 return profile()->GetTokenService() && |
121 profile()->GetTokenService()->HasTokenForService( | 121 profile()->GetTokenService()->HasTokenForService( |
122 GaiaConstants::kSyncService)) { | 122 SyncSetupWizard::IsUsingOAuth() ? |
123 return true; | 123 GaiaConstants::kSyncServiceOAuth : |
124 } | 124 GaiaConstants::kSyncService); |
125 } | 125 } |
126 return false; | 126 return false; |
127 } | 127 } |
128 | 128 |
129 void ProfileSyncService::Initialize() { | 129 void ProfileSyncService::Initialize() { |
130 InitSettings(); | 130 InitSettings(); |
131 RegisterPreferences(); | 131 RegisterPreferences(); |
132 | 132 |
133 // We clear this here (vs Shutdown) because we want to remember that an error | 133 // We clear this here (vs Shutdown) because we want to remember that an error |
134 // happened on shutdown so we can display details (message, location) about it | 134 // happened on shutdown so we can display details (message, location) about it |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void ProfileSyncService::RegisterPreferences() { | 258 void ProfileSyncService::RegisterPreferences() { |
259 PrefService* pref_service = profile_->GetPrefs(); | 259 PrefService* pref_service = profile_->GetPrefs(); |
260 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) | 260 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) |
261 return; | 261 return; |
262 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, | 262 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, |
263 0, | 263 0, |
264 PrefService::UNSYNCABLE_PREF); | 264 PrefService::UNSYNCABLE_PREF); |
265 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, | 265 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, |
266 false, | 266 false, |
267 PrefService::UNSYNCABLE_PREF); | 267 PrefService::UNSYNCABLE_PREF); |
| 268 pref_service->RegisterBooleanPref(prefs::kSyncUsingOAuth, |
| 269 false, |
| 270 PrefService::UNSYNCABLE_PREF); |
268 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, | 271 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, |
269 false, | 272 false, |
270 PrefService::UNSYNCABLE_PREF); | 273 PrefService::UNSYNCABLE_PREF); |
271 | 274 |
272 // If you've never synced before, or if you're using Chrome OS, all datatypes | 275 // If you've never synced before, or if you're using Chrome OS, all datatypes |
273 // are on by default. | 276 // are on by default. |
274 // TODO(nick): Perhaps a better model would be to always default to false, | 277 // TODO(nick): Perhaps a better model would be to always default to false, |
275 // and explicitly call SetDataTypes() when the user shows the wizard. | 278 // and explicitly call SetDataTypes() when the user shows the wizard. |
276 #if defined(OS_CHROMEOS) | 279 #if defined(OS_CHROMEOS) |
277 bool enable_by_default = true; | 280 bool enable_by_default = true; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 331 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
329 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); | 332 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); |
330 | 333 |
331 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 334 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
332 // Is that really what we want? | 335 // Is that really what we want? |
333 pref_service->ScheduleSavePersistentPrefs(); | 336 pref_service->ScheduleSavePersistentPrefs(); |
334 } | 337 } |
335 | 338 |
336 SyncCredentials ProfileSyncService::GetCredentials() { | 339 SyncCredentials ProfileSyncService::GetCredentials() { |
337 SyncCredentials credentials; | 340 SyncCredentials credentials; |
338 credentials.email = !cros_user_.empty() ? cros_user_ : signin_->GetUsername(); | 341 credentials.email = cros_user_.empty() ? signin_->GetUsername() : cros_user_; |
339 DCHECK(!credentials.email.empty()); | 342 DCHECK(!credentials.email.empty()); |
340 TokenService* service = profile_->GetTokenService(); | 343 TokenService* service = profile_->GetTokenService(); |
341 credentials.sync_token = service->GetTokenForService( | 344 credentials.sync_token = service->GetTokenForService( |
| 345 SyncSetupWizard::IsUsingOAuth() ? |
| 346 GaiaConstants::kSyncServiceOAuth : |
342 GaiaConstants::kSyncService); | 347 GaiaConstants::kSyncService); |
343 return credentials; | 348 return credentials; |
344 } | 349 } |
345 | 350 |
346 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { | 351 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { |
347 if (!backend_.get()) { | 352 if (!backend_.get()) { |
348 NOTREACHED(); | 353 NOTREACHED(); |
349 return; | 354 return; |
350 } | 355 } |
351 | 356 |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 break; | 1303 break; |
1299 } | 1304 } |
1300 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 1305 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
1301 const GoogleServiceSigninSuccessDetails* successful = | 1306 const GoogleServiceSigninSuccessDetails* successful = |
1302 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); | 1307 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); |
1303 // We pass 'false' to SetPassphrase to denote that this is an implicit | 1308 // We pass 'false' to SetPassphrase to denote that this is an implicit |
1304 // request and shouldn't override an explicit one. Thus, we either | 1309 // request and shouldn't override an explicit one. Thus, we either |
1305 // update the implicit passphrase (idempotent if the passphrase didn't | 1310 // update the implicit passphrase (idempotent if the passphrase didn't |
1306 // actually change), or the user has an explicit passphrase set so this | 1311 // actually change), or the user has an explicit passphrase set so this |
1307 // becomes a no-op. | 1312 // becomes a no-op. |
1308 SetPassphrase(successful->password, false, true); | 1313 if (SyncSetupWizard::IsUsingOAuth()) { |
| 1314 // TODO(rickcam): Bug 92323: Fetch password through special Gaia request |
| 1315 DCHECK(successful->password.empty()); |
| 1316 LOG(WARNING) << "Not initializing sync passphrase."; |
| 1317 } else { |
| 1318 SetPassphrase(successful->password, false, true); |
| 1319 } |
1309 break; | 1320 break; |
1310 } | 1321 } |
1311 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { | 1322 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { |
1312 GoogleServiceAuthError error = | 1323 GoogleServiceAuthError error = |
1313 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1324 *(Details<const GoogleServiceAuthError>(details).ptr()); |
1314 UpdateAuthErrorState(error); | 1325 UpdateAuthErrorState(error); |
1315 break; | 1326 break; |
1316 } | 1327 } |
1317 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1328 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
1318 GoogleServiceAuthError error( | 1329 GoogleServiceAuthError error( |
1319 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 1330 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
1320 UpdateAuthErrorState(error); | 1331 UpdateAuthErrorState(error); |
1321 break; | 1332 break; |
1322 } | 1333 } |
1323 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1334 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
1324 if (AreCredentialsAvailable()) { | 1335 if (AreCredentialsAvailable()) { |
1325 if (backend_initialized_) { | 1336 if (backend_initialized_) { |
1326 backend_->UpdateCredentials(GetCredentials()); | 1337 backend_->UpdateCredentials(GetCredentials()); |
1327 } | 1338 } |
1328 | |
1329 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) | 1339 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) |
1330 StartUp(); | 1340 StartUp(); |
1331 } | 1341 } |
1332 break; | 1342 break; |
1333 } | 1343 } |
1334 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1344 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1335 // If not in Chrome OS, and we have a username without tokens, | 1345 // If not in Chrome OS, and we have a username without tokens, |
1336 // the user will need to signin again, so sign out. | 1346 // the user will need to signin again, so sign out. |
1337 if (cros_user_.empty() && | 1347 if (cros_user_.empty() && |
1338 !signin_->GetUsername().empty() && | 1348 !signin_->GetUsername().empty() && |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 // is initialized, all enabled data types are consistent with one | 1394 // is initialized, all enabled data types are consistent with one |
1385 // another, and no unrecoverable error has transpired. | 1395 // another, and no unrecoverable error has transpired. |
1386 if (unrecoverable_error_detected_) | 1396 if (unrecoverable_error_detected_) |
1387 return false; | 1397 return false; |
1388 | 1398 |
1389 if (!data_type_manager_.get()) | 1399 if (!data_type_manager_.get()) |
1390 return false; | 1400 return false; |
1391 | 1401 |
1392 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1402 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1393 } | 1403 } |
OLD | NEW |