David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS 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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_CLOCK_INTERFACE_H_ |
| 6 | #define UPDATE_ENGINE_CLOCK_INTERFACE_H_ |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 10 | #include <base/time/time.h> |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | // The clock interface allows access to various system clocks. The |
| 15 | // sole reason for providing this as an interface is unit testing. |
| 16 | // Additionally, the sole reason for the methods not being static |
| 17 | // is also unit testing. |
| 18 | class ClockInterface { |
| 19 | public: |
| 20 | // Gets the current time e.g. similar to base::Time::Now(). |
| 21 | virtual base::Time GetWallclockTime() = 0; |
| 22 | |
| 23 | // Returns monotonic time since some unspecified starting point. It |
| 24 | // is not increased when the system is sleeping nor is it affected |
| 25 | // by NTP or the user changing the time. |
| 26 | // |
| 27 | // (This is a simple wrapper around clock_gettime(2) / CLOCK_MONOTONIC_RAW.) |
| 28 | virtual base::Time GetMonotonicTime() = 0; |
| 29 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 30 | // Returns monotonic time since some unspecified starting point. It |
| 31 | // is increased when the system is sleeping but it's not affected |
| 32 | // by NTP or the user changing the time. |
| 33 | // |
| 34 | // (This is a simple wrapper around clock_gettime(2) / CLOCK_BOOTTIME.) |
| 35 | virtual base::Time GetBootTime() = 0; |
| 36 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 37 | virtual ~ClockInterface() {} |
| 38 | }; |
| 39 | |
| 40 | } // namespace chromeos_update_engine |
| 41 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 42 | #endif // UPDATE_ENGINE_CLOCK_INTERFACE_H_ |