timer_sampling_event_source.h 978 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2021 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_POWER_MONITOR_TIMER_SAMPLING_EVENT_SOURCE_H_
  5. #define BASE_POWER_MONITOR_TIMER_SAMPLING_EVENT_SOURCE_H_
  6. #include "base/base_export.h"
  7. #include "base/power_monitor/sampling_event_source.h"
  8. #include "base/time/time.h"
  9. #include "base/timer/timer.h"
  10. namespace base {
  11. // Generates a sampling event at regular time intervals.
  12. class BASE_EXPORT TimerSamplingEventSource : public SamplingEventSource {
  13. public:
  14. // |interval| is the time interval between sampling events.
  15. explicit TimerSamplingEventSource(TimeDelta interval);
  16. ~TimerSamplingEventSource() override;
  17. // SamplingEventSource:
  18. bool Start(SamplingEventCallback callback) override;
  19. private:
  20. const TimeDelta interval_;
  21. RepeatingTimer timer_;
  22. };
  23. } // namespace base
  24. #endif // BASE_POWER_MONITOR_TIMER_SAMPLING_EVENT_SOURCE_H_