File: autofill_experiments.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (229 lines) | stat: -rw-r--r-- 8,769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/autofill_experiments.h"

#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/suggestion.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service.h"
#include "components/variations/variations_associated_data.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"

namespace autofill {

const base::Feature kAutofillCreditCardAssist{
    "AutofillCreditCardAssist", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kAutofillCreditCardSigninPromo{
    "AutofillCreditCardSigninPromo", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kAutofillScanCardholderName{
    "AutofillScanCardholderName", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kAutofillCreditCardPopupLayout{
    "AutofillCreditCardPopupLayout", base::FEATURE_DISABLED_BY_DEFAULT};
const char kCreditCardSigninPromoImpressionLimitParamKey[] = "impression_limit";
const char kAutofillCreditCardPopupBackgroundColorKey[] = "background_color";
const char kAutofillCreditCardPopupDividerColorKey[] = "dropdown_divider_color";
const char kAutofillCreditCardPopupValueBoldKey[] = "is_value_bold";
const char kAutofillCreditCardPopupIsValueAndLabelInSingleLineKey[] =
    "is_value_and_label_in_single_line";
const char kAutofillPopupDropdownItemHeightKey[] =
    "dropdown_item_height";
const char kAutofillCreditCardPopupIsIconAtStartKey[] =
    "is_credit_card_icon_at_start";
const char kAutofillPopupMarginKey[] = "margin";

namespace {

// Returns parameter value in |kAutofillCreditCardPopupLayout| feature, or 0 if
// parameter is not specified.
unsigned int GetCreditCardPopupParameterUintValue(
    const std::string& param_name) {
  unsigned int value;
  const std::string param_value = variations::GetVariationParamValueByFeature(
      kAutofillCreditCardPopupLayout, param_name);
  if (!param_value.empty() && base::StringToUint(param_value, &value))
    return value;
  return 0;
}

}  // namespace

bool IsAutofillEnabled(const PrefService* pref_service) {
  return pref_service->GetBoolean(prefs::kAutofillEnabled);
}

bool IsInAutofillSuggestionsDisabledExperiment() {
  std::string group_name =
      base::FieldTrialList::FindFullName("AutofillEnabled");
  return group_name == "Disabled";
}

bool IsAutofillCreditCardSigninPromoEnabled() {
  return base::FeatureList::IsEnabled(kAutofillCreditCardSigninPromo);
}

bool IsAutofillCreditCardAssistEnabled() {
#if !defined(OS_ANDROID) && !defined(OS_IOS)
  return false;
#else
  return base::FeatureList::IsEnabled(kAutofillCreditCardAssist);
#endif
}

int GetCreditCardSigninPromoImpressionLimit() {
  int impression_limit;
  std::string param_value = variations::GetVariationParamValueByFeature(
      kAutofillCreditCardSigninPromo,
      kCreditCardSigninPromoImpressionLimitParamKey);
  if (!param_value.empty() && base::StringToInt(param_value, &impression_limit))
    return impression_limit;

  return 0;
}

bool IsAutofillCreditCardPopupLayoutExperimentEnabled() {
  return base::FeatureList::IsEnabled(kAutofillCreditCardPopupLayout);
}

// |GetCreditCardPopupParameterUintValue| returns 0 if experiment parameter is
// not specified. 0 == |SK_ColorTRANSPARENT|.
SkColor GetCreditCardPopupBackgroundColor() {
  return GetCreditCardPopupParameterUintValue(
      kAutofillCreditCardPopupBackgroundColorKey);
}

SkColor GetCreditCardPopupDividerColor() {
  return GetCreditCardPopupParameterUintValue(
      kAutofillCreditCardPopupDividerColorKey);
}

bool IsCreditCardPopupValueBold() {
  const std::string param_value = variations::GetVariationParamValueByFeature(
      kAutofillCreditCardPopupLayout, kAutofillCreditCardPopupValueBoldKey);
  return param_value == "true";
}

unsigned int GetPopupDropdownItemHeight() {
  return GetCreditCardPopupParameterUintValue(
      kAutofillPopupDropdownItemHeightKey);
}

bool IsIconInCreditCardPopupAtStart() {
  const std::string param_value = variations::GetVariationParamValueByFeature(
      kAutofillCreditCardPopupLayout, kAutofillCreditCardPopupIsIconAtStartKey);
  return param_value == "true";
}

// Modifies |suggestion| as follows if experiment to display value and label in
// a single line is enabled.
// Say, |value| is 'Visa ....1111' and |label| is '01/18' (expiration date).
// Modifies |value| to 'Visa ....1111, exp 01/18' and clears |label|.
void ModifyAutofillCreditCardSuggestion(Suggestion* suggestion) {
  DCHECK(IsAutofillCreditCardPopupLayoutExperimentEnabled());
  const std::string param_value = variations::GetVariationParamValueByFeature(
      kAutofillCreditCardPopupLayout,
      kAutofillCreditCardPopupIsValueAndLabelInSingleLineKey);
  if (param_value == "true") {
    const base::string16 format_string = l10n_util::GetStringUTF16(
        IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_LABEL_AND_ABBR);
    if (!format_string.empty()) {
      suggestion->value.append(l10n_util::GetStringFUTF16(
          IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_LABEL_AND_ABBR,
          suggestion->label));
    }
    suggestion->label.clear();
  }
}

unsigned int GetPopupMargin() {
  return GetCreditCardPopupParameterUintValue(kAutofillPopupMarginKey);
}

bool OfferStoreUnmaskedCards() {
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
  // The checkbox can be forced on with a flag, but by default we don't store
  // on Linux due to lack of system keychain integration. See crbug.com/162735
  return base::CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kEnableOfferStoreUnmaskedWalletCards);
#else
  // Query the field trial before checking command line flags to ensure UMA
  // reports the correct group.
  std::string group_name =
      base::FieldTrialList::FindFullName("OfferStoreUnmaskedWalletCards");

  // The checkbox can be forced on or off with flags.
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kEnableOfferStoreUnmaskedWalletCards))
    return true;
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kDisableOfferStoreUnmaskedWalletCards))
    return false;

  // Otherwise use the field trial to show the checkbox or not.
  return group_name != "Disabled";
