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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 | 457 |
458 // TimeTicks ------------------------------------------------------------------ | 458 // TimeTicks ------------------------------------------------------------------ |
459 | 459 |
460 class BASE_EXPORT TimeTicks { | 460 class BASE_EXPORT TimeTicks { |
461 public: | 461 public: |
462 TimeTicks() : ticks_(0) { | 462 TimeTicks() : ticks_(0) { |
463 } | 463 } |
464 | 464 |
465 // Platform-dependent tick count representing "right now." | 465 // Platform-dependent tick count representing "right now." |
466 // The resolution of this clock is ~1-15ms. Resolution varies depending | 466 // The resolution of this clock is ~1-15ms. Resolution varies depending |
467 // on hardware/operating system configuration. | 467 // on hardware/operating system configuration. The value should be the same |
468 // across processes. | |
wtc
2011/08/29 21:59:41
Nit: this comment is a little unclear. You can pe
| |
468 static TimeTicks Now(); | 469 static TimeTicks Now(); |
469 | 470 |
470 // Returns a platform-dependent high-resolution tick count. Implementation | 471 // Returns a platform-dependent high-resolution tick count. Implementation |
471 // is hardware dependent and may or may not return sub-millisecond | 472 // is hardware dependent and may or may not return sub-millisecond |
472 // resolution. THIS CALL IS GENERALLY MUCH MORE EXPENSIVE THAN Now() AND | 473 // resolution. THIS CALL IS GENERALLY MUCH MORE EXPENSIVE THAN Now() AND |
473 // SHOULD ONLY BE USED WHEN IT IS REALLY NEEDED. | 474 // SHOULD ONLY BE USED WHEN IT IS REALLY NEEDED. |
474 static TimeTicks HighResNow(); | 475 static TimeTicks HighResNow(); |
475 | 476 |
476 #if defined(OS_WIN) | 477 #if defined(OS_WIN) |
477 // Get the absolute value of QPC time drift. For testing. | 478 // Get the absolute value of QPC time drift. For testing. |
478 static int64 GetQPCDriftMicroseconds(); | 479 static int64 GetQPCDriftMicroseconds(); |
479 | 480 |
480 // Returns true if the high resolution clock is working on this system. | 481 // Returns true if the high resolution clock is working on this system. |
481 // This is only for testing. | 482 // This is only for testing. |
482 static bool IsHighResClockWorking(); | 483 static bool IsHighResClockWorking(); |
483 #endif | 484 #endif |
484 | 485 |
485 // Returns true if this object has not been initialized. | 486 // Returns true if this object has not been initialized. |
486 bool is_null() const { | 487 bool is_null() const { |
487 return ticks_ == 0; | 488 return ticks_ == 0; |
488 } | 489 } |
489 | 490 |
490 // Returns the internal numeric value of the TimeTicks object. | 491 // Returns the internal numeric value of the TimeTicks object. |
491 int64 ToInternalValue() const { | 492 int64 ToInternalValue() const { |
492 return ticks_; | 493 return ticks_; |
493 } | 494 } |
494 | 495 |
496 // Converts an integer value representing TimeTicks to a class. This is used | |
497 // when deserializing a |TimeTicks| structure, using a value that originated | |
498 // from |TimeTicks::ToInternalValue()|. It is not provided as a constructor | |
499 // because the integer type may be unclear from the perspective of a caller. | |
500 static TimeTicks FromInternalValue(int64 ticks) { | |
501 return TimeTicks(ticks); | |
502 } | |
503 | |
495 TimeTicks& operator=(TimeTicks other) { | 504 TimeTicks& operator=(TimeTicks other) { |
496 ticks_ = other.ticks_; | 505 ticks_ = other.ticks_; |
497 return *this; | 506 return *this; |
498 } | 507 } |
499 | 508 |
500 // Compute the difference between two times. | 509 // Compute the difference between two times. |
501 TimeDelta operator-(TimeTicks other) const { | 510 TimeDelta operator-(TimeTicks other) const { |
502 return TimeDelta(ticks_ - other.ticks_); | 511 return TimeDelta(ticks_ - other.ticks_); |
503 } | 512 } |
504 | 513 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 #endif | 566 #endif |
558 }; | 567 }; |
559 | 568 |
560 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 569 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
561 return TimeTicks(t.ticks_ + delta_); | 570 return TimeTicks(t.ticks_ + delta_); |
562 } | 571 } |
563 | 572 |
564 } // namespace base | 573 } // namespace base |
565 | 574 |
566 #endif // BASE_TIME_H_ | 575 #endif // BASE_TIME_H_ |
OLD | NEW |