| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/settings/people_handler.h" | 5 #include "chrome/browser/ui/webui/settings/people_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/sync/sync_ui_util.h" | 28 #include "chrome/browser/sync/sync_ui_util.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
| 31 #include "chrome/browser/ui/singleton_tabs.h" | 31 #include "chrome/browser/ui/singleton_tabs.h" |
| 32 #include "chrome/browser/ui/user_manager.h" | 32 #include "chrome/browser/ui/user_manager.h" |
| 33 #include "chrome/browser/ui/webui/profile_helper.h" | 33 #include "chrome/browser/ui/webui/profile_helper.h" |
| 34 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 34 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 35 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 35 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/grit/generated_resources.h" | 37 #include "chrome/grit/generated_resources.h" |
| 38 #include "components/autofill/core/common/autofill_constants.h" |
| 39 #include "components/autofill/core/common/autofill_pref_names.h" |
| 38 #include "components/browser_sync/browser/profile_sync_service.h" | 40 #include "components/browser_sync/browser/profile_sync_service.h" |
| 39 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
| 40 #include "components/signin/core/browser/signin_error_controller.h" | 42 #include "components/signin/core/browser/signin_error_controller.h" |
| 41 #include "components/signin/core/browser/signin_header_helper.h" | 43 #include "components/signin/core/browser/signin_header_helper.h" |
| 42 #include "components/signin/core/browser/signin_metrics.h" | 44 #include "components/signin/core/browser/signin_metrics.h" |
| 43 #include "components/signin/core/common/profile_management_switches.h" | 45 #include "components/signin/core/common/profile_management_switches.h" |
| 44 #include "components/signin/core/common/signin_pref_names.h" | 46 #include "components/signin/core/common/signin_pref_names.h" |
| 45 #include "components/sync_driver/sync_prefs.h" | 47 #include "components/sync_driver/sync_prefs.h" |
| 46 #include "content/public/browser/render_view_host.h" | 48 #include "content/public/browser/render_view_host.h" |
| 47 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 namespace { | 68 namespace { |
| 67 | 69 |
| 68 // A structure which contains all the configuration information for sync. | 70 // A structure which contains all the configuration information for sync. |
| 69 struct SyncConfigInfo { | 71 struct SyncConfigInfo { |
| 70 SyncConfigInfo(); | 72 SyncConfigInfo(); |
| 71 ~SyncConfigInfo(); | 73 ~SyncConfigInfo(); |
| 72 | 74 |
| 73 bool encrypt_all; | 75 bool encrypt_all; |
| 74 bool sync_everything; | 76 bool sync_everything; |
| 75 syncer::ModelTypeSet data_types; | 77 syncer::ModelTypeSet data_types; |
| 78 bool payments_integration_enabled; |
| 76 std::string passphrase; | 79 std::string passphrase; |
| 77 bool set_new_passphrase; | 80 bool set_new_passphrase; |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 SyncConfigInfo::SyncConfigInfo() | 83 SyncConfigInfo::SyncConfigInfo() |
| 81 : encrypt_all(false), | 84 : encrypt_all(false), |
| 82 sync_everything(false), | 85 sync_everything(false), |
| 86 payments_integration_enabled(false), |
| 83 set_new_passphrase(false) {} | 87 set_new_passphrase(false) {} |
| 84 | 88 |
| 85 SyncConfigInfo::~SyncConfigInfo() {} | 89 SyncConfigInfo::~SyncConfigInfo() {} |
| 86 | 90 |
| 87 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { | 91 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { |
| 88 std::unique_ptr<base::Value> parsed_value = base::JSONReader::Read(json); | 92 std::unique_ptr<base::Value> parsed_value = base::JSONReader::Read(json); |
| 89 base::DictionaryValue* result; | 93 base::DictionaryValue* result; |
| 90 if (!parsed_value || !parsed_value->GetAsDictionary(&result)) { | 94 if (!parsed_value || !parsed_value->GetAsDictionary(&result)) { |
| 91 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; | 95 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; |
| 92 return false; | 96 return false; |
| 93 } | 97 } |
| 94 | 98 |
| 95 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { | 99 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { |
| 96 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; | 100 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; |
| 97 return false; | 101 return false; |
| 98 } | 102 } |
| 99 | 103 |
| 104 if (!result->GetBoolean("paymentsIntegrationEnabled", |
| 105 &config->payments_integration_enabled)) { |
| 106 DLOG(ERROR) << "GetConfiguration() not passed a paymentsIntegrationEnabled " |
| 107 << "value"; |
| 108 return false; |
| 109 } |
| 110 |
| 100 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); | 111 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); |
| 101 | 112 |
| 102 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); | 113 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); |
| 103 it != type_names.end(); ++it) { | 114 it != type_names.end(); ++it) { |
| 104 std::string key_name = it->second + std::string("Synced"); | 115 std::string key_name = it->second + std::string("Synced"); |
| 105 bool sync_value; | 116 bool sync_value; |
| 106 if (!result->GetBoolean(key_name, &sync_value)) { | 117 if (!result->GetBoolean(key_name, &sync_value)) { |
| 107 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; | 118 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; |
| 108 return false; | 119 return false; |
| 109 } | 120 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 : nullptr; | 381 : nullptr; |
| 371 } | 382 } |
| 372 | 383 |
| 373 void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) { | 384 void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) { |
| 374 DCHECK(!sync_startup_tracker_); | 385 DCHECK(!sync_startup_tracker_); |
| 375 | 386 |
| 376 SyncConfigInfo configuration; | 387 SyncConfigInfo configuration; |
| 377 const base::Value* callback_id = nullptr; | 388 const base::Value* callback_id = nullptr; |
| 378 ParseConfigurationArguments(args, &configuration, &callback_id); | 389 ParseConfigurationArguments(args, &configuration, &callback_id); |
| 379 | 390 |
| 391 PrefService* pref_service = profile_->GetPrefs(); |
| 392 pref_service->SetBoolean(autofill::prefs::kAutofillWalletImportEnabled, |
| 393 configuration.payments_integration_enabled); |
| 394 |
| 380 // Start configuring the ProfileSyncService using the configuration passed | 395 // Start configuring the ProfileSyncService using the configuration passed |
| 381 // to us from the JS layer. | 396 // to us from the JS layer. |
| 382 ProfileSyncService* service = GetSyncService(); | 397 ProfileSyncService* service = GetSyncService(); |
| 383 | 398 |
| 384 // If the sync engine has shutdown for some reason, just close the sync | 399 // If the sync engine has shutdown for some reason, just close the sync |
| 385 // dialog. | 400 // dialog. |
| 386 if (!service || !service->IsBackendInitialized()) { | 401 if (!service || !service->IsBackendInitialized()) { |
| 387 CloseSyncSetup(); | 402 CloseSyncSetup(); |
| 388 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); | 403 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); |
| 389 return; | 404 return; |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 815 } |
| 801 | 816 |
| 802 configuring_sync_ = true; | 817 configuring_sync_ = true; |
| 803 DCHECK(service->IsBackendInitialized()) | 818 DCHECK(service->IsBackendInitialized()) |
| 804 << "Cannot configure sync until the sync backend is initialized"; | 819 << "Cannot configure sync until the sync backend is initialized"; |
| 805 | 820 |
| 806 // Setup args for the sync configure screen: | 821 // Setup args for the sync configure screen: |
| 807 // syncAllDataTypes: true if the user wants to sync everything | 822 // syncAllDataTypes: true if the user wants to sync everything |
| 808 // <data_type>Registered: true if the associated data type is supported | 823 // <data_type>Registered: true if the associated data type is supported |
| 809 // <data_type>Synced: true if the user wants to sync that specific data type | 824 // <data_type>Synced: true if the user wants to sync that specific data type |
| 825 // paymentsIntegrationEnabled: true if the user wants Payments integration |
| 810 // encryptionEnabled: true if sync supports encryption | 826 // encryptionEnabled: true if sync supports encryption |
| 811 // encryptAllData: true if user wants to encrypt all data (not just | 827 // encryptAllData: true if user wants to encrypt all data (not just |
| 812 // passwords) | 828 // passwords) |
| 813 // passphraseRequired: true if a passphrase is needed to start sync | 829 // passphraseRequired: true if a passphrase is needed to start sync |
| 814 // passphraseTypeIsCustom: true if the passphrase type is custom | 830 // passphraseTypeIsCustom: true if the passphrase type is custom |
| 815 // | 831 // |
| 816 base::DictionaryValue args; | 832 base::DictionaryValue args; |
| 817 | 833 |
| 818 // Tell the UI layer which data types are registered/enabled by the user. | 834 // Tell the UI layer which data types are registered/enabled by the user. |
| 819 const syncer::ModelTypeSet registered_types = | 835 const syncer::ModelTypeSet registered_types = |
| 820 service->GetRegisteredDataTypes(); | 836 service->GetRegisteredDataTypes(); |
| 821 const syncer::ModelTypeSet preferred_types = service->GetPreferredDataTypes(); | 837 const syncer::ModelTypeSet preferred_types = service->GetPreferredDataTypes(); |
| 822 const syncer::ModelTypeSet enforced_types = service->GetForcedDataTypes(); | 838 const syncer::ModelTypeSet enforced_types = service->GetForcedDataTypes(); |
| 823 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); | 839 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); |
| 824 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); | 840 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); |
| 825 it != type_names.end(); ++it) { | 841 it != type_names.end(); ++it) { |
| 826 syncer::ModelType sync_type = it->first; | 842 syncer::ModelType sync_type = it->first; |
| 827 const std::string key_name = it->second; | 843 const std::string key_name = it->second; |
| 828 args.SetBoolean(key_name + "Registered", registered_types.Has(sync_type)); | 844 args.SetBoolean(key_name + "Registered", registered_types.Has(sync_type)); |
| 829 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type)); | 845 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type)); |
| 830 args.SetBoolean(key_name + "Enforced", enforced_types.Has(sync_type)); | 846 args.SetBoolean(key_name + "Enforced", enforced_types.Has(sync_type)); |
| 831 // TODO(treib): How do we want to handle pref groups, i.e. when only some of | 847 // TODO(treib): How do we want to handle pref groups, i.e. when only some of |
| 832 // the sync types behind a checkbox are force-enabled? crbug.com/403326 | 848 // the sync types behind a checkbox are force-enabled? crbug.com/403326 |
| 833 } | 849 } |
| 834 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); | 850 PrefService* pref_service = profile_->GetPrefs(); |
| 851 sync_driver::SyncPrefs sync_prefs(pref_service); |
| 835 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced()); | 852 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced()); |
| 853 args.SetBoolean( |
| 854 "paymentsIntegrationEnabled", |
| 855 pref_service->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled)); |
| 836 args.SetBoolean("encryptAllData", service->IsEncryptEverythingEnabled()); | 856 args.SetBoolean("encryptAllData", service->IsEncryptEverythingEnabled()); |
| 837 args.SetBoolean("encryptAllDataAllowed", | 857 args.SetBoolean("encryptAllDataAllowed", |
| 838 service->IsEncryptEverythingAllowed()); | 858 service->IsEncryptEverythingAllowed()); |
| 839 | 859 |
| 840 // We call IsPassphraseRequired() here, instead of calling | 860 // We call IsPassphraseRequired() here, instead of calling |
| 841 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase | 861 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase |
| 842 // UI even if no encrypted data types are enabled. | 862 // UI even if no encrypted data types are enabled. |
| 843 args.SetBoolean("passphraseRequired", service->IsPassphraseRequired()); | 863 args.SetBoolean("passphraseRequired", service->IsPassphraseRequired()); |
| 844 | 864 |
| 845 // To distinguish between FROZEN_IMPLICIT_PASSPHRASE and CUSTOM_PASSPHRASE | 865 // To distinguish between FROZEN_IMPLICIT_PASSPHRASE and CUSTOM_PASSPHRASE |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 base::FilePath profile_file_path = profile_->GetPath(); | 932 base::FilePath profile_file_path = profile_->GetPath(); |
| 913 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 933 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 914 | 934 |
| 915 // We're done configuring, so notify ProfileSyncService that it is OK to | 935 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 916 // start syncing. | 936 // start syncing. |
| 917 service->SetSetupInProgress(false); | 937 service->SetSetupInProgress(false); |
| 918 service->SetFirstSetupComplete(); | 938 service->SetFirstSetupComplete(); |
| 919 } | 939 } |
| 920 | 940 |
| 921 } // namespace settings | 941 } // namespace settings |
| OLD | NEW |