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 // 16 17 #ifndef UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_ 18 #define UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_ 19 20 #include <string> 21 22 #include <base/time/time.h> 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: 32 virtual ~ClockInterface() = default; 33 34 // Gets the current time e.g. similar to base::Time::Now(). 35 virtual base::Time GetWallclockTime() = 0; 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.) 42 virtual base::Time GetMonotonicTime() = 0; 43 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.) 49 virtual base::Time GetBootTime() = 0; 50 }; 51 52 } // namespace chromeos_update_engine 53 54 #endif // UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_ 55