xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_clock.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // 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 
16 namespace quic {
17 
18 // Interface for retrieving the current time.
19 class QUICHE_EXPORT QuicClock {
20  public:
21   QuicClock() = default;
22   virtual ~QuicClock() = default;
23 
24   QuicClock(const QuicClock&) = delete;
25   QuicClock& operator=(const QuicClock&) = delete;
26 
27   // 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  protected:
39   // Creates a new QuicTime using |time_us| as the internal value.
CreateTimeFromMicroseconds(uint64_t time_us)40   QuicTime CreateTimeFromMicroseconds(uint64_t time_us) const {
41     return QuicTime(time_us);
42   }
43 };
44 
45 }  // namespace quic
46 
47 #endif  // QUICHE_QUIC_CORE_QUIC_CLOCK_H_
48