feat: promisify In-App Purchase (#17355)
* feat: promisify In-App Purchase * use mate::Arguments in GetProducts
This commit is contained in:
parent
faabd0cc8b
commit
3e5a98b5f4
11 changed files with 113 additions and 46 deletions
|
@ -25,7 +25,7 @@
|
|||
NSInteger quantity_;
|
||||
}
|
||||
|
||||
- (id)initWithCallback:(const in_app_purchase::InAppPurchaseCallback&)callback
|
||||
- (id)initWithCallback:(in_app_purchase::InAppPurchaseCallback)callback
|
||||
quantity:(NSInteger)quantity;
|
||||
|
||||
- (void)purchaseProduct:(NSString*)productID;
|
||||
|
@ -42,10 +42,10 @@
|
|||
* @param callback - The callback that will be called when the payment is added
|
||||
* to the queue.
|
||||
*/
|
||||
- (id)initWithCallback:(const in_app_purchase::InAppPurchaseCallback&)callback
|
||||
- (id)initWithCallback:(in_app_purchase::InAppPurchaseCallback)callback
|
||||
quantity:(NSInteger)quantity {
|
||||
if ((self = [super init])) {
|
||||
callback_ = callback;
|
||||
callback_ = std::move(callback);
|
||||
quantity_ = quantity;
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,9 @@
|
|||
*/
|
||||
- (void)runCallback:(bool)isProductValid {
|
||||
if (callback_) {
|
||||
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
|
||||
base::Bind(callback_, isProductValid));
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {content::BrowserThread::UI},
|
||||
base::BindOnce(std::move(callback_), isProductValid));
|
||||
}
|
||||
// Release this delegate.
|
||||
[self release];
|
||||
|
@ -177,9 +178,9 @@ std::string GetReceiptURL() {
|
|||
|
||||
void PurchaseProduct(const std::string& productID,
|
||||
int quantity,
|
||||
const InAppPurchaseCallback& callback) {
|
||||
auto* iap =
|
||||
[[InAppPurchase alloc] initWithCallback:callback quantity:quantity];
|
||||
InAppPurchaseCallback callback) {
|
||||
auto* iap = [[InAppPurchase alloc] initWithCallback:std::move(callback)
|
||||
quantity:quantity];
|
||||
|
||||
[iap purchaseProduct:base::SysUTF8ToNSString(productID)];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue