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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 public: | 59 public: |
60 TimeDelta() : delta_(0) { | 60 TimeDelta() : delta_(0) { |
61 } | 61 } |
62 | 62 |
63 // Converts units of time to TimeDeltas. | 63 // Converts units of time to TimeDeltas. |
64 static TimeDelta FromDays(int days); | 64 static TimeDelta FromDays(int days); |
65 static TimeDelta FromHours(int hours); | 65 static TimeDelta FromHours(int hours); |
66 static TimeDelta FromMinutes(int minutes); | 66 static TimeDelta FromMinutes(int minutes); |
67 static TimeDelta FromSeconds(int64 secs); | 67 static TimeDelta FromSeconds(int64 secs); |
68 static TimeDelta FromMilliseconds(int64 ms); | 68 static TimeDelta FromMilliseconds(int64 ms); |
| 69 static TimeDelta FromSecondsD(double secs); |
| 70 static TimeDelta FromMillisecondsD(double ms); |
69 static TimeDelta FromMicroseconds(int64 us); | 71 static TimeDelta FromMicroseconds(int64 us); |
70 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
71 static TimeDelta FromQPCValue(LONGLONG qpc_value); | 73 static TimeDelta FromQPCValue(LONGLONG qpc_value); |
72 #endif | 74 #endif |
73 | 75 |
74 // Converts an integer value representing TimeDelta to a class. This is used | 76 // Converts an integer value representing TimeDelta to a class. This is used |
75 // when deserializing a |TimeDelta| structure, using a value known to be | 77 // when deserializing a |TimeDelta| structure, using a value known to be |
76 // compatible. It is not provided as a constructor because the integer type | 78 // compatible. It is not provided as a constructor because the integer type |
77 // may be unclear from the perspective of a caller. | 79 // may be unclear from the perspective of a caller. |
78 static TimeDelta FromInternalValue(int64 delta) { | 80 static TimeDelta FromInternalValue(int64 delta) { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 538 |
537 // static | 539 // static |
538 inline TimeDelta TimeDelta::FromMilliseconds(int64 ms) { | 540 inline TimeDelta TimeDelta::FromMilliseconds(int64 ms) { |
539 // Preserve max to prevent overflow. | 541 // Preserve max to prevent overflow. |
540 if (ms == std::numeric_limits<int64>::max()) | 542 if (ms == std::numeric_limits<int64>::max()) |
541 return Max(); | 543 return Max(); |
542 return TimeDelta(ms * Time::kMicrosecondsPerMillisecond); | 544 return TimeDelta(ms * Time::kMicrosecondsPerMillisecond); |
543 } | 545 } |
544 | 546 |
545 // static | 547 // static |
| 548 inline TimeDelta TimeDelta::FromSecondsD(double secs) { |
| 549 // Preserve max to prevent overflow. |
| 550 if (secs == std::numeric_limits<double>::infinity()) |
| 551 return Max(); |
| 552 return TimeDelta(secs * Time::kMicrosecondsPerSecond); |
| 553 } |
| 554 |
| 555 // static |
| 556 inline TimeDelta TimeDelta::FromMillisecondsD(double ms) { |
| 557 // Preserve max to prevent overflow. |
| 558 if (ms == std::numeric_limits<double>::infinity()) |
| 559 return Max(); |
| 560 return TimeDelta(ms * Time::kMicrosecondsPerMillisecond); |
| 561 } |
| 562 |
| 563 // static |
546 inline TimeDelta TimeDelta::FromMicroseconds(int64 us) { | 564 inline TimeDelta TimeDelta::FromMicroseconds(int64 us) { |
547 // Preserve max to prevent overflow. | 565 // Preserve max to prevent overflow. |
548 if (us == std::numeric_limits<int64>::max()) | 566 if (us == std::numeric_limits<int64>::max()) |
549 return Max(); | 567 return Max(); |
550 return TimeDelta(us); | 568 return TimeDelta(us); |
551 } | 569 } |
552 | 570 |
553 inline Time TimeDelta::operator+(Time t) const { | 571 inline Time TimeDelta::operator+(Time t) const { |
554 return Time(t.us_ + delta_); | 572 return Time(t.us_ + delta_); |
555 } | 573 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 #endif | 730 #endif |
713 }; | 731 }; |
714 | 732 |
715 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 733 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
716 return TimeTicks(t.ticks_ + delta_); | 734 return TimeTicks(t.ticks_ + delta_); |
717 } | 735 } |
718 | 736 |
719 } // namespace base | 737 } // namespace base |
720 | 738 |
721 #endif // BASE_TIME_TIME_H_ | 739 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |