blob: 0cbcf08263282d9a1581d24a7977ba9e224d3c4f [file] [log] [blame]
[email protected]0cb3d72e2013-02-21 21:50:341// 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
danakj0a448602015-03-10 00:31:165#ifndef BASE_TEST_SIMPLE_TEST_CLOCK_H_
6#define BASE_TEST_SIMPLE_TEST_CLOCK_H_
[email protected]0cb3d72e2013-02-21 21:50:347
8#include "base/compiler_specific.h"
9#include "base/synchronization/lock.h"
[email protected]0cb3d72e2013-02-21 21:50:3410#include "base/time/clock.h"
[email protected]8f9a3a52013-06-28 15:14:1811#include "base/time/time.h"
[email protected]0cb3d72e2013-02-21 21:50:3412
13namespace base {
14
15// SimpleTestClock is a Clock implementation that gives control over
[email protected]014eb202013-02-26 01:51:1716// the returned Time objects. All methods may be called from any
[email protected]0cb3d72e2013-02-21 21:50:3417// thread.
18class SimpleTestClock : public Clock {
19 public:
20 // Starts off with a clock set to Time().
21 SimpleTestClock();
dcheng56488182014-10-21 10:54:5122 ~SimpleTestClock() override;
[email protected]0cb3d72e2013-02-21 21:50:3423
tzikee78e4962018-04-13 12:25:4624 Time Now() const override;
[email protected]0cb3d72e2013-02-21 21:50:3425
[email protected]014eb202013-02-26 01:51:1726 // Advances the clock by |delta|.
[email protected]0cb3d72e2013-02-21 21:50:3427 void Advance(TimeDelta delta);
28
[email protected]014eb202013-02-26 01:51:1729 // Sets the clock to the given time.
30 void SetNow(Time now);
31
[email protected]0cb3d72e2013-02-21 21:50:3432 private:
33 // Protects |now_|.
tzikee78e4962018-04-13 12:25:4634 mutable Lock lock_;
[email protected]0cb3d72e2013-02-21 21:50:3435
36 Time now_;
37};
38
39} // namespace base
40
danakj0a448602015-03-10 00:31:1641#endif // BASE_TEST_SIMPLE_TEST_CLOCK_H_