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:
parent
bff113760a
commit
eaf2c61bef
48 changed files with 483 additions and 479 deletions
|
@ -298,11 +298,10 @@ bool ShowOpenDialogSync(const DialogSettings& settings,
|
|||
return true;
|
||||
}
|
||||
|
||||
void OpenDialogCompletion(
|
||||
int chosen,
|
||||
NSOpenPanel* dialog,
|
||||
bool security_scoped_bookmarks,
|
||||
electron::util::Promise<gin_helper::Dictionary> promise) {
|
||||
void OpenDialogCompletion(int chosen,
|
||||
NSOpenPanel* dialog,
|
||||
bool security_scoped_bookmarks,
|
||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||
dict.Set("canceled", true);
|
||||
|
@ -310,7 +309,7 @@ void OpenDialogCompletion(
|
|||
#if defined(MAS_BUILD)
|
||||
dict.Set("bookmarks", std::vector<std::string>());
|
||||
#endif
|
||||
promise.ResolveWithGin(dict);
|
||||
promise.Resolve(dict);
|
||||
} else {
|
||||
std::vector<base::FilePath> paths;
|
||||
dict.Set("canceled", false);
|
||||
|
@ -326,12 +325,12 @@ void OpenDialogCompletion(
|
|||
ReadDialogPaths(dialog, &paths);
|
||||
dict.Set("filePaths", paths);
|
||||
#endif
|
||||
promise.ResolveWithGin(dict);
|
||||
promise.Resolve(dict);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowOpenDialog(const DialogSettings& settings,
|
||||
electron::util::Promise<gin_helper::Dictionary> promise) {
|
||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||
NSOpenPanel* dialog = [NSOpenPanel openPanel];
|
||||
|
||||
SetupDialog(dialog, settings);
|
||||
|
@ -341,8 +340,7 @@ void ShowOpenDialog(const DialogSettings& settings,
|
|||
// and pass it to the completion handler.
|
||||
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
||||
|
||||
__block electron::util::Promise<gin_helper::Dictionary> p =
|
||||
std::move(promise);
|
||||
__block gin_helper::Promise<gin_helper::Dictionary> p = std::move(promise);
|
||||
|
||||
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
||||
settings.force_detached) {
|
||||
|
@ -377,11 +375,10 @@ bool ShowSaveDialogSync(const DialogSettings& settings, base::FilePath* path) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void SaveDialogCompletion(
|
||||
int chosen,
|
||||
NSSavePanel* dialog,
|
||||
bool security_scoped_bookmarks,
|
||||
electron::util::Promise<gin_helper::Dictionary> promise) {
|
||||
void SaveDialogCompletion(int chosen,
|
||||
NSSavePanel* dialog,
|
||||
bool security_scoped_bookmarks,
|
||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||
dict.Set("canceled", true);
|
||||
|
@ -401,11 +398,11 @@ void SaveDialogCompletion(
|
|||
}
|
||||
#endif
|
||||
}
|
||||
promise.ResolveWithGin(dict);
|
||||
promise.Resolve(dict);
|
||||
}
|
||||
|
||||
void ShowSaveDialog(const DialogSettings& settings,
|
||||
electron::util::Promise<gin_helper::Dictionary> promise) {
|
||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||
NSSavePanel* dialog = [NSSavePanel savePanel];
|
||||
|
||||
SetupDialog(dialog, settings);
|
||||
|
@ -416,8 +413,7 @@ void ShowSaveDialog(const DialogSettings& settings,
|
|||
// and pass it to the completion handler.
|
||||
bool security_scoped_bookmarks = settings.security_scoped_bookmarks;
|
||||
|
||||
__block electron::util::Promise<gin_helper::Dictionary> p =
|
||||
std::move(promise);
|
||||
__block gin_helper::Promise<gin_helper::Dictionary> p = std::move(promise);
|
||||
|
||||
if (!settings.parent_window || !settings.parent_window->GetNativeWindow() ||
|
||||
settings.force_detached) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue