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

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: Rebase 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 16 matching lines...) Expand all
27 #include "base/strings/string16.h" 27 #include "base/strings/string16.h"
28 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
29 #include "base/strings/string_split.h" 29 #include "base/strings/string_split.h"
30 #include "base/strings/string_util.h" 30 #include "base/strings/string_util.h"
31 #include "base/strings/utf_string_conversions.h" 31 #include "base/strings/utf_string_conversions.h"
32 #include "base/threading/sequenced_worker_pool.h" 32 #include "base/threading/sequenced_worker_pool.h"
33 #include "base/threading/thread_restrictions.h" 33 #include "base/threading/thread_restrictions.h"
34 #include "build/build_config.h" 34 #include "build/build_config.h"
35 #include "components/autofill/core/browser/autocomplete_history_manager.h" 35 #include "components/autofill/core/browser/autocomplete_history_manager.h"
36 #include "components/autofill/core/browser/autofill_client.h" 36 #include "components/autofill/core/browser/autofill_client.h"
37 #include "components/autofill/core/browser/autofill_clock.h"
37 #include "components/autofill/core/browser/autofill_data_model.h" 38 #include "components/autofill/core/browser/autofill_data_model.h"
38 #include "components/autofill/core/browser/autofill_experiments.h" 39 #include "components/autofill/core/browser/autofill_experiments.h"
39 #include "components/autofill/core/browser/autofill_external_delegate.h" 40 #include "components/autofill/core/browser/autofill_external_delegate.h"
40 #include "components/autofill/core/browser/autofill_field.h" 41 #include "components/autofill/core/browser/autofill_field.h"
41 #include "components/autofill/core/browser/autofill_manager_test_delegate.h" 42 #include "components/autofill/core/browser/autofill_manager_test_delegate.h"
42 #include "components/autofill/core/browser/autofill_metrics.h" 43 #include "components/autofill/core/browser/autofill_metrics.h"
43 #include "components/autofill/core/browser/autofill_profile.h" 44 #include "components/autofill/core/browser/autofill_profile.h"
44 #include "components/autofill/core/browser/autofill_type.h" 45 #include "components/autofill/core/browser/autofill_type.h"
45 #include "components/autofill/core/browser/country_names.h" 46 #include "components/autofill/core/browser/country_names.h"
46 #include "components/autofill/core/browser/credit_card.h" 47 #include "components/autofill/core/browser/credit_card.h"
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 // All required data is available, start the upload process. 1192 // All required data is available, start the upload process.
1192 payments_client_->GetUploadDetails(upload_request_.profiles, app_locale_); 1193 payments_client_->GetUploadDetails(upload_request_.profiles, app_locale_);
1193 } 1194 }
1194 } 1195 }
1195 1196
1196 bool AutofillManager::GetProfilesForCreditCardUpload( 1197 bool AutofillManager::GetProfilesForCreditCardUpload(
1197 const CreditCard& card, 1198 const CreditCard& card,
1198 std::vector<AutofillProfile>* profiles, 1199 std::vector<AutofillProfile>* profiles,
1199 const GURL& source_url) const { 1200 const GURL& source_url) const {
1200 std::vector<AutofillProfile> candidate_profiles; 1201 std::vector<AutofillProfile> candidate_profiles;
1201 const base::Time now = base::Time::Now(); 1202 const base::Time now = AutofillClock::Now();
1202 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); 1203 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15);
1203 1204
1204 // First, collect all of the addresses used recently. 1205 // First, collect all of the addresses used recently.
1205 for (AutofillProfile* profile : personal_data_->GetProfiles()) { 1206 for (AutofillProfile* profile : personal_data_->GetProfiles()) {
1206 if ((now - profile->use_date()) < fifteen_minutes || 1207 if ((now - profile->use_date()) < fifteen_minutes ||
1207 (now - profile->modification_date()) < fifteen_minutes) { 1208 (now - profile->modification_date()) < fifteen_minutes) {
1208 candidate_profiles.push_back(*profile); 1209 candidate_profiles.push_back(*profile);
1209 } 1210 }
1210 } 1211 }
1211 if (candidate_profiles.empty()) { 1212 if (candidate_profiles.empty()) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 1560
1560 base::string16 value = 1561 base::string16 value =
1561 data_model.GetInfo(cached_field->Type(), app_locale_); 1562 data_model.GetInfo(cached_field->Type(), app_locale_);
1562 if (is_credit_card && 1563 if (is_credit_card &&
1563 cached_field->Type().GetStorableType() == 1564 cached_field->Type().GetStorableType() ==
1564 CREDIT_CARD_VERIFICATION_CODE) { 1565 CREDIT_CARD_VERIFICATION_CODE) {
1565 value = cvc; 1566 value = cvc;
1566 } else if (is_credit_card && IsCreditCardExpirationType( 1567 } else if (is_credit_card && IsCreditCardExpirationType(
1567 cached_field->Type().GetStorableType()) && 1568 cached_field->Type().GetStorableType()) &&
1568 static_cast<const CreditCard*>(&data_model) 1569 static_cast<const CreditCard*>(&data_model)
1569 ->IsExpired(base::Time::Now())) { 1570 ->IsExpired(AutofillClock::Now())) {
1570 // Don't fill expired cards expiration date. 1571 // Don't fill expired cards expiration date.
1571 value = base::string16(); 1572 value = base::string16();
1572 } 1573 }
1573 1574
1574 // Must match ForEachMatchingFormField() in form_autofill_util.cc. 1575 // Must match ForEachMatchingFormField() in form_autofill_util.cc.
1575 // Only notify autofilling of empty fields and the field that initiated 1576 // Only notify autofilling of empty fields and the field that initiated
1576 // the filling (note that "select-one" controls may not be empty but will 1577 // the filling (note that "select-one" controls may not be empty but will
1577 // still be autofilled). 1578 // still be autofilled).
1578 bool should_notify = 1579 bool should_notify =
1579 !is_credit_card && 1580 !is_credit_card &&
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 #if defined(OS_ANDROID) || defined(OS_IOS) 1858 #if defined(OS_ANDROID) || defined(OS_IOS)
1858 // When a credit card form is parsed and conditions are met, show an infobar 1859 // When a credit card form is parsed and conditions are met, show an infobar
1859 // prompt for credit card assisted filling. Upon accepting the infobar, the 1860 // prompt for credit card assisted filling. Upon accepting the infobar, the
1860 // form will automatically be filled with the user's information through this 1861 // form will automatically be filled with the user's information through this
1861 // class' FillCreditCardForm(). 1862 // class' FillCreditCardForm().
1862 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_)) { 1863 if (autofill_assistant_.CanShowCreditCardAssist(form_structures_)) {
1863 const std::vector<CreditCard*> cards = 1864 const std::vector<CreditCard*> cards =
1864 personal_data_->GetCreditCardsToSuggest(); 1865 personal_data_->GetCreditCardsToSuggest();
1865 // Expired cards are last in the sorted order, so if the first one is 1866 // Expired cards are last in the sorted order, so if the first one is
1866 // expired, they all are. 1867 // expired, they all are.
1867 if (!cards.empty() && !cards.front()->IsExpired(base::Time::Now())) 1868 if (!cards.empty() && !cards.front()->IsExpired(AutofillClock::Now()))
1868 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); 1869 autofill_assistant_.ShowAssistForCreditCard(*cards.front());
1869 } 1870 }
1870 #endif 1871 #endif
1871 1872
1872 // For the |non_queryable_forms|, we have all the field type info we're ever 1873 // For the |non_queryable_forms|, we have all the field type info we're ever
1873 // going to get about them. For the other forms, we'll wait until we get a 1874 // going to get about them. For the other forms, we'll wait until we get a
1874 // response from the server. 1875 // response from the server.
1875 driver_->SendAutofillTypePredictionsToRenderer(non_queryable_forms); 1876 driver_->SendAutofillTypePredictionsToRenderer(non_queryable_forms);
1876 } 1877 }
1877 1878
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 if (i > 0) 2139 if (i > 0)
2139 fputs("Next oldest form:\n", file); 2140 fputs("Next oldest form:\n", file);
2140 } 2141 }
2141 fputs("\n", file); 2142 fputs("\n", file);
2142 2143
2143 fclose(file); 2144 fclose(file);
2144 } 2145 }
2145 #endif // ENABLE_FORM_DEBUG_DUMP 2146 #endif // ENABLE_FORM_DEBUG_DUMP
2146 2147
2147 } // namespace autofill 2148 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698