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

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

Issue 2572183002: PaymentApp: Introduce PaymentAppDatabase class. (Closed)
Patch Set: 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() {
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
24 PaymentAppContextImpl::~PaymentAppContextImpl() { 22 void PaymentAppContextImpl::Init(
25 DCHECK(services_.empty()); 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,
29 service_worker_context));
26 } 30 }
27 31
28 void PaymentAppContextImpl::Shutdown() { 32 void PaymentAppContextImpl::Shutdown() {
29 DCHECK_CURRENTLY_ON(BrowserThread::UI); 33 DCHECK_CURRENTLY_ON(BrowserThread::UI);
30 34
31 BrowserThread::PostTask( 35 BrowserThread::PostTask(
32 BrowserThread::IO, FROM_HERE, 36 BrowserThread::IO, FROM_HERE,
33 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this)); 37 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this));
34 } 38 }
35 39
36 void PaymentAppContextImpl::CreateService( 40 void PaymentAppContextImpl::CreateService(
37 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { 41 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) {
38 DCHECK_CURRENTLY_ON(BrowserThread::UI); 42 DCHECK_CURRENTLY_ON(BrowserThread::UI);
39 43
40 BrowserThread::PostTask( 44 BrowserThread::PostTask(
41 BrowserThread::IO, FROM_HERE, 45 BrowserThread::IO, FROM_HERE,
42 base::Bind(&PaymentAppContextImpl::CreateServiceOnIOThread, this, 46 base::Bind(&PaymentAppContextImpl::CreateServiceOnIOThread, this,
43 base::Passed(&request))); 47 base::Passed(&request)));
44 } 48 }
45 49
46 void PaymentAppContextImpl::ServiceHadConnectionError( 50 void PaymentAppContextImpl::ServiceHadConnectionError(
47 PaymentAppManager* service) { 51 PaymentAppManager* service) {
48 DCHECK_CURRENTLY_ON(BrowserThread::IO); 52 DCHECK_CURRENTLY_ON(BrowserThread::IO);
49 DCHECK(base::ContainsKey(services_, service)); 53 DCHECK(base::ContainsKey(services_, service));
50 54
51 services_.erase(service); 55 services_.erase(service);
52 } 56 }
53 57
54 ServiceWorkerContextWrapper* PaymentAppContextImpl::service_worker_context() 58 PaymentAppDatabase* PaymentAppContextImpl::payment_app_database() const {
55 const { 59 return payment_app_database_.get();
56 return service_worker_context_.get();
57 } 60 }
58 61
59 void PaymentAppContextImpl::GetAllManifests( 62 void PaymentAppContextImpl::GetAllManifests(
60 const GetAllManifestsCallback& callback) { 63 const GetAllManifestsCallback& callback) {
61 NOTIMPLEMENTED(); 64 NOTIMPLEMENTED();
62 } 65 }
63 66
67 PaymentAppContextImpl::~PaymentAppContextImpl() {
68 DCHECK(services_.empty());
69 DCHECK(!payment_app_database_);
70 }
71
72 void PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO(
73 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
74 DCHECK_CURRENTLY_ON(BrowserThread::IO);
75 payment_app_database_ =
76 base::WrapUnique(new PaymentAppDatabase(service_worker_context));
Avi (use Gerrit) 2016/12/14 17:10:11 MakeUnique unless there is some reason you can't u
zino 2016/12/14 17:27:41 Done.
77 }
78
64 void PaymentAppContextImpl::CreateServiceOnIOThread( 79 void PaymentAppContextImpl::CreateServiceOnIOThread(
65 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { 80 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) {
66 DCHECK_CURRENTLY_ON(BrowserThread::IO); 81 DCHECK_CURRENTLY_ON(BrowserThread::IO);
67 PaymentAppManager* service = new PaymentAppManager(this, std::move(request)); 82 PaymentAppManager* service = new PaymentAppManager(this, std::move(request));
68 services_[service] = base::WrapUnique(service); 83 services_[service] = base::WrapUnique(service);
69 } 84 }
70 85
71 void PaymentAppContextImpl::ShutdownOnIO() { 86 void PaymentAppContextImpl::ShutdownOnIO() {
72 DCHECK_CURRENTLY_ON(BrowserThread::IO); 87 DCHECK_CURRENTLY_ON(BrowserThread::IO);
73 88
74 services_.clear(); 89 services_.clear();
90 payment_app_database_.reset();
75 } 91 }
76 92
77 } // namespace content 93 } // 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