refactor: ginify powerMonitor (#22751)

This commit is contained in:
Jeremy Apthorp 2020-03-24 09:03:29 -07:00 committed by GitHub
parent aeae0d47bd
commit 07cd70a37e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 216 additions and 176 deletions

View file

@ -5,36 +5,44 @@
#ifndef SHELL_BROWSER_API_ELECTRON_API_POWER_MONITOR_H_
#define SHELL_BROWSER_API_ELECTRON_API_POWER_MONITOR_H_
#include "base/compiler_specific.h"
#include "shell/browser/lib/power_observer.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "base/power_monitor/power_observer.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/common/gin_helper/pinnable.h"
#include "ui/base/idle/idle.h"
#if defined(OS_LINUX)
#include "shell/browser/lib/power_observer_linux.h"
#endif
namespace electron {
namespace api {
class PowerMonitor : public gin_helper::TrackableObject<PowerMonitor>,
public PowerObserver {
class PowerMonitor : public gin::Wrappable<PowerMonitor>,
public gin_helper::EventEmitterMixin<PowerMonitor>,
public gin_helper::Pinnable<PowerMonitor>,
public base::PowerObserver {
public:
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
const char* GetTypeName() override;
protected:
private:
explicit PowerMonitor(v8::Isolate* isolate);
~PowerMonitor() override;
#if defined(OS_LINUX)
void SetListeningForShutdown(bool);
#endif
// Called by native calles.
bool ShouldShutdown();
#if defined(OS_LINUX)
// Private JS APIs.
void BlockShutdown();
void UnblockShutdown();
#endif
#if defined(OS_MACOSX) || defined(OS_WIN)
void InitPlatformSpecificMonitors();
#endif
@ -44,10 +52,6 @@ class PowerMonitor : public gin_helper::TrackableObject<PowerMonitor>,
void OnSuspend() override;
void OnResume() override;
private:
ui::IdleState GetSystemIdleState(v8::Isolate* isolate, int idle_threshold);
int GetSystemIdleTime();
#if defined(OS_WIN)
// Static callback invoked when a message comes in to our messaging window.
static LRESULT CALLBACK WndProcStatic(HWND hwnd,
@ -70,6 +74,12 @@ class PowerMonitor : public gin_helper::TrackableObject<PowerMonitor>,
HWND window_;
#endif
#if defined(OS_LINUX)
PowerObserverLinux power_observer_linux_{this};
#endif
v8::Global<v8::Value> pinned_;
DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
};