Chromium Code Reviews| 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_database.h" | |
| 12 #include "content/browser/payments/payment_app_manager.h" | 13 #include "content/browser/payments/payment_app_manager.h" |
| 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" | |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 PaymentAppContextImpl::PaymentAppContextImpl( | 18 PaymentAppContextImpl::PaymentAppContextImpl() { |
| 19 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) | |
| 20 : service_worker_context_(std::move(service_worker_context)) { | |
| 21 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 19 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 22 } | 20 } |
| 23 | 21 |
| 22 void PaymentAppContextImpl::Init( | |
| 23 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { | |
| 24 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 25 | |
| 26 BrowserThread::PostTask( | |
| 27 BrowserThread::IO, FROM_HERE, | |
| 28 base::Bind(&PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO, this, | |
|
please use gerrit instead
2016/12/14 19:44:00
Either call this InitOnIO() or rename the Init() m
zino
2016/12/15 17:56:52
The Init() function is paired with Shutdown() and
| |
| 29 service_worker_context)); | |
| 30 } | |
| 31 | |
| 24 void PaymentAppContextImpl::Shutdown() { | 32 void PaymentAppContextImpl::Shutdown() { |
| 25 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 33 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 26 | 34 |
| 27 BrowserThread::PostTask( | 35 BrowserThread::PostTask( |
| 28 BrowserThread::IO, FROM_HERE, | 36 BrowserThread::IO, FROM_HERE, |
| 29 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this)); | 37 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this)); |
| 30 } | 38 } |
| 31 | 39 |
| 32 void PaymentAppContextImpl::CreateService( | 40 void PaymentAppContextImpl::CreateService( |
| 33 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { | 41 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { |
| 34 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 35 | 43 |
| 36 BrowserThread::PostTask( | 44 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 37 BrowserThread::IO, FROM_HERE, | 45 base::Bind(&PaymentAppContextImpl::CreateServiceOnIO, |
| 38 base::Bind(&PaymentAppContextImpl::CreateServiceOnIOThread, this, | 46 this, base::Passed(&request))); |
| 39 base::Passed(&request))); | |
| 40 } | 47 } |
| 41 | 48 |
| 42 void PaymentAppContextImpl::ServiceHadConnectionError( | 49 void PaymentAppContextImpl::ServiceHadConnectionError( |
| 43 PaymentAppManager* service) { | 50 PaymentAppManager* service) { |
| 44 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 45 DCHECK(base::ContainsKey(services_, service)); | 52 DCHECK(base::ContainsKey(services_, service)); |
| 46 | 53 |
| 47 services_.erase(service); | 54 services_.erase(service); |
| 48 } | 55 } |
| 49 | 56 |
| 50 ServiceWorkerContextWrapper* PaymentAppContextImpl::service_worker_context() | 57 PaymentAppDatabase* PaymentAppContextImpl::payment_app_database() const { |
|
please use gerrit instead
2016/12/14 19:44:00
DCHECK IO thread.
zino
2016/12/15 17:56:52
Done.
| |
| 51 const { | 58 return payment_app_database_.get(); |
| 52 return service_worker_context_.get(); | |
| 53 } | 59 } |
| 54 | 60 |
| 55 void PaymentAppContextImpl::GetAllManifests( | 61 void PaymentAppContextImpl::GetAllManifests( |
| 56 const GetAllManifestsCallback& callback) { | 62 const GetAllManifestsCallback& callback) { |
| 57 NOTIMPLEMENTED(); | 63 NOTIMPLEMENTED(); |
| 58 } | 64 } |
| 59 | 65 |
| 60 PaymentAppContextImpl::~PaymentAppContextImpl() { | 66 PaymentAppContextImpl::~PaymentAppContextImpl() { |
|
please use gerrit instead
2016/12/14 19:44:00
DCHECK you're on UI thread, same as constructor.
zino
2016/12/15 17:56:52
Done.
| |
| 61 DCHECK(services_.empty()); | 67 DCHECK(services_.empty()); |
| 68 DCHECK(!payment_app_database_); | |
| 62 } | 69 } |
| 63 | 70 |
| 64 void PaymentAppContextImpl::CreateServiceOnIOThread( | 71 void PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO( |
| 72 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { | |
| 73 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 74 payment_app_database_ = | |
| 75 base::MakeUnique<PaymentAppDatabase>(service_worker_context); | |
| 76 } | |
| 77 | |
| 78 void PaymentAppContextImpl::CreateServiceOnIO( | |
| 65 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { | 79 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 67 PaymentAppManager* service = new PaymentAppManager(this, std::move(request)); | 81 PaymentAppManager* service = new PaymentAppManager(this, std::move(request)); |
| 68 services_[service] = base::WrapUnique(service); | 82 services_[service] = base::WrapUnique(service); |
| 69 } | 83 } |
| 70 | 84 |
| 71 void PaymentAppContextImpl::ShutdownOnIO() { | 85 void PaymentAppContextImpl::ShutdownOnIO() { |
| 72 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 73 | 87 |
| 74 services_.clear(); | 88 services_.clear(); |
| 89 payment_app_database_.reset(); | |
| 75 } | 90 } |
| 76 | 91 |
| 77 } // namespace content | 92 } // namespace content |
| OLD | NEW |