blob: 176505dc78dd77c9a2671a96647d449a9387a064 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Zeuthenf413fe52013-04-22 14:04:39 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_
18#define UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_
David Zeuthenf413fe52013-04-22 14:04:39 -070019
20#include <string>
21
Alex Vakulenko75039d72014-03-25 12:36:28 -070022#include <base/time/time.h>
David Zeuthenf413fe52013-04-22 14:04:39 -070023
24namespace 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.
30class ClockInterface {
31 public:
Alex Deymo610277e2014-11-11 21:18:11 -080032 virtual ~ClockInterface() = default;
33
David Zeuthenf413fe52013-04-22 14:04:39 -070034 // Gets the current time e.g. similar to base::Time::Now().
Amin Hassani0468a762020-11-17 23:53:48 -080035 virtual base::Time GetWallclockTime() const = 0;
David Zeuthenf413fe52013-04-22 14:04:39 -070036
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 Hassani0468a762020-11-17 23:53:48 -080042 virtual base::Time GetMonotonicTime() const = 0;
David Zeuthenf413fe52013-04-22 14:04:39 -070043
David Zeuthen3c55abd2013-10-14 12:48:03 -070044 // 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 Hassani0468a762020-11-17 23:53:48 -080049 virtual base::Time GetBootTime() const = 0;
David Zeuthenf413fe52013-04-22 14:04:39 -070050};
51
52} // namespace chromeos_update_engine
53
Alex Deymo39910dc2015-11-09 17:04:30 -080054#endif // UPDATE_ENGINE_COMMON_CLOCK_INTERFACE_H_