refactor: migrates util::Promise to gin (#20871)

* refactor: use gin in Promise

* refactor: separate Promise impl that returns nothing

* refactor: use Promise<void> for promise that returns nothing

* fix: methods should be able to run on both browser and renderer process

* fix: should not pass base::StringPiece across threads

* refactor: no more need to use different ResolvePromise for empty Promise

* refactor: move Promise to gin_helper
This commit is contained in:
Cheng Zhao 2019-11-01 15:10:32 +09:00 committed by GitHub
parent bff113760a
commit eaf2c61bef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 483 additions and 479 deletions

View file

@ -104,7 +104,7 @@ v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
const std::string& product_id,
gin::Arguments* args) {
v8::Isolate* isolate = args->isolate();
electron::util::Promise<bool> promise(isolate);
gin_helper::Promise<bool> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
int quantity = 1;
@ -112,7 +112,8 @@ v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
in_app_purchase::PurchaseProduct(
product_id, quantity,
base::BindOnce(util::Promise<bool>::ResolvePromise, std::move(promise)));
base::BindOnce(gin_helper::Promise<bool>::ResolvePromise,
std::move(promise)));
return handle;
}
@ -121,15 +122,14 @@ v8::Local<v8::Promise> InAppPurchase::GetProducts(
const std::vector<std::string>& productIDs,
gin::Arguments* args) {
v8::Isolate* isolate = args->isolate();
electron::util::Promise<std::vector<in_app_purchase::Product>> promise(
isolate);
gin_helper::Promise<std::vector<in_app_purchase::Product>> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
in_app_purchase::GetProducts(
productIDs,
base::BindOnce(
util::Promise<std::vector<in_app_purchase::Product>>::ResolvePromise,
std::move(promise)));
base::BindOnce(gin_helper::Promise<
std::vector<in_app_purchase::Product>>::ResolvePromise,
std::move(promise)));
return handle;
}