chore: clean up promise resoution with helpers (#17268)

This commit is contained in:
Shelley Vohr 2019-03-13 14:30:21 -07:00 committed by GitHub
parent 3e5a98b5f4
commit d9234798d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 52 deletions

View file

@ -451,14 +451,6 @@ bool SystemPreferences::CanPromptTouchID() {
return false;
}
void OnTouchIDCompleted(util::Promise promise) {
promise.Resolve();
}
void OnTouchIDFailed(util::Promise promise, const std::string& reason) {
promise.RejectWithErrorMessage(reason);
}
v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
v8::Isolate* isolate,
const std::string& reason) {
@ -486,16 +478,19 @@ v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
localizedReason:[NSString stringWithUTF8String:reason.c_str()]
reply:^(BOOL success, NSError* error) {
if (!success) {
std::string err_msg = std::string(
[error.localizedDescription UTF8String]);
runner->PostTask(
FROM_HERE,
base::BindOnce(util::Promise::RejectPromise,
std::move(p),
std::move(err_msg)));
} else {
runner->PostTask(
FROM_HERE,
base::BindOnce(
&OnTouchIDFailed, std::move(p),
std::string([error.localizedDescription
UTF8String])));
} else {
runner->PostTask(FROM_HERE,
base::BindOnce(&OnTouchIDCompleted,
std::move(p)));
util::Promise::ResolveEmptyPromise,
std::move(p)));
}
}];
} else {