OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstddef> | 7 #include <cstddef> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 bool ProfileSyncService::IsSyncTokenAvailable() { | 198 bool ProfileSyncService::IsSyncTokenAvailable() { |
199 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 199 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
200 if (!token_service) | 200 if (!token_service) |
201 return false; | 201 return false; |
202 return token_service->HasTokenForService(GaiaConstants::kSyncService); | 202 return token_service->HasTokenForService(GaiaConstants::kSyncService); |
203 } | 203 } |
204 #if defined(OS_ANDROID) | 204 #if defined(OS_ANDROID) |
205 bool ProfileSyncService::ShouldEnablePasswordSyncForAndroid() const { | 205 bool ProfileSyncService::ShouldEnablePasswordSyncForAndroid() const { |
206 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 206 if (!GetPreferredDataTypes().Has(syncer::PASSWORDS)) |
207 const syncer::ModelTypeSet preferred_types = | |
208 sync_prefs_.GetPreferredDataTypes(registered_types); | |
209 if (!preferred_types.Has(syncer::PASSWORDS)) | |
210 return false; | 207 return false; |
211 // If backend has not completed initializing we cannot check if the | 208 // If backend has not completed initializing we cannot check if the |
212 // cryptographer is ready. | 209 // cryptographer is ready. |
213 if (!sync_initialized()) | 210 if (!sync_initialized()) |
214 return false; | 211 return false; |
215 // On Android we do not want to prompt user to enter a passphrase. If | 212 // On Android we do not want to prompt user to enter a passphrase. If |
216 // passwords cannot be decrypted we just disable them. | 213 // passwords cannot be decrypted we just disable them. |
217 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); | 214 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); |
218 return IsCryptographerReady(&trans); | 215 return IsCryptographerReady(&trans); |
219 } | 216 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return; | 253 return; |
257 | 254 |
258 // There was a bug where OnUserChoseDatatypes was not properly called on | 255 // There was a bug where OnUserChoseDatatypes was not properly called on |
259 // configuration (see crbug.com/154940). We detect this by checking whether | 256 // configuration (see crbug.com/154940). We detect this by checking whether |
260 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has | 257 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has |
261 // completed, it means sync was not properly configured, so we manually | 258 // completed, it means sync was not properly configured, so we manually |
262 // set kSyncKeepEverythingSynced. | 259 // set kSyncKeepEverythingSynced. |
263 PrefService* const pref_service = profile_->GetPrefs(); | 260 PrefService* const pref_service = profile_->GetPrefs(); |
264 if (!pref_service) | 261 if (!pref_service) |
265 return; | 262 return; |
266 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 263 if (GetPreferredDataTypes().Size() > 1) |
267 if (sync_prefs_.GetPreferredDataTypes(registered_types).Size() > 1) | |
268 return; | 264 return; |
269 | 265 |
270 const PrefService::Preference* keep_everything_synced = | 266 const PrefService::Preference* keep_everything_synced = |
271 pref_service->FindPreference(prefs::kSyncKeepEverythingSynced); | 267 pref_service->FindPreference(prefs::kSyncKeepEverythingSynced); |
272 // This will be false if the preference was properly set or if it's controlled | 268 // This will be false if the preference was properly set or if it's controlled |
273 // by policy. | 269 // by policy. |
274 if (!keep_everything_synced->IsDefaultValue()) | 270 if (!keep_everything_synced->IsDefaultValue()) |
275 return; | 271 return; |
276 | 272 |
277 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred | 273 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred |
278 // types now, before we configure. | 274 // types now, before we configure. |
279 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); | 275 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); |
280 sync_prefs_.SetKeepEverythingSynced(true); | 276 sync_prefs_.SetKeepEverythingSynced(true); |
| 277 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
281 sync_prefs_.SetPreferredDataTypes(registered_types, | 278 sync_prefs_.SetPreferredDataTypes(registered_types, |
282 registered_types); | 279 registered_types); |
283 } | 280 } |
284 | 281 |
285 void ProfileSyncService::TryStart() { | 282 void ProfileSyncService::TryStart() { |
286 if (!IsSyncEnabledAndLoggedIn()) | 283 if (!IsSyncEnabledAndLoggedIn()) |
287 return; | 284 return; |
288 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 285 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
289 if (!token_service) | 286 if (!token_service) |
290 return; | 287 return; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 550 |
554 void ProfileSyncService::OnDataTypeRequestsSyncStartup( | 551 void ProfileSyncService::OnDataTypeRequestsSyncStartup( |
555 syncer::ModelType type) { | 552 syncer::ModelType type) { |
556 DCHECK(syncer::UserTypes().Has(type)); | 553 DCHECK(syncer::UserTypes().Has(type)); |
557 if (backend_.get()) { | 554 if (backend_.get()) { |
558 DVLOG(1) << "A data type requested sync startup, but it looks like " | 555 DVLOG(1) << "A data type requested sync startup, but it looks like " |
559 "something else beat it to the punch."; | 556 "something else beat it to the punch."; |
560 return; | 557 return; |
561 } | 558 } |
562 | 559 |
563 if (!GetPreferredDataTypes().Has(type)) { | 560 if (!GetActiveDataTypes().Has(type)) { |
564 // We can get here as datatype SyncableServices are typically wired up | 561 // We can get here as datatype SyncableServices are typically wired up |
565 // to the native datatype even if sync isn't enabled. | 562 // to the native datatype even if sync isn't enabled. |
566 DVLOG(1) << "Dropping sync startup request because type " | 563 DVLOG(1) << "Dropping sync startup request because type " |
567 << syncer::ModelTypeToString(type) << "not enabled."; | 564 << syncer::ModelTypeToString(type) << "not enabled."; |
568 return; | 565 return; |
569 } | 566 } |
570 | 567 |
571 if (CommandLine::ForCurrentProcess()->HasSwitch( | 568 if (CommandLine::ForCurrentProcess()->HasSwitch( |
572 switches::kSyncEnableDeferredStartup)) { | 569 switches::kSyncEnableDeferredStartup)) { |
573 DVLOG(2) << "Data type requesting sync startup: " | 570 DVLOG(2) << "Data type requesting sync startup: " |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 // Re-enable passwords if we have disabled them. | 1136 // Re-enable passwords if we have disabled them. |
1140 if (failed_datatypes_handler_.GetFailedTypes().Has(syncer::PASSWORDS) && | 1137 if (failed_datatypes_handler_.GetFailedTypes().Has(syncer::PASSWORDS) && |
1141 ShouldEnablePasswordSyncForAndroid()) { | 1138 ShouldEnablePasswordSyncForAndroid()) { |
1142 // Clear the data type errors. | 1139 // Clear the data type errors. |
1143 failed_datatypes_handler_.OnUserChoseDatatypes(); | 1140 failed_datatypes_handler_.OnUserChoseDatatypes(); |
1144 } | 1141 } |
1145 #endif | 1142 #endif |
1146 | 1143 |
1147 // Make sure the data types that depend on the passphrase are started at | 1144 // Make sure the data types that depend on the passphrase are started at |
1148 // this time. | 1145 // this time. |
1149 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | 1146 const syncer::ModelTypeSet types = GetActiveDataTypes(); |
1150 | |
1151 if (data_type_manager_) { | 1147 if (data_type_manager_) { |
1152 // Unblock the data type manager if necessary. | 1148 // Unblock the data type manager if necessary. |
1153 data_type_manager_->Configure(types, | 1149 data_type_manager_->Configure(types, |
1154 syncer::CONFIGURE_REASON_RECONFIGURATION); | 1150 syncer::CONFIGURE_REASON_RECONFIGURATION); |
1155 } | 1151 } |
1156 | 1152 |
1157 NotifyObservers(); | 1153 NotifyObservers(); |
1158 } | 1154 } |
1159 | 1155 |
1160 void ProfileSyncService::OnEncryptedTypesChanged( | 1156 void ProfileSyncService::OnEncryptedTypesChanged( |
1161 syncer::ModelTypeSet encrypted_types, | 1157 syncer::ModelTypeSet encrypted_types, |
1162 bool encrypt_everything) { | 1158 bool encrypt_everything) { |
1163 encrypted_types_ = encrypted_types; | 1159 encrypted_types_ = encrypted_types; |
1164 encrypt_everything_ = encrypt_everything; | 1160 encrypt_everything_ = encrypt_everything; |
1165 DVLOG(1) << "Encrypted types changed to " | 1161 DVLOG(1) << "Encrypted types changed to " |
1166 << syncer::ModelTypeSetToString(encrypted_types_) | 1162 << syncer::ModelTypeSetToString(encrypted_types_) |
1167 << " (encrypt everything is set to " | 1163 << " (encrypt everything is set to " |
1168 << (encrypt_everything_ ? "true" : "false") << ")"; | 1164 << (encrypt_everything_ ? "true" : "false") << ")"; |
1169 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); | 1165 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); |
1170 | 1166 |
1171 // If sessions are encrypted, full history sync is not possible, and | 1167 // If sessions are encrypted, full history sync is not possible, and |
1172 // delete directives are unnecessary. | 1168 // delete directives are unnecessary. |
1173 if (GetPreferredDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && | 1169 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && |
1174 encrypted_types_.Has(syncer::SESSIONS)) { | 1170 encrypted_types_.Has(syncer::SESSIONS)) { |
1175 DisableBrokenDatatype(syncer::HISTORY_DELETE_DIRECTIVES, | 1171 DisableBrokenDatatype(syncer::HISTORY_DELETE_DIRECTIVES, |
1176 FROM_HERE, | 1172 FROM_HERE, |
1177 "Delete directives not supported with encryption."); | 1173 "Delete directives not supported with encryption."); |
1178 } | 1174 } |
1179 } | 1175 } |
1180 | 1176 |
1181 void ProfileSyncService::OnEncryptionComplete() { | 1177 void ProfileSyncService::OnEncryptionComplete() { |
1182 DVLOG(1) << "Encryption complete"; | 1178 DVLOG(1) << "Encryption complete"; |
1183 if (encryption_pending_ && encrypt_everything_) { | 1179 if (encryption_pending_ && encrypt_everything_) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 | 1426 |
1431 bool ProfileSyncService::HasUnrecoverableError() const { | 1427 bool ProfileSyncService::HasUnrecoverableError() const { |
1432 return unrecoverable_error_reason_ != ERROR_REASON_UNSET; | 1428 return unrecoverable_error_reason_ != ERROR_REASON_UNSET; |
1433 } | 1429 } |
1434 | 1430 |
1435 bool ProfileSyncService::IsPassphraseRequired() const { | 1431 bool ProfileSyncService::IsPassphraseRequired() const { |
1436 return passphrase_required_reason_ != | 1432 return passphrase_required_reason_ != |
1437 syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 1433 syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
1438 } | 1434 } |
1439 | 1435 |
1440 // TODO(zea): Rename this IsPassphraseNeededFromUI and ensure it's used | |
1441 // appropriately (see http://crbug.com/91379). | |
1442 bool ProfileSyncService::IsPassphraseRequiredForDecryption() const { | 1436 bool ProfileSyncService::IsPassphraseRequiredForDecryption() const { |
1443 // If there is an encrypted datatype enabled and we don't have the proper | 1437 // If there is an encrypted datatype enabled and we don't have the proper |
1444 // passphrase, we must prompt the user for a passphrase. The only way for the | 1438 // passphrase, we must prompt the user for a passphrase. The only way for the |
1445 // user to avoid entering their passphrase is to disable the encrypted types. | 1439 // user to avoid entering their passphrase is to disable the encrypted types. |
1446 return IsEncryptedDatatypeEnabled() && IsPassphraseRequired(); | 1440 return IsEncryptedDatatypeEnabled() && IsPassphraseRequired(); |
1447 } | 1441 } |
1448 | 1442 |
1449 string16 ProfileSyncService::GetLastSyncedTimeString() const { | 1443 string16 ProfileSyncService::GetLastSyncedTimeString() const { |
1450 if (last_synced_time_.is_null()) | 1444 if (last_synced_time_.is_null()) |
1451 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER); | 1445 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 1541 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
1548 const syncer::ModelTypeSet registered_preferred_types = | 1542 const syncer::ModelTypeSet registered_preferred_types = |
1549 Intersection(registered_types, preferred_types); | 1543 Intersection(registered_types, preferred_types); |
1550 sync_prefs_.SetPreferredDataTypes(registered_types, | 1544 sync_prefs_.SetPreferredDataTypes(registered_types, |
1551 registered_preferred_types); | 1545 registered_preferred_types); |
1552 | 1546 |
1553 // Now reconfigure the DTM. | 1547 // Now reconfigure the DTM. |
1554 ReconfigureDatatypeManager(); | 1548 ReconfigureDatatypeManager(); |
1555 } | 1549 } |
1556 | 1550 |
| 1551 syncer::ModelTypeSet ProfileSyncService::GetActiveDataTypes() const { |
| 1552 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); |
| 1553 const syncer::ModelTypeSet failed_types = |
| 1554 failed_datatypes_handler_.GetFailedTypes(); |
| 1555 return Difference(preferred_types, failed_types); |
| 1556 } |
| 1557 |
1557 syncer::ModelTypeSet ProfileSyncService::GetPreferredDataTypes() const { | 1558 syncer::ModelTypeSet ProfileSyncService::GetPreferredDataTypes() const { |
1558 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 1559 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
1559 const syncer::ModelTypeSet preferred_types = | 1560 const syncer::ModelTypeSet preferred_types = |
1560 sync_prefs_.GetPreferredDataTypes(registered_types); | 1561 sync_prefs_.GetPreferredDataTypes(registered_types); |
1561 const syncer::ModelTypeSet failed_types = | 1562 return preferred_types; |
1562 failed_datatypes_handler_.GetFailedTypes(); | |
1563 return Difference(preferred_types, failed_types); | |
1564 } | 1563 } |
1565 | 1564 |
1566 syncer::ModelTypeSet ProfileSyncService::GetRegisteredDataTypes() const { | 1565 syncer::ModelTypeSet ProfileSyncService::GetRegisteredDataTypes() const { |
1567 syncer::ModelTypeSet registered_types; | 1566 syncer::ModelTypeSet registered_types; |
1568 // The data_type_controllers_ are determined by command-line flags; that's | 1567 // The data_type_controllers_ are determined by command-line flags; that's |
1569 // effectively what controls the values returned here. | 1568 // effectively what controls the values returned here. |
1570 for (DataTypeController::TypeMap::const_iterator it = | 1569 for (DataTypeController::TypeMap::const_iterator it = |
1571 data_type_controllers_.begin(); | 1570 data_type_controllers_.begin(); |
1572 it != data_type_controllers_.end(); ++it) { | 1571 it != data_type_controllers_.end(); ++it) { |
1573 registered_types.Put(it->first); | 1572 registered_types.Put(it->first); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 profile_->GetDebugName(), GetUserShare(), | 1635 profile_->GetDebugName(), GetUserShare(), |
1637 this, data_type_manager_.get(), | 1636 this, data_type_manager_.get(), |
1638 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1637 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
1639 base::Unretained(this)))); | 1638 base::Unretained(this)))); |
1640 } | 1639 } |
1641 | 1640 |
1642 // This is probably where we want to trigger configuration of priority | 1641 // This is probably where we want to trigger configuration of priority |
1643 // datatypes, but we need to resolve crbug.com/226195 first. | 1642 // datatypes, but we need to resolve crbug.com/226195 first. |
1644 | 1643 |
1645 #if defined(OS_ANDROID) | 1644 #if defined(OS_ANDROID) |
1646 if (GetPreferredDataTypes().Has(syncer::PASSWORDS) && | 1645 if (GetActiveDataTypes().Has(syncer::PASSWORDS) && |
1647 !ShouldEnablePasswordSyncForAndroid()) { | 1646 !ShouldEnablePasswordSyncForAndroid()) { |
1648 DisableBrokenDatatype(syncer::PASSWORDS, FROM_HERE, "Not supported."); | 1647 DisableBrokenDatatype(syncer::PASSWORDS, FROM_HERE, "Not supported."); |
1649 } | 1648 } |
1650 #endif | 1649 #endif |
1651 | 1650 |
1652 const syncer::ModelTypeSet types = GetPreferredDataTypes(); | |
1653 if (IsPassphraseRequiredForDecryption()) { | 1651 if (IsPassphraseRequiredForDecryption()) { |
1654 // We need a passphrase still. We don't bother to attempt to configure | 1652 // We need a passphrase still. We don't bother to attempt to configure |
1655 // until we receive an OnPassphraseAccepted (which triggers a configure). | 1653 // until we receive an OnPassphraseAccepted (which triggers a configure). |
1656 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " | 1654 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " |
1657 << "because a passphrase required"; | 1655 << "because a passphrase required"; |
1658 NotifyObservers(); | 1656 NotifyObservers(); |
1659 return; | 1657 return; |
1660 } | 1658 } |
| 1659 |
| 1660 const syncer::ModelTypeSet types = GetActiveDataTypes(); |
1661 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1661 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
1662 if (!HasSyncSetupCompleted()) { | 1662 if (!HasSyncSetupCompleted()) { |
1663 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; | 1663 reason = syncer::CONFIGURE_REASON_NEW_CLIENT; |
1664 } else if (restart) { | 1664 } else if (restart) { |
1665 // Datatype downloads on restart are generally due to newly supported | 1665 // Datatype downloads on restart are generally due to newly supported |
1666 // datatypes (although it's also possible we're picking up where a failed | 1666 // datatypes (although it's also possible we're picking up where a failed |
1667 // previous configuration left off). | 1667 // previous configuration left off). |
1668 // TODO(sync): consider detecting configuration recovery and setting | 1668 // TODO(sync): consider detecting configuration recovery and setting |
1669 // the reason here appropriately. | 1669 // the reason here appropriately. |
1670 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; | 1670 reason = syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 #if defined(ENABLE_MANAGED_USERS) | 2112 #if defined(ENABLE_MANAGED_USERS) |
2113 if (ManagedUserService::ProfileIsManaged(profile_)) { | 2113 if (ManagedUserService::ProfileIsManaged(profile_)) { |
2114 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); | 2114 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); |
2115 return ManagedUserService::GetManagedUserPseudoEmail(); | 2115 return ManagedUserService::GetManagedUserPseudoEmail(); |
2116 } | 2116 } |
2117 #endif | 2117 #endif |
2118 | 2118 |
2119 return signin_->GetAuthenticatedUsername(); | 2119 return signin_->GetAuthenticatedUsername(); |
2120 } | 2120 } |
2121 | 2121 |
OLD | NEW |