Commit badc743a authored by watk's avatar watk Committed by Commit bot

base: Make ElapsedTimer movable

Previously if you wanted to reset the starting point of the interval
(for measuring an idle timeout, for example) you had to construct a new
instance on the heap.

Now it's possible to keep a stack/member variable (potentially
base::Optional) and assign fresh values to it to reset it.

Review-Url: https://codereview.chromium.org/2851493004
Cr-Commit-Position: refs/heads/master@{#468193}
parent fd60d8ca
......@@ -10,6 +10,14 @@ ElapsedTimer::ElapsedTimer() {
begin_ = TimeTicks::Now();
}
ElapsedTimer::ElapsedTimer(ElapsedTimer&& other) {
begin_ = other.begin_;
}
void ElapsedTimer::operator=(ElapsedTimer&& other) {
begin_ = other.begin_;
}
TimeDelta ElapsedTimer::Elapsed() const {
return TimeTicks::Now() - begin_;
}
......
......@@ -15,6 +15,9 @@ namespace base {
class BASE_EXPORT ElapsedTimer {
public:
ElapsedTimer();
ElapsedTimer(ElapsedTimer&& other);
void operator=(ElapsedTimer&& other);
// Returns the time elapsed since object construction.
TimeDelta Elapsed() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment