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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 sync_prefs_.RemoveSyncPrefObserver(this); | 139 sync_prefs_.RemoveSyncPrefObserver(this); |
140 Shutdown(false); | 140 Shutdown(false); |
141 } | 141 } |
142 | 142 |
143 bool ProfileSyncService::AreCredentialsAvailable() { | 143 bool ProfileSyncService::AreCredentialsAvailable() { |
144 if (IsManaged()) { | 144 if (IsManaged()) { |
145 return false; | 145 return false; |
146 } | 146 } |
147 | 147 |
148 // CrOS user is always logged in. Chrome uses signin_ to check logged in. | 148 // CrOS user is always logged in. Chrome uses signin_ to check logged in. |
149 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { | 149 if (!cros_user_.empty() || !signin_->GetAuthenticatedUsername().empty()) { |
150 // TODO(chron): Verify CrOS unit test behavior. | 150 // TODO(chron): Verify CrOS unit test behavior. |
151 return profile()->GetTokenService() && | 151 return profile()->GetTokenService() && |
152 profile()->GetTokenService()->HasTokenForService( | 152 profile()->GetTokenService()->HasTokenForService( |
153 browser_sync::SyncServiceName()); | 153 browser_sync::SyncServiceName()); |
154 } | 154 } |
155 return false; | 155 return false; |
156 } | 156 } |
157 | 157 |
158 void ProfileSyncService::Initialize() { | 158 void ProfileSyncService::Initialize() { |
159 InitSettings(); | 159 InitSettings(); |
160 | 160 |
161 // We clear this here (vs Shutdown) because we want to remember that an error | 161 // We clear this here (vs Shutdown) because we want to remember that an error |
162 // happened on shutdown so we can display details (message, location) about it | 162 // happened on shutdown so we can display details (message, location) about it |
163 // in about:sync. | 163 // in about:sync. |
164 ClearStaleErrors(); | 164 ClearStaleErrors(); |
165 | 165 |
166 sync_prefs_.AddSyncPrefObserver(this); | 166 sync_prefs_.AddSyncPrefObserver(this); |
167 | 167 |
168 // For now, the only thing we can do through policy is to turn sync off. | 168 // For now, the only thing we can do through policy is to turn sync off. |
169 if (IsManaged()) { | 169 if (IsManaged()) { |
170 DisableForUser(); | 170 DisableForUser(); |
171 return; | 171 return; |
172 } | 172 } |
173 | 173 |
174 RegisterAuthNotifications(); | 174 RegisterAuthNotifications(); |
175 | 175 |
176 if (!HasSyncSetupCompleted()) | 176 if (!HasSyncSetupCompleted()) |
177 DisableForUser(); // Clean up in case of previous crash / setup abort. | 177 DisableForUser(); // Clean up in case of previous crash / setup abort. |
178 | 178 |
179 // In Chrome, we integrate a SigninManager which works with the sync | 179 signin_->Initialize(profile_); |
180 // setup wizard to kick off the TokenService. CrOS does its own plumbing | |
181 // for the TokenService in login and does not normally rely on signin_, | |
182 // so only initialize this if the token service has not been initialized | |
183 // (e.g. the browser crashed or is being debugged). | |
184 if (cros_user_.empty() || | |
185 !profile_->GetTokenService()->Initialized()) { | |
186 // Will load tokens from DB and broadcast Token events after. | |
187 // Note: We rely on signin_ != NULL unless !cros_user_.empty(). | |
188 signin_->Initialize(profile_); | |
189 } | |
190 | 180 |
191 TryStart(); | 181 TryStart(); |
192 } | 182 } |
193 | 183 |
194 void ProfileSyncService::TryStart() { | 184 void ProfileSyncService::TryStart() { |
195 if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) { | 185 if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) { |
196 if (HasSyncSetupCompleted() || auto_start_enabled_) { | 186 if (HasSyncSetupCompleted() || auto_start_enabled_) { |
197 // If sync setup has completed we always start the backend. | 187 // If sync setup has completed we always start the backend. |
198 // If autostart is enabled, but we haven't completed sync setup, we try to | 188 // If autostart is enabled, but we haven't completed sync setup, we try to |
199 // start sync anyway, since it's possible we crashed/shutdown after | 189 // start sync anyway, since it's possible we crashed/shutdown after |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 } else { | 262 } else { |
273 LOG(WARNING) << "The following sync URL specified at the command-line " | 263 LOG(WARNING) << "The following sync URL specified at the command-line " |
274 << "is invalid: " << value; | 264 << "is invalid: " << value; |
275 } | 265 } |
276 } | 266 } |
277 } | 267 } |
278 } | 268 } |
279 | 269 |
280 SyncCredentials ProfileSyncService::GetCredentials() { | 270 SyncCredentials ProfileSyncService::GetCredentials() { |
281 SyncCredentials credentials; | 271 SyncCredentials credentials; |
282 credentials.email = cros_user_.empty() ? signin_->GetUsername() : cros_user_; | 272 credentials.email = cros_user_.empty() ? |
273 signin_->GetAuthenticatedUsername() : cros_user_; | |
283 DCHECK(!credentials.email.empty()); | 274 DCHECK(!credentials.email.empty()); |
284 TokenService* service = profile_->GetTokenService(); | 275 TokenService* service = profile_->GetTokenService(); |
285 credentials.sync_token = service->GetTokenForService( | 276 credentials.sync_token = service->GetTokenForService( |
286 browser_sync::SyncServiceName()); | 277 browser_sync::SyncServiceName()); |
287 return credentials; | 278 return credentials; |
288 } | 279 } |
289 | 280 |
290 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { | 281 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { |
291 if (!backend_.get()) { | 282 if (!backend_.get()) { |
292 NOTREACHED(); | 283 NOTREACHED(); |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1058 | 1049 |
1059 void ProfileSyncService::OnUserSubmittedAuth( | 1050 void ProfileSyncService::OnUserSubmittedAuth( |
1060 const std::string& username, const std::string& password, | 1051 const std::string& username, const std::string& password, |
1061 const std::string& captcha, const std::string& access_code) { | 1052 const std::string& captcha, const std::string& access_code) { |
1062 last_attempted_user_email_ = username; | 1053 last_attempted_user_email_ = username; |
1063 is_auth_in_progress_ = true; | 1054 is_auth_in_progress_ = true; |
1064 NotifyObservers(); | 1055 NotifyObservers(); |
1065 | 1056 |
1066 auth_start_time_ = base::TimeTicks::Now(); | 1057 auth_start_time_ = base::TimeTicks::Now(); |
1067 | 1058 |
1068 if (!signin_->IsInitialized()) { | |
1069 // In ChromeOS we sign in during login, so we do not initialize signin_. | |
1070 // If this function gets called, we need to re-authenticate (e.g. for | |
1071 // two factor signin), so initialize signin_ here. | |
1072 signin_->Initialize(profile_); | |
1073 } | |
1074 | |
1075 if (!access_code.empty()) { | 1059 if (!access_code.empty()) { |
1076 signin_->ProvideSecondFactorAccessCode(access_code); | 1060 signin_->ProvideSecondFactorAccessCode(access_code); |
1077 return; | 1061 return; |
1078 } | 1062 } |
1079 | 1063 |
1080 if (!signin_->GetUsername().empty()) { | |
1081 signin_->ClearInMemoryData(); | |
1082 } | |
1083 | |
1084 // The user has submitted credentials, which indicates they don't | 1064 // The user has submitted credentials, which indicates they don't |
1085 // want to suppress start up anymore. | 1065 // want to suppress start up anymore. |
1086 sync_prefs_.SetStartSuppressed(false); | 1066 sync_prefs_.SetStartSuppressed(false); |
1087 | 1067 |
1088 signin_->StartSignIn(username, | 1068 signin_->StartSignIn(username, |
1089 password, | 1069 password, |
1090 last_auth_error_.captcha().token, | 1070 last_auth_error_.captcha().token, |
1091 captcha); | 1071 captcha); |
1092 } | 1072 } |
1093 | 1073 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1443 if (AreCredentialsAvailable()) { | 1423 if (AreCredentialsAvailable()) { |
1444 if (backend_initialized_) { | 1424 if (backend_initialized_) { |
1445 backend_->UpdateCredentials(GetCredentials()); | 1425 backend_->UpdateCredentials(GetCredentials()); |
1446 } | 1426 } |
1447 if (!sync_prefs_.IsStartSuppressed()) | 1427 if (!sync_prefs_.IsStartSuppressed()) |
1448 StartUp(); | 1428 StartUp(); |
1449 } | 1429 } |
1450 break; | 1430 break; |
1451 } | 1431 } |
1452 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1432 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1453 // If not in Chrome OS, and we have a username without tokens, | 1433 // If not in auto-start / Chrome OS mode, and we have a username |
1454 // the user will need to signin again, so sign out. | 1434 // without tokens, the user will need to signin again. NotifyObservers to |
1435 // trigger errors in the UI that will allow the user to re-login. | |
1455 if (cros_user_.empty() && | 1436 if (cros_user_.empty() && |
1456 !signin_->GetUsername().empty() && | 1437 !signin_->GetAuthenticatedUsername().empty() && |
1457 !AreCredentialsAvailable()) { | 1438 !AreCredentialsAvailable()) { |
1458 DisableForUser(); | 1439 NotifyObservers(); |
Andrew T Wilson (Slow)
2011/11/28 04:54:02
I'm not entirely sure why it's now OK to NotifyObs
tim (not reviewing)
2011/12/05 21:24:50
I'm in the same boat here, honestly. In fact I'm n
lipalani1
2011/12/05 21:40:44
I assumed this meant the following:
If we have an
| |
1459 } | 1440 } |
1460 break; | 1441 break; |
1461 } | 1442 } |
1462 default: { | 1443 default: { |
1463 NOTREACHED(); | 1444 NOTREACHED(); |
1464 } | 1445 } |
1465 } | 1446 } |
1466 } | 1447 } |
1467 | 1448 |
1468 void ProfileSyncService::AddObserver(Observer* observer) { | 1449 void ProfileSyncService::AddObserver(Observer* observer) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1512 void ProfileSyncService::StopAndSuppress() { | 1493 void ProfileSyncService::StopAndSuppress() { |
1513 sync_prefs_.SetStartSuppressed(true); | 1494 sync_prefs_.SetStartSuppressed(true); |
1514 Shutdown(false); | 1495 Shutdown(false); |
1515 } | 1496 } |
1516 | 1497 |
1517 void ProfileSyncService::UnsuppressAndStart() { | 1498 void ProfileSyncService::UnsuppressAndStart() { |
1518 DCHECK(profile_); | 1499 DCHECK(profile_); |
1519 sync_prefs_.SetStartSuppressed(false); | 1500 sync_prefs_.SetStartSuppressed(false); |
1520 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | 1501 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess |
1521 // is never called for some clients. | 1502 // is never called for some clients. |
1522 if (signin_->GetUsername().empty()) { | 1503 if (signin_->GetAuthenticatedUsername().empty()) { |
1523 signin_->SetUsername(sync_prefs_.GetGoogleServicesUsername()); | 1504 signin_->SetAuthenticatedUsername( |
1505 sync_prefs_.GetGoogleServicesUsername()); | |
1524 } | 1506 } |
1525 TryStart(); | 1507 TryStart(); |
1526 } | 1508 } |
1527 | 1509 |
1528 void ProfileSyncService::AcknowledgeSyncedTypes() { | 1510 void ProfileSyncService::AcknowledgeSyncedTypes() { |
1529 syncable::ModelTypeSet registered_types; | 1511 syncable::ModelTypeSet registered_types; |
1530 GetRegisteredDataTypes(®istered_types); | 1512 GetRegisteredDataTypes(®istered_types); |
1531 sync_prefs_.AcknowledgeSyncedTypes(registered_types); | 1513 sync_prefs_.AcknowledgeSyncedTypes(registered_types); |
1532 } | 1514 } |
1533 | 1515 |
(...skipping 15 matching lines...) Expand all Loading... | |
1549 << "Unrecoverable error."; | 1531 << "Unrecoverable error."; |
1550 } else { | 1532 } else { |
1551 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1533 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1552 << "initialized"; | 1534 << "initialized"; |
1553 } | 1535 } |
1554 } | 1536 } |
1555 | 1537 |
1556 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1538 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1557 return failed_datatypes_handler_; | 1539 return failed_datatypes_handler_; |
1558 } | 1540 } |
OLD | NEW |