diff --git a/atom/browser/api/atom_api_content_tracing.cc b/atom/browser/api/atom_api_content_tracing.cc index 64159b1b99c5..3242305507e6 100644 --- a/atom/browser/api/atom_api_content_tracing.cc +++ b/atom/browser/api/atom_api_content_tracing.cc @@ -65,11 +65,6 @@ scoped_refptr 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 StopRecording(v8::Isolate* isolate, const base::FilePath& path) { atom::util::Promise promise(isolate); @@ -78,28 +73,22 @@ v8::Local 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& categories) { - promise.Resolve(categories); -} - v8::Local GetCategories(v8::Isolate* isolate) { atom::util::Promise promise(isolate); v8::Local 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&>, + std::move(promise))); -void OnTracingStarted(atom::util::Promise promise) { - promise.Resolve(); + return handle; } v8::Local StartTracing( @@ -110,7 +99,8 @@ v8::Local 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; } diff --git a/atom/browser/api/atom_api_cookies.cc b/atom/browser/api/atom_api_cookies.cc index 366db5a86e6f..2be84fd1cc85 100644 --- a/atom/browser/api/atom_api_cookies.cc +++ b/atom/browser/api/atom_api_cookies.cc @@ -149,7 +149,7 @@ void FilterCookies(std::unique_ptr filter, base::PostTaskWithTraits( FROM_HERE, {BrowserThread::UI}, - base::BindOnce(util::Promise::ResolvePromise, + base::BindOnce(util::Promise::ResolvePromise, std::move(promise), std::move(result))); } diff --git a/atom/browser/api/atom_api_net_log.cc b/atom/browser/api/atom_api_net_log.cc index 6eb1b704b8d7..3c1aea105145 100644 --- a/atom/browser/api/atom_api_net_log.cc +++ b/atom/browser/api/atom_api_net_log.cc @@ -19,15 +19,6 @@ #include "native_mate/handle.h" #include "net/url_request/url_request_context_getter.h" -namespace { - -void OnGetFilePathToCompletedLog(const atom::util::CopyablePromise& promise, - const base::FilePath& file_path) { - promise.GetPromise().Resolve(file_path); -} - -} // namespace - namespace atom { namespace api { @@ -120,7 +111,8 @@ void NetLog::OnNewState(const base::DictionaryValue& state) { // TODO(zcbenz): Remove the use of CopyablePromise when the // GetFilePathToCompletedLog API accepts OnceCallback. net_log_writer_->GetFilePathToCompletedLog(base::Bind( - &OnGetFilePathToCompletedLog, util::CopyablePromise(promise))); + util::CopyablePromise::ResolveCopyablePromise, + util::CopyablePromise(promise))); } stop_callback_queue_.clear(); } diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index ce1f97584869..25206d3d8f63 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -177,10 +177,6 @@ bool IsProtocolHandledInIO( return is_handled; } -void PromiseCallback(util::Promise promise, bool handled) { - promise.Resolve(handled); -} - v8::Local Protocol::IsProtocolHandled(const std::string& scheme) { util::Promise promise(isolate()); v8::Local handle = promise.GetHandle(); @@ -190,7 +186,7 @@ v8::Local Protocol::IsProtocolHandled(const std::string& scheme) { base::PostTaskWithTraitsAndReplyWithResult( FROM_HERE, {content::BrowserThread::IO}, base::BindOnce(&IsProtocolHandledInIO, base::RetainedRef(getter), scheme), - base::BindOnce(&PromiseCallback, std::move(promise))); + base::BindOnce(util::Promise::ResolvePromise, std::move(promise))); return handle; } diff --git a/atom/browser/api/atom_api_system_preferences_mac.mm b/atom/browser/api/atom_api_system_preferences_mac.mm index 2a7fc29ffaee..18930f8343e0 100644 --- a/atom/browser/api/atom_api_system_preferences_mac.mm +++ b/atom/browser/api/atom_api_system_preferences_mac.mm @@ -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 SystemPreferences::PromptTouchID( v8::Isolate* isolate, const std::string& reason) { @@ -486,16 +478,19 @@ v8::Local 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 { diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index c50bf589385f..e5f6b948d273 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1300,11 +1300,12 @@ v8::Local WebContents::SavePage( const base::FilePath& full_file_path, const content::SavePageType& save_type) { util::Promise promise(isolate()); - v8::Local ret = promise.GetHandle(); + v8::Local handle = promise.GetHandle(); auto* handler = new SavePageHandler(web_contents(), std::move(promise)); handler->Handle(full_file_path, save_type); - return ret; + + return handle; } void WebContents::OpenDevTools(mate::Arguments* args) {