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

@ -9,9 +9,9 @@
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_includes.h"
#include "shell/common/platform_util.h"
#include "shell/common/promise_util.h"
#if defined(OS_WIN)
#include "base/win/scoped_com_initializer.h"
@ -44,7 +44,7 @@ struct Converter<base::win::ShortcutOperation> {
namespace {
void OnOpenExternalFinished(electron::util::Promise<void*> promise,
void OnOpenExternalFinished(gin_helper::Promise<void> promise,
const std::string& error) {
if (error.empty())
promise.Resolve();
@ -53,7 +53,7 @@ void OnOpenExternalFinished(electron::util::Promise<void*> promise,
}
v8::Local<v8::Promise> OpenExternal(const GURL& url, gin::Arguments* args) {
electron::util::Promise<void*> promise(args->isolate());
gin_helper::Promise<void> promise(args->isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
platform_util::OpenExternalOptions options;

View file

@ -25,9 +25,9 @@
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/locker.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/heap_snapshot.h"
#include "shell/common/node_includes.h"
#include "shell/common/promise_util.h"
#include "third_party/blink/renderer/platform/heap/process_heap.h" // nogncheck
namespace electron {
@ -231,7 +231,7 @@ v8::Local<v8::Value> ElectronBindings::GetSystemMemoryInfo(
// static
v8::Local<v8::Promise> ElectronBindings::GetProcessMemoryInfo(
v8::Isolate* isolate) {
util::Promise<gin_helper::Dictionary> promise(isolate);
gin_helper::Promise<gin_helper::Dictionary> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
if (gin_helper::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) {
@ -265,7 +265,7 @@ v8::Local<v8::Value> ElectronBindings::GetBlinkMemoryInfo(
// static
void ElectronBindings::DidReceiveMemoryDump(
v8::Global<v8::Context> context,
util::Promise<gin_helper::Dictionary> promise,
gin_helper::Promise<gin_helper::Dictionary> promise,
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> global_dump) {
v8::Isolate* isolate = promise.isolate();
@ -292,7 +292,7 @@ void ElectronBindings::DidReceiveMemoryDump(
#endif
dict.Set("private", osdump.private_footprint_kb);
dict.Set("shared", osdump.shared_footprint_kb);
promise.ResolveWithGin(dict);
promise.Resolve(dict);
resolved = true;
break;
}

View file

@ -13,7 +13,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/process/process_metrics.h"
#include "base/strings/string16.h"
#include "shell/common/promise_util.h"
#include "shell/common/gin_helper/promise.h"
#include "uv.h" // NOLINT(build/include)
namespace gin_helper {
@ -70,7 +70,7 @@ class ElectronBindings {
static void DidReceiveMemoryDump(
v8::Global<v8::Context> context,
util::Promise<gin_helper::Dictionary> promise,
gin_helper::Promise<gin_helper::Dictionary> promise,
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);