Commit 5fb72312 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

Payments: Prepare for service worker core on the UI thread.

The thread ServiceWorkerContextCore lives on (the "core thread") will
move from the IO thread to the UI thread.

This CL makes PaymentAppBrowserTest tests pass when run with
ServiceWorkerOnUI enabled. It is fairly mechanical. One tricky
part is whether the callbacks here need to be called asynchronously.
In some cases we may already be on the thread the callback needs
to run on, the CL still uses PostTask() to run the callback in case
sync callbacks are not ok.

Bug: 824858
Change-Id: I195d4ce93d267d9417a1e671d64b3d6ae4a8acc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1763551
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689181}
parent 5c29f5ce
......@@ -22,79 +22,81 @@ void PaymentAppContextImpl::Init(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
#if DCHECK_IS_ON()
DCHECK(!did_shutdown_on_io_.IsSet());
DCHECK(!did_shutdown_on_core_.IsSet());
#endif
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO, this,
service_worker_context));
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce(
&PaymentAppContextImpl::CreatePaymentAppDatabaseOnCoreThread, this,
service_worker_context));
}
void PaymentAppContextImpl::Shutdown() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Schedule a ShutdownOnIO() callback that holds a reference to |this| on the
// IO thread. When the last reference to |this| is released, |this| is
// automatically scheduled for deletion on the UI thread (see
// Schedule a ShutdownOnCoreThread() callback that holds a reference to |this|
// on the core thread. When the last reference to |this| is released, |this|
// is automatically scheduled for deletion on the UI thread (see
// content::BrowserThread::DeleteOnUIThread in the header file).
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::BindOnce(&PaymentAppContextImpl::ShutdownOnIO, this));
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce(&PaymentAppContextImpl::ShutdownOnCoreThread, this));
}
void PaymentAppContextImpl::CreatePaymentManager(
payments::mojom::PaymentManagerRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&PaymentAppContextImpl::CreatePaymentManagerOnIO, this,
std::move(request)));
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce(&PaymentAppContextImpl::CreatePaymentManagerOnCoreThread,
this, std::move(request)));
}
void PaymentAppContextImpl::PaymentManagerHadConnectionError(
PaymentManager* payment_manager) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
DCHECK(base::Contains(payment_managers_, payment_manager));
payment_managers_.erase(payment_manager);
}
PaymentAppDatabase* PaymentAppContextImpl::payment_app_database() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
return payment_app_database_.get();
}
PaymentAppContextImpl::~PaymentAppContextImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
#if DCHECK_IS_ON()
DCHECK(did_shutdown_on_io_.IsSet());
DCHECK(did_shutdown_on_core_.IsSet());
#endif
}
void PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO(
void PaymentAppContextImpl::CreatePaymentAppDatabaseOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_database_ =
std::make_unique<PaymentAppDatabase>(service_worker_context);
}
void PaymentAppContextImpl::CreatePaymentManagerOnIO(
void PaymentAppContextImpl::CreatePaymentManagerOnCoreThread(
mojo::InterfaceRequest<payments::mojom::PaymentManager> request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
auto payment_manager =
std::make_unique<PaymentManager>(this, std::move(request));
payment_managers_[payment_manager.get()] = std::move(payment_manager);
}
void PaymentAppContextImpl::ShutdownOnIO() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
void PaymentAppContextImpl::ShutdownOnCoreThread() {
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_managers_.clear();
payment_app_database_.reset();
#if DCHECK_IS_ON()
did_shutdown_on_io_.Set();
did_shutdown_on_core_.Set();
#endif
}
......
......@@ -25,11 +25,13 @@ class ServiceWorkerContextWrapper;
// One instance of this exists per StoragePartition, and services multiple child
// processes/origins. Most logic is delegated to the owned PaymentAppDatabase
// instance, which is only accessed on the IO thread.
// instance, which is only accessed on the thread identified by
// ServiceWorkerContextWrapper::GetCoreThreadId() (the service worker "core"
// thread).
//
// This class is created/destructed by StoragePartitionImpl on UI thread.
// However, the PaymentAppDatabase that this class has internally should work on
// IO thread. So, this class has Init() and Shutdown() methods in addition to
// core thread. So, this class has Init() and Shutdown() methods in addition to
// constructor and destructor. They should be called explicitly when creating
// and destroying StoragePartitionImpl.
//
......@@ -39,8 +41,8 @@ class ServiceWorkerContextWrapper;
// 3) Can now call other public methods in this class in any order.
// - Can call CreatePaymentManager() on UI thread.
// - Can call GetAllPaymentApps() on UI thread.
// - Can call PaymentManagerHadConnectionError() on IO thread.
// - Can call payment_app_database() on IO thread.
// - Can call PaymentManagerHadConnectionError() on core thread.
// - Can call payment_app_database() on the core thread.
// 4) Shutdown()
// 5) Destructor
class CONTENT_EXPORT PaymentAppContextImpl
......@@ -62,10 +64,10 @@ class CONTENT_EXPORT PaymentAppContextImpl
void CreatePaymentManager(payments::mojom::PaymentManagerRequest request);
// Called by PaymentManager objects so that they can
// be deleted. Call on the IO thread.
// be deleted. Call on the core thread.
void PaymentManagerHadConnectionError(PaymentManager* service);
// Should be accessed only on the IO thread.
// Should be accessed only on the core thread.
PaymentAppDatabase* payment_app_database() const;
private:
......@@ -75,26 +77,26 @@ class CONTENT_EXPORT PaymentAppContextImpl
friend class base::DeleteHelper<PaymentAppContextImpl>;
~PaymentAppContextImpl();
void CreatePaymentAppDatabaseOnIO(
void CreatePaymentAppDatabaseOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
void CreatePaymentManagerOnIO(
void CreatePaymentManagerOnCoreThread(
mojo::InterfaceRequest<payments::mojom::PaymentManager> request);
void ShutdownOnIO();
void ShutdownOnCoreThread();
// Only accessed on the IO thread.
// Only accessed on the core thread.
std::unique_ptr<PaymentAppDatabase> payment_app_database_;
// The PaymentManagers are owned by this. They're either deleted during
// ShutdownOnIO or when the channel is closed via
// PaymentManagerHadConnectionError. Only accessed on the IO thread.
// ShutdownOnCoreThread or when the channel is closed via
// PaymentManagerHadConnectionError. Only accessed on the core thread.
std::map<PaymentManager*, std::unique_ptr<PaymentManager>> payment_managers_;
#if DCHECK_IS_ON()
// Set after ShutdownOnIO() has run on the IO thread. |this| shouldn't be
// deleted before this is set.
base::AtomicFlag did_shutdown_on_io_;
// Set after ShutdownOnCoreThread() has run on the core thread. |this|
// shouldn't be deleted before this is set.
base::AtomicFlag did_shutdown_on_core_;
#endif
DISALLOW_COPY_AND_ASSIGN(PaymentAppContextImpl);
......
......@@ -123,16 +123,16 @@ std::unique_ptr<StoredPaymentApp> ToStoredPaymentApp(const std::string& input) {
PaymentAppDatabase::PaymentAppDatabase(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
: service_worker_context_(service_worker_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
}
PaymentAppDatabase::~PaymentAppDatabase() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
}
void PaymentAppDatabase::ReadAllPaymentApps(
ReadAllPaymentAppsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->GetUserDataForAllRegistrationsByKeyPrefix(
kPaymentAppPrefix,
......@@ -144,7 +144,7 @@ void PaymentAppDatabase::DeletePaymentInstrument(
const GURL& scope,
const std::string& instrument_key,
DeletePaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForScope(
scope,
......@@ -157,7 +157,7 @@ void PaymentAppDatabase::ReadPaymentInstrument(
const GURL& scope,
const std::string& instrument_key,
ReadPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForScope(
scope,
......@@ -169,7 +169,7 @@ void PaymentAppDatabase::ReadPaymentInstrument(
void PaymentAppDatabase::KeysOfPaymentInstruments(
const GURL& scope,
KeysOfPaymentInstrumentsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForScope(
scope,
......@@ -181,7 +181,7 @@ void PaymentAppDatabase::HasPaymentInstrument(
const GURL& scope,
const std::string& instrument_key,
HasPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForScope(
scope,
......@@ -195,7 +195,7 @@ void PaymentAppDatabase::WritePaymentInstrument(
const std::string& instrument_key,
PaymentInstrumentPtr instrument,
WritePaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (instrument->icons.size() > 0) {
std::vector<blink::Manifest::ImageResource> icons(instrument->icons);
......@@ -221,7 +221,7 @@ void PaymentAppDatabase::DidFetchedPaymentInstrumentIcon(
payments::mojom::PaymentInstrumentPtr instrument,
WritePaymentInstrumentCallback callback,
const std::string& icon) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (icon.empty()) {
std::move(callback).Run(PaymentHandlerStatus::FETCH_INSTRUMENT_ICON_FAILED);
......@@ -240,7 +240,7 @@ void PaymentAppDatabase::FetchAndUpdatePaymentAppInfo(
const GURL& context,
const GURL& scope,
FetchAndUpdatePaymentAppInfoCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
PaymentAppInfoFetcher::Start(
context, service_worker_context_,
......@@ -253,7 +253,7 @@ void PaymentAppDatabase::FetchPaymentAppInfoCallback(
const GURL& scope,
FetchAndUpdatePaymentAppInfoCallback callback,
std::unique_ptr<PaymentAppInfoFetcher::PaymentAppInfo> app_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForScope(
scope, base::BindOnce(
......@@ -267,7 +267,7 @@ void PaymentAppDatabase::DidFindRegistrationToUpdatePaymentAppInfo(
std::unique_ptr<PaymentAppInfoFetcher::PaymentAppInfo> app_info,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
return;
......@@ -287,7 +287,7 @@ void PaymentAppDatabase::DidGetPaymentAppInfoToUpdatePaymentAppInfo(
scoped_refptr<ServiceWorkerRegistration> registration,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
return;
......@@ -333,7 +333,7 @@ void PaymentAppDatabase::DidUpdatePaymentApp(
FetchAndUpdatePaymentAppInfoCallback callback,
bool fetch_app_info_failed,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
PaymentHandlerStatus handler_status =
fetch_app_info_failed
......@@ -348,7 +348,7 @@ void PaymentAppDatabase::DidUpdatePaymentApp(
void PaymentAppDatabase::ClearPaymentInstruments(
const GURL& scope,
ClearPaymentInstrumentsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForScope(
scope,
......@@ -359,7 +359,7 @@ void PaymentAppDatabase::ClearPaymentInstruments(
void PaymentAppDatabase::SetPaymentAppUserHint(const GURL& scope,
const std::string& user_hint) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForScope(
scope,
......@@ -372,7 +372,7 @@ void PaymentAppDatabase::DidFindRegistrationToSetPaymentAppUserHint(
const std::string& user_hint,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk)
return;
......@@ -389,7 +389,7 @@ void PaymentAppDatabase::DidGetPaymentAppInfoToSetUserHint(
const GURL& pattern,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk)
return;
......@@ -413,7 +413,7 @@ void PaymentAppDatabase::DidGetPaymentAppInfoToSetUserHint(
void PaymentAppDatabase::DidSetPaymentAppUserHint(
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
DCHECK(status == blink::ServiceWorkerStatusCode::kOk);
}
......@@ -424,7 +424,7 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker(
const std::string& icon,
const std::string& method,
SetPaymentAppInfoCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context_->FindReadyRegistrationForIdOnly(
registration_id,
......@@ -441,7 +441,7 @@ void PaymentAppDatabase::DidFindRegistrationToSetPaymentApp(
SetPaymentAppInfoCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
......@@ -479,7 +479,7 @@ void PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp(
SetPaymentAppInfoCallback callback,
scoped_refptr<ServiceWorkerRegistration> registration,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::STORAGE_OPERATION_FAILED);
......@@ -516,7 +516,7 @@ void PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp(
void PaymentAppDatabase::DidWritePaymentInstrumentForSetPaymentApp(
SetPaymentAppInfoCallback callback,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
return std::move(callback).Run(
status == blink::ServiceWorkerStatusCode::kOk
? PaymentHandlerStatus::SUCCESS
......@@ -527,7 +527,7 @@ void PaymentAppDatabase::DidReadAllPaymentApps(
ReadAllPaymentAppsCallback callback,
const std::vector<std::pair<int64_t, std::string>>& raw_data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentApps());
return;
......@@ -558,7 +558,7 @@ void PaymentAppDatabase::DidReadAllPaymentInstruments(
ReadAllPaymentAppsCallback callback,
const std::vector<std::pair<int64_t, std::string>>& raw_data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(std::move(apps));
return;
......@@ -592,7 +592,7 @@ void PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument(
DeletePaymentInstrumentCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
return;
......@@ -611,7 +611,7 @@ void PaymentAppDatabase::DidFindPaymentInstrument(
DeletePaymentInstrumentCallback callback,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk || data.size() != 1) {
std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND);
return;
......@@ -628,7 +628,7 @@ void PaymentAppDatabase::DidFindPaymentInstrument(
void PaymentAppDatabase::DidDeletePaymentInstrument(
DeletePaymentInstrumentCallback callback,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
return std::move(callback).Run(status == blink::ServiceWorkerStatusCode::kOk
? PaymentHandlerStatus::SUCCESS
: PaymentHandlerStatus::NOT_FOUND);
......@@ -639,7 +639,7 @@ void PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument(
ReadPaymentInstrumentCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentInstrument::New(),
PaymentHandlerStatus::NO_ACTIVE_WORKER);
......@@ -656,7 +656,7 @@ void PaymentAppDatabase::DidReadPaymentInstrument(
ReadPaymentInstrumentCallback callback,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk || data.size() != 1) {
std::move(callback).Run(PaymentInstrument::New(),
PaymentHandlerStatus::NOT_FOUND);
......@@ -677,7 +677,7 @@ void PaymentAppDatabase::DidFindRegistrationToGetKeys(
KeysOfPaymentInstrumentsCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(std::vector<std::string>(),
PaymentHandlerStatus::NO_ACTIVE_WORKER);
......@@ -694,7 +694,7 @@ void PaymentAppDatabase::DidGetKeysOfPaymentInstruments(
KeysOfPaymentInstrumentsCallback callback,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(std::vector<std::string>(),
PaymentHandlerStatus::NOT_FOUND);
......@@ -714,7 +714,7 @@ void PaymentAppDatabase::DidFindRegistrationToHasPaymentInstrument(
HasPaymentInstrumentCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
return;
......@@ -730,7 +730,7 @@ void PaymentAppDatabase::DidHasPaymentInstrument(
DeletePaymentInstrumentCallback callback,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk || data.size() != 1) {
std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND);
return;
......@@ -746,7 +746,7 @@ void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument(
WritePaymentInstrumentCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
return;
......@@ -802,7 +802,7 @@ void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument(
void PaymentAppDatabase::DidWritePaymentInstrument(
WritePaymentInstrumentCallback callback,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
return std::move(callback).Run(
status == blink::ServiceWorkerStatusCode::kOk
? PaymentHandlerStatus::SUCCESS
......@@ -814,7 +814,7 @@ void PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments(
ClearPaymentInstrumentsCallback callback,
blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
......@@ -833,7 +833,7 @@ void PaymentAppDatabase::DidGetKeysToClearPaymentInstruments(
ClearPaymentInstrumentsCallback callback,
const std::vector<std::string>& keys,
PaymentHandlerStatus status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != PaymentHandlerStatus::SUCCESS) {
std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND);
......@@ -858,7 +858,7 @@ void PaymentAppDatabase::DidGetKeysToClearPaymentInstruments(
void PaymentAppDatabase::DidClearPaymentInstruments(
ClearPaymentInstrumentsCallback callback,
blink::ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
return std::move(callback).Run(status == blink::ServiceWorkerStatusCode::kOk
? PaymentHandlerStatus::SUCCESS
: PaymentHandlerStatus::NOT_FOUND);
......
......@@ -33,13 +33,13 @@ void PaymentAppInfoFetcher::Start(
const GURL& context_url,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
PaymentAppInfoFetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
std::unique_ptr<std::vector<GlobalFrameRoutingId>> provider_hosts =
service_worker_context->GetProviderHostIds(context_url.GetOrigin());
base::PostTask(
FROM_HERE, {BrowserThread::UI},
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(&PaymentAppInfoFetcher::StartOnUI, context_url,
std::move(provider_hosts), std::move(callback)));
}
......@@ -166,7 +166,7 @@ void PaymentAppInfoFetcher::SelfDeleteFetcher::Start(
void PaymentAppInfoFetcher::SelfDeleteFetcher::RunCallbackAndDestroy() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::PostTask(FROM_HERE, {ServiceWorkerContextWrapper::GetCoreThreadId()},
base::BindOnce(std::move(callback_),
std::move(fetched_payment_app_info_)));
delete this;
......
......@@ -32,7 +32,7 @@ class PaymentAppInfoFetcher {
using PaymentAppInfoFetchCallback =
base::OnceCallback<void(std::unique_ptr<PaymentAppInfo> app_info)>;
// Only accessed on the IO thread.
// Only accessed on the service worker core thread.
static void Start(
const GURL& context_url,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
......
......@@ -138,21 +138,21 @@ class SelfDeleteInstaller
scoped_refptr<PaymentAppContextImpl> payment_app_context =
partition->GetPaymentAppContext();
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&SelfDeleteInstaller::SetPaymentAppInfoOnIO, this,
payment_app_context, registration_id_, scope_.spec(),
app_name_, app_icon_, method_));
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce(&SelfDeleteInstaller::SetPaymentAppInfoOnCoreThread,
this, payment_app_context, registration_id_,
scope_.spec(), app_name_, app_icon_, method_));
}
void SetPaymentAppInfoOnIO(
void SetPaymentAppInfoOnCoreThread(
scoped_refptr<PaymentAppContextImpl> payment_app_context,
int64_t registration_id,
const std::string& instrument_key,
const std::string& name,
const std::string& app_icon,
const std::string& method) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context->payment_app_database()
->SetPaymentAppInfoForRegisteredServiceWorker(
......@@ -161,10 +161,10 @@ class SelfDeleteInstaller
}
void OnSetPaymentAppInfo(payments::mojom::PaymentHandlerStatus status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
base::PostTask(
FROM_HERE, {BrowserThread::UI},
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(&SelfDeleteInstaller::FinishInstallation, this,
status == payments::mojom::PaymentHandlerStatus::SUCCESS
? true
......
......@@ -57,12 +57,12 @@ class RespondWithCallbacks;
class InvokePaymentAppCallbackRepository {
public:
static InvokePaymentAppCallbackRepository* GetInstance() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
return base::Singleton<InvokePaymentAppCallbackRepository>::get();
}
RespondWithCallbacks* GetCallback(BrowserContext* browser_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
auto it = invoke_callbacks_.find(browser_context);
if (it != invoke_callbacks_.end()) {
return it->second;
......@@ -72,12 +72,12 @@ class InvokePaymentAppCallbackRepository {
void SetCallback(BrowserContext* browser_context,
RespondWithCallbacks* callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
invoke_callbacks_[browser_context] = callback;
}
void RemoveCallback(BrowserContext* browser_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
invoke_callbacks_.erase(browser_context);
}
......@@ -137,50 +137,53 @@ class RespondWithCallbacks
void OnResponseForPaymentRequest(
payments::mojom::PaymentHandlerResponsePtr response) override {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_version_->FinishRequest(request_id_, false);
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(invoke_payment_app_callback_),
std::move(response)));
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(invoke_payment_app_callback_),
std::move(response)));
ClearCallbackRepositoryAndCloseWindow();
delete this;
}
void OnResponseForCanMakePayment(bool can_make_payment) override {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_version_->FinishRequest(request_id_, false);
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(payment_event_result_callback_),
can_make_payment));
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(payment_event_result_callback_),
can_make_payment));
delete this;
}
void OnResponseForAbortPayment(bool payment_aborted) override {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_version_->FinishRequest(request_id_, false);
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(payment_event_result_callback_),
payment_aborted));
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(payment_event_result_callback_),
payment_aborted));
ClearCallbackRepositoryAndCloseWindow();
delete this;
}
void RespondWithErrorAndDeleteSelf(PaymentEventResponseType response_type) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (event_type_ == ServiceWorkerMetrics::EventType::PAYMENT_REQUEST) {
base::PostTask(
FROM_HERE, {BrowserThread::UI},
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(invoke_payment_app_callback_),
payments::mojom::PaymentHandlerResponse::New(
"", "", response_type)));
} else if (event_type_ ==
ServiceWorkerMetrics::EventType::CAN_MAKE_PAYMENT ||
event_type_ == ServiceWorkerMetrics::EventType::ABORT_PAYMENT) {
base::PostTask(
FROM_HERE, {BrowserThread::UI},
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(payment_event_result_callback_), false));
}
......@@ -192,7 +195,7 @@ class RespondWithCallbacks
}
void OnErrorStatus(blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
DCHECK(service_worker_status != blink::ServiceWorkerStatusCode::kOk);
PaymentEventResponseType response_type =
......@@ -213,7 +216,7 @@ class RespondWithCallbacks
int request_id() { return request_id_; }
void AbortPaymentSinceOpennedWindowClosing(PaymentEventResponseType reason) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_version_->FinishRequest(request_id_, false);
RespondWithErrorAndDeleteSelf(reason);
......@@ -223,7 +226,7 @@ class RespondWithCallbacks
~RespondWithCallbacks() override {}
void ClearCallbackRepositoryAndCloseWindow() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
InvokePaymentAppCallbackRepository::GetInstance()->RemoveCallback(
browser_context_);
......@@ -251,20 +254,20 @@ class RespondWithCallbacks
DISALLOW_COPY_AND_ASSIGN(RespondWithCallbacks);
};
void DidGetAllPaymentAppsOnIO(
void DidGetAllPaymentAppsOnCoreThread(
PaymentAppProvider::GetAllPaymentAppsCallback callback,
PaymentAppProvider::PaymentApps apps) {
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(callback), std::move(apps)));
}
void GetAllPaymentAppsOnIO(
void GetAllPaymentAppsOnCoreThread(
scoped_refptr<PaymentAppContextImpl> payment_app_context,
PaymentAppProvider::GetAllPaymentAppsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context->payment_app_database()->ReadAllPaymentApps(
base::BindOnce(&DidGetAllPaymentAppsOnIO, std::move(callback)));
base::BindOnce(&DidGetAllPaymentAppsOnCoreThread, std::move(callback)));
}
void DispatchAbortPaymentEvent(
......@@ -272,7 +275,7 @@ void DispatchAbortPaymentEvent(
PaymentAppProvider::PaymentEventResultCallback callback,
scoped_refptr<ServiceWorkerVersion> active_version,
blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (service_worker_status != blink::ServiceWorkerStatusCode::kOk) {
base::PostTask(FROM_HERE, {BrowserThread::UI},
......@@ -301,7 +304,7 @@ void DispatchCanMakePaymentEvent(
PaymentAppProvider::PaymentEventResultCallback callback,
scoped_refptr<ServiceWorkerVersion> active_version,
blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (service_worker_status != blink::ServiceWorkerStatusCode::kOk) {
base::PostTask(FROM_HERE, {BrowserThread::UI},
......@@ -330,7 +333,7 @@ void DispatchPaymentRequestEvent(
PaymentAppProvider::InvokePaymentAppCallback callback,
scoped_refptr<ServiceWorkerVersion> active_version,
blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (service_worker_status != blink::ServiceWorkerStatusCode::kOk) {
base::PostTask(
......@@ -358,11 +361,11 @@ void DispatchPaymentRequestEvent(
active_version->CreateSimpleEventCallback(event_finish_id));
}
void DidFindRegistrationOnIO(
void DidFindRegistrationOnCoreThread(
ServiceWorkerStartCallback callback,
blink::ServiceWorkerStatusCode service_worker_status,
scoped_refptr<ServiceWorkerRegistration> service_worker_registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (service_worker_status != blink::ServiceWorkerStatusCode::kOk) {
std::move(callback).Run(nullptr, service_worker_status);
......@@ -378,15 +381,15 @@ void DidFindRegistrationOnIO(
base::WrapRefCounted(active_version)));
}
void FindRegistrationOnIO(
void FindRegistrationOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
int64_t registration_id,
ServiceWorkerStartCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
service_worker_context->FindReadyRegistrationForIdOnly(
registration_id,
base::BindOnce(&DidFindRegistrationOnIO, std::move(callback)));
base::BindOnce(&DidFindRegistrationOnCoreThread, std::move(callback)));
}
void StartServiceWorkerForDispatch(BrowserContext* browser_context,
......@@ -399,10 +402,11 @@ void StartServiceWorkerForDispatch(BrowserContext* browser_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context =
partition->GetServiceWorkerContext();
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&FindRegistrationOnIO, std::move(service_worker_context),
registration_id, std::move(callback)));
RunOrPostTaskOnThread(FROM_HERE,
ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce(&FindRegistrationOnCoreThread,
std::move(service_worker_context),
registration_id, std::move(callback)));
}
void OnInstallPaymentApp(
......@@ -450,7 +454,7 @@ void CheckPermissionForPaymentApps(
void AbortInvokePaymentApp(BrowserContext* browser_context,
PaymentEventResponseType reason) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
RespondWithCallbacks* callback =
InvokePaymentAppCallbackRepository::GetInstance()->GetCallback(
......@@ -597,9 +601,9 @@ void PaymentAppProviderImpl::GetAllPaymentApps(
scoped_refptr<PaymentAppContextImpl> payment_app_context =
partition->GetPaymentAppContext();
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&GetAllPaymentAppsOnIO, payment_app_context,
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce(&GetAllPaymentAppsOnCoreThread, payment_app_context,
base::BindOnce(&CheckPermissionForPaymentApps,
browser_context, std::move(callback))));
}
......@@ -774,8 +778,8 @@ void PaymentAppProviderImpl::OnClosingOpenedWindow(
PaymentEventResponseType reason) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::PostTask(
FROM_HERE, {BrowserThread::IO},
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce(&AbortInvokePaymentApp, browser_context, reason));
}
......
......@@ -39,7 +39,8 @@ void OnIconFetched(
if (bitmap.drawsNothing()) {
if (icons.empty()) {
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::PostTask(FROM_HERE,
{ServiceWorkerContextWrapper::GetCoreThreadId()},
base::BindOnce(std::move(callback), std::string()));
} else {
// If could not download or decode the chosen image(e.g. not supported,
......@@ -57,7 +58,7 @@ void OnIconFetched(
base::StringPiece(reinterpret_cast<const char*>(&bitmap_data[0]),
bitmap_data.size()),
&encoded_data);
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::PostTask(FROM_HERE, {ServiceWorkerContextWrapper::GetCoreThreadId()},
base::BindOnce(std::move(callback), encoded_data));
}
......@@ -69,7 +70,7 @@ void DownloadBestMatchingIcon(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (web_contents == nullptr) {
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::PostTask(FROM_HERE, {ServiceWorkerContextWrapper::GetCoreThreadId()},
base::BindOnce(std::move(callback), std::string()));
return;
}
......@@ -85,7 +86,7 @@ void DownloadBestMatchingIcon(
// developers in advance unlike when fetching or decoding fails. We already
// checked whether they are valid in renderer side. So, if the icon url is
// invalid, it's something wrong.
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::PostTask(FROM_HERE, {ServiceWorkerContextWrapper::GetCoreThreadId()},
base::BindOnce(std::move(callback), std::string()));
return;
}
......@@ -151,11 +152,12 @@ void PaymentInstrumentIconFetcher::Start(
std::unique_ptr<std::vector<GlobalFrameRoutingId>> provider_hosts,
const std::vector<blink::Manifest::ImageResource>& icons,
PaymentInstrumentIconFetcherCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(&StartOnUI, scope, std::move(provider_hosts),
icons, std::move(callback)));
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(&StartOnUI, scope, std::move(provider_hosts), icons,
std::move(callback)));
}
} // namespace content
......@@ -23,7 +23,7 @@ class PaymentInstrumentIconFetcher {
using PaymentInstrumentIconFetcherCallback =
base::OnceCallback<void(const std::string&)>;
// Should be called on IO thread.
// Should be called on the service worker core thread.
static void Start(
const GURL& scope,
std::unique_ptr<std::vector<GlobalFrameRoutingId>> provider_hosts,
......
......@@ -19,7 +19,7 @@
namespace content {
PaymentManager::~PaymentManager() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
}
PaymentManager::PaymentManager(
......@@ -27,7 +27,7 @@ PaymentManager::PaymentManager(
mojo::InterfaceRequest<payments::mojom::PaymentManager> request)
: payment_app_context_(payment_app_context),
binding_(this, std::move(request)) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
DCHECK(payment_app_context);
binding_.set_connection_error_handler(base::BindOnce(
......@@ -35,7 +35,7 @@ PaymentManager::PaymentManager(
}
void PaymentManager::Init(const GURL& context_url, const std::string& scope) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
should_set_payment_app_info_ = true;
context_url_ = context_url;
......@@ -59,7 +59,7 @@ void PaymentManager::Init(const GURL& context_url, const std::string& scope) {
void PaymentManager::DeletePaymentInstrument(
const std::string& instrument_key,
PaymentManager::DeletePaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context_->payment_app_database()->DeletePaymentInstrument(
scope_, instrument_key, std::move(callback));
......@@ -68,7 +68,7 @@ void PaymentManager::DeletePaymentInstrument(
void PaymentManager::GetPaymentInstrument(
const std::string& instrument_key,
PaymentManager::GetPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context_->payment_app_database()->ReadPaymentInstrument(
scope_, instrument_key, std::move(callback));
......@@ -76,7 +76,7 @@ void PaymentManager::GetPaymentInstrument(
void PaymentManager::KeysOfPaymentInstruments(
PaymentManager::KeysOfPaymentInstrumentsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context_->payment_app_database()->KeysOfPaymentInstruments(
scope_, std::move(callback));
......@@ -85,7 +85,7 @@ void PaymentManager::KeysOfPaymentInstruments(
void PaymentManager::HasPaymentInstrument(
const std::string& instrument_key,
PaymentManager::HasPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context_->payment_app_database()->HasPaymentInstrument(
scope_, instrument_key, std::move(callback));
......@@ -95,7 +95,7 @@ void PaymentManager::SetPaymentInstrument(
const std::string& instrument_key,
payments::mojom::PaymentInstrumentPtr details,
PaymentManager::SetPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (should_set_payment_app_info_) {
payment_app_context_->payment_app_database()->WritePaymentInstrument(
......@@ -112,7 +112,7 @@ void PaymentManager::SetPaymentInstrument(
void PaymentManager::SetPaymentInstrumentIntermediateCallback(
PaymentManager::SetPaymentInstrumentCallback callback,
payments::mojom::PaymentHandlerStatus status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
if (status != payments::mojom::PaymentHandlerStatus::SUCCESS ||
!should_set_payment_app_info_) {
......@@ -127,7 +127,7 @@ void PaymentManager::SetPaymentInstrumentIntermediateCallback(
void PaymentManager::ClearPaymentInstruments(
ClearPaymentInstrumentsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context_->payment_app_database()->ClearPaymentInstruments(
scope_, std::move(callback));
......@@ -139,7 +139,7 @@ void PaymentManager::SetUserHint(const std::string& user_hint) {
}
void PaymentManager::OnConnectionError() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContextWrapper::GetCoreThreadId());
payment_app_context_->PaymentManagerHadConnectionError(this);
}
......
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