Chromium Code Reviews| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 // for the TokenService in login and does not normally rely on signin_, | 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 | 182 // so only initialize this if the token service has not been initialized |
| 183 // (e.g. the browser crashed or is being debugged). | 183 // (e.g. the browser crashed or is being debugged). |
| 184 if (cros_user_.empty() || | 184 if (cros_user_.empty() || |
| 185 !profile_->GetTokenService()->Initialized()) { | 185 !profile_->GetTokenService()->Initialized()) { |
| 186 // Will load tokens from DB and broadcast Token events after. | 186 // Will load tokens from DB and broadcast Token events after. |
| 187 // Note: We rely on signin_ != NULL unless !cros_user_.empty(). | 187 // Note: We rely on signin_ != NULL unless !cros_user_.empty(). |
| 188 signin_->Initialize(profile_); | 188 signin_->Initialize(profile_); |
| 189 } | 189 } |
| 190 | 190 |
| 191 if (!HasSyncSetupCompleted()) { | 191 StartUpIfNotSuppressed(); |
| 192 // If autostart is enabled, but we haven't completed sync setup, try to | 192 } |
| 193 // start sync anyway (it's possible we crashed/shutdown after logging in | 193 |
| 194 // but before the backend finished initializing the last time). | 194 void ProfileSyncService::StartUpIfNotSuppressed() { |
| 195 if (auto_start_enabled_ && !sync_prefs_.IsStartSuppressed() && | 195 if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) { |
| 196 AreCredentialsAvailable()) { | 196 if (!HasSyncSetupCompleted()) { |
|
Andrew T Wilson (Slow)
2011/10/26 01:23:26
Should we combine this whole if statement into:
i
qsr
2011/10/26 07:07:00
That would need changing the else statement and ma
| |
| 197 // If autostart is enabled, but we haven't completed sync setup, try to | |
| 198 // start sync anyway (it's possible we crashed/shutdown after logging in | |
| 199 // but before the backend finished initializing the last time). | |
| 200 if (auto_start_enabled_) { | |
| 201 StartUp(); | |
| 202 } | |
| 203 } else { | |
| 204 // If we have credentials and sync setup finished, autostart the backend. | |
| 205 // Note that if we haven't finished setting up sync, backend bring up will | |
| 206 // be done by the wizard. | |
| 197 StartUp(); | 207 StartUp(); |
| 198 } | 208 } |
| 199 } else if (AreCredentialsAvailable()) { | |
| 200 // If we have credentials and sync setup finished, autostart the backend. | |
| 201 // Note that if we haven't finished setting up sync, backend bring up will | |
| 202 // be done by the wizard. | |
| 203 StartUp(); | |
| 204 } | 209 } |
| 205 } | 210 } |
| 206 | 211 |
| 207 void ProfileSyncService::RegisterAuthNotifications() { | 212 void ProfileSyncService::RegisterAuthNotifications() { |
| 208 registrar_.Add(this, | 213 registrar_.Add(this, |
| 209 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 214 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 210 content::Source<TokenService>(profile_->GetTokenService())); | 215 content::Source<TokenService>(profile_->GetTokenService())); |
| 211 registrar_.Add(this, | 216 registrar_.Add(this, |
| 212 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, | 217 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
| 213 content::Source<TokenService>(profile_->GetTokenService())); | 218 content::Source<TokenService>(profile_->GetTokenService())); |
| (...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1505 // another, and no unrecoverable error has transpired. | 1510 // another, and no unrecoverable error has transpired. |
| 1506 if (unrecoverable_error_detected_) | 1511 if (unrecoverable_error_detected_) |
| 1507 return false; | 1512 return false; |
| 1508 | 1513 |
| 1509 if (!data_type_manager_.get()) | 1514 if (!data_type_manager_.get()) |
| 1510 return false; | 1515 return false; |
| 1511 | 1516 |
| 1512 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1517 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1513 } | 1518 } |
| 1514 | 1519 |
| 1520 void ProfileSyncService::StopSyncAndSuppressStartUp() { | |
| 1521 sync_prefs_.SetStartSuppressed(true); | |
| 1522 Shutdown(false); | |
| 1523 } | |
| 1524 | |
| 1525 void ProfileSyncService::DisableSyncSuppressionAndStartUpSync() { | |
| 1526 DCHECK(profile_); | |
| 1527 sync_prefs_.SetStartSuppressed(false); | |
| 1528 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | |
| 1529 // is never called for some clients. | |
| 1530 if (signin_->GetUsername().empty()) { | |
| 1531 signin_->SetUsername(profile_->GetProfileName()); | |
| 1532 } | |
| 1533 StartUpIfNotSuppressed(); | |
| 1534 } | |
| 1535 | |
| 1515 void ProfileSyncService::AcknowledgeSyncedTypes() { | 1536 void ProfileSyncService::AcknowledgeSyncedTypes() { |
| 1516 syncable::ModelTypeSet registered_types; | 1537 syncable::ModelTypeSet registered_types; |
| 1517 GetRegisteredDataTypes(®istered_types); | 1538 GetRegisteredDataTypes(®istered_types); |
| 1518 sync_prefs_.AcknowledgeSyncedTypes(registered_types); | 1539 sync_prefs_.AcknowledgeSyncedTypes(registered_types); |
| 1519 } | 1540 } |
| 1520 | 1541 |
| 1521 void ProfileSyncService::ReconfigureDatatypeManager() { | 1542 void ProfileSyncService::ReconfigureDatatypeManager() { |
| 1522 // If we haven't initialized yet, don't configure the DTM as it could cause | 1543 // If we haven't initialized yet, don't configure the DTM as it could cause |
| 1523 // association to start before a Directory has even been created. | 1544 // association to start before a Directory has even been created. |
| 1524 if (backend_initialized_) { | 1545 if (backend_initialized_) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1536 << "Unrecoverable error."; | 1557 << "Unrecoverable error."; |
| 1537 } else { | 1558 } else { |
| 1538 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1559 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
| 1539 << "initialized"; | 1560 << "initialized"; |
| 1540 } | 1561 } |
| 1541 } | 1562 } |
| 1542 | 1563 |
| 1543 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1564 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
| 1544 return failed_datatypes_handler_; | 1565 return failed_datatypes_handler_; |
| 1545 } | 1566 } |
| OLD | NEW |