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> | |
8 #include <cstddef> | 7 #include <cstddef> |
9 #include <map> | 8 #include <map> |
10 #include <set> | 9 #include <set> |
11 #include <utility> | 10 #include <utility> |
12 | 11 |
13 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
14 #include "base/bind.h" | 13 #include "base/bind.h" |
15 #include "base/callback.h" | 14 #include "base/callback.h" |
16 #include "base/command_line.h" | 15 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 browser_sync::SyncServiceName()); | 299 browser_sync::SyncServiceName()); |
301 return credentials; | 300 return credentials; |
302 } | 301 } |
303 | 302 |
304 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { | 303 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { |
305 if (!backend_.get()) { | 304 if (!backend_.get()) { |
306 NOTREACHED(); | 305 NOTREACHED(); |
307 return; | 306 return; |
308 } | 307 } |
309 | 308 |
310 syncable::ModelTypeSet initial_types; | 309 syncable::ModelEnumSet initial_types; |
311 // If sync setup hasn't finished, we don't want to initialize routing info | 310 // If sync setup hasn't finished, we don't want to initialize routing info |
312 // for any data types so that we don't download updates for types that the | 311 // for any data types so that we don't download updates for types that the |
313 // user chooses not to sync on the first DownloadUpdatesCommand. | 312 // user chooses not to sync on the first DownloadUpdatesCommand. |
314 if (HasSyncSetupCompleted()) { | 313 if (HasSyncSetupCompleted()) { |
315 GetPreferredDataTypes(&initial_types); | 314 initial_types = GetPreferredDataTypes(); |
316 } | 315 } |
317 | 316 |
318 SyncCredentials credentials = GetCredentials(); | 317 SyncCredentials credentials = GetCredentials(); |
319 | 318 |
320 scoped_refptr<net::URLRequestContextGetter> request_context_getter( | 319 scoped_refptr<net::URLRequestContextGetter> request_context_getter( |
321 profile_->GetRequestContext()); | 320 profile_->GetRequestContext()); |
322 | 321 |
323 if (delete_stale_data) | 322 if (delete_stale_data) |
324 ClearStaleErrors(); | 323 ClearStaleErrors(); |
325 | 324 |
326 backend_->Initialize( | 325 backend_->Initialize( |
327 this, | 326 this, |
328 MakeWeakHandle(sync_js_controller_.AsWeakPtr()), | 327 MakeWeakHandle(sync_js_controller_.AsWeakPtr()), |
329 sync_service_url_, | 328 sync_service_url_, |
330 initial_types, | 329 initial_types, |
331 credentials, | 330 credentials, |
332 delete_stale_data); | 331 delete_stale_data); |
333 } | 332 } |
334 | 333 |
335 void ProfileSyncService::CreateBackend() { | 334 void ProfileSyncService::CreateBackend() { |
336 backend_.reset( | 335 backend_.reset( |
337 new SyncBackendHost(profile_->GetDebugName(), | 336 new SyncBackendHost(profile_->GetDebugName(), |
338 profile_, sync_prefs_.AsWeakPtr())); | 337 profile_, sync_prefs_.AsWeakPtr())); |
339 } | 338 } |
340 | 339 |
341 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 340 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
342 if (encryption_pending()) | 341 if (encryption_pending()) |
343 return true; | 342 return true; |
344 syncable::ModelTypeSet preferred_types; | 343 const syncable::ModelEnumSet preferred_types = GetPreferredDataTypes(); |
345 GetPreferredDataTypes(&preferred_types); | 344 const syncable::ModelEnumSet encrypted_types = GetEncryptedDataTypes(); |
346 syncable::ModelTypeSet encrypted_types; | 345 DCHECK(encrypted_types.Has(syncable::PASSWORDS)); |
347 GetEncryptedDataTypes(&encrypted_types); | 346 return !Intersection(preferred_types, encrypted_types).Empty(); |
348 const syncable::ModelEnumSet preferred_types_enum_set = | |
349 syncable::ModelTypeSetToEnumSet(preferred_types); | |
350 const syncable::ModelEnumSet encrypted_types_enum_set = | |
351 syncable::ModelTypeSetToEnumSet(encrypted_types); | |
352 DCHECK(encrypted_types.count(syncable::PASSWORDS)); | |
353 return | |
354 !Intersection(preferred_types_enum_set, | |
355 encrypted_types_enum_set).Empty(); | |
356 } | 347 } |
357 | 348 |
358 void ProfileSyncService::OnSyncConfigureDone( | 349 void ProfileSyncService::OnSyncConfigureDone( |
359 DataTypeManager::ConfigureResult result) { | 350 DataTypeManager::ConfigureResult result) { |
360 if (failed_datatypes_handler_.UpdateFailedDatatypes(result)) { | 351 if (failed_datatypes_handler_.UpdateFailedDatatypes(result)) { |
361 ReconfigureDatatypeManager(); | 352 ReconfigureDatatypeManager(); |
362 } | 353 } |
363 } | 354 } |
364 | 355 |
365 void ProfileSyncService::StartUp() { | 356 void ProfileSyncService::StartUp() { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 MessageLoop::current()->PostTask(FROM_HERE, | 623 MessageLoop::current()->PostTask(FROM_HERE, |
633 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, | 624 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, |
634 GetSessionModelAssociator()->AsWeakPtr())); | 625 GetSessionModelAssociator()->AsWeakPtr())); |
635 } | 626 } |
636 DVLOG(2) << "Notifying observers sync cycle completed"; | 627 DVLOG(2) << "Notifying observers sync cycle completed"; |
637 NotifyObservers(); | 628 NotifyObservers(); |
638 } | 629 } |
639 | 630 |
640 // TODO(sync): eventually support removing datatypes too. | 631 // TODO(sync): eventually support removing datatypes too. |
641 void ProfileSyncService::OnDataTypesChanged( | 632 void ProfileSyncService::OnDataTypesChanged( |
642 const syncable::ModelTypeSet& to_add) { | 633 syncable::ModelEnumSet to_add) { |
643 // If this is a first time sync for a client, this will be called before | 634 // If this is a first time sync for a client, this will be called before |
644 // OnBackendInitialized() to ensure the new datatypes are available at sync | 635 // OnBackendInitialized() to ensure the new datatypes are available at sync |
645 // setup. As a result, the migrator won't exist yet. This is fine because for | 636 // setup. As a result, the migrator won't exist yet. This is fine because for |
646 // first time sync cases we're only concerned with making the datatype | 637 // first time sync cases we're only concerned with making the datatype |
647 // available. | 638 // available. |
648 if (migrator_.get() && | 639 if (migrator_.get() && |
649 migrator_->state() != browser_sync::BackendMigrator::IDLE) { | 640 migrator_->state() != browser_sync::BackendMigrator::IDLE) { |
650 DVLOG(1) << "Dropping OnDataTypesChanged due to migrator busy."; | 641 DVLOG(1) << "Dropping OnDataTypesChanged due to migrator busy."; |
651 return; | 642 return; |
652 } | 643 } |
653 | 644 |
654 DVLOG(2) << "OnDataTypesChanged called with types: " | 645 DVLOG(2) << "OnDataTypesChanged called with types: " |
655 << syncable::ModelTypeSetToString(to_add); | 646 << syncable::ModelEnumSetToString(to_add); |
656 | 647 |
657 syncable::ModelTypeSet registered_types; | 648 const syncable::ModelEnumSet registered_types = GetRegisteredDataTypes(); |
658 GetRegisteredDataTypes(®istered_types); | |
659 | 649 |
660 syncable::ModelTypeSet to_register; | 650 const syncable::ModelEnumSet to_register = |
661 std::set_difference(to_add.begin(), to_add.end(), | 651 Difference(to_add, registered_types); |
662 registered_types.begin(), registered_types.end(), | |
663 std::inserter(to_register, to_register.end())); | |
664 | 652 |
665 DVLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register); | 653 DVLOG(2) << "Enabling types: " << syncable::ModelEnumSetToString(to_register); |
666 | 654 |
667 for (syncable::ModelTypeSet::const_iterator it = to_register.begin(); | 655 for (syncable::ModelEnumSet::Iterator it = to_register.First(); |
668 it != to_register.end(); ++it) { | 656 it.Good(); it.Inc()) { |
669 // Received notice to enable experimental type. Check if the type is | 657 // Received notice to enable experimental type. Check if the type is |
670 // registered, and if not register a new datatype controller. | 658 // registered, and if not register a new datatype controller. |
671 RegisterNewDataType(*it); | 659 RegisterNewDataType(it.Get()); |
672 // Enable the about:flags switch for the experimental type so we don't have | 660 // Enable the about:flags switch for the experimental type so we don't have |
673 // to always perform this reconfiguration. Once we set this, the type will | 661 // to always perform this reconfiguration. Once we set this, the type will |
674 // remain registered on restart, so we will no longer go down this code | 662 // remain registered on restart, so we will no longer go down this code |
675 // path. | 663 // path. |
676 std::string experiment_name = GetExperimentNameForDataType(*it); | 664 std::string experiment_name = GetExperimentNameForDataType(it.Get()); |
677 if (experiment_name.empty()) | 665 if (experiment_name.empty()) |
678 continue; | 666 continue; |
679 about_flags::SetExperimentEnabled(g_browser_process->local_state(), | 667 about_flags::SetExperimentEnabled(g_browser_process->local_state(), |
680 experiment_name, | 668 experiment_name, |
681 true); | 669 true); |
682 } | 670 } |
683 | 671 |
684 // Check if the user has "Keep Everything Synced" enabled. If so, we want | 672 // Check if the user has "Keep Everything Synced" enabled. If so, we want |
685 // to turn on all experimental types if they're not already on. Otherwise we | 673 // to turn on all experimental types if they're not already on. Otherwise we |
686 // leave them off. | 674 // leave them off. |
687 // Note: if any types are already registered, we don't turn them on. This | 675 // Note: if any types are already registered, we don't turn them on. This |
688 // covers the case where we're already in the process of reconfiguring | 676 // covers the case where we're already in the process of reconfiguring |
689 // to turn an experimental type on. | 677 // to turn an experimental type on. |
690 if (sync_prefs_.HasKeepEverythingSynced()) { | 678 if (sync_prefs_.HasKeepEverythingSynced()) { |
691 // Mark all data types as preferred. | 679 // Mark all data types as preferred. |
692 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); | 680 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); |
693 | 681 |
694 // Only automatically turn on types if we have already finished set up. | 682 // Only automatically turn on types if we have already finished set up. |
695 // Otherwise, just leave the experimental types on by default. | 683 // Otherwise, just leave the experimental types on by default. |
696 if (!to_register.empty() && HasSyncSetupCompleted() && migrator_.get()) { | 684 if (!to_register.Empty() && HasSyncSetupCompleted() && migrator_.get()) { |
697 DVLOG(1) << "Dynamically enabling new datatypes: " | 685 DVLOG(1) << "Dynamically enabling new datatypes: " |
698 << syncable::ModelTypeSetToString(to_register); | 686 << syncable::ModelEnumSetToString(to_register); |
699 OnMigrationNeededForTypes(to_register); | 687 OnMigrationNeededForTypes(to_register); |
700 } | 688 } |
701 } | 689 } |
702 } | 690 } |
703 | 691 |
704 void ProfileSyncService::UpdateAuthErrorState( | 692 void ProfileSyncService::UpdateAuthErrorState( |
705 const GoogleServiceAuthError& error) { | 693 const GoogleServiceAuthError& error) { |
706 last_auth_error_ = error; | 694 last_auth_error_ = error; |
707 // Protect against the in-your-face dialogs that pop out of nowhere. | 695 // Protect against the in-your-face dialogs that pop out of nowhere. |
708 // Require the user to click somewhere to run the setup wizard in the case | 696 // Require the user to click somewhere to run the setup wizard in the case |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 void ProfileSyncService::OnPassphraseAccepted() { | 818 void ProfileSyncService::OnPassphraseAccepted() { |
831 DVLOG(1) << "Received OnPassphraseAccepted."; | 819 DVLOG(1) << "Received OnPassphraseAccepted."; |
832 // Reset passphrase_required_reason_ since we know we no longer require the | 820 // Reset passphrase_required_reason_ since we know we no longer require the |
833 // passphrase. We do this here rather than down in ResolvePassphraseRequired() | 821 // passphrase. We do this here rather than down in ResolvePassphraseRequired() |
834 // because that can be called by OnPassphraseRequired() if no encrypted data | 822 // because that can be called by OnPassphraseRequired() if no encrypted data |
835 // types are enabled, and we don't want to clobber the true passphrase error. | 823 // types are enabled, and we don't want to clobber the true passphrase error. |
836 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; | 824 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; |
837 | 825 |
838 // Make sure the data types that depend on the passphrase are started at | 826 // Make sure the data types that depend on the passphrase are started at |
839 // this time. | 827 // this time. |
840 syncable::ModelTypeSet types; | 828 const syncable::ModelEnumSet types = GetPreferredDataTypes(); |
841 GetPreferredDataTypes(&types); | |
842 | 829 |
843 if (data_type_manager_.get()) { | 830 if (data_type_manager_.get()) { |
844 // Unblock the data type manager if necessary. | 831 // Unblock the data type manager if necessary. |
845 data_type_manager_->Configure(types, | 832 data_type_manager_->Configure(types, |
846 sync_api::CONFIGURE_REASON_RECONFIGURATION); | 833 sync_api::CONFIGURE_REASON_RECONFIGURATION); |
847 } | 834 } |
848 | 835 |
849 ResolvePassphraseRequired(); | 836 ResolvePassphraseRequired(); |
850 } | 837 } |
851 | 838 |
852 void ProfileSyncService::ResolvePassphraseRequired() { | 839 void ProfileSyncService::ResolvePassphraseRequired() { |
853 DCHECK(!IsPassphraseRequiredForDecryption()); | 840 DCHECK(!IsPassphraseRequiredForDecryption()); |
854 // Don't hold on to a passphrase in raw form longer than needed. | 841 // Don't hold on to a passphrase in raw form longer than needed. |
855 cached_passphrases_ = CachedPassphrases(); | 842 cached_passphrases_ = CachedPassphrases(); |
856 | 843 |
857 // If No encryption is pending and our passphrase has been accepted, tell the | 844 // If No encryption is pending and our passphrase has been accepted, tell the |
858 // wizard we're done (no need to hang around waiting for the sync to | 845 // wizard we're done (no need to hang around waiting for the sync to |
859 // complete). If encryption is pending, its successful completion will trigger | 846 // complete). If encryption is pending, its successful completion will trigger |
860 // the done step. | 847 // the done step. |
861 if (WizardIsVisible() && !encryption_pending()) | 848 if (WizardIsVisible() && !encryption_pending()) |
862 wizard_.Step(SyncSetupWizard::DONE); | 849 wizard_.Step(SyncSetupWizard::DONE); |
863 | 850 |
864 NotifyObservers(); | 851 NotifyObservers(); |
865 } | 852 } |
866 | 853 |
867 void ProfileSyncService::OnEncryptedTypesChanged( | 854 void ProfileSyncService::OnEncryptedTypesChanged( |
868 const syncable::ModelTypeSet& encrypted_types, | 855 syncable::ModelEnumSet encrypted_types, |
869 bool encrypt_everything) { | 856 bool encrypt_everything) { |
870 encrypted_types_ = encrypted_types; | 857 encrypted_types_ = encrypted_types; |
871 encrypt_everything_ = encrypt_everything; | 858 encrypt_everything_ = encrypt_everything; |
872 DVLOG(1) << "Encrypted types changed to " | 859 DVLOG(1) << "Encrypted types changed to " |
873 << syncable::ModelTypeSetToString(encrypted_types_) | 860 << syncable::ModelEnumSetToString(encrypted_types_) |
874 << " (encrypt everything is set to " | 861 << " (encrypt everything is set to " |
875 << (encrypt_everything_ ? "true" : "false") << ")"; | 862 << (encrypt_everything_ ? "true" : "false") << ")"; |
876 DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u); | 863 DCHECK(encrypted_types_.Has(syncable::PASSWORDS)); |
877 } | 864 } |
878 | 865 |
879 void ProfileSyncService::OnEncryptionComplete() { | 866 void ProfileSyncService::OnEncryptionComplete() { |
880 DVLOG(1) << "Encryption complete"; | 867 DVLOG(1) << "Encryption complete"; |
881 if (encryption_pending_ && encrypt_everything_) { | 868 if (encryption_pending_ && encrypt_everything_) { |
882 encryption_pending_ = false; | 869 encryption_pending_ = false; |
883 // The user had chosen to encrypt datatypes. This is the last thing to | 870 // The user had chosen to encrypt datatypes. This is the last thing to |
884 // complete, so now that we're done notify the UI. | 871 // complete, so now that we're done notify the UI. |
885 wizard_.Step(SyncSetupWizard::DONE); | 872 wizard_.Step(SyncSetupWizard::DONE); |
886 // This is to nudge the integration tests when encryption is | 873 // This is to nudge the integration tests when encryption is |
887 // finished. | 874 // finished. |
888 NotifyObservers(); | 875 NotifyObservers(); |
889 } | 876 } |
890 } | 877 } |
891 | 878 |
892 void ProfileSyncService::OnMigrationNeededForTypes( | 879 void ProfileSyncService::OnMigrationNeededForTypes( |
893 const syncable::ModelTypeSet& types) { | 880 syncable::ModelEnumSet types) { |
894 DCHECK(backend_initialized_); | 881 DCHECK(backend_initialized_); |
895 DCHECK(data_type_manager_.get()); | 882 DCHECK(data_type_manager_.get()); |
896 | 883 |
897 // Migrator must be valid, because we don't sync until it is created and this | 884 // Migrator must be valid, because we don't sync until it is created and this |
898 // callback originates from a sync cycle. | 885 // callback originates from a sync cycle. |
899 migrator_->MigrateTypes(types); | 886 migrator_->MigrateTypes(types); |
900 } | 887 } |
901 | 888 |
902 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { | 889 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { |
903 last_actionable_error_ = error; | 890 last_actionable_error_ = error; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 is_auth_in_progress_ = true; | 1090 is_auth_in_progress_ = true; |
1104 | 1091 |
1105 // The user has submitted credentials, which indicates they don't | 1092 // The user has submitted credentials, which indicates they don't |
1106 // want to suppress start up anymore. | 1093 // want to suppress start up anymore. |
1107 sync_prefs_.SetStartSuppressed(false); | 1094 sync_prefs_.SetStartSuppressed(false); |
1108 | 1095 |
1109 signin_->StartOAuthSignIn(oauth1_request_token); | 1096 signin_->StartOAuthSignIn(oauth1_request_token); |
1110 } | 1097 } |
1111 | 1098 |
1112 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, | 1099 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, |
1113 const syncable::ModelTypeSet& chosen_types) { | 1100 syncable::ModelEnumSet chosen_types) { |
1114 if (!backend_.get() && | 1101 if (!backend_.get() && |
1115 unrecoverable_error_detected_ == false) { | 1102 unrecoverable_error_detected_ == false) { |
1116 NOTREACHED(); | 1103 NOTREACHED(); |
1117 return; | 1104 return; |
1118 } | 1105 } |
1119 | 1106 |
1120 sync_prefs_.SetKeepEverythingSynced(sync_everything); | 1107 sync_prefs_.SetKeepEverythingSynced(sync_everything); |
1121 | 1108 |
1122 failed_datatypes_handler_.OnUserChoseDatatypes(); | 1109 failed_datatypes_handler_.OnUserChoseDatatypes(); |
1123 ChangePreferredDataTypes(chosen_types); | 1110 ChangePreferredDataTypes(chosen_types); |
(...skipping 19 matching lines...) Expand all Loading... |
1143 // succeeds, calling OnAuthError(NONE), or b) the user clicks the button, | 1130 // succeeds, calling OnAuthError(NONE), or b) the user clicks the button, |
1144 // and tries to re-authenticate. (b) is a little awkward as this second | 1131 // and tries to re-authenticate. (b) is a little awkward as this second |
1145 // request will get queued behind the first and could wind up "undoing" the | 1132 // request will get queued behind the first and could wind up "undoing" the |
1146 // good if invalid creds were provided, but it's an edge case and the user | 1133 // good if invalid creds were provided, but it's an edge case and the user |
1147 // can of course get themselves out of it. | 1134 // can of course get themselves out of it. |
1148 is_auth_in_progress_ = false; | 1135 is_auth_in_progress_ = false; |
1149 NotifyObservers(); | 1136 NotifyObservers(); |
1150 } | 1137 } |
1151 | 1138 |
1152 void ProfileSyncService::ChangePreferredDataTypes( | 1139 void ProfileSyncService::ChangePreferredDataTypes( |
1153 const syncable::ModelTypeSet& preferred_types) { | 1140 syncable::ModelEnumSet preferred_types) { |
1154 | 1141 |
1155 DVLOG(1) << "ChangePreferredDataTypes invoked"; | 1142 DVLOG(1) << "ChangePreferredDataTypes invoked"; |
1156 syncable::ModelTypeSet registered_types; | 1143 const syncable::ModelEnumSet registered_types = GetRegisteredDataTypes(); |
1157 GetRegisteredDataTypes(®istered_types); | 1144 const syncable::ModelEnumSet registered_preferred_types = |
1158 syncable::ModelTypeSet registered_preferred_types; | 1145 Intersection(registered_types, preferred_types); |
1159 std::set_intersection( | |
1160 registered_types.begin(), registered_types.end(), | |
1161 preferred_types.begin(), preferred_types.end(), | |
1162 std::inserter(registered_preferred_types, | |
1163 registered_preferred_types.end())); | |
1164 sync_prefs_.SetPreferredDataTypes(registered_types, | 1146 sync_prefs_.SetPreferredDataTypes(registered_types, |
1165 registered_preferred_types); | 1147 registered_preferred_types); |
1166 | 1148 |
1167 // Now reconfigure the DTM. | 1149 // Now reconfigure the DTM. |
1168 ReconfigureDatatypeManager(); | 1150 ReconfigureDatatypeManager(); |
1169 } | 1151 } |
1170 | 1152 |
1171 void ProfileSyncService::GetPreferredDataTypes( | 1153 syncable::ModelEnumSet ProfileSyncService::GetPreferredDataTypes() const { |
1172 syncable::ModelTypeSet* preferred_types) const { | 1154 const syncable::ModelEnumSet registered_types = GetRegisteredDataTypes(); |
1173 syncable::ModelTypeSet registered_types; | 1155 const syncable::ModelEnumSet preferred_types = |
1174 GetRegisteredDataTypes(®istered_types); | 1156 sync_prefs_.GetPreferredDataTypes(registered_types); |
1175 *preferred_types = sync_prefs_.GetPreferredDataTypes(registered_types); | 1157 const syncable::ModelEnumSet failed_types = |
1176 | |
1177 syncable::ModelTypeSet failed_types = | |
1178 failed_datatypes_handler_.GetFailedTypes(); | 1158 failed_datatypes_handler_.GetFailedTypes(); |
1179 syncable::ModelTypeSet difference; | 1159 return Difference(preferred_types, failed_types); |
1180 std::set_difference(preferred_types->begin(), preferred_types->end(), | |
1181 failed_types.begin(), failed_types.end(), | |
1182 std::inserter(difference, difference.end())); | |
1183 std::swap(*preferred_types, difference); | |
1184 } | 1160 } |
1185 | 1161 |
1186 void ProfileSyncService::GetRegisteredDataTypes( | 1162 syncable::ModelEnumSet ProfileSyncService::GetRegisteredDataTypes() const { |
1187 syncable::ModelTypeSet* registered_types) const { | 1163 syncable::ModelEnumSet registered_types; |
1188 registered_types->clear(); | |
1189 // The data_type_controllers_ are determined by command-line flags; that's | 1164 // The data_type_controllers_ are determined by command-line flags; that's |
1190 // effectively what controls the values returned here. | 1165 // effectively what controls the values returned here. |
1191 for (DataTypeController::TypeMap::const_iterator it = | 1166 for (DataTypeController::TypeMap::const_iterator it = |
1192 data_type_controllers_.begin(); | 1167 data_type_controllers_.begin(); |
1193 it != data_type_controllers_.end(); ++it) { | 1168 it != data_type_controllers_.end(); ++it) { |
1194 registered_types->insert((*it).first); | 1169 registered_types.Put(it->first); |
1195 } | 1170 } |
| 1171 return registered_types; |
1196 } | 1172 } |
1197 | 1173 |
1198 bool ProfileSyncService::IsUsingSecondaryPassphrase() const { | 1174 bool ProfileSyncService::IsUsingSecondaryPassphrase() const { |
1199 // Should never be called when the backend is not initialized, since at that | 1175 // Should never be called when the backend is not initialized, since at that |
1200 // time we have no idea whether we have an explicit passphrase or not because | 1176 // time we have no idea whether we have an explicit passphrase or not because |
1201 // the nigori node has not been downloaded yet. | 1177 // the nigori node has not been downloaded yet. |
1202 if (!sync_initialized()) { | 1178 if (!sync_initialized()) { |
1203 NOTREACHED() << "Cannot call IsUsingSecondaryPassphrase() before the sync " | 1179 NOTREACHED() << "Cannot call IsUsingSecondaryPassphrase() before the sync " |
1204 << "backend has downloaded the nigori node"; | 1180 << "backend has downloaded the nigori node"; |
1205 return false; | 1181 return false; |
(...skipping 26 matching lines...) Expand all Loading... |
1232 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 1208 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
1233 content::Source<DataTypeManager>(data_type_manager_.get())); | 1209 content::Source<DataTypeManager>(data_type_manager_.get())); |
1234 | 1210 |
1235 // We create the migrator at the same time. | 1211 // We create the migrator at the same time. |
1236 migrator_.reset( | 1212 migrator_.reset( |
1237 new browser_sync::BackendMigrator( | 1213 new browser_sync::BackendMigrator( |
1238 profile_->GetDebugName(), GetUserShare(), | 1214 profile_->GetDebugName(), GetUserShare(), |
1239 this, data_type_manager_.get())); | 1215 this, data_type_manager_.get())); |
1240 } | 1216 } |
1241 | 1217 |
1242 syncable::ModelTypeSet types; | 1218 const syncable::ModelEnumSet types = GetPreferredDataTypes(); |
1243 GetPreferredDataTypes(&types); | |
1244 if (IsPassphraseRequiredForDecryption()) { | 1219 if (IsPassphraseRequiredForDecryption()) { |
1245 // We need a passphrase still. We don't bother to attempt to configure | 1220 // We need a passphrase still. We don't bother to attempt to configure |
1246 // until we receive an OnPassphraseAccepted (which triggers a configure). | 1221 // until we receive an OnPassphraseAccepted (which triggers a configure). |
1247 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " | 1222 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " |
1248 << "because a passphrase required"; | 1223 << "because a passphrase required"; |
1249 return; | 1224 return; |
1250 } | 1225 } |
1251 sync_api::ConfigureReason reason = sync_api::CONFIGURE_REASON_UNKNOWN; | 1226 sync_api::ConfigureReason reason = sync_api::CONFIGURE_REASON_UNKNOWN; |
1252 if (!HasSyncSetupCompleted()) { | 1227 if (!HasSyncSetupCompleted()) { |
1253 reason = sync_api::CONFIGURE_REASON_NEW_CLIENT; | 1228 reason = sync_api::CONFIGURE_REASON_NEW_CLIENT; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 // initialized (via IsEncryptedDatatypeEnabled and | 1322 // initialized (via IsEncryptedDatatypeEnabled and |
1348 // IsPassphraseRequiredForDecryption). | 1323 // IsPassphraseRequiredForDecryption). |
1349 return encryption_pending_; | 1324 return encryption_pending_; |
1350 } | 1325 } |
1351 | 1326 |
1352 bool ProfileSyncService::EncryptEverythingEnabled() const { | 1327 bool ProfileSyncService::EncryptEverythingEnabled() const { |
1353 DCHECK(backend_initialized_); | 1328 DCHECK(backend_initialized_); |
1354 return encrypt_everything_; | 1329 return encrypt_everything_; |
1355 } | 1330 } |
1356 | 1331 |
1357 void ProfileSyncService::GetEncryptedDataTypes( | 1332 syncable::ModelEnumSet ProfileSyncService::GetEncryptedDataTypes() const { |
1358 syncable::ModelTypeSet* encrypted_types) const { | 1333 DCHECK(encrypted_types_.Has(syncable::PASSWORDS)); |
1359 CHECK(encrypted_types); | |
1360 // We may be called during the setup process before we're | 1334 // We may be called during the setup process before we're |
1361 // initialized. In this case, we default to the sensitive types. | 1335 // initialized. In this case, we default to the sensitive types. |
1362 *encrypted_types = encrypted_types_; | 1336 return encrypted_types_; |
1363 DCHECK_GT(encrypted_types->count(syncable::PASSWORDS), 0u); | |
1364 } | 1337 } |
1365 | 1338 |
1366 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { | 1339 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { |
1367 NotifyObservers(); | 1340 NotifyObservers(); |
1368 if (is_sync_managed) { | 1341 if (is_sync_managed) { |
1369 DisableForUser(); | 1342 DisableForUser(); |
1370 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1343 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
1371 StartUp(); | 1344 StartUp(); |
1372 } | 1345 } |
1373 } | 1346 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess | 1537 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess |
1565 // is never called for some clients. | 1538 // is never called for some clients. |
1566 if (signin_->GetAuthenticatedUsername().empty()) { | 1539 if (signin_->GetAuthenticatedUsername().empty()) { |
1567 signin_->SetAuthenticatedUsername( | 1540 signin_->SetAuthenticatedUsername( |
1568 sync_prefs_.GetGoogleServicesUsername()); | 1541 sync_prefs_.GetGoogleServicesUsername()); |
1569 } | 1542 } |
1570 TryStart(); | 1543 TryStart(); |
1571 } | 1544 } |
1572 | 1545 |
1573 void ProfileSyncService::AcknowledgeSyncedTypes() { | 1546 void ProfileSyncService::AcknowledgeSyncedTypes() { |
1574 syncable::ModelTypeSet registered_types; | 1547 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes()); |
1575 GetRegisteredDataTypes(®istered_types); | |
1576 sync_prefs_.AcknowledgeSyncedTypes(registered_types); | |
1577 } | 1548 } |
1578 | 1549 |
1579 void ProfileSyncService::ReconfigureDatatypeManager() { | 1550 void ProfileSyncService::ReconfigureDatatypeManager() { |
1580 // If we haven't initialized yet, don't configure the DTM as it could cause | 1551 // If we haven't initialized yet, don't configure the DTM as it could cause |
1581 // association to start before a Directory has even been created. | 1552 // association to start before a Directory has even been created. |
1582 if (backend_initialized_) { | 1553 if (backend_initialized_) { |
1583 DCHECK(backend_.get()); | 1554 DCHECK(backend_.get()); |
1584 ConfigureDataTypeManager(); | 1555 ConfigureDataTypeManager(); |
1585 } else if (unrecoverable_error_detected()) { | 1556 } else if (unrecoverable_error_detected()) { |
1586 // Close the wizard. | 1557 // Close the wizard. |
1587 if (WizardIsVisible()) { | 1558 if (WizardIsVisible()) { |
1588 wizard_.Step(SyncSetupWizard::DONE); | 1559 wizard_.Step(SyncSetupWizard::DONE); |
1589 } | 1560 } |
1590 // There is nothing more to configure. So inform the listeners, | 1561 // There is nothing more to configure. So inform the listeners, |
1591 NotifyObservers(); | 1562 NotifyObservers(); |
1592 | 1563 |
1593 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " | 1564 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " |
1594 << "Unrecoverable error."; | 1565 << "Unrecoverable error."; |
1595 } else { | 1566 } else { |
1596 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1567 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1597 << "initialized"; | 1568 << "initialized"; |
1598 } | 1569 } |
1599 } | 1570 } |
1600 | 1571 |
1601 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1572 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1602 return failed_datatypes_handler_; | 1573 return failed_datatypes_handler_; |
1603 } | 1574 } |
OLD | NEW |