| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
| 17 #include "base/string16.h" | 17 #include "base/string16.h" |
| 18 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/task.h" | 20 #include "base/task.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "chrome/browser/browser_thread.h" | 22 #include "chrome/browser/browser_thread.h" |
| 23 #include "chrome/browser/history/history_types.h" | 23 #include "chrome/browser/history/history_types.h" |
| 24 #include "chrome/browser/platform_util.h" | 24 #include "chrome/browser/platform_util.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/net/gaia/token_service.h" | 27 #include "chrome/browser/net/gaia/token_service.h" |
| 28 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" |
| 28 #include "chrome/browser/sync/glue/change_processor.h" | 29 #include "chrome/browser/sync/glue/change_processor.h" |
| 29 #include "chrome/browser/sync/glue/data_type_controller.h" | 30 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 30 #include "chrome/browser/sync/glue/data_type_manager.h" | 31 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 31 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 32 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 32 #include "chrome/browser/sync/profile_sync_factory.h" | 33 #include "chrome/browser/sync/profile_sync_factory.h" |
| 33 #include "chrome/browser/sync/signin_manager.h" | 34 #include "chrome/browser/sync/signin_manager.h" |
| 34 #include "chrome/browser/sync/token_migrator.h" | 35 #include "chrome/browser/sync/token_migrator.h" |
| 35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/net/gaia/gaia_constants.h" | 37 #include "chrome/common/net/gaia/gaia_constants.h" |
| 37 #include "chrome/common/notification_details.h" | 38 #include "chrome/common/notification_details.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 pref_service->RegisterBooleanPref(prefs::kSyncAutofill, enable_by_default); | 363 pref_service->RegisterBooleanPref(prefs::kSyncAutofill, enable_by_default); |
| 363 pref_service->RegisterBooleanPref(prefs::kSyncThemes, enable_by_default); | 364 pref_service->RegisterBooleanPref(prefs::kSyncThemes, enable_by_default); |
| 364 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls, enable_by_default); | 365 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls, enable_by_default); |
| 365 pref_service->RegisterBooleanPref(prefs::kSyncExtensions, enable_by_default); | 366 pref_service->RegisterBooleanPref(prefs::kSyncExtensions, enable_by_default); |
| 366 pref_service->RegisterBooleanPref(prefs::kSyncApps, enable_by_default); | 367 pref_service->RegisterBooleanPref(prefs::kSyncApps, enable_by_default); |
| 367 pref_service->RegisterBooleanPref(prefs::kSyncSessions, enable_by_default); | 368 pref_service->RegisterBooleanPref(prefs::kSyncSessions, enable_by_default); |
| 368 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, | 369 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, |
| 369 enable_by_default); | 370 enable_by_default); |
| 370 pref_service->RegisterBooleanPref(prefs::kSyncManaged, false); | 371 pref_service->RegisterBooleanPref(prefs::kSyncManaged, false); |
| 371 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, ""); | 372 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, ""); |
| 373 |
| 374 pref_service->RegisterBooleanPref(prefs::kSyncAutofill_profile, |
| 375 enable_by_default); |
| 372 } | 376 } |
| 373 | 377 |
| 374 void ProfileSyncService::ClearPreferences() { | 378 void ProfileSyncService::ClearPreferences() { |
| 375 PrefService* pref_service = profile_->GetPrefs(); | 379 PrefService* pref_service = profile_->GetPrefs(); |
| 376 pref_service->ClearPref(prefs::kSyncLastSyncedTime); | 380 pref_service->ClearPref(prefs::kSyncLastSyncedTime); |
| 377 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 381 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
| 378 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); | 382 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); |
| 379 | 383 |
| 380 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 384 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
| 381 // Is that really what we want? | 385 // Is that really what we want? |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 Source<SyncBackendHost>(backend_.get())); | 454 Source<SyncBackendHost>(backend_.get())); |
| 451 | 455 |
| 452 // Initialize the backend. Every time we start up a new SyncBackendHost, | 456 // Initialize the backend. Every time we start up a new SyncBackendHost, |
| 453 // we'll want to start from a fresh SyncDB, so delete any old one that might | 457 // we'll want to start from a fresh SyncDB, so delete any old one that might |
| 454 // be there. | 458 // be there. |
| 455 InitializeBackend(!HasSyncSetupCompleted()); | 459 InitializeBackend(!HasSyncSetupCompleted()); |
| 456 } | 460 } |
| 457 | 461 |
| 458 void ProfileSyncService::Shutdown(bool sync_disabled) { | 462 void ProfileSyncService::Shutdown(bool sync_disabled) { |
| 459 // Stop all data type controllers, if needed. | 463 // Stop all data type controllers, if needed. |
| 464 |
| 460 if (data_type_manager_.get()) { | 465 if (data_type_manager_.get()) { |
| 461 if (data_type_manager_->state() != DataTypeManager::STOPPED) { | 466 if (data_type_manager_->state() != DataTypeManager::STOPPED) { |
| 462 data_type_manager_->Stop(); | 467 data_type_manager_->Stop(); |
| 463 } | 468 } |
| 464 | 469 |
| 465 registrar_.Remove(this, | 470 registrar_.Remove(this, |
| 466 NotificationType::SYNC_CONFIGURE_START, | 471 NotificationType::SYNC_CONFIGURE_START, |
| 467 Source<DataTypeManager>(data_type_manager_.get())); | 472 Source<DataTypeManager>(data_type_manager_.get())); |
| 468 registrar_.Remove(this, | 473 registrar_.Remove(this, |
| 469 NotificationType::SYNC_CONFIGURE_DONE, | 474 NotificationType::SYNC_CONFIGURE_DONE, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 syncable::ModelType data_type) { | 549 syncable::ModelType data_type) { |
| 545 switch (data_type) { | 550 switch (data_type) { |
| 546 case syncable::BOOKMARKS: | 551 case syncable::BOOKMARKS: |
| 547 return prefs::kSyncBookmarks; | 552 return prefs::kSyncBookmarks; |
| 548 case syncable::PASSWORDS: | 553 case syncable::PASSWORDS: |
| 549 return prefs::kSyncPasswords; | 554 return prefs::kSyncPasswords; |
| 550 case syncable::PREFERENCES: | 555 case syncable::PREFERENCES: |
| 551 return prefs::kSyncPreferences; | 556 return prefs::kSyncPreferences; |
| 552 case syncable::AUTOFILL: | 557 case syncable::AUTOFILL: |
| 553 return prefs::kSyncAutofill; | 558 return prefs::kSyncAutofill; |
| 559 case syncable::AUTOFILL_PROFILE: |
| 560 return prefs::kSyncAutofill_profile; |
| 561 break; |
| 554 case syncable::THEMES: | 562 case syncable::THEMES: |
| 555 return prefs::kSyncThemes; | 563 return prefs::kSyncThemes; |
| 556 case syncable::TYPED_URLS: | 564 case syncable::TYPED_URLS: |
| 557 return prefs::kSyncTypedUrls; | 565 return prefs::kSyncTypedUrls; |
| 558 case syncable::EXTENSIONS: | 566 case syncable::EXTENSIONS: |
| 559 return prefs::kSyncExtensions; | 567 return prefs::kSyncExtensions; |
| 560 case syncable::APPS: | 568 case syncable::APPS: |
| 561 return prefs::kSyncApps; | 569 return prefs::kSyncApps; |
| 562 case syncable::SESSIONS: | 570 case syncable::SESSIONS: |
| 563 return prefs::kSyncSessions; | 571 return prefs::kSyncSessions; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 GetRegisteredDataTypes(®istered_types); | 881 GetRegisteredDataTypes(®istered_types); |
| 874 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 882 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 875 syncable::ModelType model_type = syncable::ModelTypeFromInt(i); | 883 syncable::ModelType model_type = syncable::ModelTypeFromInt(i); |
| 876 if (!registered_types.count(model_type)) | 884 if (!registered_types.count(model_type)) |
| 877 continue; | 885 continue; |
| 878 const char* pref_name = GetPrefNameForDataType(model_type); | 886 const char* pref_name = GetPrefNameForDataType(model_type); |
| 879 if (!pref_name) | 887 if (!pref_name) |
| 880 continue; | 888 continue; |
| 881 profile_->GetPrefs()->SetBoolean(pref_name, | 889 profile_->GetPrefs()->SetBoolean(pref_name, |
| 882 preferred_types.count(model_type) != 0); | 890 preferred_types.count(model_type) != 0); |
| 891 if (syncable::AUTOFILL == model_type) { |
| 892 profile_->GetPrefs()->SetBoolean(prefs::kSyncAutofill_profile, |
| 893 preferred_types.count(model_type) != 0); |
| 894 } |
| 883 } | 895 } |
| 884 | 896 |
| 885 // If we haven't initialized yet, don't configure the DTM as it could cause | 897 // If we haven't initialized yet, don't configure the DTM as it could cause |
| 886 // association to start before a Directory has even been created. | 898 // association to start before a Directory has even been created. |
| 887 if (backend_initialized_) | 899 if (backend_initialized_) |
| 888 ConfigureDataTypeManager(); | 900 ConfigureDataTypeManager(); |
| 889 } | 901 } |
| 890 | 902 |
| 891 void ProfileSyncService::GetPreferredDataTypes( | 903 void ProfileSyncService::GetPreferredDataTypes( |
| 892 syncable::ModelTypeSet* preferred_types) const { | 904 syncable::ModelTypeSet* preferred_types) const { |
| 893 preferred_types->clear(); | 905 preferred_types->clear(); |
| 894 | |
| 895 // Filter out any datatypes which aren't registered, or for which | |
| 896 // the preference can't be read. | |
| 897 syncable::ModelTypeSet registered_types; | |
| 898 GetRegisteredDataTypes(®istered_types); | |
| 899 if (profile_->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)) { | 906 if (profile_->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)) { |
| 900 *preferred_types = registered_types; | 907 GetRegisteredDataTypes(preferred_types); |
| 901 } else { | 908 } else { |
| 909 // Filter out any datatypes which aren't registered, or for which |
| 910 // the preference can't be read. |
| 911 syncable::ModelTypeSet registered_types; |
| 912 GetRegisteredDataTypes(®istered_types); |
| 902 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 913 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 903 syncable::ModelType model_type = syncable::ModelTypeFromInt(i); | 914 syncable::ModelType model_type = syncable::ModelTypeFromInt(i); |
| 904 if (!registered_types.count(model_type)) | 915 if (!registered_types.count(model_type)) |
| 905 continue; | 916 continue; |
| 917 if (model_type == syncable::AUTOFILL_PROFILE) |
| 918 continue; |
| 906 const char* pref_name = GetPrefNameForDataType(model_type); | 919 const char* pref_name = GetPrefNameForDataType(model_type); |
| 907 if (!pref_name) | 920 if (!pref_name) |
| 908 continue; | 921 continue; |
| 909 if (profile_->GetPrefs()->GetBoolean(pref_name)) | 922 if (profile_->GetPrefs()->GetBoolean(pref_name)) { |
| 910 preferred_types->insert(model_type); | 923 preferred_types->insert(model_type); |
| 924 if (model_type == syncable::AUTOFILL) { |
| 925 if (!registered_types.count(syncable::AUTOFILL_PROFILE)) |
| 926 continue; |
| 927 preferred_types->insert(syncable::AUTOFILL_PROFILE); |
| 928 } |
| 929 } |
| 911 } | 930 } |
| 912 } | 931 } |
| 913 } | 932 } |
| 914 | 933 |
| 915 void ProfileSyncService::GetRegisteredDataTypes( | 934 void ProfileSyncService::GetRegisteredDataTypes( |
| 916 syncable::ModelTypeSet* registered_types) const { | 935 syncable::ModelTypeSet* registered_types) const { |
| 917 registered_types->clear(); | 936 registered_types->clear(); |
| 918 // The data_type_controllers_ are determined by command-line flags; that's | 937 // The data_type_controllers_ are determined by command-line flags; that's |
| 919 // effectively what controls the values returned here. | 938 // effectively what controls the values returned here. |
| 920 for (DataTypeController::TypeMap::const_iterator it = | 939 for (DataTypeController::TypeMap::const_iterator it = |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 // is initialized, all enabled data types are consistent with one | 1168 // is initialized, all enabled data types are consistent with one |
| 1150 // another, and no unrecoverable error has transpired. | 1169 // another, and no unrecoverable error has transpired. |
| 1151 if (unrecoverable_error_detected_) | 1170 if (unrecoverable_error_detected_) |
| 1152 return false; | 1171 return false; |
| 1153 | 1172 |
| 1154 if (!data_type_manager_.get()) | 1173 if (!data_type_manager_.get()) |
| 1155 return false; | 1174 return false; |
| 1156 | 1175 |
| 1157 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1176 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 1158 } | 1177 } |
| OLD | NEW |