Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2013 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_ |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 22 | #include <base/time/time.h> |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 23 | |
| 24 | namespace chromeos_update_engine { |
| 25 | |
| 26 | // The clock interface allows access to various system clocks. The |
| 27 | // sole reason for providing this as an interface is unit testing. |
| 28 | // Additionally, the sole reason for the methods not being static |
| 29 | // is also unit testing. |
| 30 | class ClockInterface { |
| 31 | public: |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 32 | virtual ~ClockInterface() = default; |
| 33 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 34 | // Gets the current time e.g. similar to base::Time::Now(). |
Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 35 | virtual base::Time GetWallclockTime() const = 0; |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 36 | |
| 37 | // Returns monotonic time since some unspecified starting point. It |
| 38 | // is not increased when the system is sleeping nor is it affected |
| 39 | // by NTP or the user changing the time. |
| 40 | // |
| 41 | // (This is a simple wrapper around clock_gettime(2) / CLOCK_MONOTONIC_RAW.) |
Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 42 | virtual base::Time GetMonotonicTime() const = 0; |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 43 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 44 | // Returns monotonic time since some unspecified starting point. It |
| 45 | // is increased when the system is sleeping but it's not affected |
| 46 | // by NTP or the user changing the time. |
| 47 | // |
| 48 | // (This is a simple wrapper around clock_gettime(2) / CLOCK_BOOTTIME.) |
Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 49 | virtual base::Time GetBootTime() const = 0; |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | } // namespace chromeos_update_engine |
| 53 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 54 | #endif // UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_ |