Index: components/scheduler/renderer/coarse_duration_timer.cc |
diff --git a/components/scheduler/renderer/coarse_duration_timer.cc b/components/scheduler/renderer/coarse_duration_timer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9c58f39b8b71e9884c574d0ebe158609ac4d3b4f |
--- /dev/null |
+++ b/components/scheduler/renderer/coarse_duration_timer.cc |
@@ -0,0 +1,39 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/scheduler/renderer/coarse_duration_timer.h" |
+ |
+#include "base/message_loop/message_loop.h" |
+ |
+namespace scheduler { |
+ |
+void CoarseDurationTimer::OnUpdateRecentTime(base::TimeTicks recent_time) { |
+ most_recent_time_ = recent_time; |
+ if (state_ == State::WITHIN_INTERVAL_NEEDS_START) { |
+ start_time_ = recent_time; |
+ state_ = State::WITHIN_INTERVAL; |
+ } |
+} |
+ |
+void CoarseDurationTimer::BeginInterval() { |
+ // DCHECK(state_ == State::OUTSIDE_INTERVAL); |
+ state_ = State::WITHIN_INTERVAL_NEEDS_START; |
+} |
+ |
+base::TimeDelta CoarseDurationTimer::EndInterval() { |
+ base::TimeDelta duration; |
+ // DCHECK(state_ != State::OUTSIDE_INTERVAL); |
+ |
+ // If we haven't received a single time update within this interval, report |
+ // a duration of 0. |
+ if (state_ != State::WITHIN_INTERVAL_NEEDS_START) |
+ duration = most_recent_time_ - start_time_; |
+ state_ = State::OUTSIDE_INTERVAL; |
+ |
+ if (!duration.is_zero()) |
+ LOG(ERROR) << "DURATION IS " << duration.InMillisecondsF(); |
+ return duration; |
+} |
+ |
+} // namespace scheduler |