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() ? |
Andrew T Wilson (Slow)
2011/12/06 21:09:15
BTW, is the plan to eventually get rid of cros_use
tim (not reviewing)
2011/12/06 21:23:47
As I mention in the CL description and in my first
| |
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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1066 | 1057 |
1067 void ProfileSyncService::OnUserSubmittedAuth( | 1058 void ProfileSyncService::OnUserSubmittedAuth( |
1068 const std::string& username, const std::string& password, | 1059 const std::string& username, const std::string& password, |
1069 const std::string& captcha, const std::string& access_code) { | 1060 const std::string& captcha, const std::string& access_code) { |
1070 last_attempted_user_email_ = username; | 1061 last_attempted_user_email_ = username; |
1071 is_auth_in_progress_ = true; | 1062 is_auth_in_progress_ = true; |
1072 NotifyObservers(); | 1063 NotifyObservers(); |
1073 | 1064 |
1074 auth_start_time_ = base::TimeTicks::Now(); | 1065 auth_start_time_ = base::TimeTicks::Now(); |
1075 | 1066 |
1076 if (!signin_->IsInitialized()) { | |
1077 // In ChromeOS we sign in during login, so we do not initialize signin_. | |
1078 // If this function gets called, we need to re-authenticate (e.g. for | |
1079 // two factor signin), so initialize signin_ here. | |
1080 signin_->Initialize(profile_); | |
1081 } | |
1082 | |
1083 if (!access_code.empty()) { | 1067 if (!access_code.empty()) { |
1084 signin_->ProvideSecondFactorAccessCode(access_code); | 1068 signin_->ProvideSecondFactorAccessCode(access_code); |
1085 return; | 1069 return; |
1086 } | 1070 } |
1087 | 1071 |
1088 if (!signin_->GetUsername().empty()) { | |
1089 signin_->ClearInMemoryData(); | |
1090 } | |
1091 | |
1092 // The user has submitted credentials, which indicates they don't | 1072 // The user has submitted credentials, which indicates they don't |
1093 // want to suppress start up anymore. | 1073 // want to suppress start up anymore. |
1094 sync_prefs_.SetStartSuppressed(false); | 1074 sync_prefs_.SetStartSuppressed(false); |
1095 | 1075 |
1096 signin_->StartSignIn(username, | 1076 signin_->StartSignIn(username, |
1097 password, | 1077 password, |
1098 last_auth_error_.captcha().token, | 1078 last_auth_error_.captcha().token, |
1099 captcha); | 1079 captcha); |
1100 } | 1080 } |
1101 | 1081 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1451 if (AreCredentialsAvailable()) { | 1431 if (AreCredentialsAvailable()) { |
1452 if (backend_initialized_) { | 1432 if (backend_initialized_) { |
1453 backend_->UpdateCredentials(GetCredentials()); | 1433 backend_->UpdateCredentials(GetCredentials()); |
1454 } | 1434 } |
1455 if (!sync_prefs_.IsStartSuppressed()) | 1435 if (!sync_prefs_.IsStartSuppressed()) |
1456 StartUp(); | 1436 StartUp(); |
1457 } | 1437 } |
1458 break; | 1438 break; |
1459 } | 1439 } |
1460 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1440 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1461 // If not in Chrome OS, and we have a username without tokens, | 1441 // If not in auto-start / Chrome OS mode, and we have a username |
1462 // the user will need to signin again, so sign out. | 1442 // without tokens, the user will need to signin again. NotifyObservers to |
1443 // trigger errors in the UI that will allow the user to re-login. | |
1463 if (cros_user_.empty() && | 1444 if (cros_user_.empty() && |
1464 !signin_->GetUsername().empty() && | 1445 !signin_->GetAuthenticatedUsername().empty() && |
1465 !AreCredentialsAvailable()) { | 1446 !AreCredentialsAvailable()) { |
1466 DisableForUser(); | 1447 NotifyObservers(); |
Andrew T Wilson (Slow)
2011/12/06 21:09:15
Agreed with Lingesh - can you explain why the UI i
tim (not reviewing)
2011/12/06 21:23:47
Woops, I musn't have uploaded the right patchset.
| |
1467 } | 1448 } |
1468 break; | 1449 break; |
1469 } | 1450 } |
1470 default: { | 1451 default: { |
1471 NOTREACHED(); | 1452 NOTREACHED(); |
1472 } | 1453 } |
1473 } | 1454 } |
1474 } | 1455 } |
1475 | 1456 |
1476 void ProfileSyncService::AddObserver(Observer* observer) { | 1457 void ProfileSyncService::AddObserver(Observer* observer) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 void ProfileSyncService::StopAndSuppress() { | 1501 void ProfileSyncService::StopAndSuppress() { |
1521 sync_prefs_.SetStartSuppressed(true); | 1502 sync_prefs_.SetStartSuppressed(true); |
1522 Shutdown(false); | 1503 Shutdown(false); |
1523 } | 1504 } |
1524 | 1505 |
1525 void ProfileSyncService::UnsuppressAndStart() { | 1506 void ProfileSyncService::UnsuppressAndStart() { |
1526 DCHECK(profile_); | 1507 DCHECK(profile_); |
1527 sync_prefs_.SetStartSuppressed(false); | 1508 sync_prefs_.SetStartSuppressed(false); |
1528 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | 1509 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess |
1529 // is never called for some clients. | 1510 // is never called for some clients. |
1530 if (signin_->GetUsername().empty()) { | 1511 if (signin_->GetAuthenticatedUsername().empty()) { |
1531 signin_->SetUsername(sync_prefs_.GetGoogleServicesUsername()); | 1512 signin_->SetAuthenticatedUsername( |
1513 sync_prefs_.GetGoogleServicesUsername()); | |
1532 } | 1514 } |
1533 TryStart(); | 1515 TryStart(); |
1534 } | 1516 } |
1535 | 1517 |
1536 void ProfileSyncService::AcknowledgeSyncedTypes() { | 1518 void ProfileSyncService::AcknowledgeSyncedTypes() { |
1537 syncable::ModelTypeSet registered_types; | 1519 syncable::ModelTypeSet registered_types; |
1538 GetRegisteredDataTypes(®istered_types); | 1520 GetRegisteredDataTypes(®istered_types); |
1539 sync_prefs_.AcknowledgeSyncedTypes(registered_types); | 1521 sync_prefs_.AcknowledgeSyncedTypes(registered_types); |
1540 } | 1522 } |
1541 | 1523 |
(...skipping 15 matching lines...) Expand all Loading... | |
1557 << "Unrecoverable error."; | 1539 << "Unrecoverable error."; |
1558 } else { | 1540 } else { |
1559 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1541 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1560 << "initialized"; | 1542 << "initialized"; |
1561 } | 1543 } |
1562 } | 1544 } |
1563 | 1545 |
1564 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1546 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1565 return failed_datatypes_handler_; | 1547 return failed_datatypes_handler_; |
1566 } | 1548 } |
OLD | NEW |