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 <algorithm> | 7 #include <algorithm> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 return AreCredentialsAvailable(false); | 158 return AreCredentialsAvailable(false); |
159 } | 159 } |
160 | 160 |
161 bool ProfileSyncService::AreCredentialsAvailable( | 161 bool ProfileSyncService::AreCredentialsAvailable( |
162 bool check_oauth_login_token) { | 162 bool check_oauth_login_token) { |
163 if (IsManaged()) { | 163 if (IsManaged()) { |
164 return false; | 164 return false; |
165 } | 165 } |
166 | 166 |
167 // CrOS user is always logged in. Chrome uses signin_ to check logged in. | 167 // CrOS user is always logged in. Chrome uses signin_ to check logged in. |
168 if (cros_user_.empty() && signin_->GetUsername().empty()) | 168 if (cros_user_.empty() && signin_->GetAuthenticatedUsername().empty()) |
169 return false; | 169 return false; |
170 | 170 |
171 TokenService* token_service = profile()->GetTokenService(); | 171 TokenService* token_service = profile()->GetTokenService(); |
172 if (!token_service) | 172 if (!token_service) |
173 return false; | 173 return false; |
174 | 174 |
175 // TODO(chron): Verify CrOS unit test behavior. | 175 // TODO(chron): Verify CrOS unit test behavior. |
176 if (!token_service->HasTokenForService(browser_sync::SyncServiceName())) | 176 if (!token_service->HasTokenForService(browser_sync::SyncServiceName())) |
177 return false; | 177 return false; |
178 return !check_oauth_login_token || token_service->HasOAuthLoginToken(); | 178 return !check_oauth_login_token || token_service->HasOAuthLoginToken(); |
(...skipping 13 matching lines...) Expand all Loading... | |
192 if (IsManaged()) { | 192 if (IsManaged()) { |
193 DisableForUser(); | 193 DisableForUser(); |
194 return; | 194 return; |
195 } | 195 } |
196 | 196 |
197 RegisterAuthNotifications(); | 197 RegisterAuthNotifications(); |
198 | 198 |
199 if (!HasSyncSetupCompleted()) | 199 if (!HasSyncSetupCompleted()) |
200 DisableForUser(); // Clean up in case of previous crash / setup abort. | 200 DisableForUser(); // Clean up in case of previous crash / setup abort. |
201 | 201 |
202 // In Chrome, we integrate a SigninManager which works with the sync | 202 signin_->Initialize(profile_); |
203 // setup wizard to kick off the TokenService. CrOS does its own plumbing | |
204 // for the TokenService in login and does not normally rely on signin_, | |
205 // so only initialize this if the token service has not been initialized | |
206 // (e.g. the browser crashed or is being debugged). | |
207 if (cros_user_.empty() || | |
208 !profile_->GetTokenService()->Initialized()) { | |
209 // Will load tokens from DB and broadcast Token events after. | |
210 // Note: We rely on signin_ != NULL unless !cros_user_.empty(). | |
211 signin_->Initialize(profile_); | |
212 } | |
213 | 203 |
214 TryStart(); | 204 TryStart(); |
215 } | 205 } |
216 | 206 |
217 void ProfileSyncService::TryStart() { | 207 void ProfileSyncService::TryStart() { |
218 if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) { | 208 if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) { |
219 if (HasSyncSetupCompleted() || auto_start_enabled_) { | 209 if (HasSyncSetupCompleted() || auto_start_enabled_) { |
220 // If sync setup has completed we always start the backend. | 210 // If sync setup has completed we always start the backend. |
221 // If autostart is enabled, but we haven't completed sync setup, we try to | 211 // If autostart is enabled, but we haven't completed sync setup, we try to |
222 // start sync anyway, since it's possible we crashed/shutdown after | 212 // start sync anyway, since it's possible we crashed/shutdown after |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 } else { | 285 } else { |
296 LOG(WARNING) << "The following sync URL specified at the command-line " | 286 LOG(WARNING) << "The following sync URL specified at the command-line " |
297 << "is invalid: " << value; | 287 << "is invalid: " << value; |
298 } | 288 } |
299 } | 289 } |
300 } | 290 } |
301 } | 291 } |
302 | 292 |
303 SyncCredentials ProfileSyncService::GetCredentials() { | 293 SyncCredentials ProfileSyncService::GetCredentials() { |
304 SyncCredentials credentials; | 294 SyncCredentials credentials; |
305 credentials.email = cros_user_.empty() ? signin_->GetUsername() : cros_user_; | 295 credentials.email = cros_user_.empty() ? |
296 signin_->GetAuthenticatedUsername() : cros_user_; | |
306 DCHECK(!credentials.email.empty()); | 297 DCHECK(!credentials.email.empty()); |
307 TokenService* service = profile_->GetTokenService(); | 298 TokenService* service = profile_->GetTokenService(); |
308 credentials.sync_token = service->GetTokenForService( | 299 credentials.sync_token = service->GetTokenForService( |
309 browser_sync::SyncServiceName()); | 300 browser_sync::SyncServiceName()); |
310 return credentials; | 301 return credentials; |
311 } | 302 } |
312 | 303 |
313 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { | 304 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { |
314 if (!backend_.get()) { | 305 if (!backend_.get()) { |
315 NOTREACHED(); | 306 NOTREACHED(); |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 | 1073 |
1083 void ProfileSyncService::OnUserSubmittedAuth( | 1074 void ProfileSyncService::OnUserSubmittedAuth( |
1084 const std::string& username, const std::string& password, | 1075 const std::string& username, const std::string& password, |
1085 const std::string& captcha, const std::string& access_code) { | 1076 const std::string& captcha, const std::string& access_code) { |
1086 last_attempted_user_email_ = username; | 1077 last_attempted_user_email_ = username; |
1087 is_auth_in_progress_ = true; | 1078 is_auth_in_progress_ = true; |
1088 NotifyObservers(); | 1079 NotifyObservers(); |
1089 | 1080 |
1090 auth_start_time_ = base::TimeTicks::Now(); | 1081 auth_start_time_ = base::TimeTicks::Now(); |
1091 | 1082 |
1092 if (!signin_->IsInitialized()) { | |
1093 // In ChromeOS we sign in during login, so we do not initialize signin_. | |
1094 // If this function gets called, we need to re-authenticate (e.g. for | |
1095 // two factor signin), so initialize signin_ here. | |
1096 signin_->Initialize(profile_); | |
1097 } | |
1098 | |
1099 if (!access_code.empty()) { | 1083 if (!access_code.empty()) { |
1100 signin_->ProvideSecondFactorAccessCode(access_code); | 1084 signin_->ProvideSecondFactorAccessCode(access_code); |
1101 return; | 1085 return; |
1102 } | 1086 } |
1103 | 1087 |
1104 if (!signin_->GetUsername().empty()) { | |
1105 signin_->ClearInMemoryData(); | |
1106 } | |
1107 | |
1108 // The user has submitted credentials, which indicates they don't | 1088 // The user has submitted credentials, which indicates they don't |
1109 // want to suppress start up anymore. | 1089 // want to suppress start up anymore. |
1110 sync_prefs_.SetStartSuppressed(false); | 1090 sync_prefs_.SetStartSuppressed(false); |
1111 | 1091 |
1112 signin_->StartSignIn(username, | 1092 signin_->StartSignIn(username, |
1113 password, | 1093 password, |
1114 last_auth_error_.captcha().token, | 1094 last_auth_error_.captcha().token, |
1115 captcha); | 1095 captcha); |
1116 } | 1096 } |
1117 | 1097 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1503 // start up sync successfully for already logged in users who may | 1483 // start up sync successfully for already logged in users who may |
1504 // only have chromiumsync token if they logged in before the code | 1484 // only have chromiumsync token if they logged in before the code |
1505 // to generate oauth login token released. | 1485 // to generate oauth login token released. |
1506 if (AreCredentialsAvailable()) { | 1486 if (AreCredentialsAvailable()) { |
1507 // Initialize the backend if sync token was loaded. | 1487 // Initialize the backend if sync token was loaded. |
1508 if (backend_initialized_) { | 1488 if (backend_initialized_) { |
1509 backend_->UpdateCredentials(GetCredentials()); | 1489 backend_->UpdateCredentials(GetCredentials()); |
1510 } | 1490 } |
1511 if (!sync_prefs_.IsStartSuppressed()) | 1491 if (!sync_prefs_.IsStartSuppressed()) |
1512 StartUp(); | 1492 StartUp(); |
1513 } else if (cros_user_.empty() && !signin_->GetUsername().empty()) { | 1493 } else if (cros_user_.empty() && |
1514 // If not in Chrome OS, and we have a username without tokens, | 1494 !signin_->GetAuthenticatedUsername().empty()) { |
1515 // the user will need to signin again, so sign out. | 1495 // If not in auto-start / Chrome OS mode, and we have a username |
1516 DisableForUser(); | 1496 // without tokens, the user will need to signin again. NotifyObservers |
1497 // to trigger errors in the UI that will allow the user to re-login. | |
Andrew T Wilson (Slow)
2011/12/07 00:50:15
Is this comment referring to NotifyObservers still
| |
1498 UpdateAuthErrorState(GoogleServiceAuthError( | |
1499 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); | |
1517 } | 1500 } |
1518 break; | 1501 break; |
1519 } | 1502 } |
1520 default: { | 1503 default: { |
1521 NOTREACHED(); | 1504 NOTREACHED(); |
1522 } | 1505 } |
1523 } | 1506 } |
1524 } | 1507 } |
1525 | 1508 |
1526 void ProfileSyncService::AddObserver(Observer* observer) { | 1509 void ProfileSyncService::AddObserver(Observer* observer) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1570 void ProfileSyncService::StopAndSuppress() { | 1553 void ProfileSyncService::StopAndSuppress() { |
1571 sync_prefs_.SetStartSuppressed(true); | 1554 sync_prefs_.SetStartSuppressed(true); |
1572 Shutdown(false); | 1555 Shutdown(false); |
1573 } | 1556 } |
1574 | 1557 |
1575 void ProfileSyncService::UnsuppressAndStart() { | 1558 void ProfileSyncService::UnsuppressAndStart() { |
1576 DCHECK(profile_); | 1559 DCHECK(profile_); |
1577 sync_prefs_.SetStartSuppressed(false); | 1560 sync_prefs_.SetStartSuppressed(false); |
1578 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | 1561 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess |
1579 // is never called for some clients. | 1562 // is never called for some clients. |
1580 if (signin_->GetUsername().empty()) { | 1563 if (signin_->GetAuthenticatedUsername().empty()) { |
1581 signin_->SetUsername(sync_prefs_.GetGoogleServicesUsername()); | 1564 signin_->SetAuthenticatedUsername( |
1565 sync_prefs_.GetGoogleServicesUsername()); | |
1582 } | 1566 } |
1583 TryStart(); | 1567 TryStart(); |
1584 } | 1568 } |
1585 | 1569 |
1586 void ProfileSyncService::AcknowledgeSyncedTypes() { | 1570 void ProfileSyncService::AcknowledgeSyncedTypes() { |
1587 syncable::ModelTypeSet registered_types; | 1571 syncable::ModelTypeSet registered_types; |
1588 GetRegisteredDataTypes(®istered_types); | 1572 GetRegisteredDataTypes(®istered_types); |
1589 sync_prefs_.AcknowledgeSyncedTypes(registered_types); | 1573 sync_prefs_.AcknowledgeSyncedTypes(registered_types); |
1590 } | 1574 } |
1591 | 1575 |
(...skipping 15 matching lines...) Expand all Loading... | |
1607 << "Unrecoverable error."; | 1591 << "Unrecoverable error."; |
1608 } else { | 1592 } else { |
1609 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1593 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1610 << "initialized"; | 1594 << "initialized"; |
1611 } | 1595 } |
1612 } | 1596 } |
1613 | 1597 |
1614 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1598 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1615 return failed_datatypes_handler_; | 1599 return failed_datatypes_handler_; |
1616 } | 1600 } |
OLD | NEW |