OLD | NEW |
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 coordinated universal time (UTC), | 5 // Time represents an absolute point in coordinated universal time (UTC), |
6 // internally represented as microseconds (s/1,000,000) since the Windows epoch | 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch |
7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are | 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are |
8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump | 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump |
9 // around as the operating system makes adjustments to synchronize (e.g., with | 9 // around as the operating system makes adjustments to synchronize (e.g., with |
10 // NTP servers). Thus, client code that uses the Time class must account for | 10 // NTP servers). Thus, client code that uses the Time class must account for |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 550 } |
551 | 551 |
552 // Converts a string representation of time to a Time object. | 552 // Converts a string representation of time to a Time object. |
553 // An example of a time string which is converted is as below:- | 553 // An example of a time string which is converted is as below:- |
554 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified | 554 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified |
555 // in the input string, FromString assumes local time and FromUTCString | 555 // in the input string, FromString assumes local time and FromUTCString |
556 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not | 556 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not |
557 // specified in RFC822) is treated as if the timezone is not specified. | 557 // specified in RFC822) is treated as if the timezone is not specified. |
558 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to | 558 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to |
559 // a new time converter class. | 559 // a new time converter class. |
560 static bool FromString(const char* time_string, Time* parsed_time) { | 560 static bool FromString(const char* time_string, |
| 561 Time* parsed_time) WARN_UNUSED_RESULT { |
561 return FromStringInternal(time_string, true, parsed_time); | 562 return FromStringInternal(time_string, true, parsed_time); |
562 } | 563 } |
563 static bool FromUTCString(const char* time_string, Time* parsed_time) { | 564 static bool FromUTCString(const char* time_string, |
| 565 Time* parsed_time) WARN_UNUSED_RESULT { |
564 return FromStringInternal(time_string, false, parsed_time); | 566 return FromStringInternal(time_string, false, parsed_time); |
565 } | 567 } |
566 | 568 |
567 // Fills the given exploded structure with either the local time or UTC from | 569 // Fills the given exploded structure with either the local time or UTC from |
568 // this time structure (containing UTC). | 570 // this time structure (containing UTC). |
569 void UTCExplode(Exploded* exploded) const { | 571 void UTCExplode(Exploded* exploded) const { |
570 return Explode(false, exploded); | 572 return Explode(false, exploded); |
571 } | 573 } |
572 void LocalExplode(Exploded* exploded) const { | 574 void LocalExplode(Exploded* exploded) const { |
573 return Explode(true, exploded); | 575 return Explode(true, exploded); |
(...skipping 22 matching lines...) Expand all Loading... |
596 | 598 |
597 // Converts a string representation of time to a Time object. | 599 // Converts a string representation of time to a Time object. |
598 // An example of a time string which is converted is as below:- | 600 // An example of a time string which is converted is as below:- |
599 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified | 601 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified |
600 // in the input string, local time |is_local = true| or | 602 // in the input string, local time |is_local = true| or |
601 // UTC |is_local = false| is assumed. A timezone that cannot be parsed | 603 // UTC |is_local = false| is assumed. A timezone that cannot be parsed |
602 // (e.g. "UTC" which is not specified in RFC822) is treated as if the | 604 // (e.g. "UTC" which is not specified in RFC822) is treated as if the |
603 // timezone is not specified. | 605 // timezone is not specified. |
604 static bool FromStringInternal(const char* time_string, | 606 static bool FromStringInternal(const char* time_string, |
605 bool is_local, | 607 bool is_local, |
606 Time* parsed_time); | 608 Time* parsed_time) WARN_UNUSED_RESULT; |
607 | 609 |
608 // Comparison does not consider |day_of_week| when doing the operation. | 610 // Comparison does not consider |day_of_week| when doing the operation. |
609 static bool ExplodedMostlyEquals(const Exploded& lhs, const Exploded& rhs); | 611 static bool ExplodedMostlyEquals(const Exploded& lhs, |
| 612 const Exploded& rhs) WARN_UNUSED_RESULT; |
610 }; | 613 }; |
611 | 614 |
612 // static | 615 // static |
613 constexpr TimeDelta TimeDelta::FromDays(int days) { | 616 constexpr TimeDelta TimeDelta::FromDays(int days) { |
614 return days == std::numeric_limits<int>::max() | 617 return days == std::numeric_limits<int>::max() |
615 ? Max() | 618 ? Max() |
616 : TimeDelta(days * Time::kMicrosecondsPerDay); | 619 : TimeDelta(days * Time::kMicrosecondsPerDay); |
617 } | 620 } |
618 | 621 |
619 // static | 622 // static |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 // Platform-dependent tick count representing "right now." When | 709 // Platform-dependent tick count representing "right now." When |
707 // IsHighResolution() returns false, the resolution of the clock could be | 710 // IsHighResolution() returns false, the resolution of the clock could be |
708 // as coarse as ~15.6ms. Otherwise, the resolution should be no worse than one | 711 // as coarse as ~15.6ms. Otherwise, the resolution should be no worse than one |
709 // microsecond. | 712 // microsecond. |
710 static TimeTicks Now(); | 713 static TimeTicks Now(); |
711 | 714 |
712 // Returns true if the high resolution clock is working on this system and | 715 // Returns true if the high resolution clock is working on this system and |
713 // Now() will return high resolution values. Note that, on systems where the | 716 // Now() will return high resolution values. Note that, on systems where the |
714 // high resolution clock works but is deemed inefficient, the low resolution | 717 // high resolution clock works but is deemed inefficient, the low resolution |
715 // clock will be used instead. | 718 // clock will be used instead. |
716 static bool IsHighResolution(); | 719 static bool IsHighResolution() WARN_UNUSED_RESULT; |
717 | 720 |
718 // Returns true if TimeTicks is consistent across processes, meaning that | 721 // Returns true if TimeTicks is consistent across processes, meaning that |
719 // timestamps taken on different processes can be safely compared with one | 722 // timestamps taken on different processes can be safely compared with one |
720 // another. (Note that, even on platforms where this returns true, time values | 723 // another. (Note that, even on platforms where this returns true, time values |
721 // from different threads that are within one tick of each other must be | 724 // from different threads that are within one tick of each other must be |
722 // considered to have an ambiguous ordering.) | 725 // considered to have an ambiguous ordering.) |
723 static bool IsConsistentAcrossProcesses(); | 726 static bool IsConsistentAcrossProcesses() WARN_UNUSED_RESULT; |
724 | 727 |
725 #if defined(OS_WIN) | 728 #if defined(OS_WIN) |
726 // Translates an absolute QPC timestamp into a TimeTicks value. The returned | 729 // Translates an absolute QPC timestamp into a TimeTicks value. The returned |
727 // value has the same origin as Now(). Do NOT attempt to use this if | 730 // value has the same origin as Now(). Do NOT attempt to use this if |
728 // IsHighResolution() returns false. | 731 // IsHighResolution() returns false. |
729 static TimeTicks FromQPCValue(LONGLONG qpc_value); | 732 static TimeTicks FromQPCValue(LONGLONG qpc_value); |
730 #endif | 733 #endif |
731 | 734 |
732 #if defined(OS_MACOSX) && !defined(OS_IOS) | 735 #if defined(OS_MACOSX) && !defined(OS_IOS) |
733 static TimeTicks FromMachAbsoluteTime(uint64_t mach_absolute_time); | 736 static TimeTicks FromMachAbsoluteTime(uint64_t mach_absolute_time); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 // ThreadTicks ---------------------------------------------------------------- | 777 // ThreadTicks ---------------------------------------------------------------- |
775 | 778 |
776 // Represents a clock, specific to a particular thread, than runs only while the | 779 // Represents a clock, specific to a particular thread, than runs only while the |
777 // thread is running. | 780 // thread is running. |
778 class BASE_EXPORT ThreadTicks : public time_internal::TimeBase<ThreadTicks> { | 781 class BASE_EXPORT ThreadTicks : public time_internal::TimeBase<ThreadTicks> { |
779 public: | 782 public: |
780 ThreadTicks() : TimeBase(0) { | 783 ThreadTicks() : TimeBase(0) { |
781 } | 784 } |
782 | 785 |
783 // Returns true if ThreadTicks::Now() is supported on this system. | 786 // Returns true if ThreadTicks::Now() is supported on this system. |
784 static bool IsSupported() { | 787 static bool IsSupported() WARN_UNUSED_RESULT { |
785 #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ | 788 #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ |
786 (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) | 789 (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) |
787 return true; | 790 return true; |
788 #elif defined(OS_WIN) | 791 #elif defined(OS_WIN) |
789 return IsSupportedWin(); | 792 return IsSupportedWin(); |
790 #else | 793 #else |
791 return false; | 794 return false; |
792 #endif | 795 #endif |
793 } | 796 } |
794 | 797 |
(...skipping 30 matching lines...) Expand all Loading... |
825 | 828 |
826 #if defined(OS_WIN) | 829 #if defined(OS_WIN) |
827 FRIEND_TEST_ALL_PREFIXES(TimeTicks, TSCTicksPerSecond); | 830 FRIEND_TEST_ALL_PREFIXES(TimeTicks, TSCTicksPerSecond); |
828 | 831 |
829 // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't | 832 // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't |
830 // been measured yet. Needs to be guarded with a call to IsSupported(). | 833 // been measured yet. Needs to be guarded with a call to IsSupported(). |
831 // This method is declared here rather than in the anonymous namespace to | 834 // This method is declared here rather than in the anonymous namespace to |
832 // allow testing. | 835 // allow testing. |
833 static double TSCTicksPerSecond(); | 836 static double TSCTicksPerSecond(); |
834 | 837 |
835 static bool IsSupportedWin(); | 838 static bool IsSupportedWin() WARN_UNUSED_RESULT; |
836 static void WaitUntilInitializedWin(); | 839 static void WaitUntilInitializedWin(); |
837 #endif | 840 #endif |
838 }; | 841 }; |
839 | 842 |
840 // For logging use only. | 843 // For logging use only. |
841 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 844 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
842 | 845 |
843 } // namespace base | 846 } // namespace base |
844 | 847 |
845 #endif // BASE_TIME_TIME_H_ | 848 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |