blob: 722fd9890f20ff3722d36b850343bd628b5e5f2f [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_CLOCK_INTERFACE_H_
18#define UPDATE_ENGINE_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().
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
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.)
49 virtual base::Time GetBootTime() = 0;
David Zeuthenf413fe52013-04-22 14:04:39 -070050};
51
52} // namespace chromeos_update_engine
53
Gilad Arnoldcf175a02014-07-10 16:48:47 -070054#endif // UPDATE_ENGINE_CLOCK_INTERFACE_H_