power_observer_linux.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_LIB_POWER_OBSERVER_LINUX_H_
  5. #define ATOM_BROWSER_LIB_POWER_OBSERVER_LINUX_H_
  6. #include <string>
  7. #include "base/macros.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/power_monitor/power_observer.h"
  10. #include "dbus/bus.h"
  11. #include "dbus/message.h"
  12. #include "dbus/object_proxy.h"
  13. namespace atom {
  14. class PowerObserverLinux : public base::PowerObserver {
  15. public:
  16. PowerObserverLinux();
  17. ~PowerObserverLinux() override;
  18. protected:
  19. void BlockSleep();
  20. void UnblockSleep();
  21. void BlockShutdown();
  22. void UnblockShutdown();
  23. void SetShutdownHandler(base::Callback<bool()> should_shutdown);
  24. private:
  25. void OnLoginServiceAvailable(bool available);
  26. void OnInhibitResponse(base::ScopedFD* scoped_fd, dbus::Response* response);
  27. void OnPrepareForSleep(dbus::Signal* signal);
  28. void OnPrepareForShutdown(dbus::Signal* signal);
  29. void OnSignalConnected(const std::string& interface,
  30. const std::string& signal,
  31. bool success);
  32. base::Callback<bool()> should_shutdown_;
  33. scoped_refptr<dbus::Bus> bus_;
  34. scoped_refptr<dbus::ObjectProxy> logind_;
  35. std::string lock_owner_name_;
  36. base::ScopedFD sleep_lock_;
  37. base::ScopedFD shutdown_lock_;
  38. base::WeakPtrFactory<PowerObserverLinux> weak_ptr_factory_;
  39. DISALLOW_COPY_AND_ASSIGN(PowerObserverLinux);
  40. };
  41. } // namespace atom
  42. #endif // ATOM_BROWSER_LIB_POWER_OBSERVER_LINUX_H_