| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 a platform-dependent epoch. Each | 6 // microseconds (s/1,000,000) since a platform-dependent epoch. Each |
| 7 // platform's epoch, along with other system-dependent clock interface | 7 // platform's epoch, along with other system-dependent clock interface |
| 8 // routines, is defined in time_PLATFORM.cc. | 8 // routines, is 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 |
| 11 // microseconds. | 11 // microseconds. |
| 12 // | 12 // |
| 13 // TimeTicks represents an abstract time that is always incrementing for use | 13 // TimeTicks represents an abstract time that is always incrementing for use |
| 14 // in measuring time durations. It is internally represented in microseconds. | 14 // in measuring time durations. It is internally represented in microseconds. |
| 15 // It can not be converted to a human-readable time, but is guaranteed not to | 15 // It can not be converted to a human-readable time, but is guaranteed not to |
| 16 // decrease (if the user changes the computer clock, Time::Now() may actually | 16 // decrease (if the user changes the computer clock, Time::Now() may actually |
| 17 // decrease or jump). | 17 // decrease or jump). |
| 18 // | 18 // |
| 19 // These classes are represented as only a 64-bit value, so they can be | 19 // These classes are represented as only a 64-bit value, so they can be |
| 20 // efficiently passed by value. | 20 // efficiently passed by value. |
| 21 | 21 |
| 22 #ifndef BASE_TIME_H_ | 22 #ifndef BASE_TIME_H_ |
| 23 #define BASE_TIME_H_ | 23 #define BASE_TIME_H_ |
| 24 #pragma once | 24 #pragma once |
| 25 | 25 |
| 26 #include <time.h> | 26 #include <time.h> |
| 27 | 27 |
| 28 #include "base/base_api.h" |
| 28 #include "base/basictypes.h" | 29 #include "base/basictypes.h" |
| 29 | 30 |
| 30 #if defined(OS_POSIX) | 31 #if defined(OS_POSIX) |
| 31 // For struct timeval. | 32 // For struct timeval. |
| 32 #include <sys/time.h> | 33 #include <sys/time.h> |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 36 // For FILETIME in FromFileTime, until it moves to a new converter class. | 37 // For FILETIME in FromFileTime, until it moves to a new converter class. |
| 37 // See TODO(iyengar) below. | 38 // See TODO(iyengar) below. |
| 38 #include <windows.h> | 39 #include <windows.h> |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 namespace base { | 42 namespace base { |
| 42 | 43 |
| 43 class Time; | 44 class Time; |
| 44 class TimeTicks; | 45 class TimeTicks; |
| 45 | 46 |
| 46 // This unit test does a lot of manual time manipulation. | 47 // This unit test does a lot of manual time manipulation. |
| 47 class PageLoadTrackerUnitTest; | 48 class PageLoadTrackerUnitTest; |
| 48 | 49 |
| 49 // TimeDelta ------------------------------------------------------------------ | 50 // TimeDelta ------------------------------------------------------------------ |
| 50 | 51 |
| 51 class TimeDelta { | 52 class BASE_API TimeDelta { |
| 52 public: | 53 public: |
| 53 TimeDelta() : delta_(0) { | 54 TimeDelta() : delta_(0) { |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Converts units of time to TimeDeltas. | 57 // Converts units of time to TimeDeltas. |
| 57 static TimeDelta FromDays(int64 days); | 58 static TimeDelta FromDays(int64 days); |
| 58 static TimeDelta FromHours(int64 hours); | 59 static TimeDelta FromHours(int64 hours); |
| 59 static TimeDelta FromMinutes(int64 minutes); | 60 static TimeDelta FromMinutes(int64 minutes); |
| 60 static TimeDelta FromSeconds(int64 secs); | 61 static TimeDelta FromSeconds(int64 secs); |
| 61 static TimeDelta FromMilliseconds(int64 ms); | 62 static TimeDelta FromMilliseconds(int64 ms); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 int64 delta_; | 172 int64 delta_; |
| 172 }; | 173 }; |
| 173 | 174 |
| 174 inline TimeDelta operator*(int64 a, TimeDelta td) { | 175 inline TimeDelta operator*(int64 a, TimeDelta td) { |
| 175 return TimeDelta(a * td.delta_); | 176 return TimeDelta(a * td.delta_); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Time ----------------------------------------------------------------------- | 179 // Time ----------------------------------------------------------------------- |
| 179 | 180 |
| 180 // Represents a wall clock time. | 181 // Represents a wall clock time. |
| 181 class Time { | 182 class BASE_API Time { |
| 182 public: | 183 public: |
| 183 static const int64 kMillisecondsPerSecond = 1000; | 184 static const int64 kMillisecondsPerSecond = 1000; |
| 184 static const int64 kMicrosecondsPerMillisecond = 1000; | 185 static const int64 kMicrosecondsPerMillisecond = 1000; |
| 185 static const int64 kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * | 186 static const int64 kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * |
| 186 kMillisecondsPerSecond; | 187 kMillisecondsPerSecond; |
| 187 static const int64 kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; | 188 static const int64 kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; |
| 188 static const int64 kMicrosecondsPerHour = kMicrosecondsPerMinute * 60; | 189 static const int64 kMicrosecondsPerHour = kMicrosecondsPerMinute * 60; |
| 189 static const int64 kMicrosecondsPerDay = kMicrosecondsPerHour * 24; | 190 static const int64 kMicrosecondsPerDay = kMicrosecondsPerHour * 24; |
| 190 static const int64 kMicrosecondsPerWeek = kMicrosecondsPerDay * 7; | 191 static const int64 kMicrosecondsPerWeek = kMicrosecondsPerDay * 7; |
| 191 static const int64 kNanosecondsPerMicrosecond = 1000; | 192 static const int64 kNanosecondsPerMicrosecond = 1000; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 inline TimeDelta TimeDelta::FromMicroseconds(int64 us) { | 443 inline TimeDelta TimeDelta::FromMicroseconds(int64 us) { |
| 443 return TimeDelta(us); | 444 return TimeDelta(us); |
| 444 } | 445 } |
| 445 | 446 |
| 446 inline Time TimeDelta::operator+(Time t) const { | 447 inline Time TimeDelta::operator+(Time t) const { |
| 447 return Time(t.us_ + delta_); | 448 return Time(t.us_ + delta_); |
| 448 } | 449 } |
| 449 | 450 |
| 450 // TimeTicks ------------------------------------------------------------------ | 451 // TimeTicks ------------------------------------------------------------------ |
| 451 | 452 |
| 452 class TimeTicks { | 453 class BASE_API TimeTicks { |
| 453 public: | 454 public: |
| 454 TimeTicks() : ticks_(0) { | 455 TimeTicks() : ticks_(0) { |
| 455 } | 456 } |
| 456 | 457 |
| 457 // Platform-dependent tick count representing "right now." | 458 // Platform-dependent tick count representing "right now." |
| 458 // The resolution of this clock is ~1-15ms. Resolution varies depending | 459 // The resolution of this clock is ~1-15ms. Resolution varies depending |
| 459 // on hardware/operating system configuration. | 460 // on hardware/operating system configuration. |
| 460 static TimeTicks Now(); | 461 static TimeTicks Now(); |
| 461 | 462 |
| 462 // Returns a platform-dependent high-resolution tick count. Implementation | 463 // Returns a platform-dependent high-resolution tick count. Implementation |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 #endif | 551 #endif |
| 551 }; | 552 }; |
| 552 | 553 |
| 553 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 554 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
| 554 return TimeTicks(t.ticks_ + delta_); | 555 return TimeTicks(t.ticks_ + delta_); |
| 555 } | 556 } |
| 556 | 557 |
| 557 } // namespace base | 558 } // namespace base |
| 558 | 559 |
| 559 #endif // BASE_TIME_H_ | 560 #endif // BASE_TIME_H_ |
| OLD | NEW |