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

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

Issue 2741343011: [Payments] Move PersonalDataManager and locale to PaymentRequestState (Closed)
Patch Set: Initial Created 3 years, 9 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 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/content/payment_request.h" 5 #include "components/payments/content/payment_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/autofill/core/browser/personal_data_manager.h"
11 #include "components/payments/content/payment_details_validation.h" 10 #include "components/payments/content/payment_details_validation.h"
12 #include "components/payments/content/payment_request_web_contents_manager.h" 11 #include "components/payments/content/payment_request_web_contents_manager.h"
13 #include "components/payments/core/currency_formatter.h"
14 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
16 14
17 namespace payments { 15 namespace payments {
18 16
19 PaymentRequest::PaymentRequest( 17 PaymentRequest::PaymentRequest(
20 content::WebContents* web_contents, 18 content::WebContents* web_contents,
21 std::unique_ptr<PaymentRequestDelegate> delegate, 19 std::unique_ptr<PaymentRequestDelegate> delegate,
22 PaymentRequestWebContentsManager* manager, 20 PaymentRequestWebContentsManager* manager,
23 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) 21 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request)
(...skipping 19 matching lines...) Expand all
43 payments::mojom::PaymentOptionsPtr options) { 41 payments::mojom::PaymentOptionsPtr options) {
44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
45 std::string error; 43 std::string error;
46 if (!payments::validatePaymentDetails(details, &error)) { 44 if (!payments::validatePaymentDetails(details, &error)) {
47 LOG(ERROR) << error; 45 LOG(ERROR) << error;
48 OnConnectionTerminated(); 46 OnConnectionTerminated();
49 return; 47 return;
50 } 48 }
51 client_ = std::move(client); 49 client_ = std::move(client);
52 spec_ = base::MakeUnique<PaymentRequestSpec>( 50 spec_ = base::MakeUnique<PaymentRequestSpec>(
53 std::move(options), std::move(details), std::move(method_data), this); 51 std::move(options), std::move(details), std::move(method_data), this,
54 state_ = base::MakeUnique<PaymentRequestState>(spec_.get(), this); 52 delegate_->GetApplicationLocale());
53 state_ = base::MakeUnique<PaymentRequestState>(
54 spec_.get(), this, delegate_->GetApplicationLocale(),
55 delegate_->GetPersonalDataManager());
55 } 56 }
56 57
57 void PaymentRequest::Show() { 58 void PaymentRequest::Show() {
58 if (!client_.is_bound() || !binding_.is_bound()) { 59 if (!client_.is_bound() || !binding_.is_bound()) {
59 LOG(ERROR) << "Attempted Show(), but binding(s) missing."; 60 LOG(ERROR) << "Attempted Show(), but binding(s) missing.";
60 OnConnectionTerminated(); 61 OnConnectionTerminated();
61 return; 62 return;
62 } 63 }
63 delegate_->ShowDialog(this); 64 delegate_->ShowDialog(this);
64 } 65 }
(...skipping 19 matching lines...) Expand all
84 85
85 void PaymentRequest::CanMakePayment() { 86 void PaymentRequest::CanMakePayment() {
86 // TODO(mathp): Return whether we can make payment. 87 // TODO(mathp): Return whether we can make payment.
87 client_->OnCanMakePayment(mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT); 88 client_->OnCanMakePayment(mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT);
88 } 89 }
89 90
90 void PaymentRequest::OnInvalidSpecProvided() { 91 void PaymentRequest::OnInvalidSpecProvided() {
91 OnConnectionTerminated(); 92 OnConnectionTerminated();
92 } 93 }
93 94
94 const std::string& PaymentRequest::GetApplicationLocale() {
95 return delegate_->GetApplicationLocale();
96 }
97
98 autofill::PersonalDataManager* PaymentRequest::GetPersonalDataManager() {
99 return delegate_->GetPersonalDataManager();
100 }
101
102 void PaymentRequest::OnPaymentResponseAvailable( 95 void PaymentRequest::OnPaymentResponseAvailable(
103 mojom::PaymentResponsePtr response) { 96 mojom::PaymentResponsePtr response) {
104 client_->OnPaymentResponse(std::move(response)); 97 client_->OnPaymentResponse(std::move(response));
105 } 98 }
106 99
107 void PaymentRequest::UserCancelled() { 100 void PaymentRequest::UserCancelled() {
108 // If |client_| is not bound, then the object is already being destroyed as 101 // If |client_| is not bound, then the object is already being destroyed as
109 // a result of a renderer event. 102 // a result of a renderer event.
110 if (!client_.is_bound()) 103 if (!client_.is_bound())
111 return; 104 return;
(...skipping 18 matching lines...) Expand all
130 delegate_->CloseDialog(); 123 delegate_->CloseDialog();
131 manager_->DestroyRequest(this); 124 manager_->DestroyRequest(this);
132 } 125 }
133 126
134 void PaymentRequest::Pay() { 127 void PaymentRequest::Pay() {
135 DCHECK(state_->is_ready_to_pay()); 128 DCHECK(state_->is_ready_to_pay());
136 129
137 state_->GeneratePaymentResponse(); 130 state_->GeneratePaymentResponse();
138 } 131 }
139 132
140 CurrencyFormatter* PaymentRequest::GetOrCreateCurrencyFormatter(
141 const std::string& currency_code,
142 const std::string& currency_system,
143 const std::string& locale_name) {
144 if (!currency_formatter_) {
145 currency_formatter_.reset(
146 new CurrencyFormatter(currency_code, currency_system, locale_name));
147 }
148 return currency_formatter_.get();
149 }
150
151 base::string16 PaymentRequest::GetFormattedCurrencyAmount(
152 const std::string& amount) {
153 CurrencyFormatter* formatter = GetOrCreateCurrencyFormatter(
154 spec_->details().total->amount->currency,
155 spec_->details().total->amount->currency_system, GetApplicationLocale());
156 return formatter->Format(amount);
157 }
158
159 std::string PaymentRequest::GetFormattedCurrencyCode() {
160 CurrencyFormatter* formatter = GetOrCreateCurrencyFormatter(
161 spec_->details().total->amount->currency,
162 spec_->details().total->amount->currency_system, GetApplicationLocale());
163
164 return formatter->formatted_currency_code();
165 }
166
167 } // namespace payments 133 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request.h ('k') | components/payments/content/payment_request_spec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698