refactor: convert powerSaveBlocker to gin (#18073)
This commit is contained in:
parent
913bd4c832
commit
dd3913fada
2 changed files with 24 additions and 25 deletions
|
@ -7,15 +7,17 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
#include "base/bind_helpers.h"
|
||||||
#include "base/task/post_task.h"
|
#include "base/task/post_task.h"
|
||||||
#include "base/threading/thread_task_runner_handle.h"
|
#include "base/threading/thread_task_runner_handle.h"
|
||||||
#include "content/public/common/service_manager_connection.h"
|
#include "content/public/common/service_manager_connection.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
|
#include "gin/function_template.h"
|
||||||
#include "services/device/public/mojom/constants.mojom.h"
|
#include "services/device/public/mojom/constants.mojom.h"
|
||||||
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
|
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
|
||||||
#include "services/service_manager/public/cpp/connector.h"
|
#include "services/service_manager/public/cpp/connector.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<device::mojom::WakeLockType> {
|
struct Converter<device::mojom::WakeLockType> {
|
||||||
|
@ -35,17 +37,17 @@ struct Converter<device::mojom::WakeLockType> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
|
gin::WrapperInfo PowerSaveBlocker::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
|
|
||||||
PowerSaveBlocker::PowerSaveBlocker(v8::Isolate* isolate)
|
PowerSaveBlocker::PowerSaveBlocker(v8::Isolate* isolate)
|
||||||
: current_lock_type_(device::mojom::WakeLockType::kPreventAppSuspension),
|
: current_lock_type_(device::mojom::WakeLockType::kPreventAppSuspension),
|
||||||
is_wake_lock_active_(false) {
|
is_wake_lock_active_(false) {}
|
||||||
Init(isolate);
|
|
||||||
}
|
|
||||||
|
|
||||||
PowerSaveBlocker::~PowerSaveBlocker() {}
|
PowerSaveBlocker::~PowerSaveBlocker() {}
|
||||||
|
|
||||||
|
@ -118,16 +120,13 @@ bool PowerSaveBlocker::IsStarted(int id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<PowerSaveBlocker> PowerSaveBlocker::Create(v8::Isolate* isolate) {
|
gin::Handle<PowerSaveBlocker> PowerSaveBlocker::Create(v8::Isolate* isolate) {
|
||||||
return mate::CreateHandle(isolate, new PowerSaveBlocker(isolate));
|
return gin::CreateHandle(isolate, new PowerSaveBlocker(isolate));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
gin::ObjectTemplateBuilder PowerSaveBlocker::GetObjectTemplateBuilder(
|
||||||
void PowerSaveBlocker::BuildPrototype(
|
v8::Isolate* isolate) {
|
||||||
v8::Isolate* isolate,
|
return gin::Wrappable<PowerSaveBlocker>::GetObjectTemplateBuilder(isolate)
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "PowerSaveBlocker"));
|
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
|
||||||
.SetMethod("start", &PowerSaveBlocker::Start)
|
.SetMethod("start", &PowerSaveBlocker::Start)
|
||||||
.SetMethod("stop", &PowerSaveBlocker::Stop)
|
.SetMethod("stop", &PowerSaveBlocker::Stop)
|
||||||
.SetMethod("isStarted", &PowerSaveBlocker::IsStarted);
|
.SetMethod("isStarted", &PowerSaveBlocker::IsStarted);
|
||||||
|
@ -144,7 +143,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
gin::Dictionary dict(isolate, exports);
|
||||||
dict.Set("powerSaveBlocker", atom::api::PowerSaveBlocker::Create(isolate));
|
dict.Set("powerSaveBlocker", atom::api::PowerSaveBlocker::Create(isolate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,24 +8,24 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "atom/browser/api/trackable_object.h"
|
#include "gin/handle.h"
|
||||||
#include "native_mate/handle.h"
|
#include "gin/object_template_builder.h"
|
||||||
|
#include "gin/wrappable.h"
|
||||||
#include "services/device/public/mojom/wake_lock.mojom.h"
|
#include "services/device/public/mojom/wake_lock.mojom.h"
|
||||||
|
|
||||||
namespace mate {
|
|
||||||
class Dictionary;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class PowerSaveBlocker : public mate::TrackableObject<PowerSaveBlocker> {
|
class PowerSaveBlocker : public gin::Wrappable<PowerSaveBlocker> {
|
||||||
public:
|
public:
|
||||||
static mate::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
|
static gin::Handle<PowerSaveBlocker> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
// gin::Wrappable
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
v8::Isolate* isolate) override;
|
||||||
|
|
||||||
|
static gin::WrapperInfo kWrapperInfo;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit PowerSaveBlocker(v8::Isolate* isolate);
|
explicit PowerSaveBlocker(v8::Isolate* isolate);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue