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 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // When disabling the high resolution timer, this function will not cause | 277 // When disabling the high resolution timer, this function will not cause |
278 // the high resolution timer to be deactivated, but will prevent future | 278 // the high resolution timer to be deactivated, but will prevent future |
279 // activations. | 279 // activations. |
280 // Must be called from the main thread. | 280 // Must be called from the main thread. |
281 // For more details see comments in time_win.cc. | 281 // For more details see comments in time_win.cc. |
282 static void EnableHighResolutionTimer(bool enable); | 282 static void EnableHighResolutionTimer(bool enable); |
283 | 283 |
284 // Activates or deactivates the high resolution timer based on the |activate| | 284 // Activates or deactivates the high resolution timer based on the |activate| |
285 // flag. If the HighResolutionTimer is not Enabled (see | 285 // flag. If the HighResolutionTimer is not Enabled (see |
286 // EnableHighResolutionTimer), this function will return false. Otherwise | 286 // EnableHighResolutionTimer), this function will return false. Otherwise |
287 // returns true. | 287 // returns true. Each successful activate call must be paired with a |
| 288 // subsequent deactivate call. |
288 // All callers to activate the high resolution timer must eventually call | 289 // All callers to activate the high resolution timer must eventually call |
289 // this function to deactivate the high resolution timer. | 290 // this function to deactivate the high resolution timer. |
290 static bool ActivateHighResolutionTimer(bool activate); | 291 static bool ActivateHighResolutionTimer(bool activate); |
| 292 |
| 293 // Returns true if the high resolution timer is both enabled and activated. |
| 294 // This is provided for testing only, and is not tracked in a thread-safe |
| 295 // way. |
| 296 static bool IsHighResolutionTimerInUse(); |
291 #endif | 297 #endif |
292 | 298 |
293 // Converts an exploded structure representing either the local time or UTC | 299 // Converts an exploded structure representing either the local time or UTC |
294 // into a Time class. | 300 // into a Time class. |
295 static Time FromUTCExploded(const Exploded& exploded) { | 301 static Time FromUTCExploded(const Exploded& exploded) { |
296 return FromExploded(false, exploded); | 302 return FromExploded(false, exploded); |
297 } | 303 } |
298 static Time FromLocalExploded(const Exploded& exploded) { | 304 static Time FromLocalExploded(const Exploded& exploded) { |
299 return FromExploded(true, exploded); | 305 return FromExploded(true, exploded); |
300 } | 306 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 405 |
400 // The representation of Jan 1, 1970 UTC in microseconds since the | 406 // The representation of Jan 1, 1970 UTC in microseconds since the |
401 // platform-dependent epoch. | 407 // platform-dependent epoch. |
402 static const int64 kTimeTToMicrosecondsOffset; | 408 static const int64 kTimeTToMicrosecondsOffset; |
403 | 409 |
404 #if defined(OS_WIN) | 410 #if defined(OS_WIN) |
405 // Indicates whether fast timers are usable right now. For instance, | 411 // Indicates whether fast timers are usable right now. For instance, |
406 // when using battery power, we might elect to prevent high speed timers | 412 // when using battery power, we might elect to prevent high speed timers |
407 // which would draw more power. | 413 // which would draw more power. |
408 static bool high_resolution_timer_enabled_; | 414 static bool high_resolution_timer_enabled_; |
| 415 // Count of activations on the high resolution timer. Only use in tests |
| 416 // which are single threaded. |
| 417 static int high_resolution_timer_activated_; |
409 #endif | 418 #endif |
410 | 419 |
411 // Time in microseconds in UTC. | 420 // Time in microseconds in UTC. |
412 int64 us_; | 421 int64 us_; |
413 }; | 422 }; |
414 | 423 |
415 // Inline the TimeDelta factory methods, for fast TimeDelta construction. | 424 // Inline the TimeDelta factory methods, for fast TimeDelta construction. |
416 | 425 |
417 // static | 426 // static |
418 inline TimeDelta TimeDelta::FromDays(int64 days) { | 427 inline TimeDelta TimeDelta::FromDays(int64 days) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 #endif | 560 #endif |
552 }; | 561 }; |
553 | 562 |
554 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 563 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
555 return TimeTicks(t.ticks_ + delta_); | 564 return TimeTicks(t.ticks_ + delta_); |
556 } | 565 } |
557 | 566 |
558 } // namespace base | 567 } // namespace base |
559 | 568 |
560 #endif // BASE_TIME_H_ | 569 #endif // BASE_TIME_H_ |
OLD | NEW |