Commit 2e363d05 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Empty cross-platform Android payment app factory.

This patch adds the skeleton code for a payment app factory for Android
payment apps. The new factory is disabled by default, but can be enabled
via chrome://flags/#enable-web-payments-experimental-features drop-down
or --enable-features=CrossPlatformAndroidPaymentAppFactory command line
flag. When enabled, the new factory does not return any payment apps in
this patch.

Bug: 1061503
Change-Id: Iea19c68889be77d5083f86d2b9063db64de38cd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2299855
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798471}
parent ee381778
...@@ -8,6 +8,8 @@ static_library("content") { ...@@ -8,6 +8,8 @@ static_library("content") {
"android_app_communication.h", "android_app_communication.h",
"android_payment_app.cc", "android_payment_app.cc",
"android_payment_app.h", "android_payment_app.h",
"android_payment_app_factory.cc",
"android_payment_app_factory.h",
"autofill_payment_app.cc", "autofill_payment_app.cc",
"autofill_payment_app.h", "autofill_payment_app.h",
"autofill_payment_app_factory.cc", "autofill_payment_app_factory.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/content/android_payment_app_factory.h"
#include <utility>
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
namespace payments {
namespace {
class AppFinder : public base::SupportsUserData::Data {
public:
static base::WeakPtr<AppFinder> CreateAndSetOwnedBy(
base::SupportsUserData* owner) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(owner);
auto owned = std::make_unique<AppFinder>(owner);
auto weak_ptr = owned->weak_ptr_factory_.GetWeakPtr();
const void* key = owned.get();
owner->SetUserData(key, std::move(owned));
return weak_ptr;
}
explicit AppFinder(base::SupportsUserData* owner) : owner_(owner) {}
~AppFinder() override = default;
AppFinder(const AppFinder& other) = delete;
AppFinder& operator=(const AppFinder& other) = delete;
void FindApps(base::WeakPtr<PaymentAppFactory::Delegate> delegate) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_EQ(nullptr, delegate_.get());
DCHECK_NE(nullptr, delegate.get());
delegate_ = delegate;
OnDoneCreatingPaymentApps();
}
private:
void OnDoneCreatingPaymentApps() {
if (delegate_)
delegate_->OnDoneCreatingPaymentApps();
owner_->RemoveUserData(this);
}
base::SupportsUserData* owner_;
base::WeakPtr<PaymentAppFactory::Delegate> delegate_;
base::WeakPtrFactory<AppFinder> weak_ptr_factory_{this};
};
} // namespace
AndroidPaymentAppFactory::AndroidPaymentAppFactory()
: PaymentAppFactory(PaymentApp::Type::NATIVE_MOBILE_APP) {}
AndroidPaymentAppFactory::~AndroidPaymentAppFactory() = default;
void AndroidPaymentAppFactory::Create(base::WeakPtr<Delegate> delegate) {
auto app_finder = AppFinder::CreateAndSetOwnedBy(delegate->GetWebContents());
app_finder->FindApps(delegate);
}
} // namespace payments
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_APP_FACTORY_H_
#define COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_APP_FACTORY_H_
#include "components/payments/content/payment_app_factory.h"
namespace payments {
// Retrieves Android payment apps.
class AndroidPaymentAppFactory : public PaymentAppFactory {
public:
AndroidPaymentAppFactory();
~AndroidPaymentAppFactory() override;
AndroidPaymentAppFactory(const AndroidPaymentAppFactory& other) = delete;
AndroidPaymentAppFactory& operator=(const AndroidPaymentAppFactory& other) =
delete;
// PaymentAppFactory:
void Create(base::WeakPtr<Delegate> delegate) override;
};
} // namespace payments
#endif // COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_APP_FACTORY_H_
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
#include "components/payments/content/payment_app_service.h" #include "components/payments/content/payment_app_service.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "components/payments/content/android_payment_app_factory.h"
#include "components/payments/content/autofill_payment_app_factory.h" #include "components/payments/content/autofill_payment_app_factory.h"
#include "components/payments/content/payment_app.h" #include "components/payments/content/payment_app.h"
#include "components/payments/content/service_worker_payment_app_factory.h" #include "components/payments/content/service_worker_payment_app_factory.h"
#include "components/payments/core/features.h"
#include "components/payments/core/payments_experimental_features.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
namespace payments { namespace payments {
...@@ -15,8 +18,17 @@ namespace payments { ...@@ -15,8 +18,17 @@ namespace payments {
PaymentAppService::PaymentAppService() { PaymentAppService::PaymentAppService() {
factories_.emplace_back(std::make_unique<AutofillPaymentAppFactory>()); factories_.emplace_back(std::make_unique<AutofillPaymentAppFactory>());
if (base::FeatureList::IsEnabled(::features::kServiceWorkerPaymentApps)) if (base::FeatureList::IsEnabled(::features::kServiceWorkerPaymentApps)) {
factories_.emplace_back(std::make_unique<ServiceWorkerPaymentAppFactory>()); factories_.emplace_back(std::make_unique<ServiceWorkerPaymentAppFactory>());
}
// TODO(https://crbug.com/1022512): Review the feature flag name when
// AndroidPaymentAppFactory works on Android OS with generic 3rd party payment
// apps. (Currently it works only on Chrome OS with app store billing payment
// methods.)
if (PaymentsExperimentalFeatures::IsEnabled(features::kAppStoreBilling)) {
factories_.emplace_back(std::make_unique<AndroidPaymentAppFactory>());
}
} }
PaymentAppService::~PaymentAppService() = default; PaymentAppService::~PaymentAppService() = default;
......
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