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_manager.h" | 5 #include "content/browser/payments/payment_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/optional.h" | 10 #include "base/optional.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 : payment_app_context_(payment_app_context), | 27 : payment_app_context_(payment_app_context), |
28 binding_(this, std::move(request)), | 28 binding_(this, std::move(request)), |
29 weak_ptr_factory_(this) { | 29 weak_ptr_factory_(this) { |
30 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 30 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
31 DCHECK(payment_app_context); | 31 DCHECK(payment_app_context); |
32 | 32 |
33 binding_.set_connection_error_handler( | 33 binding_.set_connection_error_handler( |
34 base::Bind(&PaymentManager::OnConnectionError, base::Unretained(this))); | 34 base::Bind(&PaymentManager::OnConnectionError, base::Unretained(this))); |
35 } | 35 } |
36 | 36 |
37 void PaymentManager::Init(const std::string& scope) { | 37 void PaymentManager::Init(const std::string& context, |
| 38 const std::string& scope) { |
38 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 40 should_set_payment_app_info_ = true; |
| 41 context_ = GURL(context); |
39 scope_ = GURL(scope); | 42 scope_ = GURL(scope); |
40 } | 43 } |
41 | 44 |
42 void PaymentManager::DeletePaymentInstrument( | 45 void PaymentManager::DeletePaymentInstrument( |
43 const std::string& instrument_key, | 46 const std::string& instrument_key, |
44 PaymentManager::DeletePaymentInstrumentCallback callback) { | 47 PaymentManager::DeletePaymentInstrumentCallback callback) { |
45 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
46 | 49 |
47 payment_app_context_->payment_app_database()->DeletePaymentInstrument( | 50 payment_app_context_->payment_app_database()->DeletePaymentInstrument( |
48 scope_, instrument_key, std::move(callback)); | 51 scope_, instrument_key, std::move(callback)); |
(...skipping 24 matching lines...) Expand all Loading... |
73 payment_app_context_->payment_app_database()->HasPaymentInstrument( | 76 payment_app_context_->payment_app_database()->HasPaymentInstrument( |
74 scope_, instrument_key, std::move(callback)); | 77 scope_, instrument_key, std::move(callback)); |
75 } | 78 } |
76 | 79 |
77 void PaymentManager::SetPaymentInstrument( | 80 void PaymentManager::SetPaymentInstrument( |
78 const std::string& instrument_key, | 81 const std::string& instrument_key, |
79 payments::mojom::PaymentInstrumentPtr details, | 82 payments::mojom::PaymentInstrumentPtr details, |
80 PaymentManager::SetPaymentInstrumentCallback callback) { | 83 PaymentManager::SetPaymentInstrumentCallback callback) { |
81 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 84 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
82 | 85 |
83 payment_app_context_->payment_app_database()->WritePaymentInstrument( | 86 if (should_set_payment_app_info_) { |
84 scope_, instrument_key, std::move(details), std::move(callback)); | 87 payment_app_context_->payment_app_database()->WritePaymentInstrument( |
| 88 scope_, instrument_key, std::move(details), |
| 89 base::BindOnce( |
| 90 &PaymentManager::SetPaymentInstrumentIntermediateCallback, |
| 91 weak_ptr_factory_.GetWeakPtr(), std::move(callback))); |
| 92 } else { |
| 93 payment_app_context_->payment_app_database()->WritePaymentInstrument( |
| 94 scope_, instrument_key, std::move(details), std::move(callback)); |
| 95 } |
| 96 } |
| 97 |
| 98 void PaymentManager::SetPaymentInstrumentIntermediateCallback( |
| 99 PaymentManager::SetPaymentInstrumentCallback callback, |
| 100 payments::mojom::PaymentHandlerStatus status) { |
| 101 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 102 |
| 103 if (status != payments::mojom::PaymentHandlerStatus::SUCCESS || |
| 104 !should_set_payment_app_info_) { |
| 105 std::move(callback).Run(status); |
| 106 return; |
| 107 } |
| 108 |
| 109 payment_app_context_->payment_app_database()->FetchAndWritePaymentAppInfo( |
| 110 context_, scope_, std::move(callback)); |
| 111 should_set_payment_app_info_ = false; |
85 } | 112 } |
86 | 113 |
87 void PaymentManager::ClearPaymentInstruments( | 114 void PaymentManager::ClearPaymentInstruments( |
88 ClearPaymentInstrumentsCallback callback) { | 115 ClearPaymentInstrumentsCallback callback) { |
89 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 116 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
90 | 117 |
91 payment_app_context_->payment_app_database()->ClearPaymentInstruments( | 118 payment_app_context_->payment_app_database()->ClearPaymentInstruments( |
92 scope_, std::move(callback)); | 119 scope_, std::move(callback)); |
93 } | 120 } |
94 | 121 |
95 void PaymentManager::OnConnectionError() { | 122 void PaymentManager::OnConnectionError() { |
96 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 123 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
97 payment_app_context_->PaymentManagerHadConnectionError(this); | 124 payment_app_context_->PaymentManagerHadConnectionError(this); |
98 } | 125 } |
99 | 126 |
100 } // namespace content | 127 } // namespace content |
OLD | NEW |