| 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 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 base::Bind(&ProfileSyncService::ShutdownImpl, | 948 base::Bind(&ProfileSyncService::ShutdownImpl, |
| 949 weak_factory_.GetWeakPtr(), | 949 weak_factory_.GetWeakPtr(), |
| 950 delete_sync_database ? | 950 delete_sync_database ? |
| 951 browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD : | 951 browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD : |
| 952 browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD)); | 952 browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD)); |
| 953 } | 953 } |
| 954 | 954 |
| 955 // TODO(zea): Move this logic into the DataTypeController/DataTypeManager. | 955 // TODO(zea): Move this logic into the DataTypeController/DataTypeManager. |
| 956 void ProfileSyncService::DisableDatatype( | 956 void ProfileSyncService::DisableDatatype( |
| 957 syncer::ModelType type, | 957 syncer::ModelType type, |
| 958 const tracked_objects::Location& from_here, | 958 const syncer::SyncError& error) { |
| 959 std::string message) { | |
| 960 // First deactivate the type so that no further server changes are | 959 // First deactivate the type so that no further server changes are |
| 961 // passed onto the change processor. | 960 // passed onto the change processor. |
| 962 DeactivateDataType(type); | 961 DeactivateDataType(type); |
| 963 | 962 |
| 964 syncer::SyncError error(from_here, | |
| 965 syncer::SyncError::DATATYPE_ERROR, | |
| 966 message, | |
| 967 type); | |
| 968 | |
| 969 std::map<syncer::ModelType, syncer::SyncError> errors; | 963 std::map<syncer::ModelType, syncer::SyncError> errors; |
| 970 errors[type] = error; | 964 errors[type] = error; |
| 971 | 965 |
| 972 // Update this before posting a task. So if a configure happens before | 966 // Update this before posting a task. So if a configure happens before |
| 973 // the task that we are going to post, this type would still be disabled. | 967 // the task that we are going to post, this type would still be disabled. |
| 974 failed_data_types_handler_.UpdateFailedDataTypes(errors); | 968 failed_data_types_handler_.UpdateFailedDataTypes(errors); |
| 975 | 969 |
| 976 base::MessageLoop::current()->PostTask(FROM_HERE, | 970 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 977 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, | 971 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, |
| 978 weak_factory_.GetWeakPtr())); | 972 weak_factory_.GetWeakPtr())); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 DVLOG(1) << "Encrypted types changed to " | 1358 DVLOG(1) << "Encrypted types changed to " |
| 1365 << syncer::ModelTypeSetToString(encrypted_types_) | 1359 << syncer::ModelTypeSetToString(encrypted_types_) |
| 1366 << " (encrypt everything is set to " | 1360 << " (encrypt everything is set to " |
| 1367 << (encrypt_everything_ ? "true" : "false") << ")"; | 1361 << (encrypt_everything_ ? "true" : "false") << ")"; |
| 1368 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); | 1362 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); |
| 1369 | 1363 |
| 1370 // If sessions are encrypted, full history sync is not possible, and | 1364 // If sessions are encrypted, full history sync is not possible, and |
| 1371 // delete directives are unnecessary. | 1365 // delete directives are unnecessary. |
| 1372 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && | 1366 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && |
| 1373 encrypted_types_.Has(syncer::SESSIONS)) { | 1367 encrypted_types_.Has(syncer::SESSIONS)) { |
| 1374 DisableDatatype(syncer::HISTORY_DELETE_DIRECTIVES, | 1368 syncer::SyncError error( |
| 1375 FROM_HERE, | 1369 FROM_HERE, |
| 1376 "Delete directives not supported with encryption."); | 1370 syncer::SyncError::DATATYPE_POLICY_ERROR, |
| 1371 "Delete directives not supported with encryption.", |
| 1372 syncer::HISTORY_DELETE_DIRECTIVES); |
| 1373 DisableDatatype(syncer::HISTORY_DELETE_DIRECTIVES, error); |
| 1377 } | 1374 } |
| 1378 } | 1375 } |
| 1379 | 1376 |
| 1380 void ProfileSyncService::OnEncryptionComplete() { | 1377 void ProfileSyncService::OnEncryptionComplete() { |
| 1381 DVLOG(1) << "Encryption complete"; | 1378 DVLOG(1) << "Encryption complete"; |
| 1382 if (encryption_pending_ && encrypt_everything_) { | 1379 if (encryption_pending_ && encrypt_everything_) { |
| 1383 encryption_pending_ = false; | 1380 encryption_pending_ = false; |
| 1384 // This is to nudge the integration tests when encryption is | 1381 // This is to nudge the integration tests when encryption is |
| 1385 // finished. | 1382 // finished. |
| 1386 NotifyObservers(); | 1383 NotifyObservers(); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 NOTREACHED(); | 1769 NOTREACHED(); |
| 1773 return; | 1770 return; |
| 1774 } | 1771 } |
| 1775 | 1772 |
| 1776 UpdateSelectedTypesHistogram(sync_everything, chosen_types); | 1773 UpdateSelectedTypesHistogram(sync_everything, chosen_types); |
| 1777 sync_prefs_.SetKeepEverythingSynced(sync_everything); | 1774 sync_prefs_.SetKeepEverythingSynced(sync_everything); |
| 1778 | 1775 |
| 1779 failed_data_types_handler_.Reset(); | 1776 failed_data_types_handler_.Reset(); |
| 1780 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && | 1777 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && |
| 1781 encrypted_types_.Has(syncer::SESSIONS)) { | 1778 encrypted_types_.Has(syncer::SESSIONS)) { |
| 1782 DisableDatatype(syncer::HISTORY_DELETE_DIRECTIVES, | 1779 syncer::SyncError error( |
| 1783 FROM_HERE, | 1780 FROM_HERE, |
| 1784 "Delete directives not supported with encryption."); | 1781 syncer::SyncError::DATATYPE_POLICY_ERROR, |
| 1782 "Delete directives not supported with encryption.", |
| 1783 syncer::HISTORY_DELETE_DIRECTIVES); |
| 1784 DisableDatatype(syncer::HISTORY_DELETE_DIRECTIVES, error); |
| 1785 } | 1785 } |
| 1786 ChangePreferredDataTypes(chosen_types); | 1786 ChangePreferredDataTypes(chosen_types); |
| 1787 AcknowledgeSyncedTypes(); | 1787 AcknowledgeSyncedTypes(); |
| 1788 NotifyObservers(); | 1788 NotifyObservers(); |
| 1789 } | 1789 } |
| 1790 | 1790 |
| 1791 void ProfileSyncService::ChangePreferredDataTypes( | 1791 void ProfileSyncService::ChangePreferredDataTypes( |
| 1792 syncer::ModelTypeSet preferred_types) { | 1792 syncer::ModelTypeSet preferred_types) { |
| 1793 | 1793 |
| 1794 DVLOG(1) << "ChangePreferredDataTypes invoked"; | 1794 DVLOG(1) << "ChangePreferredDataTypes invoked"; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2019 scoped_ptr<base::DictionaryValue> type_status; | 2019 scoped_ptr<base::DictionaryValue> type_status; |
| 2020 for (ModelTypeSet::Iterator it = registered.First(); it.Good(); it.Inc()) { | 2020 for (ModelTypeSet::Iterator it = registered.First(); it.Good(); it.Inc()) { |
| 2021 ModelType type = it.Get(); | 2021 ModelType type = it.Get(); |
| 2022 | 2022 |
| 2023 type_status.reset(new base::DictionaryValue()); | 2023 type_status.reset(new base::DictionaryValue()); |
| 2024 type_status->SetString("name", ModelTypeToString(type)); | 2024 type_status->SetString("name", ModelTypeToString(type)); |
| 2025 | 2025 |
| 2026 if (error_map.find(type) != error_map.end()) { | 2026 if (error_map.find(type) != error_map.end()) { |
| 2027 const syncer::SyncError &error = error_map.find(type)->second; | 2027 const syncer::SyncError &error = error_map.find(type)->second; |
| 2028 DCHECK(error.IsSet()); | 2028 DCHECK(error.IsSet()); |
| 2029 std::string error_text = "Error: " + error.location().ToString() + | 2029 switch (error.GetSeverity()) { |
| 2030 ", " + error.message(); | 2030 case syncer::SyncError::SYNC_ERROR_SEVERITY_ERROR: { |
| 2031 type_status->SetString("status", "error"); | 2031 std::string error_text = "Error: " + error.location().ToString() + |
| 2032 type_status->SetString("value", error_text); | 2032 ", " + error.GetMessagePrefix() + error.message(); |
| 2033 type_status->SetString("status", "error"); |
| 2034 type_status->SetString("value", error_text); |
| 2035 } |
| 2036 break; |
| 2037 case syncer::SyncError::SYNC_ERROR_SEVERITY_INFO: |
| 2038 type_status->SetString("status", "disabled"); |
| 2039 type_status->SetString("value", error.message()); |
| 2040 break; |
| 2041 default: |
| 2042 NOTREACHED() << "Unexpected error severity."; |
| 2043 break; |
| 2044 } |
| 2033 } else if (syncer::IsProxyType(type) && passive_types.Has(type)) { | 2045 } else if (syncer::IsProxyType(type) && passive_types.Has(type)) { |
| 2034 // Show a proxy type in "ok" state unless it is disabled by user. | 2046 // Show a proxy type in "ok" state unless it is disabled by user. |
| 2035 DCHECK(!throttled_types.Has(type)); | 2047 DCHECK(!throttled_types.Has(type)); |
| 2036 type_status->SetString("status", "ok"); | 2048 type_status->SetString("status", "ok"); |
| 2037 type_status->SetString("value", "Passive"); | 2049 type_status->SetString("value", "Passive"); |
| 2038 } else if (throttled_types.Has(type) && passive_types.Has(type)) { | 2050 } else if (throttled_types.Has(type) && passive_types.Has(type)) { |
| 2039 type_status->SetString("status", "warning"); | 2051 type_status->SetString("status", "warning"); |
| 2040 type_status->SetString("value", "Passive, Throttled"); | 2052 type_status->SetString("value", "Passive, Throttled"); |
| 2041 } else if (passive_types.Has(type)) { | 2053 } else if (passive_types.Has(type)) { |
| 2042 type_status->SetString("status", "warning"); | 2054 type_status->SetString("status", "warning"); |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2590 } | 2602 } |
| 2591 return result; | 2603 return result; |
| 2592 } | 2604 } |
| 2593 | 2605 |
| 2594 void ProfileSyncService::StartStopBackupForTesting() { | 2606 void ProfileSyncService::StartStopBackupForTesting() { |
| 2595 if (backend_mode_ == BACKUP) | 2607 if (backend_mode_ == BACKUP) |
| 2596 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); | 2608 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); |
| 2597 else | 2609 else |
| 2598 backup_rollback_controller_.Start(base::TimeDelta()); | 2610 backup_rollback_controller_.Start(base::TimeDelta()); |
| 2599 } | 2611 } |
| OLD | NEW |