| OLD | NEW |
| 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_state.h" | 5 #include "components/payments/content/payment_request_state.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/autofill_data_util.h" | 10 #include "components/autofill/core/browser/autofill_data_util.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 selected_shipping_profile_ = shipping_profiles()[0]; | 172 selected_shipping_profile_ = shipping_profiles()[0]; |
| 173 | 173 |
| 174 if (!contact_profiles().empty()) | 174 if (!contact_profiles().empty()) |
| 175 selected_contact_profile_ = contact_profiles()[0]; | 175 selected_contact_profile_ = contact_profiles()[0]; |
| 176 | 176 |
| 177 // TODO(crbug.com/702063): Change this code to prioritize instruments by use | 177 // TODO(crbug.com/702063): Change this code to prioritize instruments by use |
| 178 // count and other means, and implement a way to modify this function's return | 178 // count and other means, and implement a way to modify this function's return |
| 179 // value. | 179 // value. |
| 180 const std::vector<std::unique_ptr<PaymentInstrument>>& instruments = | 180 const std::vector<std::unique_ptr<PaymentInstrument>>& instruments = |
| 181 available_instruments(); | 181 available_instruments(); |
| 182 auto first_complete_instrument = | 182 auto first_complete_instrument = std::find_if( |
| 183 std::find_if(instruments.begin(), instruments.end(), | 183 instruments.begin(), instruments.end(), |
| 184 [](const std::unique_ptr<PaymentInstrument>& instrument) { | 184 [](const std::unique_ptr<PaymentInstrument>& instrument) { |
| 185 return instrument->IsCompleteForPayment(); | 185 return instrument->IsCompleteForPayment(/*missing_info=*/nullptr); |
| 186 }); | 186 }); |
| 187 | 187 |
| 188 selected_instrument_ = first_complete_instrument == instruments.end() | 188 selected_instrument_ = first_complete_instrument == instruments.end() |
| 189 ? nullptr | 189 ? nullptr |
| 190 : first_complete_instrument->get(); | 190 : first_complete_instrument->get(); |
| 191 | 191 |
| 192 UpdateIsReadyToPayAndNotifyObservers(); | 192 UpdateIsReadyToPayAndNotifyObservers(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void PaymentRequestState::UpdateIsReadyToPayAndNotifyObservers() { | 195 void PaymentRequestState::UpdateIsReadyToPayAndNotifyObservers() { |
| 196 is_ready_to_pay_ = | 196 is_ready_to_pay_ = |
| 197 ArePaymentDetailsSatisfied() && ArePaymentOptionsSatisfied(); | 197 ArePaymentDetailsSatisfied() && ArePaymentOptionsSatisfied(); |
| 198 NotifyOnSelectedInformationChanged(); | 198 NotifyOnSelectedInformationChanged(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void PaymentRequestState::NotifyOnSelectedInformationChanged() { | 201 void PaymentRequestState::NotifyOnSelectedInformationChanged() { |
| 202 for (auto& observer : observers_) | 202 for (auto& observer : observers_) |
| 203 observer.OnSelectedInformationChanged(); | 203 observer.OnSelectedInformationChanged(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool PaymentRequestState::ArePaymentDetailsSatisfied() { | 206 bool PaymentRequestState::ArePaymentDetailsSatisfied() { |
| 207 // There is no need to check for supported networks, because only supported | 207 // There is no need to check for supported networks, because only supported |
| 208 // instruments are listed/created in the flow. | 208 // instruments are listed/created in the flow. |
| 209 return selected_instrument_ != nullptr && | 209 return selected_instrument_ != nullptr && |
| 210 selected_instrument_->IsCompleteForPayment(); | 210 selected_instrument_->IsCompleteForPayment(/*missing_info=*/nullptr); |
| 211 } | 211 } |
| 212 | 212 |
| 213 bool PaymentRequestState::ArePaymentOptionsSatisfied() { | 213 bool PaymentRequestState::ArePaymentOptionsSatisfied() { |
| 214 // TODO(mathp): Have a measure of shipping address completeness. | 214 // TODO(mathp): Have a measure of shipping address completeness. |
| 215 if (spec_->request_shipping() && selected_shipping_profile_ == nullptr) | 215 if (spec_->request_shipping() && selected_shipping_profile_ == nullptr) |
| 216 return false; | 216 return false; |
| 217 | 217 |
| 218 profile_util::PaymentsProfileComparator comparator(app_locale_, *spec_); | 218 profile_util::PaymentsProfileComparator comparator(app_locale_, *spec_); |
| 219 return comparator.IsContactInfoComplete(selected_contact_profile_); | 219 return comparator.IsContactInfoComplete(selected_contact_profile_); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace payments | 222 } // namespace payments |
| OLD | NEW |