atom_api_power_monitor.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2013 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_API_ATOM_API_POWER_MONITOR_H_
  5. #define ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_
  6. #include "atom/browser/api/trackable_object.h"
  7. #include "atom/browser/lib/power_observer.h"
  8. #include "base/compiler_specific.h"
  9. #include "native_mate/handle.h"
  10. #include "ui/base/idle/idle.h"
  11. namespace atom {
  12. namespace api {
  13. class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
  14. public PowerObserver {
  15. public:
  16. static v8::Local<v8::Value> Create(v8::Isolate* isolate);
  17. static void BuildPrototype(v8::Isolate* isolate,
  18. v8::Local<v8::FunctionTemplate> prototype);
  19. protected:
  20. explicit PowerMonitor(v8::Isolate* isolate);
  21. ~PowerMonitor() override;
  22. // Called by native calles.
  23. bool ShouldShutdown();
  24. #if defined(OS_LINUX)
  25. // Private JS APIs.
  26. void BlockShutdown();
  27. void UnblockShutdown();
  28. #endif
  29. #if defined(OS_MACOSX) || defined(OS_WIN)
  30. void InitPlatformSpecificMonitors();
  31. #endif
  32. // base::PowerObserver implementations:
  33. void OnPowerStateChange(bool on_battery_power) override;
  34. void OnSuspend() override;
  35. void OnResume() override;
  36. private:
  37. void QuerySystemIdleState(v8::Isolate* isolate,
  38. int idle_threshold,
  39. const ui::IdleCallback& callback);
  40. void QuerySystemIdleTime(const ui::IdleTimeCallback& callback);
  41. #if defined(OS_WIN)
  42. // Static callback invoked when a message comes in to our messaging window.
  43. static LRESULT CALLBACK WndProcStatic(HWND hwnd,
  44. UINT message,
  45. WPARAM wparam,
  46. LPARAM lparam);
  47. LRESULT CALLBACK WndProc(HWND hwnd,
  48. UINT message,
  49. WPARAM wparam,
  50. LPARAM lparam);
  51. // The window class of |window_|.
  52. ATOM atom_;
  53. // The handle of the module that contains the window procedure of |window_|.
  54. HMODULE instance_;
  55. // The window used for processing events.
  56. HWND window_;
  57. #endif
  58. DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
  59. };
  60. } // namespace api
  61. } // namespace atom
  62. #endif // ATOM_BROWSER_API_ATOM_API_POWER_MONITOR_H_