Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
| 16 #include "base/i18n/time_formatting.h" | |
| 16 #include "base/i18n/timezone.h" | 17 #include "base/i18n/timezone.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 23 #include "components/autofill/core/browser/address_i18n.h" | 24 #include "components/autofill/core/browser/address_i18n.h" |
| 24 #include "components/autofill/core/browser/autofill-inl.h" | 25 #include "components/autofill/core/browser/autofill-inl.h" |
| 25 #include "components/autofill/core/browser/autofill_country.h" | 26 #include "components/autofill/core/browser/autofill_country.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 37 #include "components/autofill/core/common/autofill_pref_names.h" | 38 #include "components/autofill/core/common/autofill_pref_names.h" |
| 38 #include "components/autofill/core/common/autofill_switches.h" | 39 #include "components/autofill/core/common/autofill_switches.h" |
| 39 #include "components/autofill/core/common/autofill_util.h" | 40 #include "components/autofill/core/common/autofill_util.h" |
| 40 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
| 41 #include "components/signin/core/browser/account_tracker_service.h" | 42 #include "components/signin/core/browser/account_tracker_service.h" |
| 42 #include "components/signin/core/browser/signin_manager.h" | 43 #include "components/signin/core/browser/signin_manager.h" |
| 43 #include "components/signin/core/common/signin_pref_names.h" | 44 #include "components/signin/core/common/signin_pref_names.h" |
| 44 #include "components/sync/driver/sync_service.h" | 45 #include "components/sync/driver/sync_service.h" |
| 45 #include "components/variations/variations_associated_data.h" | 46 #include "components/variations/variations_associated_data.h" |
| 46 #include "components/version_info/version_info.h" | 47 #include "components/version_info/version_info.h" |
| 48 #include "grit/components_strings.h" | |
| 47 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" | 49 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
| 48 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" | 50 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | |
| 49 | 52 |
| 50 namespace autofill { | 53 namespace autofill { |
| 51 namespace { | 54 namespace { |
| 52 | 55 |
| 53 using ::i18n::addressinput::AddressField; | 56 using ::i18n::addressinput::AddressField; |
| 54 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; | 57 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; |
| 55 using ::i18n::addressinput::STREET_ADDRESS; | 58 using ::i18n::addressinput::STREET_ADDRESS; |
| 56 | 59 |
| 57 template<typename T> | 60 template<typename T> |
| 58 class FormGroupMatchesByGUIDFunctor { | 61 class FormGroupMatchesByGUIDFunctor { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 suggestion_canon.length() >= field_contents_canon.length() && | 244 suggestion_canon.length() >= field_contents_canon.length() && |
| 242 GetTextSelectionStart(suggestion_canon, field_contents_canon, false) != | 245 GetTextSelectionStart(suggestion_canon, field_contents_canon, false) != |
| 243 base::string16::npos) { | 246 base::string16::npos) { |
| 244 *is_prefix_matched = false; | 247 *is_prefix_matched = false; |
| 245 return true; | 248 return true; |
| 246 } | 249 } |
| 247 | 250 |
| 248 return false; | 251 return false; |
| 249 } | 252 } |
| 250 | 253 |
| 254 // Returns the date when the credit card was last used in autofill. Shows | |
| 255 // expiration date if |show_expiration_date| is true, and shows time detail | |
| 256 // if |show_time_detail| is true. | |
| 257 base::string16 GetLastUsedDateForDisplay(const CreditCard* credit_card, | |
|
Mathieu
2017/01/27 15:01:44
I would put this function in AutofillDataModel (wh
| |
| 258 bool show_expiration_date, | |
| 259 bool show_time_detail, | |
| 260 const std::string& app_locale) { | |
| 261 DCHECK(credit_card->use_count() > 0); | |
| 262 // use_count() is initialized as 1 when the card is just added. | |
| 263 if (credit_card->use_count() == 1) { | |
| 264 return show_expiration_date | |
| 265 ? l10n_util::GetStringFUTF16( | |
| 266 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE, | |
| 267 credit_card->GetInfo( | |
| 268 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 269 app_locale), | |
| 270 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 271 "MMMdd")) | |
| 272 : l10n_util::GetStringFUTF16( | |
| 273 IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE, | |
| 274 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 275 "MMMdd")); | |
| 276 } | |
| 277 // use_count() > 1 when the card has been used in autofill. | |
| 278 | |
| 279 // If the card was last used in autofill more than a year ago, | |
| 280 // display "last used > 1 year ago" without showing date detail. | |
| 281 if ((base::Time::Now() - credit_card->use_date()).InDays() > 365) { | |
| 282 return show_expiration_date | |
| 283 ? l10n_util::GetStringFUTF16( | |
| 284 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_YEAR_AGO, | |
| 285 credit_card->GetInfo( | |
| 286 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 287 app_locale)) | |
| 288 : l10n_util::GetStringUTF16( | |
| 289 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_YEAR_AGO); | |
| 290 } | |
| 291 | |
| 292 // If the card was last used in autofill within a year, show date information. | |
| 293 if (show_time_detail) { | |
| 294 return show_expiration_date | |
| 295 ? l10n_util::GetStringFUTF16( | |
| 296 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE_DETAIL, | |
| 297 credit_card->GetInfo( | |
| 298 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 299 app_locale), | |
| 300 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 301 "MMMddjmm")) | |
|
Mathieu
2017/01/27 15:01:44
Since we are ever only using two patterns (with ti
jiahuiguo
2017/02/03 07:11:17
Done.
| |
| 302 : l10n_util::GetStringFUTF16( | |
| 303 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_DETAIL, | |
| 304 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 305 "MMMddjmm")); | |
| 306 } else { | |
| 307 return show_expiration_date | |
| 308 ? l10n_util::GetStringFUTF16( | |
| 309 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE, | |
| 310 credit_card->GetInfo( | |
| 311 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 312 app_locale), | |
| 313 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 314 "MMMdd")) | |
| 315 : l10n_util::GetStringFUTF16( | |
| 316 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE, | |
| 317 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 318 "MMMdd")); | |
| 319 } | |
| 320 } | |
| 321 | |
| 251 } // namespace | 322 } // namespace |
| 252 | 323 |
| 253 const char kFrecencyFieldTrialName[] = "AutofillProfileOrderByFrecency"; | 324 const char kFrecencyFieldTrialName[] = "AutofillProfileOrderByFrecency"; |
| 254 const char kFrecencyFieldTrialLimitParam[] = "limit"; | 325 const char kFrecencyFieldTrialLimitParam[] = "limit"; |
| 255 | 326 |
| 256 PersonalDataManager::PersonalDataManager(const std::string& app_locale) | 327 PersonalDataManager::PersonalDataManager(const std::string& app_locale) |
| 257 : database_(NULL), | 328 : database_(NULL), |
| 258 is_data_loaded_(false), | 329 is_data_loaded_(false), |
| 259 pending_profiles_query_(0), | 330 pending_profiles_query_(0), |
| 260 pending_server_profiles_query_(0), | 331 pending_server_profiles_query_(0), |
| (...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1611 suggestion->backend_id = credit_card->guid(); | 1682 suggestion->backend_id = credit_card->guid(); |
| 1612 suggestion->match = prefix_matched_suggestion | 1683 suggestion->match = prefix_matched_suggestion |
| 1613 ? Suggestion::PREFIX_MATCH | 1684 ? Suggestion::PREFIX_MATCH |
| 1614 : Suggestion::SUBSTRING_MATCH; | 1685 : Suggestion::SUBSTRING_MATCH; |
| 1615 | 1686 |
| 1616 // If the value is the card number, the label is the expiration date. | 1687 // If the value is the card number, the label is the expiration date. |
| 1617 // Otherwise the label is the card number, or if that is empty the | 1688 // Otherwise the label is the card number, or if that is empty the |
| 1618 // cardholder name. The label should never repeat the value. | 1689 // cardholder name. The label should never repeat the value. |
| 1619 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | 1690 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| 1620 suggestion->value = credit_card->TypeAndLastFourDigits(); | 1691 suggestion->value = credit_card->TypeAndLastFourDigits(); |
| 1621 suggestion->label = credit_card->GetInfo( | 1692 if (IsAutofillCreditCardLastUsedDateDisplayExperimentEnabled() && |
| 1622 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); | 1693 !IsKeyboardAccessoryEnabled()) { |
| 1694 suggestion->label = GetLastUsedDateForDisplay( | |
|
Mathieu
2017/01/27 15:01:44
using the suggestion above, you will be able to do
jiahuiguo
2017/02/03 07:11:17
Done.
| |
| 1695 credit_card, ShowExpirationDateInAutofillCreditCardLastUsedDate(), | |
| 1696 ShowTimeDetailInAutofillCreditCardLastUsedDate(), app_locale_); | |
| 1697 } else { | |
| 1698 suggestion->label = credit_card->GetInfo( | |
| 1699 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); | |
| 1700 } | |
| 1623 if (IsAutofillCreditCardPopupLayoutExperimentEnabled()) | 1701 if (IsAutofillCreditCardPopupLayoutExperimentEnabled()) |
| 1624 ModifyAutofillCreditCardSuggestion(suggestion); | 1702 ModifyAutofillCreditCardSuggestion(suggestion); |
| 1625 } else if (credit_card->number().empty()) { | 1703 } else if (credit_card->number().empty()) { |
| 1626 if (type.GetStorableType() != CREDIT_CARD_NAME_FULL) { | 1704 if (type.GetStorableType() != CREDIT_CARD_NAME_FULL) { |
| 1627 suggestion->label = credit_card->GetInfo( | 1705 suggestion->label = credit_card->GetInfo( |
| 1628 AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1706 AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
| 1629 } | 1707 } |
| 1630 } else { | 1708 } else { |
| 1631 #if defined(OS_ANDROID) | 1709 #if defined(OS_ANDROID) |
| 1632 // Since Android places the label on its own row, there's more | 1710 // Since Android places the label on its own row, there's more |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 } | 1924 } |
| 1847 | 1925 |
| 1848 // If the card was modified, apply the changes to the database. | 1926 // If the card was modified, apply the changes to the database. |
| 1849 if (was_modified) { | 1927 if (was_modified) { |
| 1850 database_->UpdateCreditCard(*credit_card); | 1928 database_->UpdateCreditCard(*credit_card); |
| 1851 } | 1929 } |
| 1852 } | 1930 } |
| 1853 } | 1931 } |
| 1854 | 1932 |
| 1855 } // namespace autofill | 1933 } // namespace autofill |
| OLD | NEW |