Skip to content

Commit

Permalink
ApproximateNow
Browse files Browse the repository at this point in the history
  • Loading branch information
jellefoks committed Nov 1, 2024
1 parent a1f634b commit b6dc165
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion net/quic/platform/impl/quic_chromium_clock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

namespace quic {

namespace {
QuicTime approximate_now_{QuicTime::Zero()};
int approximate_now_usage_counter_{0};
} // namespace

QuicChromiumClock* QuicChromiumClock::GetInstance() {
static base::NoDestructor<QuicChromiumClock> instance;
return instance.get();
Expand All @@ -19,16 +24,27 @@ QuicChromiumClock::QuicChromiumClock() = default;

QuicChromiumClock::~QuicChromiumClock() = default;

void QuicChromiumClock::ZeroApproximateNow() {
approximate_now_ = QuicTime::Zero();
approximate_now_usage_counter_ = 0;
};

QuicTime QuicChromiumClock::ApproximateNow() const {
// At the moment, Chrome does not have a distinct notion of ApproximateNow().
// We should consider implementing this using MessageLoop::recent_time_.
if (approximate_now_.IsInitialized() &&
++approximate_now_usage_counter_ < 16) {
return approximate_now_;
}
return Now();
}

QuicTime QuicChromiumClock::Now() const {
int64_t ticks = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
DCHECK_GE(ticks, 0);
return CreateTimeFromMicroseconds(ticks);
approximate_now_ = CreateTimeFromMicroseconds(ticks);
approximate_now_usage_counter_ = 0;
return approximate_now_;
}

QuicWallTime QuicChromiumClock::WallNow() const {
Expand Down
2 changes: 2 additions & 0 deletions net/quic/platform/impl/quic_chromium_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class NET_EXPORT_PRIVATE QuicChromiumClock : public QuicClock {

~QuicChromiumClock() override;

void ZeroApproximateNow();

// QuicClock implementation:
QuicTime ApproximateNow() const override;
QuicTime Now() const override;
Expand Down
3 changes: 3 additions & 0 deletions net/quic/quic_chromium_packet_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/task/single_thread_task_runner.h"
#include "net/base/net_errors.h"
#include "net/quic/address_utils.h"
#include "net/quic/platform/impl/quic_chromium_clock.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_clock.h"

namespace net {
Expand Down Expand Up @@ -45,6 +46,7 @@ QuicChromiumPacketReader::~QuicChromiumPacketReader() = default;

#if defined(STARBOARD)
int QuicChromiumPacketReader::StartReadingMultiplePackets() {
quic::QuicChromiumClock::GetInstance()->ZeroApproximateNow();
for (;;) {
if (read_pending_)
return OK;
Expand Down Expand Up @@ -165,6 +167,7 @@ void QuicChromiumPacketReader::StartReading() {
}
#endif

quic::QuicChromiumClock::GetInstance()->ZeroApproximateNow();
for (;;) {
if (read_pending_)
return;
Expand Down

0 comments on commit b6dc165

Please sign in to comment.