simple_test_tick_clock.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2012 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_TEST_SIMPLE_TEST_TICK_CLOCK_H_
  5. #define BASE_TEST_SIMPLE_TEST_TICK_CLOCK_H_
  6. #include "base/compiler_specific.h"
  7. #include "base/synchronization/lock.h"
  8. #include "base/time/tick_clock.h"
  9. #include "base/time/time.h"
  10. namespace base {
  11. // SimpleTestTickClock is a TickClock implementation that gives
  12. // control over the returned TimeTicks objects. All methods may be
  13. // called from any thread.
  14. class SimpleTestTickClock : public TickClock {
  15. public:
  16. // Starts off with a clock set to TimeTicks().
  17. SimpleTestTickClock();
  18. ~SimpleTestTickClock() override;
  19. TimeTicks NowTicks() const override;
  20. // Advances the clock by |delta|, which must not be negative.
  21. void Advance(TimeDelta delta);
  22. // Sets the clock to the given time.
  23. void SetNowTicks(TimeTicks ticks);
  24. private:
  25. // Protects |now_ticks_|.
  26. mutable Lock lock_;
  27. TimeTicks now_ticks_;
  28. };
  29. } // namespace base
  30. #endif // BASE_TEST_SIMPLE_TEST_TICK_CLOCK_H_