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