[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 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 | |||||
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 5 | #ifndef BASE_TEST_SIMPLE_TEST_CLOCK_H_ |
6 | #define BASE_TEST_SIMPLE_TEST_CLOCK_H_ | ||||
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 7 | |
8 | #include "base/compiler_specific.h" | ||||
9 | #include "base/synchronization/lock.h" | ||||
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 10 | #include "base/time/clock.h" |
[email protected] | 8f9a3a5 | 2013-06-28 15:14:18 | [diff] [blame] | 11 | #include "base/time/time.h" |
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 12 | |
13 | namespace base { | ||||
14 | |||||
15 | // SimpleTestClock is a Clock implementation that gives control over | ||||
[email protected] | 014eb20 | 2013-02-26 01:51:17 | [diff] [blame] | 16 | // the returned Time objects. All methods may be called from any |
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 17 | // thread. |
18 | class SimpleTestClock : public Clock { | ||||
19 | public: | ||||
20 | // Starts off with a clock set to Time(). | ||||
21 | SimpleTestClock(); | ||||
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 22 | ~SimpleTestClock() override; |
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 23 | |
tzik | ee78e496 | 2018-04-13 12:25:46 | [diff] [blame] | 24 | Time Now() const override; |
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 25 | |
[email protected] | 014eb20 | 2013-02-26 01:51:17 | [diff] [blame] | 26 | // Advances the clock by |delta|. |
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 27 | void Advance(TimeDelta delta); |
28 | |||||
[email protected] | 014eb20 | 2013-02-26 01:51:17 | [diff] [blame] | 29 | // Sets the clock to the given time. |
30 | void SetNow(Time now); | ||||
31 | |||||
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 32 | private: |
33 | // Protects |now_|. | ||||
tzik | ee78e496 | 2018-04-13 12:25:46 | [diff] [blame] | 34 | mutable Lock lock_; |
[email protected] | 0cb3d72e | 2013-02-21 21:50:34 | [diff] [blame] | 35 | |
36 | Time now_; | ||||
37 | }; | ||||
38 | |||||
39 | } // namespace base | ||||
40 | |||||
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 41 | #endif // BASE_TEST_SIMPLE_TEST_CLOCK_H_ |