tick_clock.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_TIME_TICK_CLOCK_H_
  5. #define BASE_TIME_TICK_CLOCK_H_
  6. #include "base/base_export.h"
  7. #include "base/time/time.h"
  8. namespace base {
  9. // A TickClock is an interface for objects that vend TimeTicks. It is
  10. // intended to be able to test the behavior of classes with respect to
  11. // non-decreasing time.
  12. //
  13. // Note: Overriding Time/TimeTicks altogether via
  14. // TaskEnvironment::TimeSource::MOCK_TIME is now the preferred way of overriding
  15. // time in unit tests. As such, there shouldn't be many new use cases for
  16. // TickClock/DefaultTickClock anymore.
  17. //
  18. // See DefaultTickClock (base/time/default_tick_clock.h) for the default
  19. // implementation that simply uses TimeTicks::Now().
  20. //
  21. // (Other implementations that use TimeTicks::NowFromSystemTime() should
  22. // be added as needed.)
  23. //
  24. // See SimpleTestTickClock (base/test/simple_test_tick_clock.h) for a
  25. // simple test implementation.
  26. //
  27. // See Clock (base/time/clock.h) for the equivalent interface for Times.
  28. class BASE_EXPORT TickClock {
  29. public:
  30. virtual ~TickClock();
  31. // NowTicks() must be safe to call from any thread. The caller may
  32. // assume that NowTicks() is monotonic (but not strictly monotonic).
  33. // In other words, the returned TimeTicks will never decrease with
  34. // time, although they might "stand still".
  35. virtual TimeTicks NowTicks() const = 0;
  36. };
  37. } // namespace base
  38. #endif // BASE_TIME_TICK_CLOCK_H_