Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: content/browser/payments/payment_app_context_impl.cc

Issue 2572183002: PaymentApp: Introduce PaymentAppDatabase class. (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() : is_shutdown_(false) {
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 DCHECK(!is_shutdown_);
26
27 BrowserThread::PostTask(
28 BrowserThread::IO, FROM_HERE,
29 base::Bind(&PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO, this,
30 service_worker_context));
31 }
32
24 void PaymentAppContextImpl::Shutdown() { 33 void PaymentAppContextImpl::Shutdown() {
25 DCHECK_CURRENTLY_ON(BrowserThread::UI); 34 DCHECK_CURRENTLY_ON(BrowserThread::UI);
26 35
27 BrowserThread::PostTask( 36 BrowserThread::PostTaskAndReply(
28 BrowserThread::IO, FROM_HERE, 37 BrowserThread::IO, FROM_HERE,
29 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this)); 38 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this),
39 base::Bind(&PaymentAppContextImpl::DidShutdown, this));
30 } 40 }
31 41
32 void PaymentAppContextImpl::CreateService( 42 void PaymentAppContextImpl::CreatePaymentAppManager(
33 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { 43 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI); 44 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35 45
36 BrowserThread::PostTask( 46 BrowserThread::PostTask(
37 BrowserThread::IO, FROM_HERE, 47 BrowserThread::IO, FROM_HERE,
38 base::Bind(&PaymentAppContextImpl::CreateServiceOnIOThread, this, 48 base::Bind(&PaymentAppContextImpl::CreatePaymentAppManagerOnIO, this,
39 base::Passed(&request))); 49 base::Passed(&request)));
40 } 50 }
41 51
42 void PaymentAppContextImpl::ServiceHadConnectionError( 52 void PaymentAppContextImpl::PaymentAppManagerHadConnectionError(
43 PaymentAppManager* service) { 53 PaymentAppManager* payment_app_manager) {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO); 54 DCHECK_CURRENTLY_ON(BrowserThread::IO);
45 DCHECK(base::ContainsKey(services_, service)); 55 DCHECK(base::ContainsKey(payment_app_managers_, payment_app_manager));
46 56
47 services_.erase(service); 57 payment_app_managers_.erase(payment_app_manager);
48 } 58 }
49 59
50 ServiceWorkerContextWrapper* PaymentAppContextImpl::service_worker_context() 60 PaymentAppDatabase* PaymentAppContextImpl::payment_app_database() const {
51 const { 61 DCHECK_CURRENTLY_ON(BrowserThread::IO);
52 return service_worker_context_.get(); 62 return payment_app_database_.get();
53 } 63 }
54 64
55 void PaymentAppContextImpl::GetAllManifests( 65 void PaymentAppContextImpl::GetAllManifests(
56 const GetAllManifestsCallback& callback) { 66 const GetAllManifestsCallback& callback) {
57 NOTIMPLEMENTED(); 67 NOTIMPLEMENTED();
58 } 68 }
59 69
60 PaymentAppContextImpl::~PaymentAppContextImpl() { 70 PaymentAppContextImpl::~PaymentAppContextImpl() {
61 DCHECK(services_.empty()); 71 DCHECK_CURRENTLY_ON(BrowserThread::UI);
72 DCHECK(is_shutdown_);
62 } 73 }
63 74
64 void PaymentAppContextImpl::CreateServiceOnIOThread( 75 void PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO(
76 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
77 DCHECK_CURRENTLY_ON(BrowserThread::IO);
78 payment_app_database_ =
79 base::MakeUnique<PaymentAppDatabase>(service_worker_context);
80 }
81
82 void PaymentAppContextImpl::CreatePaymentAppManagerOnIO(
65 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { 83 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) {
66 DCHECK_CURRENTLY_ON(BrowserThread::IO); 84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
67 PaymentAppManager* service = new PaymentAppManager(this, std::move(request)); 85 PaymentAppManager* payment_app_manager =
68 services_[service] = base::WrapUnique(service); 86 new PaymentAppManager(this, std::move(request));
87 payment_app_managers_[payment_app_manager] =
88 base::WrapUnique(payment_app_manager);
69 } 89 }
70 90
71 void PaymentAppContextImpl::ShutdownOnIO() { 91 void PaymentAppContextImpl::ShutdownOnIO() {
72 DCHECK_CURRENTLY_ON(BrowserThread::IO); 92 DCHECK_CURRENTLY_ON(BrowserThread::IO);
73 93
74 services_.clear(); 94 payment_app_managers_.clear();
95 payment_app_database_.reset();
96 }
97
98 void PaymentAppContextImpl::DidShutdown() {
99 DCHECK_CURRENTLY_ON(BrowserThread::UI);
100
101 is_shutdown_ = true;
75 } 102 }
76 103
77 } // namespace content 104 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_context_impl.h ('k') | content/browser/payments/payment_app_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698