chore: make util::Promise a move-only type (#17071)
This commit is contained in:
parent
a40d826b11
commit
32a4de4a68
29 changed files with 325 additions and 260 deletions
|
@ -44,12 +44,12 @@ struct Converter<base::win::ShortcutOperation> {
|
|||
|
||||
namespace {
|
||||
|
||||
void OnOpenExternalFinished(scoped_refptr<atom::util::Promise> promise,
|
||||
void OnOpenExternalFinished(atom::util::Promise promise,
|
||||
const std::string& error) {
|
||||
if (error.empty())
|
||||
promise->Resolve();
|
||||
promise.Resolve();
|
||||
else
|
||||
promise->RejectWithErrorMessage(error.c_str());
|
||||
promise.RejectWithErrorMessage(error.c_str());
|
||||
}
|
||||
|
||||
bool OpenExternalSync(
|
||||
|
@ -78,8 +78,7 @@ v8::Local<v8::Promise> OpenExternal(
|
|||
const GURL& url,
|
||||
#endif
|
||||
mate::Arguments* args) {
|
||||
scoped_refptr<atom::util::Promise> promise =
|
||||
new atom::util::Promise(args->isolate());
|
||||
atom::util::Promise promise(args->isolate());
|
||||
|
||||
platform_util::OpenExternalOptions options;
|
||||
if (args->Length() >= 2) {
|
||||
|
@ -90,10 +89,11 @@ v8::Local<v8::Promise> OpenExternal(
|
|||
}
|
||||
}
|
||||
|
||||
platform_util::OpenExternal(url, options,
|
||||
base::Bind(&OnOpenExternalFinished, promise));
|
||||
|
||||
return promise->GetHandle();
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
platform_util::OpenExternal(
|
||||
url, options,
|
||||
base::BindOnce(&OnOpenExternalFinished, std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "atom/common/heap_snapshot.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "atom/common/promise_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/process/process.h"
|
||||
#include "base/process/process_handle.h"
|
||||
|
@ -233,30 +232,31 @@ v8::Local<v8::Value> AtomBindings::GetSystemMemoryInfo(v8::Isolate* isolate,
|
|||
// static
|
||||
v8::Local<v8::Promise> AtomBindings::GetProcessMemoryInfo(
|
||||
v8::Isolate* isolate) {
|
||||
scoped_refptr<util::Promise> promise = new util::Promise(isolate);
|
||||
util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
if (mate::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) {
|
||||
promise->RejectWithErrorMessage(
|
||||
promise.RejectWithErrorMessage(
|
||||
"Memory Info is available only after app ready");
|
||||
return promise->GetHandle();
|
||||
return handle;
|
||||
}
|
||||
|
||||
v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext());
|
||||
memory_instrumentation::MemoryInstrumentation::GetInstance()
|
||||
->RequestGlobalDumpForPid(base::GetCurrentProcId(),
|
||||
std::vector<std::string>(),
|
||||
base::Bind(&AtomBindings::DidReceiveMemoryDump,
|
||||
std::move(context), promise));
|
||||
return promise->GetHandle();
|
||||
->RequestGlobalDumpForPid(
|
||||
base::GetCurrentProcId(), std::vector<std::string>(),
|
||||
base::BindOnce(&AtomBindings::DidReceiveMemoryDump,
|
||||
std::move(context), std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
|
||||
// static
|
||||
void AtomBindings::DidReceiveMemoryDump(
|
||||
const v8::Global<v8::Context>& context,
|
||||
scoped_refptr<util::Promise> promise,
|
||||
v8::Global<v8::Context> context,
|
||||
util::Promise promise,
|
||||
bool success,
|
||||
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> global_dump) {
|
||||
v8::Isolate* isolate = promise->isolate();
|
||||
v8::Isolate* isolate = promise.isolate();
|
||||
mate::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::MicrotasksScope script_scope(isolate,
|
||||
|
@ -265,7 +265,7 @@ void AtomBindings::DidReceiveMemoryDump(
|
|||
v8::Local<v8::Context>::New(isolate, context));
|
||||
|
||||
if (!success) {
|
||||
promise->RejectWithErrorMessage("Failed to create memory dump");
|
||||
promise.RejectWithErrorMessage("Failed to create memory dump");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -280,13 +280,13 @@ void AtomBindings::DidReceiveMemoryDump(
|
|||
#endif
|
||||
dict.Set("private", osdump.private_footprint_kb);
|
||||
dict.Set("shared", osdump.shared_footprint_kb);
|
||||
promise->Resolve(dict.GetHandle());
|
||||
promise.Resolve(dict.GetHandle());
|
||||
resolved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!resolved) {
|
||||
promise->RejectWithErrorMessage(
|
||||
promise.RejectWithErrorMessage(
|
||||
R"(Failed to find current process memory details in memory dump)");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include "atom/common/promise_util.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
|
@ -31,10 +32,6 @@ class Environment;
|
|||
|
||||
namespace atom {
|
||||
|
||||
namespace util {
|
||||
class Promise;
|
||||
}
|
||||
|
||||
class AtomBindings {
|
||||
public:
|
||||
explicit AtomBindings(uv_loop_t* loop);
|
||||
|
@ -72,8 +69,8 @@ class AtomBindings {
|
|||
static void OnCallNextTick(uv_async_t* handle);
|
||||
|
||||
static void DidReceiveMemoryDump(
|
||||
const v8::Global<v8::Context>& context,
|
||||
scoped_refptr<util::Promise> promise,
|
||||
v8::Global<v8::Context> context,
|
||||
util::Promise promise,
|
||||
bool success,
|
||||
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> dump);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue