Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Unified Diff: chromecast/public/time_delta.h

Issue 1257013003: Load CMA backend from shared library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test + android fixes Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« chromecast/public/task_runner.h ('K') | « chromecast/public/task_runner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/public/time_delta.h
diff --git a/chromecast/public/time_delta.h b/chromecast/public/time_delta.h
new file mode 100644
index 0000000000000000000000000000000000000000..56f5a579db5bacd7b0a149c9331894d9c7cb25d6
--- /dev/null
+++ b/chromecast/public/time_delta.h
@@ -0,0 +1,98 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
gunsch 2015/07/27 17:14:49 no (c)
halliwell 2015/07/28 02:19:36 file removed.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMECAST_PUBLIC_TIME_DELTA_H_
+#define CHROMECAST_PUBLIC_TIME_DELTA_H_
+
+#include <stdint.h>
+
+#include <limits>
+
+namespace chromecast {
+
+class TimeDelta {
gunsch 2015/07/27 17:14:50 Could we just use |uint64_t microseconds| everywhe
byungchul 2015/07/27 18:22:23 +1
halliwell 2015/07/28 02:19:36 Done.
+ public:
+ TimeDelta() : delta_(0) {}
+
+ // Indicates an invalid or missing timestamp
+ static TimeDelta Invalid() {
+ return TimeDelta(std::numeric_limits<int64_t>::min());
+ }
+ // Maximum possible TimeDelta value
+ static TimeDelta Max() {
+ return TimeDelta(std::numeric_limits<int64_t>::max());
+ }
+
+ // Convert units of time to DeltaDelta
+ static TimeDelta FromMilliseconds(int64_t ms) {
+ if (ms == std::numeric_limits<int64_t>::max())
+ return Max();
+ return TimeDelta(ms * 1000);
+ }
+ static TimeDelta FromMicroseconds(int64_t us) { return TimeDelta(us); }
+
+ // Convert to units of time
+ int64_t InMicroseconds() const { return delta_; }
+ int64_t InMilliseconds() const {
+ if (delta_ == std::numeric_limits<int64_t>::max())
+ return std::numeric_limits<int64_t>::max();
+ return delta_ / 1000;
+ }
+ double InSecondsF() const {
+ if (delta_ == std::numeric_limits<int64_t>::max())
+ return std::numeric_limits<double>::infinity();
+ const int64_t kMicrosecondsPerSecond = 1000000;
+ return static_cast<double>(delta_) / kMicrosecondsPerSecond;
+ }
+
+ // Arithmetic operations. These prevent overflow and clamp to (+max, -max)
+ // when overflow would have occurred.
+ TimeDelta operator+(TimeDelta other) const {
gunsch 2015/07/27 17:14:49 Do we need/use the addition/subtraction operators?
halliwell 2015/07/28 02:19:36 we did use them (and no others, that's why I didn'
+ const int64_t max_int = std::numeric_limits<int64_t>::max();
+ const int64_t min_int = std::numeric_limits<int64_t>::min();
+ if (((other.delta_ > 0) && (delta_ > (max_int - other.delta_))))
+ return TimeDelta(max_int);
+ else if ((other.delta_ < 0) && (delta_ < (min_int - other.delta_)))
+ return TimeDelta(-max_int);
+ else
+ return TimeDelta(delta_ + other.delta_);
+ }
+
+ TimeDelta operator-(TimeDelta other) const {
+ const int64_t max_int = std::numeric_limits<int64_t>::max();
+ const int64_t min_int = std::numeric_limits<int64_t>::min();
+
+ if ((other.delta_ > 0) && (delta_ < (min_int + other.delta_)))
+ return TimeDelta(-max_int);
+ else if ((other.delta_ < 0) && (delta_ > (max_int + other.delta_)))
+ return TimeDelta(max_int);
+ else
+ return TimeDelta(delta_ - other.delta_);
+ }
+
+ // Comparisons
+ bool operator==(const TimeDelta& other) const {
+ return delta_ == other.delta_;
+ }
+ bool operator!=(const TimeDelta& other) const {
+ return delta_ != other.delta_;
+ }
+ bool operator<=(const TimeDelta& other) const {
+ return delta_ <= other.delta_;
+ }
+ bool operator<(const TimeDelta& other) const { return delta_ < other.delta_; }
+ bool operator>=(const TimeDelta& other) const {
+ return delta_ >= other.delta_;
+ }
+ bool operator>(const TimeDelta& other) const { return delta_ > other.delta_; }
+
+ private:
+ explicit TimeDelta(int64_t delta) : delta_(delta) {}
+
+ int64_t delta_;
+};
+
+} // namespace chromecast
+
+#endif // CHROMECAST_PUBLIC_TIME_DELTA_H_
« chromecast/public/task_runner.h ('K') | « chromecast/public/task_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698