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