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