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

@ -114,6 +114,10 @@ void PowerObserverLinux::UnblockShutdown() {
shutdown_lock_.reset();
}
void PowerObserverLinux::SetShutdownHandler(base::Callback<bool()> handler) {
should_shutdown_ = std::move(handler);
}
void PowerObserverLinux::OnInhibitResponse(base::ScopedFD* scoped_fd,
dbus::Response* response) {
dbus::MessageReader reader(response);
@ -144,7 +148,7 @@ void PowerObserverLinux::OnPrepareForShutdown(dbus::Signal* signal) {
return;
}
if (shutting_down) {
if (!OnShutdown()) {
if (!should_shutdown_ || !should_shutdown_.Run()) {
// The user didn't try to prevent shutdown. Release the lock and allow the
// shutdown to continue normally.
shutdown_lock_.reset();