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

Side by Side Diff: components/payments/payment_request.cc

Issue 2625183002: [WebPayments] Adding Shipping Address and Contact Info display to order summary (Closed)
Patch Set: sky comments Created 3 years, 11 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
« no previous file with comments | « components/payments/payment_request.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/payments/payment_request.h" 5 #include "components/payments/payment_request.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "components/autofill/core/browser/personal_data_manager.h" 8 #include "components/autofill/core/browser/personal_data_manager.h"
8 #include "components/payments/payment_details_validation.h" 9 #include "components/payments/payment_details_validation.h"
9 #include "components/payments/payment_request_delegate.h" 10 #include "components/payments/payment_request_delegate.h"
10 #include "components/payments/payment_request_web_contents_manager.h" 11 #include "components/payments/payment_request_web_contents_manager.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 14
14 namespace payments { 15 namespace payments {
15 16
16 PaymentRequest::PaymentRequest( 17 PaymentRequest::PaymentRequest(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const base::Optional<std::string> currency_system, 68 const base::Optional<std::string> currency_system,
68 const std::string& locale_name) { 69 const std::string& locale_name) {
69 if (!currency_formatter_) { 70 if (!currency_formatter_) {
70 currency_formatter_.reset( 71 currency_formatter_.reset(
71 new CurrencyFormatter(currency_code, currency_system, locale_name)); 72 new CurrencyFormatter(currency_code, currency_system, locale_name));
72 } 73 }
73 74
74 return currency_formatter_.get(); 75 return currency_formatter_.get();
75 } 76 }
76 77
78 autofill::AutofillProfile* PaymentRequest::GetCurrentlySelectedProfile() {
79 // TODO(tmartino): Implement more sophisticated algorithm for populating
80 // this when it starts empty.
81 if (!profile_) {
82 autofill::PersonalDataManager* data_manager =
83 delegate_->GetPersonalDataManager();
84 auto profiles = data_manager->GetProfiles();
85 if (!profiles.empty())
86 profile_ = base::MakeUnique<autofill::AutofillProfile>(*profiles[0]);
87 }
88 return profile_ ? profile_.get() : nullptr;
89 }
90
77 autofill::CreditCard* PaymentRequest::GetCurrentlySelectedCreditCard() { 91 autofill::CreditCard* PaymentRequest::GetCurrentlySelectedCreditCard() {
78 // TODO(anthonyvd): Change this code to prioritize server cards and implement 92 // TODO(anthonyvd): Change this code to prioritize server cards and implement
79 // a way to modify this function's return value. 93 // a way to modify this function's return value.
80 autofill::PersonalDataManager* data_manager = 94 autofill::PersonalDataManager* data_manager =
81 delegate_->GetPersonalDataManager(); 95 delegate_->GetPersonalDataManager();
82 96
83 const std::vector<autofill::CreditCard*> cards = 97 const std::vector<autofill::CreditCard*> cards =
84 data_manager->GetCreditCardsToSuggest(); 98 data_manager->GetCreditCardsToSuggest();
85 99
86 auto first_complete_card = std::find_if( 100 auto first_complete_card = std::find_if(
87 cards.begin(), 101 cards.begin(),
88 cards.end(), 102 cards.end(),
89 [] (autofill::CreditCard* card) { 103 [] (autofill::CreditCard* card) {
90 return card->IsValid(); 104 return card->IsValid();
91 }); 105 });
92 106
93 return first_complete_card == cards.end() ? nullptr : *first_complete_card; 107 return first_complete_card == cards.end() ? nullptr : *first_complete_card;
94 } 108 }
95 109
96 } // namespace payments 110 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/payment_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698