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

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

Issue 8851006: [Sync] Replace all instances of ModelTypeSet with ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 9 years 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) 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 browser_sync::SyncServiceName()); 309 browser_sync::SyncServiceName());
310 return credentials; 310 return credentials;
311 } 311 }
312 312
313 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { 313 void ProfileSyncService::InitializeBackend(bool delete_stale_data) {
314 if (!backend_.get()) { 314 if (!backend_.get()) {
315 NOTREACHED(); 315 NOTREACHED();
316 return; 316 return;
317 } 317 }
318 318
319 syncable::ModelTypeSet initial_types; 319 syncable::ModelEnumSet initial_types;
320 // If sync setup hasn't finished, we don't want to initialize routing info 320 // If sync setup hasn't finished, we don't want to initialize routing info
321 // for any data types so that we don't download updates for types that the 321 // for any data types so that we don't download updates for types that the
322 // user chooses not to sync on the first DownloadUpdatesCommand. 322 // user chooses not to sync on the first DownloadUpdatesCommand.
323 if (HasSyncSetupCompleted()) { 323 if (HasSyncSetupCompleted()) {
324 GetPreferredDataTypes(&initial_types); 324 initial_types = GetPreferredDataTypes();
325 } 325 }
326 326
327 SyncCredentials credentials = GetCredentials(); 327 SyncCredentials credentials = GetCredentials();
328 328
329 scoped_refptr<net::URLRequestContextGetter> request_context_getter( 329 scoped_refptr<net::URLRequestContextGetter> request_context_getter(
330 profile_->GetRequestContext()); 330 profile_->GetRequestContext());
331 331
332 if (delete_stale_data) 332 if (delete_stale_data)
333 ClearStaleErrors(); 333 ClearStaleErrors();
334 334
335 backend_->Initialize( 335 backend_->Initialize(
336 this, 336 this,
337 MakeWeakHandle(sync_js_controller_.AsWeakPtr()), 337 MakeWeakHandle(sync_js_controller_.AsWeakPtr()),
338 sync_service_url_, 338 sync_service_url_,
339 initial_types, 339 initial_types,
340 credentials, 340 credentials,
341 delete_stale_data); 341 delete_stale_data);
342 } 342 }
343 343
344 void ProfileSyncService::CreateBackend() { 344 void ProfileSyncService::CreateBackend() {
345 backend_.reset( 345 backend_.reset(
346 new SyncBackendHost(profile_->GetDebugName(), 346 new SyncBackendHost(profile_->GetDebugName(),
347 profile_, sync_prefs_.AsWeakPtr())); 347 profile_, sync_prefs_.AsWeakPtr()));
348 } 348 }
349 349
350 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 350 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
351 if (encryption_pending()) 351 if (encryption_pending())
352 return true; 352 return true;
353 syncable::ModelTypeSet preferred_types; 353 const syncable::ModelEnumSet preferred_types = GetPreferredDataTypes();
354 GetPreferredDataTypes(&preferred_types); 354 const syncable::ModelEnumSet encrypted_types = GetEncryptedDataTypes();
355 syncable::ModelTypeSet encrypted_types; 355 DCHECK(encrypted_types.Has(syncable::PASSWORDS));
356 GetEncryptedDataTypes(&encrypted_types); 356 return !Intersection(preferred_types, encrypted_types).Empty();
357 const syncable::ModelEnumSet preferred_types_enum_set =
358 syncable::ModelTypeSetToEnumSet(preferred_types);
359 const syncable::ModelEnumSet encrypted_types_enum_set =
360 syncable::ModelTypeSetToEnumSet(encrypted_types);
361 DCHECK(encrypted_types.count(syncable::PASSWORDS));
362 return
363 !Intersection(preferred_types_enum_set,
364 encrypted_types_enum_set).Empty();
365 } 357 }
366 358
367 void ProfileSyncService::OnSyncConfigureDone( 359 void ProfileSyncService::OnSyncConfigureDone(
368 DataTypeManager::ConfigureResult result) { 360 DataTypeManager::ConfigureResult result) {
369 if (failed_datatypes_handler_.UpdateFailedDatatypes(result)) { 361 if (failed_datatypes_handler_.UpdateFailedDatatypes(result)) {
370 ReconfigureDatatypeManager(); 362 ReconfigureDatatypeManager();
371 } 363 }
372 } 364 }
373 365
374 void ProfileSyncService::StartUp() { 366 void ProfileSyncService::StartUp() {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 MessageLoop::current()->PostTask(FROM_HERE, 632 MessageLoop::current()->PostTask(FROM_HERE,
641 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, 633 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions,
642 GetSessionModelAssociator()->AsWeakPtr())); 634 GetSessionModelAssociator()->AsWeakPtr()));
643 } 635 }
644 DVLOG(2) << "Notifying observers sync cycle completed"; 636 DVLOG(2) << "Notifying observers sync cycle completed";
645 NotifyObservers(); 637 NotifyObservers();
646 } 638 }
647 639
648 // TODO(sync): eventually support removing datatypes too. 640 // TODO(sync): eventually support removing datatypes too.
649 void ProfileSyncService::OnDataTypesChanged( 641 void ProfileSyncService::OnDataTypesChanged(
650 const syncable::ModelTypeSet& to_add) { 642 syncable::ModelEnumSet to_add) {
651 // If this is a first time sync for a client, this will be called before 643 // If this is a first time sync for a client, this will be called before
652 // OnBackendInitialized() to ensure the new datatypes are available at sync 644 // OnBackendInitialized() to ensure the new datatypes are available at sync
653 // setup. As a result, the migrator won't exist yet. This is fine because for 645 // setup. As a result, the migrator won't exist yet. This is fine because for
654 // first time sync cases we're only concerned with making the datatype 646 // first time sync cases we're only concerned with making the datatype
655 // available. 647 // available.
656 if (migrator_.get() && 648 if (migrator_.get() &&
657 migrator_->state() != browser_sync::BackendMigrator::IDLE) { 649 migrator_->state() != browser_sync::BackendMigrator::IDLE) {
658 DVLOG(1) << "Dropping OnDataTypesChanged due to migrator busy."; 650 DVLOG(1) << "Dropping OnDataTypesChanged due to migrator busy.";
659 return; 651 return;
660 } 652 }
661 653
662 DVLOG(2) << "OnDataTypesChanged called with types: " 654 DVLOG(2) << "OnDataTypesChanged called with types: "
663 << syncable::ModelTypeSetToString(to_add); 655 << syncable::ModelEnumSetToString(to_add);
664 656
665 syncable::ModelTypeSet registered_types; 657 syncable::ModelEnumSet registered_types = GetRegisteredDataTypes();
666 GetRegisteredDataTypes(&registered_types);
667 658
668 syncable::ModelTypeSet to_register; 659 syncable::ModelEnumSet to_register =
669 std::set_difference(to_add.begin(), to_add.end(), 660 Difference(to_add, registered_types);
670 registered_types.begin(), registered_types.end(),
671 std::inserter(to_register, to_register.end()));
672 661
673 DVLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register); 662 DVLOG(2) << "Enabling types: " << syncable::ModelEnumSetToString(to_register);
674 663
675 for (syncable::ModelTypeSet::const_iterator it = to_register.begin(); 664 for (syncable::ModelEnumSet::Iterator it = to_register.First();
676 it != to_register.end(); ++it) { 665 it.Good(); it.Inc()) {
677 // Received notice to enable experimental type. Check if the type is 666 // Received notice to enable experimental type. Check if the type is
678 // registered, and if not register a new datatype controller. 667 // registered, and if not register a new datatype controller.
679 RegisterNewDataType(*it); 668 RegisterNewDataType(it.Get());
680 // Enable the about:flags switch for the experimental type so we don't have 669 // Enable the about:flags switch for the experimental type so we don't have
681 // to always perform this reconfiguration. Once we set this, the type will 670 // to always perform this reconfiguration. Once we set this, the type will
682 // remain registered on restart, so we will no longer go down this code 671 // remain registered on restart, so we will no longer go down this code
683 // path. 672 // path.
684 std::string experiment_name = GetExperimentNameForDataType(*it); 673 std::string experiment_name = GetExperimentNameForDataType(it.Get());
685 if (experiment_name.empty()) 674 if (experiment_name.empty())
686 continue; 675 continue;
687 about_flags::SetExperimentEnabled(g_browser_process->local_state(), 676 about_flags::SetExperimentEnabled(g_browser_process->local_state(),
688 experiment_name, 677 experiment_name,
689 true); 678 true);
690 } 679 }
691 680
692 // Check if the user has "Keep Everything Synced" enabled. If so, we want 681 // Check if the user has "Keep Everything Synced" enabled. If so, we want
693 // to turn on all experimental types if they're not already on. Otherwise we 682 // to turn on all experimental types if they're not already on. Otherwise we
694 // leave them off. 683 // leave them off.
695 // Note: if any types are already registered, we don't turn them on. This 684 // Note: if any types are already registered, we don't turn them on. This
696 // covers the case where we're already in the process of reconfiguring 685 // covers the case where we're already in the process of reconfiguring
697 // to turn an experimental type on. 686 // to turn an experimental type on.
698 if (sync_prefs_.HasKeepEverythingSynced()) { 687 if (sync_prefs_.HasKeepEverythingSynced()) {
699 // Mark all data types as preferred. 688 // Mark all data types as preferred.
700 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); 689 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types);
701 690
702 // Only automatically turn on types if we have already finished set up. 691 // Only automatically turn on types if we have already finished set up.
703 // Otherwise, just leave the experimental types on by default. 692 // Otherwise, just leave the experimental types on by default.
704 if (!to_register.empty() && HasSyncSetupCompleted() && migrator_.get()) { 693 if (!to_register.Empty() && HasSyncSetupCompleted() && migrator_.get()) {
705 DVLOG(1) << "Dynamically enabling new datatypes: " 694 DVLOG(1) << "Dynamically enabling new datatypes: "
706 << syncable::ModelTypeSetToString(to_register); 695 << syncable::ModelEnumSetToString(to_register);
707 OnMigrationNeededForTypes(to_register); 696 OnMigrationNeededForTypes(to_register);
708 } 697 }
709 } 698 }
710 } 699 }
711 700
712 void ProfileSyncService::UpdateAuthErrorState( 701 void ProfileSyncService::UpdateAuthErrorState(
713 const GoogleServiceAuthError& error) { 702 const GoogleServiceAuthError& error) {
714 last_auth_error_ = error; 703 last_auth_error_ = error;
715 // Protect against the in-your-face dialogs that pop out of nowhere. 704 // Protect against the in-your-face dialogs that pop out of nowhere.
716 // Require the user to click somewhere to run the setup wizard in the case 705 // 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
838 void ProfileSyncService::OnPassphraseAccepted() { 827 void ProfileSyncService::OnPassphraseAccepted() {
839 DVLOG(1) << "Received OnPassphraseAccepted."; 828 DVLOG(1) << "Received OnPassphraseAccepted.";
840 // Reset passphrase_required_reason_ since we know we no longer require the 829 // Reset passphrase_required_reason_ since we know we no longer require the
841 // passphrase. We do this here rather than down in ResolvePassphraseRequired() 830 // passphrase. We do this here rather than down in ResolvePassphraseRequired()
842 // because that can be called by OnPassphraseRequired() if no encrypted data 831 // because that can be called by OnPassphraseRequired() if no encrypted data
843 // types are enabled, and we don't want to clobber the true passphrase error. 832 // types are enabled, and we don't want to clobber the true passphrase error.
844 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED; 833 passphrase_required_reason_ = sync_api::REASON_PASSPHRASE_NOT_REQUIRED;
845 834
846 // Make sure the data types that depend on the passphrase are started at 835 // Make sure the data types that depend on the passphrase are started at
847 // this time. 836 // this time.
848 syncable::ModelTypeSet types; 837 syncable::ModelEnumSet types = GetPreferredDataTypes();
849 GetPreferredDataTypes(&types);
850 838
851 if (data_type_manager_.get()) { 839 if (data_type_manager_.get()) {
852 // Unblock the data type manager if necessary. 840 // Unblock the data type manager if necessary.
853 data_type_manager_->Configure(types, 841 data_type_manager_->Configure(types,
854 sync_api::CONFIGURE_REASON_RECONFIGURATION); 842 sync_api::CONFIGURE_REASON_RECONFIGURATION);
855 } 843 }
856 844
857 ResolvePassphraseRequired(); 845 ResolvePassphraseRequired();
858 } 846 }
859 847
860 void ProfileSyncService::ResolvePassphraseRequired() { 848 void ProfileSyncService::ResolvePassphraseRequired() {
861 DCHECK(!IsPassphraseRequiredForDecryption()); 849 DCHECK(!IsPassphraseRequiredForDecryption());
862 // Don't hold on to a passphrase in raw form longer than needed. 850 // Don't hold on to a passphrase in raw form longer than needed.
863 cached_passphrases_ = CachedPassphrases(); 851 cached_passphrases_ = CachedPassphrases();
864 852
865 // If No encryption is pending and our passphrase has been accepted, tell the 853 // If No encryption is pending and our passphrase has been accepted, tell the
866 // wizard we're done (no need to hang around waiting for the sync to 854 // wizard we're done (no need to hang around waiting for the sync to
867 // complete). If encryption is pending, its successful completion will trigger 855 // complete). If encryption is pending, its successful completion will trigger
868 // the done step. 856 // the done step.
869 if (WizardIsVisible() && !encryption_pending()) 857 if (WizardIsVisible() && !encryption_pending())
870 wizard_.Step(SyncSetupWizard::DONE); 858 wizard_.Step(SyncSetupWizard::DONE);
871 859
872 NotifyObservers(); 860 NotifyObservers();
873 } 861 }
874 862
875 void ProfileSyncService::OnEncryptedTypesChanged( 863 void ProfileSyncService::OnEncryptedTypesChanged(
876 const syncable::ModelTypeSet& encrypted_types, 864 syncable::ModelEnumSet encrypted_types,
877 bool encrypt_everything) { 865 bool encrypt_everything) {
878 encrypted_types_ = encrypted_types; 866 encrypted_types_ = encrypted_types;
879 encrypt_everything_ = encrypt_everything; 867 encrypt_everything_ = encrypt_everything;
880 DVLOG(1) << "Encrypted types changed to " 868 DVLOG(1) << "Encrypted types changed to "
881 << syncable::ModelTypeSetToString(encrypted_types_) 869 << syncable::ModelEnumSetToString(encrypted_types_)
882 << " (encrypt everything is set to " 870 << " (encrypt everything is set to "
883 << (encrypt_everything_ ? "true" : "false") << ")"; 871 << (encrypt_everything_ ? "true" : "false") << ")";
884 DCHECK_GT(encrypted_types_.count(syncable::PASSWORDS), 0u); 872 DCHECK(encrypted_types_.Has(syncable::PASSWORDS));
885 } 873 }
886 874
887 void ProfileSyncService::OnEncryptionComplete() { 875 void ProfileSyncService::OnEncryptionComplete() {
888 DVLOG(1) << "Encryption complete"; 876 DVLOG(1) << "Encryption complete";
889 if (encryption_pending_ && encrypt_everything_) { 877 if (encryption_pending_ && encrypt_everything_) {
890 encryption_pending_ = false; 878 encryption_pending_ = false;
891 // The user had chosen to encrypt datatypes. This is the last thing to 879 // The user had chosen to encrypt datatypes. This is the last thing to
892 // complete, so now that we're done notify the UI. 880 // complete, so now that we're done notify the UI.
893 wizard_.Step(SyncSetupWizard::DONE); 881 wizard_.Step(SyncSetupWizard::DONE);
894 // This is to nudge the integration tests when encryption is 882 // This is to nudge the integration tests when encryption is
895 // finished. 883 // finished.
896 NotifyObservers(); 884 NotifyObservers();
897 } 885 }
898 } 886 }
899 887
900 void ProfileSyncService::OnMigrationNeededForTypes( 888 void ProfileSyncService::OnMigrationNeededForTypes(
901 const syncable::ModelTypeSet& types) { 889 syncable::ModelEnumSet types) {
902 DCHECK(backend_initialized_); 890 DCHECK(backend_initialized_);
903 DCHECK(data_type_manager_.get()); 891 DCHECK(data_type_manager_.get());
904 892
905 // Migrator must be valid, because we don't sync until it is created and this 893 // Migrator must be valid, because we don't sync until it is created and this
906 // callback originates from a sync cycle. 894 // callback originates from a sync cycle.
907 migrator_->MigrateTypes(types); 895 migrator_->MigrateTypes(types);
908 } 896 }
909 897
910 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { 898 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) {
911 last_actionable_error_ = error; 899 last_actionable_error_ = error;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 is_auth_in_progress_ = true; 1110 is_auth_in_progress_ = true;
1123 1111
1124 // The user has submitted credentials, which indicates they don't 1112 // The user has submitted credentials, which indicates they don't
1125 // want to suppress start up anymore. 1113 // want to suppress start up anymore.
1126 sync_prefs_.SetStartSuppressed(false); 1114 sync_prefs_.SetStartSuppressed(false);
1127 1115
1128 signin_->StartOAuthSignIn(oauth1_request_token); 1116 signin_->StartOAuthSignIn(oauth1_request_token);
1129 } 1117 }
1130 1118
1131 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, 1119 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything,
1132 const syncable::ModelTypeSet& chosen_types) { 1120 syncable::ModelEnumSet chosen_types) {
1133 if (!backend_.get() && 1121 if (!backend_.get() &&
1134 unrecoverable_error_detected_ == false) { 1122 unrecoverable_error_detected_ == false) {
1135 NOTREACHED(); 1123 NOTREACHED();
1136 return; 1124 return;
1137 } 1125 }
1138 1126
1139 sync_prefs_.SetKeepEverythingSynced(sync_everything); 1127 sync_prefs_.SetKeepEverythingSynced(sync_everything);
1140 1128
1141 failed_datatypes_handler_.OnUserChoseDatatypes(); 1129 failed_datatypes_handler_.OnUserChoseDatatypes();
1142 ChangePreferredDataTypes(chosen_types); 1130 ChangePreferredDataTypes(chosen_types);
(...skipping 19 matching lines...) Expand all
1162 // succeeds, calling OnAuthError(NONE), or b) the user clicks the button, 1150 // succeeds, calling OnAuthError(NONE), or b) the user clicks the button,
1163 // and tries to re-authenticate. (b) is a little awkward as this second 1151 // and tries to re-authenticate. (b) is a little awkward as this second
1164 // request will get queued behind the first and could wind up "undoing" the 1152 // request will get queued behind the first and could wind up "undoing" the
1165 // good if invalid creds were provided, but it's an edge case and the user 1153 // good if invalid creds were provided, but it's an edge case and the user
1166 // can of course get themselves out of it. 1154 // can of course get themselves out of it.
1167 is_auth_in_progress_ = false; 1155 is_auth_in_progress_ = false;
1168 NotifyObservers(); 1156 NotifyObservers();
1169 } 1157 }
1170 1158
1171 void ProfileSyncService::ChangePreferredDataTypes( 1159 void ProfileSyncService::ChangePreferredDataTypes(
1172 const syncable::ModelTypeSet& preferred_types) { 1160 syncable::ModelEnumSet preferred_types) {
1173 1161
1174 DVLOG(1) << "ChangePreferredDataTypes invoked"; 1162 DVLOG(1) << "ChangePreferredDataTypes invoked";
1175 syncable::ModelTypeSet registered_types; 1163 syncable::ModelEnumSet registered_types = GetRegisteredDataTypes();
1176 GetRegisteredDataTypes(&registered_types); 1164 syncable::ModelEnumSet registered_preferred_types =
1177 syncable::ModelTypeSet registered_preferred_types; 1165 Intersection(registered_types, preferred_types);
1178 std::set_intersection(
1179 registered_types.begin(), registered_types.end(),
1180 preferred_types.begin(), preferred_types.end(),
1181 std::inserter(registered_preferred_types,
1182 registered_preferred_types.end()));
1183 sync_prefs_.SetPreferredDataTypes(registered_types, 1166 sync_prefs_.SetPreferredDataTypes(registered_types,
1184 registered_preferred_types); 1167 registered_preferred_types);
1185 1168
1186 // Now reconfigure the DTM. 1169 // Now reconfigure the DTM.
1187 ReconfigureDatatypeManager(); 1170 ReconfigureDatatypeManager();
1188 } 1171 }
1189 1172
1190 void ProfileSyncService::GetPreferredDataTypes( 1173 syncable::ModelEnumSet ProfileSyncService::GetPreferredDataTypes() const {
1191 syncable::ModelTypeSet* preferred_types) const { 1174 syncable::ModelEnumSet registered_types = GetRegisteredDataTypes();
1192 syncable::ModelTypeSet registered_types; 1175 syncable::ModelEnumSet preferred_types =
1193 GetRegisteredDataTypes(&registered_types); 1176 sync_prefs_.GetPreferredDataTypes(registered_types);
1194 *preferred_types = sync_prefs_.GetPreferredDataTypes(registered_types); 1177 syncable::ModelEnumSet failed_types =
1195
1196 syncable::ModelTypeSet failed_types =
1197 failed_datatypes_handler_.GetFailedTypes(); 1178 failed_datatypes_handler_.GetFailedTypes();
1198 syncable::ModelTypeSet difference; 1179 return Difference(preferred_types, failed_types);
1199 std::set_difference(preferred_types->begin(), preferred_types->end(),
1200 failed_types.begin(), failed_types.end(),
1201 std::inserter(difference, difference.end()));
1202 std::swap(*preferred_types, difference);
1203 } 1180 }
1204 1181
1205 void ProfileSyncService::GetRegisteredDataTypes( 1182 syncable::ModelEnumSet ProfileSyncService::GetRegisteredDataTypes() const {
1206 syncable::ModelTypeSet* registered_types) const { 1183 syncable::ModelEnumSet registered_types;
1207 registered_types->clear();
1208 // The data_type_controllers_ are determined by command-line flags; that's 1184 // The data_type_controllers_ are determined by command-line flags; that's
1209 // effectively what controls the values returned here. 1185 // effectively what controls the values returned here.
1210 for (DataTypeController::TypeMap::const_iterator it = 1186 for (DataTypeController::TypeMap::const_iterator it =
1211 data_type_controllers_.begin(); 1187 data_type_controllers_.begin();
1212 it != data_type_controllers_.end(); ++it) { 1188 it != data_type_controllers_.end(); ++it) {
1213 registered_types->insert((*it).first); 1189 registered_types.Put(it->first);
1214 } 1190 }
1191 return registered_types;
1215 } 1192 }
1216 1193
1217 bool ProfileSyncService::IsUsingSecondaryPassphrase() const { 1194 bool ProfileSyncService::IsUsingSecondaryPassphrase() const {
1218 // Should never be called when the backend is not initialized, since at that 1195 // Should never be called when the backend is not initialized, since at that
1219 // time we have no idea whether we have an explicit passphrase or not because 1196 // time we have no idea whether we have an explicit passphrase or not because
1220 // the nigori node has not been downloaded yet. 1197 // the nigori node has not been downloaded yet.
1221 if (!sync_initialized()) { 1198 if (!sync_initialized()) {
1222 NOTREACHED() << "Cannot call IsUsingSecondaryPassphrase() before the sync " 1199 NOTREACHED() << "Cannot call IsUsingSecondaryPassphrase() before the sync "
1223 << "backend has downloaded the nigori node"; 1200 << "backend has downloaded the nigori node";
1224 return false; 1201 return false;
(...skipping 26 matching lines...) Expand all
1251 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, 1228 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE,
1252 content::Source<DataTypeManager>(data_type_manager_.get())); 1229 content::Source<DataTypeManager>(data_type_manager_.get()));
1253 1230
1254 // We create the migrator at the same time. 1231 // We create the migrator at the same time.
1255 migrator_.reset( 1232 migrator_.reset(
1256 new browser_sync::BackendMigrator( 1233 new browser_sync::BackendMigrator(
1257 profile_->GetDebugName(), GetUserShare(), 1234 profile_->GetDebugName(), GetUserShare(),
1258 this, data_type_manager_.get())); 1235 this, data_type_manager_.get()));
1259 } 1236 }
1260 1237
1261 syncable::ModelTypeSet types; 1238 syncable::ModelEnumSet types = GetPreferredDataTypes();
1262 GetPreferredDataTypes(&types);
1263 if (IsPassphraseRequiredForDecryption()) { 1239 if (IsPassphraseRequiredForDecryption()) {
1264 // We need a passphrase still. We don't bother to attempt to configure 1240 // We need a passphrase still. We don't bother to attempt to configure
1265 // until we receive an OnPassphraseAccepted (which triggers a configure). 1241 // until we receive an OnPassphraseAccepted (which triggers a configure).
1266 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " 1242 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out "
1267 << "because a passphrase required"; 1243 << "because a passphrase required";
1268 return; 1244 return;
1269 } 1245 }
1270 sync_api::ConfigureReason reason = sync_api::CONFIGURE_REASON_UNKNOWN; 1246 sync_api::ConfigureReason reason = sync_api::CONFIGURE_REASON_UNKNOWN;
1271 if (!HasSyncSetupCompleted()) { 1247 if (!HasSyncSetupCompleted()) {
1272 reason = sync_api::CONFIGURE_REASON_NEW_CLIENT; 1248 reason = sync_api::CONFIGURE_REASON_NEW_CLIENT;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 // initialized (via IsEncryptedDatatypeEnabled and 1342 // initialized (via IsEncryptedDatatypeEnabled and
1367 // IsPassphraseRequiredForDecryption). 1343 // IsPassphraseRequiredForDecryption).
1368 return encryption_pending_; 1344 return encryption_pending_;
1369 } 1345 }
1370 1346
1371 bool ProfileSyncService::EncryptEverythingEnabled() const { 1347 bool ProfileSyncService::EncryptEverythingEnabled() const {
1372 DCHECK(backend_initialized_); 1348 DCHECK(backend_initialized_);
1373 return encrypt_everything_; 1349 return encrypt_everything_;
1374 } 1350 }
1375 1351
1376 void ProfileSyncService::GetEncryptedDataTypes( 1352 syncable::ModelEnumSet ProfileSyncService::GetEncryptedDataTypes() const {
1377 syncable::ModelTypeSet* encrypted_types) const { 1353 DCHECK(encrypted_types_.Has(syncable::PASSWORDS));
1378 CHECK(encrypted_types);
1379 // We may be called during the setup process before we're 1354 // We may be called during the setup process before we're
1380 // initialized. In this case, we default to the sensitive types. 1355 // initialized. In this case, we default to the sensitive types.
1381 *encrypted_types = encrypted_types_; 1356 return encrypted_types_;
1382 DCHECK_GT(encrypted_types->count(syncable::PASSWORDS), 0u);
1383 } 1357 }
1384 1358
1385 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 1359 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
1386 NotifyObservers(); 1360 NotifyObservers();
1387 if (is_sync_managed) { 1361 if (is_sync_managed) {
1388 DisableForUser(); 1362 DisableForUser();
1389 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { 1363 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) {
1390 StartUp(); 1364 StartUp();
1391 } 1365 }
1392 } 1366 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 sync_prefs_.SetStartSuppressed(false); 1553 sync_prefs_.SetStartSuppressed(false);
1580 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess 1554 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess
1581 // is never called for some clients. 1555 // is never called for some clients.
1582 if (signin_->GetUsername().empty()) { 1556 if (signin_->GetUsername().empty()) {
1583 signin_->SetUsername(sync_prefs_.GetGoogleServicesUsername()); 1557 signin_->SetUsername(sync_prefs_.GetGoogleServicesUsername());
1584 } 1558 }
1585 TryStart(); 1559 TryStart();
1586 } 1560 }
1587 1561
1588 void ProfileSyncService::AcknowledgeSyncedTypes() { 1562 void ProfileSyncService::AcknowledgeSyncedTypes() {
1589 syncable::ModelTypeSet registered_types; 1563 syncable::ModelEnumSet registered_types = GetRegisteredDataTypes();
1590 GetRegisteredDataTypes(&registered_types);
1591 sync_prefs_.AcknowledgeSyncedTypes(registered_types); 1564 sync_prefs_.AcknowledgeSyncedTypes(registered_types);
1592 } 1565 }
1593 1566
1594 void ProfileSyncService::ReconfigureDatatypeManager() { 1567 void ProfileSyncService::ReconfigureDatatypeManager() {
1595 // If we haven't initialized yet, don't configure the DTM as it could cause 1568 // If we haven't initialized yet, don't configure the DTM as it could cause
1596 // association to start before a Directory has even been created. 1569 // association to start before a Directory has even been created.
1597 if (backend_initialized_) { 1570 if (backend_initialized_) {
1598 DCHECK(backend_.get()); 1571 DCHECK(backend_.get());
1599 ConfigureDataTypeManager(); 1572 ConfigureDataTypeManager();
1600 } else if (unrecoverable_error_detected()) { 1573 } else if (unrecoverable_error_detected()) {
1601 // Close the wizard. 1574 // Close the wizard.
1602 if (WizardIsVisible()) { 1575 if (WizardIsVisible()) {
1603 wizard_.Step(SyncSetupWizard::DONE); 1576 wizard_.Step(SyncSetupWizard::DONE);
1604 } 1577 }
1605 // There is nothing more to configure. So inform the listeners, 1578 // There is nothing more to configure. So inform the listeners,
1606 NotifyObservers(); 1579 NotifyObservers();
1607 1580
1608 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an " 1581 DVLOG(1) << "ConfigureDataTypeManager not invoked because of an "
1609 << "Unrecoverable error."; 1582 << "Unrecoverable error.";
1610 } else { 1583 } else {
1611 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " 1584 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not "
1612 << "initialized"; 1585 << "initialized";
1613 } 1586 }
1614 } 1587 }
1615 1588
1616 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { 1589 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() {
1617 return failed_datatypes_handler_; 1590 return failed_datatypes_handler_;
1618 } 1591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698