| 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 "components/autofill/core/browser/autofill_experiments.h" | 5 #include "components/autofill/core/browser/autofill_experiments.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "components/autofill/core/browser/suggestion.h" |
| 13 #include "components/autofill/core/common/autofill_pref_names.h" | 16 #include "components/autofill/core/common/autofill_pref_names.h" |
| 14 #include "components/autofill/core/common/autofill_switches.h" | 17 #include "components/autofill/core/common/autofill_switches.h" |
| 15 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 16 #include "components/security_state/core/switches.h" | 19 #include "components/security_state/core/switches.h" |
| 17 #include "components/sync/driver/sync_service.h" | 20 #include "components/sync/driver/sync_service.h" |
| 18 #include "components/variations/variations_associated_data.h" | 21 #include "components/variations/variations_associated_data.h" |
| 19 #include "google_apis/gaia/gaia_auth_util.h" | 22 #include "google_apis/gaia/gaia_auth_util.h" |
| 23 #include "grit/components_strings.h" |
| 24 #include "ui/base/l10n/l10n_util.h" |
| 20 | 25 |
| 21 namespace autofill { | 26 namespace autofill { |
| 22 | 27 |
| 23 const base::Feature kAutofillCreditCardAssist{ | 28 const base::Feature kAutofillCreditCardAssist{ |
| 24 "AutofillCreditCardAssist", base::FEATURE_DISABLED_BY_DEFAULT}; | 29 "AutofillCreditCardAssist", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 25 const base::Feature kAutofillCreditCardSigninPromo{ | 30 const base::Feature kAutofillCreditCardSigninPromo{ |
| 26 "AutofillCreditCardSigninPromo", base::FEATURE_DISABLED_BY_DEFAULT}; | 31 "AutofillCreditCardSigninPromo", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 27 const base::Feature kAutofillProfileCleanup{"AutofillProfileCleanup", | 32 const base::Feature kAutofillProfileCleanup{"AutofillProfileCleanup", |
| 28 base::FEATURE_DISABLED_BY_DEFAULT}; | 33 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 29 const base::Feature kAutofillScanCardholderName{ | 34 const base::Feature kAutofillScanCardholderName{ |
| 30 "AutofillScanCardholderName", base::FEATURE_DISABLED_BY_DEFAULT}; | 35 "AutofillScanCardholderName", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 36 const base::Feature kAutofillCreditCardPopupLayout{ |
| 37 "AutofillCreditCardPopupLayout", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 31 const char kCreditCardSigninPromoImpressionLimitParamKey[] = "impression_limit"; | 38 const char kCreditCardSigninPromoImpressionLimitParamKey[] = "impression_limit"; |
| 39 const char kAutofillCreditCardPopupBackgroundColorKey[] = "background_color"; |
| 40 const char kAutofillCreditCardPopupDividerColorKey[] = "dropdown_divider_color"; |
| 41 const char kAutofillCreditCardPopupValueBoldKey[] = "is_value_bold"; |
| 42 const char kAutofillCreditCardPopupIsValueAndLabelInSingleLineKey[] = |
| 43 "is_value_and_label_in_single_line"; |
| 44 const char kAutofillCreditCardPopupDropdownItemHeightKey[] = |
| 45 "dropdown_item_height"; |
| 46 const char kAutofillCreditCardPopupIsIconAtLeftKey[] = |
| 47 "is_credit_card_icon_at_left"; |
| 48 |
| 49 namespace { |
| 50 |
| 51 // Returns parameter value in |kAutofillCreditCardPopupLayout| feature, or 0 if |
| 52 // parameter is not specified. |
| 53 unsigned int GetCreditCardPopupParameterUintValue( |
| 54 const std::string& param_name) { |
| 55 unsigned int value; |
| 56 const std::string param_value = variations::GetVariationParamValueByFeature( |
| 57 kAutofillCreditCardPopupLayout, param_name); |
| 58 if (!param_value.empty() && base::StringToUint(param_value, &value)) |
| 59 return value; |
| 60 return 0; |
| 61 } |
| 62 |
| 63 } // namespace |
| 32 | 64 |
| 33 bool IsAutofillEnabled(const PrefService* pref_service) { | 65 bool IsAutofillEnabled(const PrefService* pref_service) { |
| 34 return pref_service->GetBoolean(prefs::kAutofillEnabled); | 66 return pref_service->GetBoolean(prefs::kAutofillEnabled); |
| 35 } | 67 } |
| 36 | 68 |
| 37 bool IsInAutofillSuggestionsDisabledExperiment() { | 69 bool IsInAutofillSuggestionsDisabledExperiment() { |
| 38 std::string group_name = | 70 std::string group_name = |
| 39 base::FieldTrialList::FindFullName("AutofillEnabled"); | 71 base::FieldTrialList::FindFullName("AutofillEnabled"); |
| 40 return group_name == "Disabled"; | 72 return group_name == "Disabled"; |
| 41 } | 73 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 60 int impression_limit; | 92 int impression_limit; |
| 61 std::string param_value = variations::GetVariationParamValueByFeature( | 93 std::string param_value = variations::GetVariationParamValueByFeature( |
| 62 kAutofillCreditCardSigninPromo, | 94 kAutofillCreditCardSigninPromo, |
| 63 kCreditCardSigninPromoImpressionLimitParamKey); | 95 kCreditCardSigninPromoImpressionLimitParamKey); |
| 64 if (!param_value.empty() && base::StringToInt(param_value, &impression_limit)) | 96 if (!param_value.empty() && base::StringToInt(param_value, &impression_limit)) |
| 65 return impression_limit; | 97 return impression_limit; |
| 66 | 98 |
| 67 return 0; | 99 return 0; |
| 68 } | 100 } |
| 69 | 101 |
| 102 bool IsAutofillCreditCardPopupLayoutExperimentEnabled() { |
| 103 return base::FeatureList::IsEnabled(kAutofillCreditCardPopupLayout); |
| 104 } |
| 105 |
| 106 SkColor GetCreditCardPopupBackgroundColor() { |
| 107 return GetCreditCardPopupParameterUintValue( |
| 108 kAutofillCreditCardPopupBackgroundColorKey); |
| 109 } |
| 110 |
| 111 SkColor GetCreditCardPopupDividerColor() { |
| 112 return GetCreditCardPopupParameterUintValue( |
| 113 kAutofillCreditCardPopupDividerColorKey); |
| 114 } |
| 115 |
| 116 bool IsCreditCardPopupValueBold() { |
| 117 const std::string param_value = variations::GetVariationParamValueByFeature( |
| 118 kAutofillCreditCardPopupLayout, kAutofillCreditCardPopupValueBoldKey); |
| 119 return param_value == "true"; |
| 120 } |
| 121 |
| 122 unsigned int GetCreditCardPopupDropdownItemHeight() { |
| 123 return GetCreditCardPopupParameterUintValue( |
| 124 kAutofillCreditCardPopupDropdownItemHeightKey); |
| 125 } |
| 126 |
| 127 bool IsCreditCardIconInPopupAtLeft() { |
| 128 const std::string param_value = variations::GetVariationParamValueByFeature( |
| 129 kAutofillCreditCardPopupLayout, kAutofillCreditCardPopupIsIconAtLeftKey); |
| 130 return param_value == "true"; |
| 131 } |
| 132 |
| 133 // Modifies |suggestion| as follows if experiment to display value and label in |
| 134 // a single line is enabled. |
| 135 // Say, |value| is 'Visa ....1111' and |label| is '01/18' (expiration date). |
| 136 // Modifies |value| to 'Visa ....1111, exp 01/18' and clears |label|. |
| 137 void ModifyAutofillCreditCardSuggestion(Suggestion* suggestion) { |
| 138 DCHECK(IsAutofillCreditCardPopupLayoutExperimentEnabled()); |
| 139 const std::string param_value = variations::GetVariationParamValueByFeature( |
| 140 kAutofillCreditCardPopupLayout, |
| 141 kAutofillCreditCardPopupIsValueAndLabelInSingleLineKey); |
| 142 if (param_value == "true") { |
| 143 suggestion->value.append(l10n_util::GetStringFUTF16( |
| 144 IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_LABEL_AND_ABBR, |
| 145 suggestion->label)); |
| 146 suggestion->label.clear(); |
| 147 } |
| 148 } |
| 149 |
| 70 bool OfferStoreUnmaskedCards() { | 150 bool OfferStoreUnmaskedCards() { |
| 71 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 151 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 72 // The checkbox can be forced on with a flag, but by default we don't store | 152 // The checkbox can be forced on with a flag, but by default we don't store |
| 73 // on Linux due to lack of system keychain integration. See crbug.com/162735 | 153 // on Linux due to lack of system keychain integration. See crbug.com/162735 |
| 74 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 154 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 75 switches::kEnableOfferStoreUnmaskedWalletCards); | 155 switches::kEnableOfferStoreUnmaskedWalletCards); |
| 76 #else | 156 #else |
| 77 // Query the field trial before checking command line flags to ensure UMA | 157 // Query the field trial before checking command line flags to ensure UMA |
| 78 // reports the correct group. | 158 // reports the correct group. |
| 79 std::string group_name = | 159 std::string group_name = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 224 |
| 145 bool IsCreditCardAutofillHttpWarningEnabled() { | 225 bool IsCreditCardAutofillHttpWarningEnabled() { |
| 146 std::string choice = | 226 std::string choice = |
| 147 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 227 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 148 security_state::switches::kMarkHttpAs); | 228 security_state::switches::kMarkHttpAs); |
| 149 return choice == security_state::switches:: | 229 return choice == security_state::switches:: |
| 150 kMarkHttpWithPasswordsOrCcWithChipAndFormWarning; | 230 kMarkHttpWithPasswordsOrCcWithChipAndFormWarning; |
| 151 } | 231 } |
| 152 | 232 |
| 153 } // namespace autofill | 233 } // namespace autofill |
| OLD | NEW |