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

@ -65,11 +65,6 @@ scoped_refptr<TracingController::TraceDataEndpoint> GetTraceDataEndpoint(
result_file_path, base::Bind(callback, result_file_path));
}
void OnRecordingStopped(const atom::util::CopyablePromise& promise,
const base::FilePath& path) {
promise.GetPromise().Resolve(path);
}
v8::Local<v8::Promise> StopRecording(v8::Isolate* isolate,
const base::FilePath& path) {
atom::util::Promise promise(isolate);
@ -78,28 +73,22 @@ v8::Local<v8::Promise> StopRecording(v8::Isolate* isolate,
// TODO(zcbenz): Remove the use of CopyablePromise when the
// CreateFileEndpoint API accepts OnceCallback.
TracingController::GetInstance()->StopTracing(GetTraceDataEndpoint(
path,
base::Bind(&OnRecordingStopped, atom::util::CopyablePromise(promise))));
path, base::Bind(atom::util::CopyablePromise::ResolveCopyablePromise<
const base::FilePath&>,
atom::util::CopyablePromise(promise))));
return handle;
}
void OnCategoriesAvailable(atom::util::Promise promise,
const std::set<std::string>& categories) {
promise.Resolve(categories);
}
v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
atom::util::Promise promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
// Note: This method always succeeds.
TracingController::GetInstance()->GetCategories(
base::BindOnce(&OnCategoriesAvailable, std::move(promise)));
return handle;
}
TracingController::GetInstance()->GetCategories(base::BindOnce(
atom::util::Promise::ResolvePromise<const std::set<std::string>&>,
std::move(promise)));
void OnTracingStarted(atom::util::Promise promise) {
promise.Resolve();
return handle;
}
v8::Local<v8::Promise> StartTracing(
@ -110,7 +99,8 @@ v8::Local<v8::Promise> StartTracing(
// Note: This method always succeeds.
TracingController::GetInstance()->StartTracing(
trace_config, base::BindOnce(&OnTracingStarted, std::move(promise)));
trace_config, base::BindOnce(atom::util::Promise::ResolveEmptyPromise,
std::move(promise)));
return handle;
}