hi_res_timer_manager.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/macros.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "base/power_monitor/power_observer.h"
  10. #include "base/timer/timer.h"
  11. #include "build/build_config.h"
  12. namespace base {
  13. // Ensures that the Windows high resolution timer is only used
  14. // when not running on battery power.
  15. class BASE_EXPORT HighResolutionTimerManager : public base::PowerObserver {
  16. public:
  17. HighResolutionTimerManager();
  18. ~HighResolutionTimerManager() override;
  19. // base::PowerObserver methods.
  20. void OnPowerStateChange(bool on_battery_power) override;
  21. void OnSuspend() override;
  22. void OnResume() override;
  23. // Returns true if the hi resolution clock could be used right now.
  24. bool hi_res_clock_available() const { return hi_res_clock_available_; }
  25. private:
  26. // Enable or disable the faster multimedia timer.
  27. void UseHiResClock(bool use);
  28. bool hi_res_clock_available_;
  29. #if defined(OS_WIN)
  30. // Timer for polling the high resolution timer usage.
  31. base::RepeatingTimer timer_;
  32. #endif
  33. DISALLOW_COPY_AND_ASSIGN(HighResolutionTimerManager);
  34. };
  35. } // namespace base
  36. #endif // BASE_TIMER_HI_RES_TIMER_MANAGER_H_