1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/payments/payment_manager.h"
#include <utility>
#include "base/bind.h"
#include "base/optional.h"
#include "content/browser/payments/payment_app.pb.h"
#include "content/browser/payments/payment_app_context_impl.h"
#include "content/browser/payments/payment_app_database.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/public/browser/browser_thread.h"
namespace content {
PaymentManager::~PaymentManager() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}
PaymentManager::PaymentManager(
PaymentAppContextImpl* payment_app_context,
mojo::InterfaceRequest<payments::mojom::PaymentManager> request)
: payment_app_context_(payment_app_context),
binding_(this, std::move(request)),
weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(payment_app_context);
binding_.set_connection_error_handler(
base::Bind(&PaymentManager::OnConnectionError, base::Unretained(this)));
}
void PaymentManager::Init(const std::string& scope) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
scope_ = GURL(scope);
}
void PaymentManager::DeletePaymentInstrument(
const std::string& instrument_key,
PaymentManager::DeletePaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->payment_app_database()->DeletePaymentInstrument(
scope_, instrument_key, std::move(callback));
}
void PaymentManager::GetPaymentInstrument(
const std::string& instrument_key,
PaymentManager::GetPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->payment_app_database()->ReadPaymentInstrument(
scope_, instrument_key, std::move(callback));
}
void PaymentManager::KeysOfPaymentInstruments(
PaymentManager::KeysOfPaymentInstrumentsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->payment_app_database()->KeysOfPaymentInstruments(
scope_, std::move(callback));
}
void PaymentManager::HasPaymentInstrument(
const std::string& instrument_key,
PaymentManager::HasPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->payment_app_database()->HasPaymentInstrument(
scope_, instrument_key, std::move(callback));
}
void PaymentManager::SetPaymentInstrument(
const std::string& instrument_key,
payments::mojom::PaymentInstrumentPtr details,
PaymentManager::SetPaymentInstrumentCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->payment_app_database()->WritePaymentInstrument(
scope_, instrument_key, std::move(details), std::move(callback));
}
void PaymentManager::ClearPaymentInstruments(
ClearPaymentInstrumentsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->payment_app_database()->ClearPaymentInstruments(
scope_, std::move(callback));
}
void PaymentManager::OnConnectionError() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->PaymentManagerHadConnectionError(this);
}
} // namespace content
|