summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/net/dcsctp/timer/timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/net/dcsctp/timer/timer.h')
-rw-r--r--third_party/libwebrtc/net/dcsctp/timer/timer.h40
1 files changed, 22 insertions, 18 deletions
diff --git a/third_party/libwebrtc/net/dcsctp/timer/timer.h b/third_party/libwebrtc/net/dcsctp/timer/timer.h
index 95aae570c8..30b07f9bfa 100644
--- a/third_party/libwebrtc/net/dcsctp/timer/timer.h
+++ b/third_party/libwebrtc/net/dcsctp/timer/timer.h
@@ -22,6 +22,7 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/task_queue/task_queue_base.h"
+#include "api/units/time_delta.h"
#include "net/dcsctp/public/timeout.h"
#include "rtc_base/strong_alias.h"
@@ -40,30 +41,31 @@ enum class TimerBackoffAlgorithm {
};
struct TimerOptions {
- explicit TimerOptions(DurationMs duration)
+ explicit TimerOptions(webrtc::TimeDelta duration)
: TimerOptions(duration, TimerBackoffAlgorithm::kExponential) {}
- TimerOptions(DurationMs duration, TimerBackoffAlgorithm backoff_algorithm)
+ TimerOptions(webrtc::TimeDelta duration,
+ TimerBackoffAlgorithm backoff_algorithm)
: TimerOptions(duration, backoff_algorithm, absl::nullopt) {}
- TimerOptions(DurationMs duration,
+ TimerOptions(webrtc::TimeDelta duration,
TimerBackoffAlgorithm backoff_algorithm,
absl::optional<int> max_restarts)
: TimerOptions(duration,
backoff_algorithm,
max_restarts,
- DurationMs::InfiniteDuration()) {}
- TimerOptions(DurationMs duration,
+ webrtc::TimeDelta::PlusInfinity()) {}
+ TimerOptions(webrtc::TimeDelta duration,
TimerBackoffAlgorithm backoff_algorithm,
absl::optional<int> max_restarts,
- DurationMs max_backoff_duration)
+ webrtc::TimeDelta max_backoff_duration)
: TimerOptions(duration,
backoff_algorithm,
max_restarts,
max_backoff_duration,
webrtc::TaskQueueBase::DelayPrecision::kLow) {}
- TimerOptions(DurationMs duration,
+ TimerOptions(webrtc::TimeDelta duration,
TimerBackoffAlgorithm backoff_algorithm,
absl::optional<int> max_restarts,
- DurationMs max_backoff_duration,
+ webrtc::TimeDelta max_backoff_duration,
webrtc::TaskQueueBase::DelayPrecision precision)
: duration(duration),
backoff_algorithm(backoff_algorithm),
@@ -72,7 +74,7 @@ struct TimerOptions {
precision(precision) {}
// The initial timer duration. Can be overridden with `set_duration`.
- const DurationMs duration;
+ const webrtc::TimeDelta duration;
// If the duration should be increased (using exponential backoff) when it is
// restarted. If not set, the same duration will be used.
const TimerBackoffAlgorithm backoff_algorithm;
@@ -80,7 +82,7 @@ struct TimerOptions {
// or absl::nullopt if there is no limit.
const absl::optional<int> max_restarts;
// The maximum timeout value for exponential backoff.
- const DurationMs max_backoff_duration;
+ const webrtc::TimeDelta max_backoff_duration;
// The precision of the webrtc::TaskQueueBase used for scheduling.
const webrtc::TaskQueueBase::DelayPrecision precision;
};
@@ -100,12 +102,14 @@ struct TimerOptions {
class Timer {
public:
// The maximum timer duration - one day.
- static constexpr DurationMs kMaxTimerDuration = DurationMs(24 * 3600 * 1000);
+ static constexpr webrtc::TimeDelta kMaxTimerDuration =
+ webrtc::TimeDelta::Seconds(24 * 3600);
- // When expired, the timer handler can optionally return a new duration which
- // will be set as `duration` and used as base duration when the timer is
- // restarted and as input to the backoff algorithm.
- using OnExpired = std::function<absl::optional<DurationMs>()>;
+ // When expired, the timer handler can optionally return a new non-zero
+ // duration which will be set as `duration` and used as base duration when the
+ // timer is restarted and as input to the backoff algorithm. If zero is
+ // returned, the current duration is used.
+ using OnExpired = std::function<webrtc::TimeDelta()>;
// TimerManager will have pointers to these instances, so they must not move.
Timer(const Timer&) = delete;
@@ -123,13 +127,13 @@ class Timer {
// Sets the base duration. The actual timer duration may be larger depending
// on the backoff algorithm.
- void set_duration(DurationMs duration) {
+ void set_duration(webrtc::TimeDelta duration) {
duration_ = std::min(duration, kMaxTimerDuration);
}
// Retrieves the base duration. The actual timer duration may be larger
// depending on the backoff algorithm.
- DurationMs duration() const { return duration_; }
+ webrtc::TimeDelta duration() const { return duration_; }
// Returns the number of times the timer has expired.
int expiration_count() const { return expiration_count_; }
@@ -167,7 +171,7 @@ class Timer {
const UnregisterHandler unregister_handler_;
const std::unique_ptr<Timeout> timeout_;
- DurationMs duration_;
+ webrtc::TimeDelta duration_;
// Increased on each start, and is matched on Trigger, to avoid races. And by
// race, meaning that a timeout - which may be evaluated/expired on a