Commit 97e1b331 authored by gogerald's avatar gogerald Committed by Commit Bot

[Payments] End-to-end test for payment handlers.

Made ServiceWorkerPaymentAppFactory singleton.

Bug: 786116
Change-Id: I263edd64e7452a81f07011f1a7bda83e8b57c90e
Reviewed-on: https://chromium-review.googlesource.com/774906Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518442}
parent 50b18e07
...@@ -15,14 +15,11 @@ ...@@ -15,14 +15,11 @@
#include "chrome/browser/web_data_service_factory.h" #include "chrome/browser/web_data_service_factory.h"
#include "components/payments/content/payment_manifest_web_data_service.h" #include "components/payments/content/payment_manifest_web_data_service.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/payment_manifest_downloader.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/payment_app_provider.h" #include "content/public/browser/payment_app_provider.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "jni/ServiceWorkerPaymentAppBridge_jni.h" #include "jni/ServiceWorkerPaymentAppBridge_jni.h"
#include "net/url_request/url_request_context_getter.h"
#include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.h" #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.h"
#include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/android/java_bitmap.h"
...@@ -51,44 +48,6 @@ using ::payments::mojom::PaymentMethodDataPtr; ...@@ -51,44 +48,6 @@ using ::payments::mojom::PaymentMethodDataPtr;
using ::payments::mojom::PaymentRequestEventData; using ::payments::mojom::PaymentRequestEventData;
using ::payments::mojom::PaymentRequestEventDataPtr; using ::payments::mojom::PaymentRequestEventDataPtr;
// Owns the service worker payment app factory and deletes it after it finishes
// using resources.
class SelfDeletingServiceWorkerPaymentAppFactory {
public:
SelfDeletingServiceWorkerPaymentAppFactory() {}
void GetAllPaymentApps(
content::WebContents* web_contents,
const std::vector<PaymentMethodDataPtr>& payment_method_data,
content::PaymentAppProvider::GetAllPaymentAppsCallback callback) {
impl_.GetAllPaymentApps(
web_contents,
std::make_unique<payments::PaymentManifestDownloader>(
content::BrowserContext::GetDefaultStoragePartition(
web_contents->GetBrowserContext())
->GetURLRequestContext()),
WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext()),
ServiceAccessType::EXPLICIT_ACCESS),
payment_method_data, std::move(callback),
base::BindOnce(&SelfDeletingServiceWorkerPaymentAppFactory::
OnFinishedUsingResources,
base::Owned(this)));
}
// The destructor needs to be public for base::Owned(this) to delete this.
~SelfDeletingServiceWorkerPaymentAppFactory() {}
private:
void OnFinishedUsingResources() {
// No need to self-delete here, because of using base::Owned(this).
}
payments::ServiceWorkerPaymentAppFactory impl_;
DISALLOW_COPY_AND_ASSIGN(SelfDeletingServiceWorkerPaymentAppFactory);
};
void OnGotAllPaymentApps(const JavaRef<jobject>& jweb_contents, void OnGotAllPaymentApps(const JavaRef<jobject>& jweb_contents,
const JavaRef<jobject>& jcallback, const JavaRef<jobject>& jcallback,
content::PaymentAppProvider::PaymentApps apps) { content::PaymentAppProvider::PaymentApps apps) {
...@@ -238,13 +197,19 @@ static void JNI_ServiceWorkerPaymentAppBridge_GetAllPaymentApps( ...@@ -238,13 +197,19 @@ static void JNI_ServiceWorkerPaymentAppBridge_GetAllPaymentApps(
content::WebContents* web_contents = content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents); content::WebContents::FromJavaWebContents(jweb_contents);
(new SelfDeletingServiceWorkerPaymentAppFactory()) payments::ServiceWorkerPaymentAppFactory::GetInstance()->GetAllPaymentApps(
->GetAllPaymentApps( web_contents,
web_contents, WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
ConvertPaymentMethodDataFromJavaToNative(env, jmethod_data), Profile::FromBrowserContext(web_contents->GetBrowserContext()),
base::BindOnce(&OnGotAllPaymentApps, ServiceAccessType::EXPLICIT_ACCESS),
ScopedJavaGlobalRef<jobject>(env, jweb_contents), ConvertPaymentMethodDataFromJavaToNative(env, jmethod_data),
ScopedJavaGlobalRef<jobject>(env, jcallback))); base::BindOnce(&OnGotAllPaymentApps,
ScopedJavaGlobalRef<jobject>(env, jweb_contents),
ScopedJavaGlobalRef<jobject>(env, jcallback)),
base::BindOnce([]() {
/* Nothing needs to be done after writing cache. This callback is used
* only in tests. */
}));
} }
static void JNI_ServiceWorkerPaymentAppBridge_CanMakePayment( static void JNI_ServiceWorkerPaymentAppBridge_CanMakePayment(
......
...@@ -110,16 +110,16 @@ class ServiceWorkerPaymentAppFactoryBrowserTest : public InProcessBrowserTest { ...@@ -110,16 +110,16 @@ class ServiceWorkerPaymentAppFactoryBrowserTest : public InProcessBrowserTest {
frankpay_.GetURL("frankpay.com", "/")); frankpay_.GetURL("frankpay.com", "/"));
downloader->AddTestServerURL("https://georgepay.com/", downloader->AddTestServerURL("https://georgepay.com/",
georgepay_.GetURL("georgepay.com", "/")); georgepay_.GetURL("georgepay.com", "/"));
ServiceWorkerPaymentAppFactory factory; ServiceWorkerPaymentAppFactory::GetInstance()
factory.IgnorePortInAppScopeForTesting(); ->SetDownloaderAndIgnorePortInAppScopeForTesting(std::move(downloader));
std::vector<mojom::PaymentMethodDataPtr> method_data; std::vector<mojom::PaymentMethodDataPtr> method_data;
method_data.emplace_back(mojom::PaymentMethodData::New()); method_data.emplace_back(mojom::PaymentMethodData::New());
method_data.back()->supported_methods = payment_method_identifiers; method_data.back()->supported_methods = payment_method_identifiers;
base::RunLoop run_loop; base::RunLoop run_loop;
factory.GetAllPaymentApps( ServiceWorkerPaymentAppFactory::GetInstance()->GetAllPaymentApps(
web_contents, std::move(downloader), web_contents,
WebDataServiceFactory::GetPaymentManifestWebDataForProfile( WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
Profile::FromBrowserContext(context), Profile::FromBrowserContext(context),
ServiceAccessType::EXPLICIT_ACCESS), ServiceAccessType::EXPLICIT_ACCESS),
......
...@@ -20,15 +20,11 @@ ...@@ -20,15 +20,11 @@
#include "components/payments/content/payment_response_helper.h" #include "components/payments/content/payment_response_helper.h"
#include "components/payments/content/service_worker_payment_app_factory.h" #include "components/payments/content/service_worker_payment_app_factory.h"
#include "components/payments/content/service_worker_payment_instrument.h" #include "components/payments/content/service_worker_payment_instrument.h"
#include "components/payments/content/utility/payment_manifest_parser.h"
#include "components/payments/core/autofill_payment_instrument.h" #include "components/payments/core/autofill_payment_instrument.h"
#include "components/payments/core/journey_logger.h" #include "components/payments/core/journey_logger.h"
#include "components/payments/core/payment_instrument.h" #include "components/payments/core/payment_instrument.h"
#include "components/payments/core/payment_manifest_downloader.h"
#include "components/payments/core/payment_request_data_util.h" #include "components/payments/core/payment_request_data_util.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "net/url_request/url_request_context_getter.h"
namespace payments { namespace payments {
...@@ -60,24 +56,18 @@ PaymentRequestState::PaymentRequestState( ...@@ -60,24 +56,18 @@ PaymentRequestState::PaymentRequestState(
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
if (base::FeatureList::IsEnabled(features::kServiceWorkerPaymentApps)) { if (base::FeatureList::IsEnabled(features::kServiceWorkerPaymentApps)) {
get_all_instruments_finished_ = false; get_all_instruments_finished_ = false;
service_worker_payment_app_factory_ = ServiceWorkerPaymentAppFactory::GetInstance()->GetAllPaymentApps(
std::make_unique<ServiceWorkerPaymentAppFactory>();
service_worker_payment_app_factory_->GetAllPaymentApps(
web_contents, web_contents,
std::make_unique<PaymentManifestDownloader>(
content::BrowserContext::GetDefaultStoragePartition(
web_contents->GetBrowserContext())
->GetURLRequestContext()),
payment_request_delegate_->GetPaymentManifestWebDataService(), payment_request_delegate_->GetPaymentManifestWebDataService(),
spec_->method_data(), spec_->method_data(),
base::BindOnce(&PaymentRequestState::GetAllPaymentAppsCallback, base::BindOnce(&PaymentRequestState::GetAllPaymentAppsCallback,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
web_contents->GetBrowserContext(), top_level_origin, web_contents->GetBrowserContext(), top_level_origin,
frame_origin), frame_origin),
base::BindOnce( base::BindOnce([]() {
&PaymentRequestState:: /* Nothing needs to be done after writing cache. This callback is used
OnServiceWorkerPaymentAppFactoryFinishedUsingResources, * only in tests. */
weak_ptr_factory_.GetWeakPtr())); }));
} else { } else {
PopulateProfileCache(); PopulateProfileCache();
SetDefaultProfileSelections(); SetDefaultProfileSelections();
...@@ -146,11 +136,6 @@ void PaymentRequestState::FinishedGetAllSWPaymentInstruments() { ...@@ -146,11 +136,6 @@ void PaymentRequestState::FinishedGetAllSWPaymentInstruments() {
std::move(are_requested_methods_supported_callback_)); std::move(are_requested_methods_supported_callback_));
} }
void PaymentRequestState::
OnServiceWorkerPaymentAppFactoryFinishedUsingResources() {
service_worker_payment_app_factory_.reset();
}
void PaymentRequestState::OnPaymentResponseReady( void PaymentRequestState::OnPaymentResponseReady(
mojom::PaymentResponsePtr payment_response) { mojom::PaymentResponsePtr payment_response) {
delegate_->OnPaymentResponseAvailable(std::move(payment_response)); delegate_->OnPaymentResponseAvailable(std::move(payment_response));
......
...@@ -31,7 +31,6 @@ namespace payments { ...@@ -31,7 +31,6 @@ namespace payments {
class ContentPaymentRequestDelegate; class ContentPaymentRequestDelegate;
class JourneyLogger; class JourneyLogger;
class PaymentInstrument; class PaymentInstrument;
class ServiceWorkerPaymentAppFactory;
class ServiceWorkerPaymentInstrument; class ServiceWorkerPaymentInstrument;
// Keeps track of the information currently selected by the user and whether the // Keeps track of the information currently selected by the user and whether the
...@@ -238,7 +237,6 @@ class PaymentRequestState : public PaymentResponseHelper::Delegate, ...@@ -238,7 +237,6 @@ class PaymentRequestState : public PaymentResponseHelper::Delegate,
ServiceWorkerPaymentInstrument* instrument, ServiceWorkerPaymentInstrument* instrument,
bool result); bool result);
void FinishedGetAllSWPaymentInstruments(); void FinishedGetAllSWPaymentInstruments();
void OnServiceWorkerPaymentAppFactoryFinishedUsingResources();
// Checks whether the user has at least one instrument that satisfies the // Checks whether the user has at least one instrument that satisfies the
// specified supported payment methods and call the |callback| to return the // specified supported payment methods and call the |callback| to return the
...@@ -297,9 +295,6 @@ class PaymentRequestState : public PaymentResponseHelper::Delegate, ...@@ -297,9 +295,6 @@ class PaymentRequestState : public PaymentResponseHelper::Delegate,
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
std::unique_ptr<ServiceWorkerPaymentAppFactory>
service_worker_payment_app_factory_;
base::WeakPtrFactory<PaymentRequestState> weak_ptr_factory_; base::WeakPtrFactory<PaymentRequestState> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); DISALLOW_COPY_AND_ASSIGN(PaymentRequestState);
......
...@@ -10,12 +10,17 @@ ...@@ -10,12 +10,17 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "components/payments/content/manifest_verifier.h" #include "components/payments/content/manifest_verifier.h"
#include "components/payments/content/payment_manifest_web_data_service.h" #include "components/payments/content/payment_manifest_web_data_service.h"
#include "components/payments/content/utility/payment_manifest_parser.h" #include "components/payments/content/utility/payment_manifest_parser.h"
#include "components/payments/core/payment_manifest_downloader.h" #include "components/payments/core/payment_manifest_downloader.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/stored_payment_app.h" #include "content/public/browser/stored_payment_app.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "net/url_request/url_request_context_getter.h"
#include "url/url_canon.h" #include "url/url_canon.h"
namespace payments { namespace payments {
...@@ -80,41 +85,124 @@ void RemovePortNumbersFromScopesForTest( ...@@ -80,41 +85,124 @@ void RemovePortNumbersFromScopesForTest(
} }
} }
} // namespace class SelfDeletingServiceWorkerPaymentAppFactory {
public:
SelfDeletingServiceWorkerPaymentAppFactory() {}
~SelfDeletingServiceWorkerPaymentAppFactory() {}
// After |callback| has fired, the factory refreshes its own cache in the
// background. Once the cache has been refreshed, the factory invokes the
// |finished_using_resources_callback|. At this point, it's safe to delete
// this factory. Don't destroy the factory and don't call this method again
// until |finished_using_resources_callback| has run.
void GetAllPaymentApps(
content::WebContents* web_contents,
std::unique_ptr<PaymentMethodManifestDownloaderInterface> downloader,
scoped_refptr<PaymentManifestWebDataService> cache,
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
content::PaymentAppProvider::GetAllPaymentAppsCallback callback,
base::OnceClosure finished_using_resources_callback) {
DCHECK(!verifier_);
verifier_ = std::make_unique<ManifestVerifier>(
web_contents, std::move(downloader),
std::make_unique<PaymentManifestParser>(), cache);
// Method data cannot be copied and is passed in as a const-ref, which
// cannot be moved, so make a manual copy for moving into the callback
// below.
std::vector<mojom::PaymentMethodDataPtr> requested_method_data_copy;
for (const auto& request : requested_method_data) {
requested_method_data_copy.emplace_back(request.Clone());
}
ServiceWorkerPaymentAppFactory::ServiceWorkerPaymentAppFactory() content::PaymentAppProvider::GetInstance()->GetAllPaymentApps(
: weak_ptr_factory_(this) {} web_contents->GetBrowserContext(),
base::BindOnce(
&SelfDeletingServiceWorkerPaymentAppFactory::OnGotAllPaymentApps,
base::Unretained(this), std::move(requested_method_data_copy),
std::move(callback),
base::BindOnce(&SelfDeletingServiceWorkerPaymentAppFactory::
OnPaymentAppsVerifierFinishedUsingResources,
base::Owned(this),
std::move(finished_using_resources_callback))));
}
ServiceWorkerPaymentAppFactory::~ServiceWorkerPaymentAppFactory() {} void IgnorePortInAppScopeForTesting() {
ignore_port_in_app_scope_for_testing_ = true;
}
private:
void OnGotAllPaymentApps(
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
content::PaymentAppProvider::GetAllPaymentAppsCallback callback,
base::OnceClosure finished_using_resources_callback,
content::PaymentAppProvider::PaymentApps apps) {
if (ignore_port_in_app_scope_for_testing_)
RemovePortNumbersFromScopesForTest(&apps);
ServiceWorkerPaymentAppFactory::RemoveAppsWithoutMatchingMethodData(
requested_method_data, &apps);
if (apps.empty()) {
std::move(callback).Run(std::move(apps));
std::move(finished_using_resources_callback).Run();
return;
}
// The |verifier_| will invoke |callback| with the list of all valid payment
// apps. This list may be empty, if none of the apps were found to be valid.
verifier_->Verify(std::move(apps), std::move(callback),
std::move(finished_using_resources_callback));
}
void OnPaymentAppsVerifierFinishedUsingResources(
base::OnceClosure finished_using_resources_callback) {
verifier_.reset();
std::move(finished_using_resources_callback).Run();
// No need to self-delete here, because of using base::Owned(this).
}
std::unique_ptr<ManifestVerifier> verifier_;
bool ignore_port_in_app_scope_for_testing_ = false;
DISALLOW_COPY_AND_ASSIGN(SelfDeletingServiceWorkerPaymentAppFactory);
};
} // namespace
// static
ServiceWorkerPaymentAppFactory* ServiceWorkerPaymentAppFactory::GetInstance() {
return base::Singleton<ServiceWorkerPaymentAppFactory>::get();
}
void ServiceWorkerPaymentAppFactory::GetAllPaymentApps( void ServiceWorkerPaymentAppFactory::GetAllPaymentApps(
content::WebContents* web_contents, content::WebContents* web_contents,
std::unique_ptr<PaymentMethodManifestDownloaderInterface> downloader,
scoped_refptr<PaymentManifestWebDataService> cache, scoped_refptr<PaymentManifestWebDataService> cache,
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data, const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
content::PaymentAppProvider::GetAllPaymentAppsCallback callback, content::PaymentAppProvider::GetAllPaymentAppsCallback callback,
base::OnceClosure finished_using_resources_callback) { base::OnceClosure finished_writing_cache_callback_for_testing) {
DCHECK(!verifier_); SelfDeletingServiceWorkerPaymentAppFactory* self_delete_factory =
new SelfDeletingServiceWorkerPaymentAppFactory();
verifier_ = std::make_unique<ManifestVerifier>( if (test_downloader_ != nullptr)
web_contents, std::move(downloader), self_delete_factory->IgnorePortInAppScopeForTesting();
std::make_unique<PaymentManifestParser>(), cache);
self_delete_factory->GetAllPaymentApps(
// Method data cannot be copied and is passed in as a const-ref, which cannot web_contents,
// be moved, so make a manual copy for moving into the callback below. test_downloader_ == nullptr
std::vector<mojom::PaymentMethodDataPtr> requested_method_data_copy; ? std::make_unique<payments::PaymentManifestDownloader>(
for (const auto& request : requested_method_data) { content::BrowserContext::GetDefaultStoragePartition(
requested_method_data_copy.emplace_back(request.Clone()); web_contents->GetBrowserContext())
} ->GetURLRequestContext())
: std::move(test_downloader_),
content::PaymentAppProvider::GetInstance()->GetAllPaymentApps( cache, requested_method_data, std::move(callback),
web_contents->GetBrowserContext(), std::move(finished_writing_cache_callback_for_testing));
base::BindOnce(&ServiceWorkerPaymentAppFactory::OnGotAllPaymentApps,
weak_ptr_factory_.GetWeakPtr(),
std::move(requested_method_data_copy), std::move(callback),
std::move(finished_using_resources_callback)));
} }
ServiceWorkerPaymentAppFactory::ServiceWorkerPaymentAppFactory()
: test_downloader_(nullptr) {}
ServiceWorkerPaymentAppFactory::~ServiceWorkerPaymentAppFactory() {}
// static // static
void ServiceWorkerPaymentAppFactory::RemoveAppsWithoutMatchingMethodData( void ServiceWorkerPaymentAppFactory::RemoveAppsWithoutMatchingMethodData(
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data, const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
...@@ -129,40 +217,10 @@ void ServiceWorkerPaymentAppFactory::RemoveAppsWithoutMatchingMethodData( ...@@ -129,40 +217,10 @@ void ServiceWorkerPaymentAppFactory::RemoveAppsWithoutMatchingMethodData(
} }
} }
void ServiceWorkerPaymentAppFactory::IgnorePortInAppScopeForTesting() {
ignore_port_in_app_scope_for_testing_ = true;
}
void ServiceWorkerPaymentAppFactory::OnGotAllPaymentApps(
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
content::PaymentAppProvider::GetAllPaymentAppsCallback callback,
base::OnceClosure finished_using_resources_callback,
content::PaymentAppProvider::PaymentApps apps) {
if (ignore_port_in_app_scope_for_testing_)
RemovePortNumbersFromScopesForTest(&apps);
RemoveAppsWithoutMatchingMethodData(requested_method_data, &apps);
if (apps.empty()) {
std::move(callback).Run(std::move(apps));
std::move(finished_using_resources_callback).Run();
return;
}
// The |verifier_| will invoke |callback| with the list of all valid payment
// apps. This list may be empty, if none of the apps were found to be valid.
verifier_->Verify(
std::move(apps), std::move(callback),
base::BindOnce(&ServiceWorkerPaymentAppFactory::
OnPaymentAppsVerifierFinishedUsingResources,
weak_ptr_factory_.GetWeakPtr(),
std::move(finished_using_resources_callback)));
}
void ServiceWorkerPaymentAppFactory:: void ServiceWorkerPaymentAppFactory::
OnPaymentAppsVerifierFinishedUsingResources( SetDownloaderAndIgnorePortInAppScopeForTesting(
base::OnceClosure finished_using_resources_callback) { std::unique_ptr<PaymentMethodManifestDownloaderInterface> downloader) {
verifier_.reset(); test_downloader_ = std::move(downloader);
std::move(finished_using_resources_callback).Run();
} }
} // namespace payments } // namespace payments
...@@ -9,10 +9,7 @@ ...@@ -9,10 +9,7 @@
#include <set> #include <set>
#include <string> #include <string>
#include "base/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/payment_app_provider.h" #include "content/public/browser/payment_app_provider.h"
#include "third_party/WebKit/public/platform/modules/payments/payment_request.mojom.h" #include "third_party/WebKit/public/platform/modules/payments/payment_request.mojom.h"
...@@ -25,23 +22,17 @@ class WebContents; ...@@ -25,23 +22,17 @@ class WebContents;
namespace payments { namespace payments {
class ManifestVerifier;
class PaymentManifestWebDataService; class PaymentManifestWebDataService;
class PaymentMethodManifestDownloaderInterface; class PaymentMethodManifestDownloaderInterface;
// Retrieves service worker payment apps. // Retrieves service worker payment apps.
class ServiceWorkerPaymentAppFactory { class ServiceWorkerPaymentAppFactory {
public: public:
ServiceWorkerPaymentAppFactory(); static ServiceWorkerPaymentAppFactory* GetInstance();
~ServiceWorkerPaymentAppFactory();
// Retrieves all service worker payment apps that can handle payments for // Retrieves all service worker payment apps that can handle payments for
// |requested_method_data|, verifies these apps are allowed to handle these // |requested_method_data|, verifies these apps are allowed to handle these
// payment methods, and filters them by their capabilities and // payment methods, and filters them by their capabilities.
// CanMakePaymentEvent responses.
//
// This method takes ownership of |downloader|. (Passing the |downloader| into
// this method is useful for testing.)
// //
// The payment apps will be returned through |callback|. After |callback| has // The payment apps will be returned through |callback|. After |callback| has
// been invoked, it's safe to show the apps in UI for user to select one of // been invoked, it's safe to show the apps in UI for user to select one of
...@@ -49,22 +40,15 @@ class ServiceWorkerPaymentAppFactory { ...@@ -49,22 +40,15 @@ class ServiceWorkerPaymentAppFactory {
// //
// After |callback| has fired, the factory refreshes its own cache in the // After |callback| has fired, the factory refreshes its own cache in the
// background. Once the cache has been refreshed, the factory invokes the // background. Once the cache has been refreshed, the factory invokes the
// |finished_using_resources_callback|. At this point, it's safe to delete // |finished_writing_cache_callback_for_testing|.
// this factory. Don't destroy the factory and don't call this method again
// until |finished_using_resources_callback| has run.
// //
// The method should be called on the UI thread. // The method should be called on the UI thread.
void GetAllPaymentApps( void GetAllPaymentApps(
content::WebContents* web_contents, content::WebContents* web_contents,
std::unique_ptr<PaymentMethodManifestDownloaderInterface> downloader,
scoped_refptr<PaymentManifestWebDataService> cache, scoped_refptr<PaymentManifestWebDataService> cache,
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data, const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
content::PaymentAppProvider::GetAllPaymentAppsCallback callback, content::PaymentAppProvider::GetAllPaymentAppsCallback callback,
base::OnceClosure finished_using_resources_callback); base::OnceClosure finished_writing_cache_callback_for_testing);
private:
friend class ServiceWorkerPaymentAppFactoryBrowserTest;
friend class ServiceWorkerPaymentAppFactoryTest;
// Removes |apps| that don't match any of the |requested_method_data| based on // Removes |apps| that don't match any of the |requested_method_data| based on
// the method names and method-specific capabilities. // the method names and method-specific capabilities.
...@@ -72,21 +56,21 @@ class ServiceWorkerPaymentAppFactory { ...@@ -72,21 +56,21 @@ class ServiceWorkerPaymentAppFactory {
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data, const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
content::PaymentAppProvider::PaymentApps* apps); content::PaymentAppProvider::PaymentApps* apps);
// Should be used only in tests. private:
void IgnorePortInAppScopeForTesting(); friend struct base::DefaultSingletonTraits<ServiceWorkerPaymentAppFactory>;
friend class PaymentRequestPaymentAppTest;
friend class ServiceWorkerPaymentAppFactoryBrowserTest;
void OnGotAllPaymentApps( ServiceWorkerPaymentAppFactory();
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data, ~ServiceWorkerPaymentAppFactory();
content::PaymentAppProvider::GetAllPaymentAppsCallback callback,
base::OnceClosure finished_using_resources_callback,
content::PaymentAppProvider::PaymentApps apps);
void OnPaymentAppsVerifierFinishedUsingResources( // Should be used only in tests.
base::OnceClosure finished_verification_callback); // Should be called before every call to GetAllPaymentApps() (because the test
// downloader is moved into the SelfDeletingServiceWorkerPaymentAppFactory).
void SetDownloaderAndIgnorePortInAppScopeForTesting(
std::unique_ptr<PaymentMethodManifestDownloaderInterface> downloader);
std::unique_ptr<ManifestVerifier> verifier_; std::unique_ptr<PaymentMethodManifestDownloaderInterface> test_downloader_;
bool ignore_port_in_app_scope_for_testing_ = false;
base::WeakPtrFactory<ServiceWorkerPaymentAppFactory> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerPaymentAppFactory); DISALLOW_COPY_AND_ASSIGN(ServiceWorkerPaymentAppFactory);
}; };
......
...@@ -14,8 +14,8 @@ class ServiceWorkerPaymentAppFactoryTest : public testing::Test { ...@@ -14,8 +14,8 @@ class ServiceWorkerPaymentAppFactoryTest : public testing::Test {
void RemoveAppsWithoutMatchingMethodData( void RemoveAppsWithoutMatchingMethodData(
const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data, const std::vector<mojom::PaymentMethodDataPtr>& requested_method_data,
content::PaymentAppProvider::PaymentApps* apps) { content::PaymentAppProvider::PaymentApps* apps) {
ServiceWorkerPaymentAppFactory::RemoveAppsWithoutMatchingMethodData( ServiceWorkerPaymentAppFactory::GetInstance()
requested_method_data, apps); ->RemoveAppsWithoutMatchingMethodData(requested_method_data, apps);
} }
}; };
......
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