blob: 69aed4e4d9efc844a76b09d4b930edfd464976d8 [file] [log] [blame]
Bence Békybac04052022-04-07 15:44:29 -04001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef QUICHE_QUIC_CORE_QUIC_CLOCK_H_
6#define QUICHE_QUIC_CORE_QUIC_CLOCK_H_
7
8#include "quiche/quic/core/quic_time.h"
9#include "quiche/quic/platform/api/quic_export.h"
10
11/* API_DESCRIPTION
12 QuicClock is used by QUIC core to get current time. Its instance is created by
13 applications and passed into QuicDispatcher and QuicConnectionHelperInterface.
14 API-DESCRIPTION */
15
16namespace quic {
17
18// Interface for retrieving the current time.
19class QUIC_EXPORT_PRIVATE QuicClock {
20 public:
vasilvv957e5522022-04-21 15:05:51 -070021 QuicClock() = default;
22 virtual ~QuicClock() = default;
Bence Békybac04052022-04-07 15:44:29 -040023
24 QuicClock(const QuicClock&) = delete;
25 QuicClock& operator=(const QuicClock&) = delete;
26
Bence Békybac04052022-04-07 15:44:29 -040027 // Returns the approximate current time as a QuicTime object.
28 virtual QuicTime ApproximateNow() const = 0;
29
30 // Returns the current time as a QuicTime object.
31 // Note: this use significant resources please use only if needed.
32 virtual QuicTime Now() const = 0;
33
34 // WallNow returns the current wall-time - a time that is consistent across
35 // different clocks.
36 virtual QuicWallTime WallNow() const = 0;
37
38 // Converts |walltime| to a QuicTime relative to this clock's epoch.
39 virtual QuicTime ConvertWallTimeToQuicTime(
40 const QuicWallTime& walltime) const;
41
42 protected:
43 // Creates a new QuicTime using |time_us| as the internal value.
44 QuicTime CreateTimeFromMicroseconds(uint64_t time_us) const {
45 return QuicTime(time_us);
46 }
Bence Békybac04052022-04-07 15:44:29 -040047};
48
49} // namespace quic
50
51#endif // QUICHE_QUIC_CORE_QUIC_CLOCK_H_