#endif
}

bool IsCreditCardUploadEnabled(const PrefService* pref_service,
                               const syncer::SyncService* sync_service,
                               const std::string& user_email) {
  // Query the field trial first to ensure UMA always reports the correct group.
  std::string group_name =
      base::FieldTrialList::FindFullName("OfferUploadCreditCards");

  // Check Autofill sync setting.
  if (!(sync_service && sync_service->CanSyncStart() &&
        sync_service->GetPreferredDataTypes().Has(syncer::AUTOFILL_PROFILE))) {
    return false;
  }

  // Users who have enabled a passphrase have chosen to not make their sync
  // information accessible to Google. Since upload makes credit card data
  // available to other Google systems, disable it for passphrase users.
  // We can't determine the passphrase state until the sync engine is
  // initialized so disable upload if sync is not yet available.
  if (!sync_service->IsEngineInitialized() ||
      sync_service->IsUsingSecondaryPassphrase()) {
    return false;
  }

  // Check Payments integration user setting.
  if (!pref_service->GetBoolean(prefs::kAutofillWalletImportEnabled))
    return false;

  // Check that the user is logged into a supported domain.
  if (user_email.empty())
    return false;
  std::string domain = gaia::ExtractDomainName(user_email);
  if (!(domain == "googlemail.com" || domain == "gmail.com" ||
        domain == "google.com")) {
    return false;
  }

  // With the user settings and logged in state verified, now we can consult the
  // command-line flags and experiment settings.
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kEnableOfferUploadCreditCards)) {
    return true;
  }
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kDisableOfferUploadCreditCards)) {
    return false;
  }

  return !group_name.empty() && group_name != "Disabled";
}

}  // namespace autofill