Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 312163004: [Sync] Add support for dynamically enabling/disabling types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment, fix purging behavior Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 // Shut all data types down. 935 // Shut all data types down.
936 base::MessageLoop::current()->PostTask(FROM_HERE, 936 base::MessageLoop::current()->PostTask(FROM_HERE,
937 base::Bind(&ProfileSyncService::ShutdownImpl, 937 base::Bind(&ProfileSyncService::ShutdownImpl,
938 weak_factory_.GetWeakPtr(), 938 weak_factory_.GetWeakPtr(),
939 delete_sync_database ? 939 delete_sync_database ?
940 browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD : 940 browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD :
941 browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD)); 941 browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD));
942 } 942 }
943 943
944 // TODO(zea): Move this logic into the DataTypeController/DataTypeManager. 944 // TODO(zea): Move this logic into the DataTypeController/DataTypeManager.
945 void ProfileSyncService::DisableBrokenDatatype( 945 void ProfileSyncService::DisableDatatype(
946 syncer::ModelType type, 946 syncer::ModelType type,
947 const tracked_objects::Location& from_here, 947 const tracked_objects::Location& from_here,
948 std::string message) { 948 std::string message) {
949 // First deactivate the type so that no further server changes are 949 // First deactivate the type so that no further server changes are
950 // passed onto the change processor. 950 // passed onto the change processor.
951 DeactivateDataType(type); 951 DeactivateDataType(type);
952 952
953 syncer::SyncError error(from_here, 953 syncer::SyncError error(from_here,
954 syncer::SyncError::DATATYPE_ERROR, 954 syncer::SyncError::DATATYPE_ERROR,
955 message, 955 message,
956 type); 956 type);
957 957
958 std::map<syncer::ModelType, syncer::SyncError> errors; 958 std::map<syncer::ModelType, syncer::SyncError> errors;
959 errors[type] = error; 959 errors[type] = error;
960 960
961 // Update this before posting a task. So if a configure happens before 961 // Update this before posting a task. So if a configure happens before
962 // the task that we are going to post, this type would still be disabled. 962 // the task that we are going to post, this type would still be disabled.
963 failed_data_types_handler_.UpdateFailedDataTypes(errors); 963 failed_data_types_handler_.UpdateFailedDataTypes(errors);
964 964
965 base::MessageLoop::current()->PostTask(FROM_HERE, 965 base::MessageLoop::current()->PostTask(FROM_HERE,
966 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 966 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
967 weak_factory_.GetWeakPtr())); 967 weak_factory_.GetWeakPtr()));
968 } 968 }
969 969
970 void ProfileSyncService::ReenableDatatype(syncer::ModelType type) {
971 // Only reconfigure if the type actually had a data type or unready error.
972 if (!failed_data_types_handler_.ResetDataTypeErrorFor(type) &&
973 !failed_data_types_handler_.ResetUnreadyErrorFor(type)) {
974 return;
975 }
976
977 // If the type is no longer enabled, don't bother reconfiguring.
978 // TODO(zea): something else should encapsulate the notion of "whether a type
979 // should be enabled".
980 if (!syncer::CoreTypes().Has(type) && !GetPreferredDataTypes().Has(type))
981 return;
982
983 base::MessageLoop::current()->PostTask(FROM_HERE,
984 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
985 weak_factory_.GetWeakPtr()));
986 }
987
970 void ProfileSyncService::UpdateBackendInitUMA(bool success) { 988 void ProfileSyncService::UpdateBackendInitUMA(bool success) {
971 if (backend_mode_ != SYNC) 989 if (backend_mode_ != SYNC)
972 return; 990 return;
973 991
974 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 992 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
975 993
976 if (is_first_time_sync_configure_) { 994 if (is_first_time_sync_configure_) {
977 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 995 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
978 } else { 996 } else {
979 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 997 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 DVLOG(1) << "Encrypted types changed to " 1353 DVLOG(1) << "Encrypted types changed to "
1336 << syncer::ModelTypeSetToString(encrypted_types_) 1354 << syncer::ModelTypeSetToString(encrypted_types_)
1337 << " (encrypt everything is set to " 1355 << " (encrypt everything is set to "
1338 << (encrypt_everything_ ? "true" : "false") << ")"; 1356 << (encrypt_everything_ ? "true" : "false") << ")";
1339 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); 1357 DCHECK(encrypted_types_.Has(syncer::PASSWORDS));
1340 1358
1341 // If sessions are encrypted, full history sync is not possible, and 1359 // If sessions are encrypted, full history sync is not possible, and
1342 // delete directives are unnecessary. 1360 // delete directives are unnecessary.
1343 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && 1361 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) &&
1344 encrypted_types_.Has(syncer::SESSIONS)) { 1362 encrypted_types_.Has(syncer::SESSIONS)) {
1345 DisableBrokenDatatype(syncer::HISTORY_DELETE_DIRECTIVES, 1363 DisableDatatype(syncer::HISTORY_DELETE_DIRECTIVES,
1346 FROM_HERE, 1364 FROM_HERE,
1347 "Delete directives not supported with encryption."); 1365 "Delete directives not supported with encryption.");
1348 } 1366 }
1349 } 1367 }
1350 1368
1351 void ProfileSyncService::OnEncryptionComplete() { 1369 void ProfileSyncService::OnEncryptionComplete() {
1352 DVLOG(1) << "Encryption complete"; 1370 DVLOG(1) << "Encryption complete";
1353 if (encryption_pending_ && encrypt_everything_) { 1371 if (encryption_pending_ && encrypt_everything_) {
1354 encryption_pending_ = false; 1372 encryption_pending_ = false;
1355 // This is to nudge the integration tests when encryption is 1373 // This is to nudge the integration tests when encryption is
1356 // finished. 1374 // finished.
1357 NotifyObservers(); 1375 NotifyObservers();
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 NOTREACHED(); 1759 NOTREACHED();
1742 return; 1760 return;
1743 } 1761 }
1744 1762
1745 UpdateSelectedTypesHistogram(sync_everything, chosen_types); 1763 UpdateSelectedTypesHistogram(sync_everything, chosen_types);
1746 sync_prefs_.SetKeepEverythingSynced(sync_everything); 1764 sync_prefs_.SetKeepEverythingSynced(sync_everything);
1747 1765
1748 failed_data_types_handler_.Reset(); 1766 failed_data_types_handler_.Reset();
1749 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && 1767 if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) &&
1750 encrypted_types_.Has(syncer::SESSIONS)) { 1768 encrypted_types_.Has(syncer::SESSIONS)) {
1751 DisableBrokenDatatype(syncer::HISTORY_DELETE_DIRECTIVES, 1769 DisableDatatype(syncer::HISTORY_DELETE_DIRECTIVES,
1752 FROM_HERE, 1770 FROM_HERE,
1753 "Delete directives not supported with encryption."); 1771 "Delete directives not supported with encryption.");
1754 } 1772 }
1755 ChangePreferredDataTypes(chosen_types); 1773 ChangePreferredDataTypes(chosen_types);
1756 AcknowledgeSyncedTypes(); 1774 AcknowledgeSyncedTypes();
1757 NotifyObservers(); 1775 NotifyObservers();
1758 } 1776 }
1759 1777
1760 void ProfileSyncService::ChangePreferredDataTypes( 1778 void ProfileSyncService::ChangePreferredDataTypes(
1761 syncer::ModelTypeSet preferred_types) { 1779 syncer::ModelTypeSet preferred_types) {
1762 1780
1763 DVLOG(1) << "ChangePreferredDataTypes invoked"; 1781 DVLOG(1) << "ChangePreferredDataTypes invoked";
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 if (custom_sync_url.is_valid()) { 2568 if (custom_sync_url.is_valid()) {
2551 result = custom_sync_url; 2569 result = custom_sync_url;
2552 } else { 2570 } else {
2553 LOG(WARNING) << "The following sync URL specified at the command-line " 2571 LOG(WARNING) << "The following sync URL specified at the command-line "
2554 << "is invalid: " << value; 2572 << "is invalid: " << value;
2555 } 2573 }
2556 } 2574 }
2557 } 2575 }
2558 return result; 2576 return result;
2559 } 2577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698