Chromium Code Reviews| 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 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 29 matching lines...) Expand all Loading... | |
| 40 #include <sys/time.h> | 40 #include <sys/time.h> |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 44 // For FILETIME in FromFileTime, until it moves to a new converter class. | 44 // For FILETIME in FromFileTime, until it moves to a new converter class. |
| 45 // See TODO(iyengar) below. | 45 // See TODO(iyengar) below. |
| 46 #include <windows.h> | 46 #include <windows.h> |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 #include <limits> | 49 #include <limits> |
| 50 #include <ostream> | |
| 50 | 51 |
| 51 namespace base { | 52 namespace base { |
| 52 | 53 |
| 53 class Time; | 54 class Time; |
| 54 class TimeTicks; | 55 class TimeTicks; |
| 55 | 56 |
| 56 // TimeDelta ------------------------------------------------------------------ | 57 // TimeDelta ------------------------------------------------------------------ |
| 57 | 58 |
| 58 class BASE_EXPORT TimeDelta { | 59 class BASE_EXPORT TimeDelta { |
| 59 public: | 60 public: |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 } | 607 } |
| 607 | 608 |
| 608 // Get the TimeTick value at the time of the UnixEpoch. This is useful when | 609 // Get the TimeTick value at the time of the UnixEpoch. This is useful when |
| 609 // you need to relate the value of TimeTicks to a real time and date. | 610 // you need to relate the value of TimeTicks to a real time and date. |
| 610 // Note: Upon first invocation, this function takes a snapshot of the realtime | 611 // Note: Upon first invocation, this function takes a snapshot of the realtime |
| 611 // clock to establish a reference point. This function will return the same | 612 // clock to establish a reference point. This function will return the same |
| 612 // value for the duration of the application, but will be different in future | 613 // value for the duration of the application, but will be different in future |
| 613 // application runs. | 614 // application runs. |
| 614 static TimeTicks UnixEpoch(); | 615 static TimeTicks UnixEpoch(); |
| 615 | 616 |
| 617 // Converts time to/from a double which is the number of seconds since epoch | |
| 618 // (Jan 1, 1970). Webkit uses this format to represent time. | |
|
jamesr
2014/02/28 00:58:16
if this is just needed for interacting with Blink
| |
| 619 // Because WebKit initializes double time value to 0 to indicate "not | |
| 620 // initialized", we map it to empty Time object that also means "not | |
| 621 // initialized". | |
| 622 static TimeTicks FromWebKit(double dt); | |
| 623 double ToWebKit() const; | |
| 624 | |
| 616 // Returns the internal numeric value of the TimeTicks object. | 625 // Returns the internal numeric value of the TimeTicks object. |
| 617 // For serializing, use FromInternalValue to reconstitute. | 626 // For serializing, use FromInternalValue to reconstitute. |
| 618 int64 ToInternalValue() const { | 627 int64 ToInternalValue() const { |
| 619 return ticks_; | 628 return ticks_; |
| 620 } | 629 } |
| 621 | 630 |
| 622 TimeTicks& operator=(TimeTicks other) { | 631 TimeTicks& operator=(TimeTicks other) { |
| 623 ticks_ = other.ticks_; | 632 ticks_ = other.ticks_; |
| 624 return *this; | 633 return *this; |
| 625 } | 634 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 #if defined(OS_WIN) | 690 #if defined(OS_WIN) |
| 682 typedef DWORD (*TickFunctionType)(void); | 691 typedef DWORD (*TickFunctionType)(void); |
| 683 static TickFunctionType SetMockTickFunction(TickFunctionType ticker); | 692 static TickFunctionType SetMockTickFunction(TickFunctionType ticker); |
| 684 #endif | 693 #endif |
| 685 }; | 694 }; |
| 686 | 695 |
| 687 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 696 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
| 688 return TimeTicks(t.ticks_ + delta_); | 697 return TimeTicks(t.ticks_ + delta_); |
| 689 } | 698 } |
| 690 | 699 |
| 700 inline ::std::ostream& operator<<(::std::ostream& os, const TimeTicks& t) { | |
| 701 os << "TimeTicks("; | |
|
jamesr
2014/02/28 00:58:16
i'm pretty sure we don't want to have these stream
| |
| 702 int64 ticks = t.ToInternalValue(); | |
| 703 if (ticks == 0) | |
| 704 ; | |
| 705 else if (ticks == std::numeric_limits<int64>::max()) | |
| 706 os << "max"; | |
| 707 else if (ticks == std::numeric_limits<int64>::min()) | |
| 708 os << "min"; | |
| 709 else | |
| 710 os << ticks; | |
| 711 os << ")"; | |
| 712 return os; | |
| 713 } | |
| 714 | |
| 691 } // namespace base | 715 } // namespace base |
| 692 | 716 |
| 693 #endif // BASE_TIME_TIME_H_ | 717 #endif // BASE_TIME_TIME_H_ |
| OLD | NEW |