hi_res_timer_manager.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_TIMER_HI_RES_TIMER_MANAGER_H_
  5. #define BASE_TIMER_HI_RES_TIMER_MANAGER_H_
  6. #include "base/base_export.h"
  7. #include "base/power_monitor/power_observer.h"
  8. #include "base/timer/timer.h"
  9. #include "build/build_config.h"
  10. namespace base {
  11. // Ensures that the Windows high resolution timer is only used
  12. // when not running on battery power.
  13. class BASE_EXPORT HighResolutionTimerManager
  14. : public base::PowerSuspendObserver,
  15. public base::PowerStateObserver {
  16. public:
  17. HighResolutionTimerManager();
  18. HighResolutionTimerManager(const HighResolutionTimerManager&) = delete;
  19. HighResolutionTimerManager& operator=(const HighResolutionTimerManager&) =
  20. delete;
  21. ~HighResolutionTimerManager() override;
  22. // base::PowerStateObserver methods.
  23. void OnPowerStateChange(bool on_battery_power) override;
  24. // base::PowerSuspendObserver methods.
  25. void OnSuspend() override;
  26. void OnResume() override;
  27. // Returns true if the hi resolution clock could be used right now.
  28. bool hi_res_clock_available() const { return hi_res_clock_available_; }
  29. private:
  30. // Enable or disable the faster multimedia timer.
  31. void UseHiResClock(bool use);
  32. bool hi_res_clock_available_;
  33. #if BUILDFLAG(IS_WIN)
  34. // Timer for polling the high resolution timer usage.
  35. base::RepeatingTimer timer_;
  36. #endif
  37. };
  38. } // namespace base
  39. #endif // BASE_TIMER_HI_RES_TIMER_MANAGER_H_