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

@ -62,7 +62,8 @@ base::File OpenFileForWriting(base::FilePath path) {
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
}
void ResolvePromiseWithNetError(util::Promise<void*> promise, int32_t error) {
void ResolvePromiseWithNetError(gin_helper::Promise<void> promise,
int32_t error) {
if (error == net::OK) {
promise.Resolve();
} else {
@ -117,7 +118,8 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
return v8::Local<v8::Promise>();
}
pending_start_promise_ = base::make_optional<util::Promise<void*>>(isolate());
pending_start_promise_ =
base::make_optional<gin_helper::Promise<void>>(isolate());
v8::Local<v8::Promise> handle = pending_start_promise_->GetHandle();
auto command_line_string =
@ -187,7 +189,7 @@ bool NetLog::IsCurrentlyLogging() const {
}
v8::Local<v8::Promise> NetLog::StopLogging(gin_helper::Arguments* args) {
util::Promise<void*> promise(isolate());
gin_helper::Promise<void> promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
if (net_log_exporter_) {
@ -197,8 +199,8 @@ v8::Local<v8::Promise> NetLog::StopLogging(gin_helper::Arguments* args) {
net_log_exporter_->Stop(
base::Value(base::Value::Type::DICTIONARY),
base::BindOnce(
[](network::mojom::NetLogExporterPtr, util::Promise<void*> promise,
int32_t error) {
[](network::mojom::NetLogExporterPtr,
gin_helper::Promise<void> promise, int32_t error) {
ResolvePromiseWithNetError(std::move(promise), error);
},
std::move(net_log_exporter_), std::move(promise)));