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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 typedef GoogleServiceAuthError AuthError; | 66 typedef GoogleServiceAuthError AuthError; |
67 | 67 |
68 const char* ProfileSyncService::kSyncServerUrl = | 68 const char* ProfileSyncService::kSyncServerUrl = |
69 "https://clients4.google.com/chrome-sync"; | 69 "https://clients4.google.com/chrome-sync"; |
70 | 70 |
71 const char* ProfileSyncService::kDevServerUrl = | 71 const char* ProfileSyncService::kDevServerUrl = |
72 "https://clients4.google.com/chrome-sync/dev"; | 72 "https://clients4.google.com/chrome-sync/dev"; |
73 | 73 |
74 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 74 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
75 | 75 |
76 namespace { | |
akalin
2011/08/11 18:03:37
since this is used in 3 places, can you maybe move
Rick Campbell
2011/08/11 21:04:08
Done.
| |
77 bool IsUsingOAuth() { | |
78 return CommandLine::ForCurrentProcess()->HasSwitch( | |
79 switches::kEnableSyncOAuth); | |
80 } | |
81 } | |
82 | |
76 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, | 83 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, |
77 Profile* profile, | 84 Profile* profile, |
78 SigninManager* signin_manager, | 85 SigninManager* signin_manager, |
79 const std::string& cros_user) | 86 const std::string& cros_user) |
80 : last_auth_error_(AuthError::None()), | 87 : last_auth_error_(AuthError::None()), |
81 passphrase_required_reason_(sync_api::REASON_PASSPHRASE_NOT_REQUIRED), | 88 passphrase_required_reason_(sync_api::REASON_PASSPHRASE_NOT_REQUIRED), |
82 factory_(factory), | 89 factory_(factory), |
83 profile_(profile), | 90 profile_(profile), |
84 cros_user_(cros_user), | 91 cros_user_(cros_user), |
85 sync_service_url_(kDevServerUrl), | 92 sync_service_url_(kDevServerUrl), |
(...skipping 24 matching lines...) Expand all Loading... | |
110 } | 117 } |
111 | 118 |
112 bool ProfileSyncService::AreCredentialsAvailable() { | 119 bool ProfileSyncService::AreCredentialsAvailable() { |
113 if (IsManaged()) { | 120 if (IsManaged()) { |
114 return false; | 121 return false; |
115 } | 122 } |
116 | 123 |
117 // CrOS user is always logged in. Chrome uses signin_ to check logged in. | 124 // CrOS user is always logged in. Chrome uses signin_ to check logged in. |
118 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { | 125 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { |
119 // TODO(chron): Verify CrOS unit test behavior. | 126 // TODO(chron): Verify CrOS unit test behavior. |
120 if (profile()->GetTokenService() && | 127 return profile()->GetTokenService() && |
121 profile()->GetTokenService()->HasTokenForService( | 128 profile()->GetTokenService()->HasTokenForService( |
122 GaiaConstants::kSyncService)) { | 129 IsUsingOAuth() ? |
123 return true; | 130 GaiaConstants::kSyncServiceOAuth : |
124 } | 131 GaiaConstants::kSyncService); |
125 } | 132 } |
126 return false; | 133 return false; |
127 } | 134 } |
128 | 135 |
129 void ProfileSyncService::Initialize() { | 136 void ProfileSyncService::Initialize() { |
130 InitSettings(); | 137 InitSettings(); |
131 RegisterPreferences(); | 138 RegisterPreferences(); |
132 | 139 |
133 // We clear this here (vs Shutdown) because we want to remember that an error | 140 // 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 | 141 // 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() { | 265 void ProfileSyncService::RegisterPreferences() { |
259 PrefService* pref_service = profile_->GetPrefs(); | 266 PrefService* pref_service = profile_->GetPrefs(); |
260 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) | 267 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) |
261 return; | 268 return; |
262 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, | 269 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, |
263 0, | 270 0, |
264 PrefService::UNSYNCABLE_PREF); | 271 PrefService::UNSYNCABLE_PREF); |
265 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, | 272 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, |
266 false, | 273 false, |
267 PrefService::UNSYNCABLE_PREF); | 274 PrefService::UNSYNCABLE_PREF); |
275 pref_service->RegisterBooleanPref(prefs::kSyncUsingOAuth, | |
276 false, | |
277 PrefService::UNSYNCABLE_PREF); | |
268 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, | 278 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, |
269 false, | 279 false, |
270 PrefService::UNSYNCABLE_PREF); | 280 PrefService::UNSYNCABLE_PREF); |
271 | 281 |
272 // If you've never synced before, or if you're using Chrome OS, all datatypes | 282 // If you've never synced before, or if you're using Chrome OS, all datatypes |
273 // are on by default. | 283 // are on by default. |
274 // TODO(nick): Perhaps a better model would be to always default to false, | 284 // TODO(nick): Perhaps a better model would be to always default to false, |
275 // and explicitly call SetDataTypes() when the user shows the wizard. | 285 // and explicitly call SetDataTypes() when the user shows the wizard. |
276 #if defined(OS_CHROMEOS) | 286 #if defined(OS_CHROMEOS) |
277 bool enable_by_default = true; | 287 bool enable_by_default = true; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 356 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
347 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); | 357 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); |
348 | 358 |
349 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 359 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
350 // Is that really what we want? | 360 // Is that really what we want? |
351 pref_service->ScheduleSavePersistentPrefs(); | 361 pref_service->ScheduleSavePersistentPrefs(); |
352 } | 362 } |
353 | 363 |
354 SyncCredentials ProfileSyncService::GetCredentials() { | 364 SyncCredentials ProfileSyncService::GetCredentials() { |
355 SyncCredentials credentials; | 365 SyncCredentials credentials; |
356 credentials.email = !cros_user_.empty() ? cros_user_ : signin_->GetUsername(); | 366 credentials.email = cros_user_.empty() ? signin_->GetUsername() : cros_user_; |
357 DCHECK(!credentials.email.empty()); | 367 DCHECK(!credentials.email.empty()); |
358 TokenService* service = profile_->GetTokenService(); | 368 TokenService* service = profile_->GetTokenService(); |
359 credentials.sync_token = service->GetTokenForService( | 369 credentials.sync_token = service->GetTokenForService( |
370 IsUsingOAuth() ? | |
akalin
2011/08/11 18:03:37
this code is also repeated
Rick Campbell
2011/08/11 21:04:08
Done.
| |
371 GaiaConstants::kSyncServiceOAuth : | |
360 GaiaConstants::kSyncService); | 372 GaiaConstants::kSyncService); |
361 return credentials; | 373 return credentials; |
362 } | 374 } |
363 | 375 |
364 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { | 376 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { |
365 if (!backend_.get()) { | 377 if (!backend_.get()) { |
366 NOTREACHED(); | 378 NOTREACHED(); |
367 return; | 379 return; |
368 } | 380 } |
369 | 381 |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1334 break; | 1346 break; |
1335 } | 1347 } |
1336 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 1348 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
1337 const GoogleServiceSigninSuccessDetails* successful = | 1349 const GoogleServiceSigninSuccessDetails* successful = |
1338 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); | 1350 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); |
1339 // We pass 'false' to SetPassphrase to denote that this is an implicit | 1351 // We pass 'false' to SetPassphrase to denote that this is an implicit |
1340 // request and shouldn't override an explicit one. Thus, we either | 1352 // request and shouldn't override an explicit one. Thus, we either |
1341 // update the implicit passphrase (idempotent if the passphrase didn't | 1353 // update the implicit passphrase (idempotent if the passphrase didn't |
1342 // actually change), or the user has an explicit passphrase set so this | 1354 // actually change), or the user has an explicit passphrase set so this |
1343 // becomes a no-op. | 1355 // becomes a no-op. |
1344 SetPassphrase(successful->password, false, true); | 1356 if (IsUsingOAuth()) { |
1357 // TODO(rickcam): Bug 92323: Fetch password through special Gaia request | |
1358 DCHECK(successful->password.empty()); | |
1359 LOG(WARNING) << "Not initializing sync passphrase."; | |
1360 } else { | |
1361 SetPassphrase(successful->password, false, true); | |
1362 } | |
1345 break; | 1363 break; |
1346 } | 1364 } |
1347 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { | 1365 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { |
1348 GoogleServiceAuthError error = | 1366 GoogleServiceAuthError error = |
1349 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1367 *(Details<const GoogleServiceAuthError>(details).ptr()); |
1350 UpdateAuthErrorState(error); | 1368 UpdateAuthErrorState(error); |
1351 break; | 1369 break; |
1352 } | 1370 } |
1353 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1371 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
1354 GoogleServiceAuthError error( | 1372 GoogleServiceAuthError error( |
1355 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 1373 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
1356 UpdateAuthErrorState(error); | 1374 UpdateAuthErrorState(error); |
1357 break; | 1375 break; |
1358 } | 1376 } |
1359 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1377 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
1360 if (AreCredentialsAvailable()) { | 1378 if (AreCredentialsAvailable()) { |
1361 if (backend_initialized_) { | 1379 if (backend_initialized_) { |
1362 backend_->UpdateCredentials(GetCredentials()); | 1380 backend_->UpdateCredentials(GetCredentials()); |
1363 } | 1381 } |
1364 | |
1365 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) | 1382 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) |
1366 StartUp(); | 1383 StartUp(); |
1367 } | 1384 } |
1368 break; | 1385 break; |
1369 } | 1386 } |
1370 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1387 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1371 // If not in Chrome OS, and we have a username without tokens, | 1388 // If not in Chrome OS, and we have a username without tokens, |
1372 // the user will need to signin again, so sign out. | 1389 // the user will need to signin again, so sign out. |
1373 if (cros_user_.empty() && | 1390 if (cros_user_.empty() && |
1374 !signin_->GetUsername().empty() && | 1391 !signin_->GetUsername().empty() && |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1454 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); | 1471 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); |
1455 syncable::ModelTypeSet registered; | 1472 syncable::ModelTypeSet registered; |
1456 GetRegisteredDataTypes(®istered); | 1473 GetRegisteredDataTypes(®istered); |
1457 syncable::ModelTypeBitSet registered_bit_set = | 1474 syncable::ModelTypeBitSet registered_bit_set = |
1458 syncable::ModelTypeBitSetFromSet(registered); | 1475 syncable::ModelTypeBitSetFromSet(registered); |
1459 unacknowledged = registered_bit_set & ~acknowledged; | 1476 unacknowledged = registered_bit_set & ~acknowledged; |
1460 } | 1477 } |
1461 return unacknowledged; | 1478 return unacknowledged; |
1462 } | 1479 } |
1463 | 1480 |
OLD | NEW |