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() || auto_start_enabled_) { |
197 // 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 | |
199 // start sync anyway, since it's possible we crashed/shutdown after | |
200 // logging in but before the backend finished initializing the last time. | |
201 // Note that if we haven't finished setting up sync, backend bring up will | |
202 // be done by the wizard. | |
197 StartUp(); | 203 StartUp(); |
198 } | 204 } |
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 } | 205 } |
205 } | 206 } |
206 | 207 |
207 void ProfileSyncService::RegisterAuthNotifications() { | 208 void ProfileSyncService::RegisterAuthNotifications() { |
208 registrar_.Add(this, | 209 registrar_.Add(this, |
209 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 210 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
210 content::Source<TokenService>(profile_->GetTokenService())); | 211 content::Source<TokenService>(profile_->GetTokenService())); |
211 registrar_.Add(this, | 212 registrar_.Add(this, |
212 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, | 213 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
213 content::Source<TokenService>(profile_->GetTokenService())); | 214 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. | 1506 // another, and no unrecoverable error has transpired. |
1506 if (unrecoverable_error_detected_) | 1507 if (unrecoverable_error_detected_) |
1507 return false; | 1508 return false; |
1508 | 1509 |
1509 if (!data_type_manager_.get()) | 1510 if (!data_type_manager_.get()) |
1510 return false; | 1511 return false; |
1511 | 1512 |
1512 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1513 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1513 } | 1514 } |
1514 | 1515 |
1516 void ProfileSyncService::StopSyncAndSuppressStartUp() { | |
1517 sync_prefs_.SetStartSuppressed(true); | |
1518 Shutdown(false); | |
1519 } | |
1520 | |
1521 void ProfileSyncService::DisableSyncSuppressionAndStartUpSync() { | |
1522 DCHECK(profile_); | |
1523 sync_prefs_.SetStartSuppressed(false); | |
1524 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | |
1525 // is never called for some clients. | |
1526 if (signin_->GetUsername().empty()) { | |
1527 signin_->SetUsername(profile_->GetProfileName()); | |
akalin
2011/10/26 18:53:09
What is the username used for? Isn't the profile
| |
1528 } | |
1529 StartUpIfNotSuppressed(); | |
1530 } | |
1531 | |
1515 void ProfileSyncService::AcknowledgeSyncedTypes() { | 1532 void ProfileSyncService::AcknowledgeSyncedTypes() { |
1516 syncable::ModelTypeSet registered_types; | 1533 syncable::ModelTypeSet registered_types; |
1517 GetRegisteredDataTypes(®istered_types); | 1534 GetRegisteredDataTypes(®istered_types); |
1518 sync_prefs_.AcknowledgeSyncedTypes(registered_types); | 1535 sync_prefs_.AcknowledgeSyncedTypes(registered_types); |
1519 } | 1536 } |
1520 | 1537 |
1521 void ProfileSyncService::ReconfigureDatatypeManager() { | 1538 void ProfileSyncService::ReconfigureDatatypeManager() { |
1522 // If we haven't initialized yet, don't configure the DTM as it could cause | 1539 // 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. | 1540 // association to start before a Directory has even been created. |
1524 if (backend_initialized_) { | 1541 if (backend_initialized_) { |
(...skipping 11 matching lines...) Expand all Loading... | |
1536 << "Unrecoverable error."; | 1553 << "Unrecoverable error."; |
1537 } else { | 1554 } else { |
1538 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1555 VLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1539 << "initialized"; | 1556 << "initialized"; |
1540 } | 1557 } |
1541 } | 1558 } |
1542 | 1559 |
1543 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1560 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1544 return failed_datatypes_handler_; | 1561 return failed_datatypes_handler_; |
1545 } | 1562 } |
OLD | NEW |