Commit 218f707b authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Move "is waiting" logic to payment app.

Before this patch, the desktop logic for checking whether the payment
app is waiting for a price update from the merchant was defined
in the desktop controller, which prevented from sharing this logic
across platforms and in different types of payment apps.

This patch moves PaymentHandlerHost.is_waiting() check from
payment_request.cc to service_worker_payment_app.cc.

After this patch, the logic for checking whether the payment app is
waiting for a price update is defined in the potentially cross-platform
payment app interface.

Design: https://bit.ly/cross-platform-pay-app-factory

Bug: 1083242
Change-Id: Idde2f1c9396641835f154be19ac7d2901c1c1d14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207973
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771029}
parent a7fee007
...@@ -343,7 +343,7 @@ void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) { ...@@ -343,7 +343,7 @@ void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) {
} }
if (state()->selected_app() && state()->IsPaymentAppInvoked() && if (state()->selected_app() && state()->IsPaymentAppInvoked() &&
payment_handler_host_.is_waiting_for_payment_details_update()) { state()->selected_app()->IsWaitingForPaymentDetailsUpdate()) {
payment_handler_host_.UpdateWith( payment_handler_host_.UpdateWith(
PaymentDetailsConverter::ConvertToPaymentRequestDetailsUpdate( PaymentDetailsConverter::ConvertToPaymentRequestDetailsUpdate(
details, state()->selected_app()->HandlesShippingAddress(), details, state()->selected_app()->HandlesShippingAddress(),
...@@ -386,8 +386,8 @@ void PaymentRequest::OnPaymentDetailsNotUpdated() { ...@@ -386,8 +386,8 @@ void PaymentRequest::OnPaymentDetailsNotUpdated() {
spec_->RecomputeSpecForDetails(); spec_->RecomputeSpecForDetails();
if (state()->IsPaymentAppInvoked() && if (state()->IsPaymentAppInvoked() && state()->selected_app() &&
payment_handler_host_.is_waiting_for_payment_details_update()) { state()->selected_app()->IsWaitingForPaymentDetailsUpdate()) {
payment_handler_host_.OnPaymentDetailsNotUpdated(); payment_handler_host_.OnPaymentDetailsNotUpdated();
} }
} }
......
...@@ -346,7 +346,7 @@ ServiceWorkerPaymentApp::CreatePaymentRequestEventData() { ...@@ -346,7 +346,7 @@ ServiceWorkerPaymentApp::CreatePaymentRequestEventData() {
} }
} }
event_data->payment_handler_host = std::move(payment_handler_host_); event_data->payment_handler_host = std::move(payment_handler_host_remote_);
return event_data; return event_data;
} }
...@@ -552,7 +552,13 @@ ukm::SourceId ServiceWorkerPaymentApp::UkmSourceId() { ...@@ -552,7 +552,13 @@ ukm::SourceId ServiceWorkerPaymentApp::UkmSourceId() {
void ServiceWorkerPaymentApp::SetPaymentHandlerHost( void ServiceWorkerPaymentApp::SetPaymentHandlerHost(
base::WeakPtr<PaymentHandlerHost> payment_handler_host) { base::WeakPtr<PaymentHandlerHost> payment_handler_host) {
payment_handler_host_ = payment_handler_host->Bind(); payment_handler_host_ = payment_handler_host;
payment_handler_host_remote_ = payment_handler_host_->Bind();
}
bool ServiceWorkerPaymentApp::IsWaitingForPaymentDetailsUpdate() const {
return payment_handler_host_ &&
payment_handler_host_->is_waiting_for_payment_details_update();
} }
} // namespace payments } // namespace payments
...@@ -29,6 +29,8 @@ class Origin; ...@@ -29,6 +29,8 @@ class Origin;
namespace payments { namespace payments {
class PaymentHandlerHost;
// Represents a service worker based payment app. // Represents a service worker based payment app.
class ServiceWorkerPaymentApp : public PaymentApp { class ServiceWorkerPaymentApp : public PaymentApp {
public: public:
...@@ -100,6 +102,7 @@ class ServiceWorkerPaymentApp : public PaymentApp { ...@@ -100,6 +102,7 @@ class ServiceWorkerPaymentApp : public PaymentApp {
ukm::SourceId UkmSourceId() override; ukm::SourceId UkmSourceId() override;
void SetPaymentHandlerHost( void SetPaymentHandlerHost(
base::WeakPtr<PaymentHandlerHost> payment_handler_host) override; base::WeakPtr<PaymentHandlerHost> payment_handler_host) override;
bool IsWaitingForPaymentDetailsUpdate() const override;
private: private:
friend class ServiceWorkerPaymentAppTest; friend class ServiceWorkerPaymentAppTest;
...@@ -141,7 +144,8 @@ class ServiceWorkerPaymentApp : public PaymentApp { ...@@ -141,7 +144,8 @@ class ServiceWorkerPaymentApp : public PaymentApp {
// after the service worker is installed. // after the service worker is installed.
IdentityCallback identity_callback_; IdentityCallback identity_callback_;
mojo::PendingRemote<mojom::PaymentHandlerHost> payment_handler_host_; base::WeakPtr<PaymentHandlerHost> payment_handler_host_;
mojo::PendingRemote<mojom::PaymentHandlerHost> payment_handler_host_remote_;
// PaymentAppProvider::CanMakePayment result of this payment app. // PaymentAppProvider::CanMakePayment result of this payment app.
bool can_make_payment_result_; bool can_make_payment_result_;
......
...@@ -64,6 +64,10 @@ ukm::SourceId PaymentApp::UkmSourceId() { ...@@ -64,6 +64,10 @@ ukm::SourceId PaymentApp::UkmSourceId() {
return ukm::kInvalidSourceId; return ukm::kInvalidSourceId;
} }
bool PaymentApp::IsWaitingForPaymentDetailsUpdate() const {
return false;
}
// static // static
void PaymentApp::SortApps(std::vector<std::unique_ptr<PaymentApp>>* apps) { void PaymentApp::SortApps(std::vector<std::unique_ptr<PaymentApp>>* apps) {
DCHECK(apps); DCHECK(apps);
......
...@@ -120,6 +120,11 @@ class PaymentApp { ...@@ -120,6 +120,11 @@ class PaymentApp {
virtual void SetPaymentHandlerHost( virtual void SetPaymentHandlerHost(
base::WeakPtr<PaymentHandlerHost> payment_handler_host) {} base::WeakPtr<PaymentHandlerHost> payment_handler_host) {}
// Whether the payment app is waiting for the merchant to update the purchase
// price based on the shipping, billing, or contact information that the user
// has selected inside of the payment app.
virtual bool IsWaitingForPaymentDetailsUpdate() const;
protected: protected:
PaymentApp(int icon_resource_id, Type type); PaymentApp(int icon_resource_id, Type type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment