Do not use virtual function to request shutdown

Would make it easier to port to other platforms.
This commit is contained in:
Cheng Zhao 2018-02-05 15:49:43 +09:00
parent 8ae3d9dd0b
commit 109e2c760f
4 changed files with 36 additions and 13 deletions

View file

@ -16,6 +16,11 @@ namespace atom {
namespace api {
PowerMonitor::PowerMonitor(v8::Isolate* isolate) {
#if defined(OS_LINUX)
SetShutdownHandler(base::Bind(&PowerMonitor::ShouldShutdown,
// Passed to base class, no need for weak ptr.
base::Unretained(this)));
#endif
base::PowerMonitor::Get()->AddObserver(this);
Init(isolate);
}
@ -24,6 +29,20 @@ PowerMonitor::~PowerMonitor() {
base::PowerMonitor::Get()->RemoveObserver(this);
}
bool PowerMonitor::ShouldShutdown() {
return Emit("shutdown");
}
#if defined(OS_LINUX)
void PowerMonitor::BlockShutdown() {
PowerObserverLinux::BlockShutdown();
}
void PowerMonitor::UnblockShutdown() {
PowerObserverLinux::UnblockShutdown();
}
#endif
void PowerMonitor::OnPowerStateChange(bool on_battery_power) {
if (on_battery_power)
Emit("on-battery");
@ -39,12 +58,6 @@ void PowerMonitor::OnResume() {
Emit("resume");
}
#if defined(OS_LINUX)
bool PowerMonitor::OnShutdown() {
return Emit("shutdown");
}
#endif
// static
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
if (!Browser::Get()->is_ready()) {