1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_TEST_SIMPLE_TEST_CLOCK_H_ 6*635a8641SAndroid Build Coastguard Worker #define BASE_TEST_SIMPLE_TEST_CLOCK_H_ 7*635a8641SAndroid Build Coastguard Worker 8*635a8641SAndroid Build Coastguard Worker #include "base/compiler_specific.h" 9*635a8641SAndroid Build Coastguard Worker #include "base/synchronization/lock.h" 10*635a8641SAndroid Build Coastguard Worker #include "base/time/clock.h" 11*635a8641SAndroid Build Coastguard Worker #include "base/time/time.h" 12*635a8641SAndroid Build Coastguard Worker 13*635a8641SAndroid Build Coastguard Worker namespace base { 14*635a8641SAndroid Build Coastguard Worker 15*635a8641SAndroid Build Coastguard Worker // SimpleTestClock is a Clock implementation that gives control over 16*635a8641SAndroid Build Coastguard Worker // the returned Time objects. All methods may be called from any 17*635a8641SAndroid Build Coastguard Worker // thread. 18*635a8641SAndroid Build Coastguard Worker class SimpleTestClock : public Clock { 19*635a8641SAndroid Build Coastguard Worker public: 20*635a8641SAndroid Build Coastguard Worker // Starts off with a clock set to Time(). 21*635a8641SAndroid Build Coastguard Worker SimpleTestClock(); 22*635a8641SAndroid Build Coastguard Worker ~SimpleTestClock() override; 23*635a8641SAndroid Build Coastguard Worker 24*635a8641SAndroid Build Coastguard Worker Time Now() const override; 25*635a8641SAndroid Build Coastguard Worker 26*635a8641SAndroid Build Coastguard Worker // Advances the clock by |delta|. 27*635a8641SAndroid Build Coastguard Worker void Advance(TimeDelta delta); 28*635a8641SAndroid Build Coastguard Worker 29*635a8641SAndroid Build Coastguard Worker // Sets the clock to the given time. 30*635a8641SAndroid Build Coastguard Worker void SetNow(Time now); 31*635a8641SAndroid Build Coastguard Worker 32*635a8641SAndroid Build Coastguard Worker private: 33*635a8641SAndroid Build Coastguard Worker // Protects |now_|. 34*635a8641SAndroid Build Coastguard Worker mutable Lock lock_; 35*635a8641SAndroid Build Coastguard Worker 36*635a8641SAndroid Build Coastguard Worker Time now_; 37*635a8641SAndroid Build Coastguard Worker }; 38*635a8641SAndroid Build Coastguard Worker 39*635a8641SAndroid Build Coastguard Worker } // namespace base 40*635a8641SAndroid Build Coastguard Worker 41*635a8641SAndroid Build Coastguard Worker #endif // BASE_TEST_SIMPLE_TEST_CLOCK_H_ 42