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

Side by Side Diff: base/time/time.h

Issue 231133002: CC::Animations should use TimeTicks & TimeDelta to represent time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code Refactored as per the comments. Created 6 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | cc/animation/animation.h » ('j') | cc/animation/animation.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Time represents an absolute point in time, internally represented as 5 // Time represents an absolute point in time, internally represented as
6 // microseconds (s/1,000,000) since the Windows epoch (1601-01-01 00:00:00 UTC) 6 // microseconds (s/1,000,000) since the Windows epoch (1601-01-01 00:00:00 UTC)
7 // (See http://crbug.com/14734). System-dependent clock interface routines are 7 // (See http://crbug.com/14734). System-dependent clock interface routines are
8 // defined in time_PLATFORM.cc. 8 // defined in time_PLATFORM.cc.
9 // 9 //
10 // TimeDelta represents a duration of time, internally represented in 10 // TimeDelta represents a duration of time, internally represented in
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // value for the duration of the application, but will be different in future 658 // value for the duration of the application, but will be different in future
659 // application runs. 659 // application runs.
660 static TimeTicks UnixEpoch(); 660 static TimeTicks UnixEpoch();
661 661
662 // Returns the internal numeric value of the TimeTicks object. 662 // Returns the internal numeric value of the TimeTicks object.
663 // For serializing, use FromInternalValue to reconstitute. 663 // For serializing, use FromInternalValue to reconstitute.
664 int64 ToInternalValue() const { 664 int64 ToInternalValue() const {
665 return ticks_; 665 return ticks_;
666 } 666 }
667 667
668 static double InSecondsF(TimeTicks time) {
669 if (time.ToInternalValue() == std::numeric_limits<int64>::max()) {
670 // Preserve max to prevent overflow.
671 return std::numeric_limits<int>::max();
672 }
673 return static_cast<double>(time.ToInternalValue()) /
674 Time::kMicrosecondsPerSecond;
675 }
676
677 static TimeTicks FromSeconds(double seconds) {
678 return TimeTicks::FromInternalValue(seconds * Time::kMicrosecondsPerSecond);
679 }
ajuma 2014/04/24 20:41:36 It's not obvious to me whether these are a good id
680
668 TimeTicks& operator=(TimeTicks other) { 681 TimeTicks& operator=(TimeTicks other) {
669 ticks_ = other.ticks_; 682 ticks_ = other.ticks_;
670 return *this; 683 return *this;
671 } 684 }
672 685
673 // Compute the difference between two times. 686 // Compute the difference between two times.
674 TimeDelta operator-(TimeTicks other) const { 687 TimeDelta operator-(TimeTicks other) const {
675 return TimeDelta(ticks_ - other.ticks_); 688 return TimeDelta(ticks_ - other.ticks_);
676 } 689 }
677 690
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 #endif 743 #endif
731 }; 744 };
732 745
733 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { 746 inline TimeTicks TimeDelta::operator+(TimeTicks t) const {
734 return TimeTicks(t.ticks_ + delta_); 747 return TimeTicks(t.ticks_ + delta_);
735 } 748 }
736 749
737 } // namespace base 750 } // namespace base
738 751
739 #endif // BASE_TIME_TIME_H_ 752 #endif // BASE_TIME_TIME_H_
OLDNEW
« no previous file with comments | « no previous file | cc/animation/animation.h » ('j') | cc/animation/animation.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698