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) (See http://crbug.com/14734). System-dependent | 7 // (1601-01-01 00:00:00 UTC) (See http://crbug.com/14734). System-dependent |
8 // clock interface routines are defined in time_PLATFORM.cc. | 8 // clock interface routines are 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 333 |
334 #if defined(OS_WIN) | 334 #if defined(OS_WIN) |
335 static Time FromFileTime(FILETIME ft); | 335 static Time FromFileTime(FILETIME ft); |
336 FILETIME ToFileTime() const; | 336 FILETIME ToFileTime() const; |
337 | 337 |
338 // The minimum time of a low resolution timer. This is basically a windows | 338 // The minimum time of a low resolution timer. This is basically a windows |
339 // constant of ~15.6ms. While it does vary on some older OS versions, we'll | 339 // constant of ~15.6ms. While it does vary on some older OS versions, we'll |
340 // treat it as static across all windows versions. | 340 // treat it as static across all windows versions. |
341 static const int kMinLowResolutionThresholdMs = 16; | 341 static const int kMinLowResolutionThresholdMs = 16; |
342 | 342 |
343 // Enable or disable Windows high resolution timer. If the high resolution | 343 // Enable or disable Windows high resolution timer. |
344 // timer is not enabled, calls to ActivateHighResolutionTimer will fail. | |
345 // When disabling the high resolution timer, this function will not cause | |
346 // the high resolution timer to be deactivated, but will prevent future | |
347 // activations. | |
348 // Must be called from the main thread. | |
349 // For more details see comments in time_win.cc. | |
350 static void EnableHighResolutionTimer(bool enable); | 344 static void EnableHighResolutionTimer(bool enable); |
351 | 345 |
352 // Activates or deactivates the high resolution timer based on the |activate| | 346 // Activates or deactivates the high resolution timer based on the |activate| |
353 // flag. If the HighResolutionTimer is not Enabled (see | 347 // flag. If the HighResolutionTimer is not Enabled (see |
354 // EnableHighResolutionTimer), this function will return false. Otherwise | 348 // EnableHighResolutionTimer), this function will return false. Otherwise |
355 // returns true. Each successful activate call must be paired with a | 349 // returns true. Each successful activate call must be paired with a |
356 // subsequent deactivate call. | 350 // subsequent deactivate call. |
357 // All callers to activate the high resolution timer must eventually call | 351 // All callers to activate the high resolution timer must eventually call |
358 // this function to deactivate the high resolution timer. | 352 // this function to deactivate the high resolution timer. |
359 static bool ActivateHighResolutionTimer(bool activate); | 353 static bool ActivateHighResolutionTimer(bool activate); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // (e.g. "UTC" which is not specified in RFC822) is treated as if the | 480 // (e.g. "UTC" which is not specified in RFC822) is treated as if the |
487 // timezone is not specified. | 481 // timezone is not specified. |
488 static bool FromStringInternal(const char* time_string, | 482 static bool FromStringInternal(const char* time_string, |
489 bool is_local, | 483 bool is_local, |
490 Time* parsed_time); | 484 Time* parsed_time); |
491 | 485 |
492 // The representation of Jan 1, 1970 UTC in microseconds since the | 486 // The representation of Jan 1, 1970 UTC in microseconds since the |
493 // platform-dependent epoch. | 487 // platform-dependent epoch. |
494 static const int64 kTimeTToMicrosecondsOffset; | 488 static const int64 kTimeTToMicrosecondsOffset; |
495 | 489 |
496 #if defined(OS_WIN) | |
497 // Indicates whether fast timers are usable right now. For instance, | |
498 // when using battery power, we might elect to prevent high speed timers | |
499 // which would draw more power. | |
500 static bool high_resolution_timer_enabled_; | |
501 // Count of activations on the high resolution timer. Only use in tests | |
502 // which are single threaded. | |
503 static int high_resolution_timer_activated_; | |
504 #endif | |
505 | |
506 // Time in microseconds in UTC. | 490 // Time in microseconds in UTC. |
507 int64 us_; | 491 int64 us_; |
508 }; | 492 }; |
509 | 493 |
510 // Inline the TimeDelta factory methods, for fast TimeDelta construction. | 494 // Inline the TimeDelta factory methods, for fast TimeDelta construction. |
511 | 495 |
512 // static | 496 // static |
513 inline TimeDelta TimeDelta::FromDays(int days) { | 497 inline TimeDelta TimeDelta::FromDays(int days) { |
514 // Preserve max to prevent overflow. | 498 // Preserve max to prevent overflow. |
515 if (days == std::numeric_limits<int>::max()) | 499 if (days == std::numeric_limits<int>::max()) |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 #endif | 727 #endif |
744 }; | 728 }; |
745 | 729 |
746 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 730 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
747 return TimeTicks(t.ticks_ + delta_); | 731 return TimeTicks(t.ticks_ + delta_); |
748 } | 732 } |
749 | 733 |
750 } // namespace base | 734 } // namespace base |
751 | 735 |
752 #endif // BASE_TIME_TIME_H_ | 736 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |