| 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 "content/browser/payments/payment_app_context_impl.h" | 5 #include "content/browser/payments/payment_app_context_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "content/browser/payments/payment_app_manager.h" | 12 #include "content/browser/payments/payment_manager.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 PaymentAppContextImpl::PaymentAppContextImpl() : is_shutdown_(false) { | 17 PaymentAppContextImpl::PaymentAppContextImpl() : is_shutdown_(false) { |
| 18 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 18 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 19 } | 19 } |
| 20 | 20 |
| 21 void PaymentAppContextImpl::Init( | 21 void PaymentAppContextImpl::Init( |
| 22 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { | 22 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { |
| 23 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 23 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 24 DCHECK(!is_shutdown_); | 24 DCHECK(!is_shutdown_); |
| 25 | 25 |
| 26 BrowserThread::PostTask( | 26 BrowserThread::PostTask( |
| 27 BrowserThread::IO, FROM_HERE, | 27 BrowserThread::IO, FROM_HERE, |
| 28 base::Bind(&PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO, this, | 28 base::Bind(&PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO, this, |
| 29 service_worker_context)); | 29 service_worker_context)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void PaymentAppContextImpl::Shutdown() { | 32 void PaymentAppContextImpl::Shutdown() { |
| 33 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 33 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 34 | 34 |
| 35 BrowserThread::PostTaskAndReply( | 35 BrowserThread::PostTaskAndReply( |
| 36 BrowserThread::IO, FROM_HERE, | 36 BrowserThread::IO, FROM_HERE, |
| 37 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this), | 37 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this), |
| 38 base::Bind(&PaymentAppContextImpl::DidShutdown, this)); | 38 base::Bind(&PaymentAppContextImpl::DidShutdown, this)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void PaymentAppContextImpl::CreatePaymentAppManager( | 41 void PaymentAppContextImpl::CreatePaymentManager( |
| 42 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { | 42 mojo::InterfaceRequest<payments::mojom::PaymentManager> request) { |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 44 | 44 |
| 45 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 46 BrowserThread::IO, FROM_HERE, | 46 BrowserThread::IO, FROM_HERE, |
| 47 base::Bind(&PaymentAppContextImpl::CreatePaymentAppManagerOnIO, this, | 47 base::Bind(&PaymentAppContextImpl::CreatePaymentManagerOnIO, this, |
| 48 base::Passed(&request))); | 48 base::Passed(&request))); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void PaymentAppContextImpl::PaymentAppManagerHadConnectionError( | 51 void PaymentAppContextImpl::PaymentManagerHadConnectionError( |
| 52 PaymentAppManager* payment_app_manager) { | 52 PaymentManager* payment_manager) { |
| 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 54 DCHECK(base::ContainsKey(payment_app_managers_, payment_app_manager)); | 54 DCHECK(base::ContainsKey(payment_managers_, payment_manager)); |
| 55 | 55 |
| 56 payment_app_managers_.erase(payment_app_manager); | 56 payment_managers_.erase(payment_manager); |
| 57 } | 57 } |
| 58 | 58 |
| 59 PaymentAppDatabase* PaymentAppContextImpl::payment_app_database() const { | 59 PaymentAppDatabase* PaymentAppContextImpl::payment_app_database() const { |
| 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 61 return payment_app_database_.get(); | 61 return payment_app_database_.get(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 PaymentAppContextImpl::~PaymentAppContextImpl() { | 64 PaymentAppContextImpl::~PaymentAppContextImpl() { |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 66 DCHECK(is_shutdown_); | 66 DCHECK(is_shutdown_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO( | 69 void PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO( |
| 70 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { | 70 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { |
| 71 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 71 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 72 payment_app_database_ = | 72 payment_app_database_ = |
| 73 base::MakeUnique<PaymentAppDatabase>(service_worker_context); | 73 base::MakeUnique<PaymentAppDatabase>(service_worker_context); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void PaymentAppContextImpl::CreatePaymentAppManagerOnIO( | 76 void PaymentAppContextImpl::CreatePaymentManagerOnIO( |
| 77 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { | 77 mojo::InterfaceRequest<payments::mojom::PaymentManager> request) { |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 79 PaymentAppManager* payment_app_manager = | 79 PaymentManager* payment_manager = |
| 80 new PaymentAppManager(this, std::move(request)); | 80 new PaymentManager(this, std::move(request)); |
| 81 payment_app_managers_[payment_app_manager] = | 81 payment_managers_[payment_manager] = base::WrapUnique(payment_manager); |
| 82 base::WrapUnique(payment_app_manager); | |
| 83 } | 82 } |
| 84 | 83 |
| 85 void PaymentAppContextImpl::ShutdownOnIO() { | 84 void PaymentAppContextImpl::ShutdownOnIO() { |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 85 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 87 | 86 |
| 88 payment_app_managers_.clear(); | 87 payment_managers_.clear(); |
| 89 payment_app_database_.reset(); | 88 payment_app_database_.reset(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void PaymentAppContextImpl::DidShutdown() { | 91 void PaymentAppContextImpl::DidShutdown() { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 94 | 93 |
| 95 is_shutdown_ = true; | 94 is_shutdown_ = true; |
| 96 } | 95 } |
| 97 | 96 |
| 98 } // namespace content | 97 } // namespace content |
| OLD | NEW |