Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 2639403002: [Autofill] Remove direct use of base::Time::Now() in Autofill (Closed)
Patch Set: Added DCHECK Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "components/autofill/core/browser/autofill_type.h" 44 #include "components/autofill/core/browser/autofill_type.h"
45 #include "components/autofill/core/browser/country_names.h" 45 #include "components/autofill/core/browser/country_names.h"
46 #include "components/autofill/core/browser/credit_card.h" 46 #include "components/autofill/core/browser/credit_card.h"
47 #include "components/autofill/core/browser/field_types.h" 47 #include "components/autofill/core/browser/field_types.h"
48 #include "components/autofill/core/browser/form_structure.h" 48 #include "components/autofill/core/browser/form_structure.h"
49 #include "components/autofill/core/browser/personal_data_manager.h" 49 #include "components/autofill/core/browser/personal_data_manager.h"
50 #include "components/autofill/core/browser/phone_number.h" 50 #include "components/autofill/core/browser/phone_number.h"
51 #include "components/autofill/core/browser/phone_number_i18n.h" 51 #include "components/autofill/core/browser/phone_number_i18n.h"
52 #include "components/autofill/core/browser/popup_item_ids.h" 52 #include "components/autofill/core/browser/popup_item_ids.h"
53 #include "components/autofill/core/browser/validation.h" 53 #include "components/autofill/core/browser/validation.h"
54 #include "components/autofill/core/common/autofill_clock.h"
54 #include "components/autofill/core/common/autofill_constants.h" 55 #include "components/autofill/core/common/autofill_constants.h"
55 #include "components/autofill/core/common/autofill_data_validation.h" 56 #include "components/autofill/core/common/autofill_data_validation.h"
56 #include "components/autofill/core/common/autofill_pref_names.h" 57 #include "components/autofill/core/common/autofill_pref_names.h"
57 #include "components/autofill/core/common/autofill_util.h" 58 #include "components/autofill/core/common/autofill_util.h"
58 #include "components/autofill/core/common/form_data.h" 59 #include "components/autofill/core/common/form_data.h"
59 #include "components/autofill/core/common/form_data_predictions.h" 60 #include "components/autofill/core/common/form_data_predictions.h"
60 #include "components/autofill/core/common/form_field_data.h" 61 #include "components/autofill/core/common/form_field_data.h"
61 #include "components/autofill/core/common/password_form_fill_data.h" 62 #include "components/autofill/core/common/password_form_fill_data.h"
62 #include "components/pref_registry/pref_registry_syncable.h" 63 #include "components/pref_registry/pref_registry_syncable.h"
63 #include "components/prefs/pref_service.h" 64 #include "components/prefs/pref_service.h"
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 } 1223 }
1223 } 1224 }
1224 1225
1225 bool AutofillManager::GetProfilesForCreditCardUpload( 1226 bool AutofillManager::GetProfilesForCreditCardUpload(
1226 const CreditCard& card, 1227 const CreditCard& card,
1227 std::vector<AutofillProfile>* profiles, 1228 std::vector<AutofillProfile>* profiles,
1228 autofill::AutofillMetrics::CardUploadDecisionMetric* 1229 autofill::AutofillMetrics::CardUploadDecisionMetric*
1229 address_upload_decision_metric, 1230 address_upload_decision_metric,
1230 std::string* rappor_metric_name) const { 1231 std::string* rappor_metric_name) const {
1231 std::vector<AutofillProfile> candidate_profiles; 1232 std::vector<AutofillProfile> candidate_profiles;
1232 const base::Time now = base::Time::Now(); 1233 const base::Time now = AutofillClock::Now();
1233 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); 1234 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15);
1234 1235
1235 // First, collect all of the addresses used recently. 1236 // First, collect all of the addresses used recently.
1236 for (AutofillProfile* profile : personal_data_->GetProfiles()) { 1237 for (AutofillProfile* profile : personal_data_->GetProfiles()) {
1237 if ((now - profile->use_date()) < fifteen_minutes || 1238 if ((now - profile->use_date()) < fifteen_minutes ||
1238 (now - profile->modification_date()) < fifteen_minutes) { 1239 (now - profile->modification_date()) < fifteen_minutes) {
1239 candidate_profiles.push_back(*profile); 1240 candidate_profiles.push_back(*profile);
1240 } 1241 }
1241 } 1242 }
1242 if (candidate_profiles.empty()) { 1243 if (candidate_profiles.empty()) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 1591
1591 base::string16 value = 1592 base::string16 value =
1592 data_model.GetInfo(cached_field->Type(), app_locale_); 1593 data_model.GetInfo(cached_field->Type(), app_locale_);
1593 if (is_credit_card && 1594 if (is_credit_card &&
1594 cached_field->Type().GetStorableType() == 1595 cached_field->Type().GetStorableType() ==
1595 CREDIT_CARD_VERIFICATION_CODE) { 1596 CREDIT_CARD_VERIFICATION_CODE) {
1596 value = cvc; 1597 value = cvc;
1597 } else if (is_credit_card && IsCreditCardExpirationType( 1598 } else if (is_credit_card && IsCreditCardExpirationType(
1598 cached_field->Type().GetStorableType()) && 1599 cached_field->Type().GetStorableType()) &&
1599 static_cast<const CreditCard*>(&data_model) 1600 static_cast<const CreditCard*>(&data_model)
1600 ->IsExpired(base::Time::Now())) { 1601 ->IsExpired(AutofillClock::Now())) {
1601 // Don't fill expired cards expiration date. 1602 // Don't fill expired cards expiration date.
1602 value = base::string16(); 1603 value = base::string16();
1603 } 1604 }
1604 1605
1605 // Must match ForEachMatchingFormField() in form_autofill_util.cc. 1606 // Must match ForEachMatchingFormField() in form_autofill_util.cc.
1606 // Only notify autofilling of empty fields and the field that initiated 1607 // Only notify autofilling of empty fields and the field that initiated
1607 // the filling (note that "select-one" controls may not be empty but will 1608 // the filling (note that "select-one" controls may not be empty but will
1608 // still be autofilled). 1609 // still be autofilled).
1609 bool should_notify = 1610 bool should_notify =
1610 !is_credit_card && 1611 !is_credit_card &&
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 #if defined(OS_ANDROID) || defined(OS_IOS) 1889 #if defined(OS_ANDROID) || defined(OS_IOS)
1889 // When a credit card form is parsed and conditions are met, show an infobar 1890 // When a credit card form is parsed and conditions are met, show an infobar
1890 // prompt for credit card assisted filling. Upon accepting the infobar, the 1891 // prompt for credit card assisted filling. Upon accepting the infobar, the
1891 // form will automatically be filled with the user's information through this 1892 // form will automatically be filled with the user's information through this
1892 // class' FillCreditCardForm(). 1893 // class' FillCreditCardForm().
1893 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_)) { 1894 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_)) {
1894 const std::vector<CreditCard*> cards = 1895 const std::vector<CreditCard*> cards =
1895 personal_data_->GetCreditCardsToSuggest(); 1896 personal_data_->GetCreditCardsToSuggest();
1896 // Expired cards are last in the sorted order, so if the first one is 1897 // Expired cards are last in the sorted order, so if the first one is
1897 // expired, they all are. 1898 // expired, they all are.
1898 if (!cards.empty() && !cards.front()->IsExpired(base::Time::Now())) 1899 if (!cards.empty() && !cards.front()->IsExpired(AutofillClock::Now()))
1899 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); 1900 autofill_assistant_.ShowAssistForCreditCard(*cards.front());
1900 } 1901 }
1901 #endif 1902 #endif
1902 1903
1903 // For the |non_queryable_forms|, we have all the field type info we're ever 1904 // For the |non_queryable_forms|, we have all the field type info we're ever
1904 // going to get about them. For the other forms, we'll wait until we get a 1905 // going to get about them. For the other forms, we'll wait until we get a
1905 // response from the server. 1906 // response from the server.
1906 driver_->SendAutofillTypePredictionsToRenderer(non_queryable_forms); 1907 driver_->SendAutofillTypePredictionsToRenderer(non_queryable_forms);
1907 } 1908 }
1908 1909
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 if (i > 0) 2170 if (i > 0)
2170 fputs("Next oldest form:\n", file); 2171 fputs("Next oldest form:\n", file);
2171 } 2172 }
2172 fputs("\n", file); 2173 fputs("\n", file);
2173 2174
2174 fclose(file); 2175 fclose(file);
2175 } 2176 }
2176 #endif // ENABLE_FORM_DEBUG_DUMP 2177 #endif // ENABLE_FORM_DEBUG_DUMP
2177 2178
2178 } // namespace autofill 2179 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_data_model.cc ('k') | components/autofill/core/browser/autofill_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698