| 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 kAutofillPopupDropdownItemHeightKey[] = |
| 45 "dropdown_item_height"; |
| 46 const char kAutofillCreditCardPopupIsIconAtStartKey[] = |
| 47 "is_credit_card_icon_at_start"; |
| 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 // |GetCreditCardPopupParameterUintValue| returns 0 if experiment parameter is |
| 107 // not specified. 0 == |SK_ColorTRANSPARENT|. |
| 108 SkColor GetCreditCardPopupBackgroundColor() { |
| 109 return GetCreditCardPopupParameterUintValue( |
| 110 kAutofillCreditCardPopupBackgroundColorKey); |
| 111 } |
| 112 |
| 113 SkColor GetCreditCardPopupDividerColor() { |
| 114 return GetCreditCardPopupParameterUintValue( |
| 115 kAutofillCreditCardPopupDividerColorKey); |
| 116 } |
| 117 |
| 118 bool IsCreditCardPopupValueBold() { |
| 119 const std::string param_value = variations::GetVariationParamValueByFeature( |
| 120 kAutofillCreditCardPopupLayout, kAutofillCreditCardPopupValueBoldKey); |
| 121 return param_value == "true"; |
| 122 } |
| 123 |
| 124 unsigned int GetPopupDropdownItemHeight() { |
| 125 return GetCreditCardPopupParameterUintValue( |
| 126 kAutofillPopupDropdownItemHeightKey); |
| 127 } |
| 128 |
| 129 bool IsIconInCreditCardPopupAtStart() { |
| 130 const std::string param_value = variations::GetVariationParamValueByFeature( |
| 131 kAutofillCreditCardPopupLayout, kAutofillCreditCardPopupIsIconAtStartKey); |
| 132 return param_value == "true"; |
| 133 } |
| 134 |
| 135 // Modifies |suggestion| as follows if experiment to display value and label in |
| 136 // a single line is enabled. |
| 137 // Say, |value| is 'Visa ....1111' and |label| is '01/18' (expiration date). |
| 138 // Modifies |value| to 'Visa ....1111, exp 01/18' and clears |label|. |
| 139 void ModifyAutofillCreditCardSuggestion(Suggestion* suggestion) { |
| 140 DCHECK(IsAutofillCreditCardPopupLayoutExperimentEnabled()); |
| 141 const std::string param_value = variations::GetVariationParamValueByFeature( |
| 142 kAutofillCreditCardPopupLayout, |
| 143 kAutofillCreditCardPopupIsValueAndLabelInSingleLineKey); |
| 144 if (param_value == "true") { |
| 145 const base::string16 format_string = l10n_util::GetStringUTF16( |
| 146 IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_LABEL_AND_ABBR); |
| 147 if (!format_string.empty()) { |
| 148 suggestion->value.append(l10n_util::GetStringFUTF16( |
| 149 IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_LABEL_AND_ABBR, |
| 150 suggestion->label)); |
| 151 } |
| 152 suggestion->label.clear(); |
| 153 } |
| 154 } |
| 155 |
| 70 bool OfferStoreUnmaskedCards() { | 156 bool OfferStoreUnmaskedCards() { |
| 71 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 157 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 72 // The checkbox can be forced on with a flag, but by default we don't store | 158 // 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 | 159 // on Linux due to lack of system keychain integration. See crbug.com/162735 |
| 74 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 160 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 75 switches::kEnableOfferStoreUnmaskedWalletCards); | 161 switches::kEnableOfferStoreUnmaskedWalletCards); |
| 76 #else | 162 #else |
| 77 // Query the field trial before checking command line flags to ensure UMA | 163 // Query the field trial before checking command line flags to ensure UMA |
| 78 // reports the correct group. | 164 // reports the correct group. |
| 79 std::string group_name = | 165 std::string group_name = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 230 |
| 145 bool IsCreditCardAutofillHttpWarningEnabled() { | 231 bool IsCreditCardAutofillHttpWarningEnabled() { |
| 146 std::string choice = | 232 std::string choice = |
| 147 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 233 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 148 security_state::switches::kMarkHttpAs); | 234 security_state::switches::kMarkHttpAs); |
| 149 return choice == security_state::switches:: | 235 return choice == security_state::switches:: |
| 150 kMarkHttpWithPasswordsOrCcWithChipAndFormWarning; | 236 kMarkHttpWithPasswordsOrCcWithChipAndFormWarning; |
| 151 } | 237 } |
| 152 | 238 |
| 153 } // namespace autofill | 239 } // namespace autofill |
| OLD | NEW |