| 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 #include "base/profiler/tracked_time.h" | 5 #include "base/profiler/tracked_time.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <mmsystem.h> // Declare timeGetTime()... after including build_config. | 10 #include <mmsystem.h> // Declare timeGetTime()... after including build_config. |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 namespace tracked_objects { | 13 namespace tracked_objects { |
| 14 | 14 |
| 15 Duration::Duration() : ms_(0) {} | 15 Duration::Duration() : ms_(0) {} |
| 16 Duration::Duration(int32 duration) : ms_(duration) {} | 16 Duration::Duration(int32_t duration) : ms_(duration) {} |
| 17 | 17 |
| 18 Duration& Duration::operator+=(const Duration& other) { | 18 Duration& Duration::operator+=(const Duration& other) { |
| 19 ms_ += other.ms_; | 19 ms_ += other.ms_; |
| 20 return *this; | 20 return *this; |
| 21 } | 21 } |
| 22 | 22 |
| 23 Duration Duration::operator+(const Duration& other) const { | 23 Duration Duration::operator+(const Duration& other) const { |
| 24 return Duration(ms_ + other.ms_); | 24 return Duration(ms_ + other.ms_); |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool Duration::operator==(const Duration& other) const { | 27 bool Duration::operator==(const Duration& other) const { |
| 28 return ms_ == other.ms_; | 28 return ms_ == other.ms_; |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool Duration::operator!=(const Duration& other) const { | 31 bool Duration::operator!=(const Duration& other) const { |
| 32 return ms_ != other.ms_; | 32 return ms_ != other.ms_; |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool Duration::operator>(const Duration& other) const { | 35 bool Duration::operator>(const Duration& other) const { |
| 36 return ms_ > other.ms_; | 36 return ms_ > other.ms_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 Duration Duration::FromMilliseconds(int ms) { return Duration(ms); } | 40 Duration Duration::FromMilliseconds(int ms) { return Duration(ms); } |
| 41 | 41 |
| 42 int32 Duration::InMilliseconds() const { return ms_; } | 42 int32_t Duration::InMilliseconds() const { |
| 43 return ms_; |
| 44 } |
| 43 | 45 |
| 44 //------------------------------------------------------------------------------ | 46 //------------------------------------------------------------------------------ |
| 45 | 47 |
| 46 TrackedTime::TrackedTime() : ms_(0) {} | 48 TrackedTime::TrackedTime() : ms_(0) {} |
| 47 TrackedTime::TrackedTime(int32 ms) : ms_(ms) {} | 49 TrackedTime::TrackedTime(int32_t ms) : ms_(ms) {} |
| 48 TrackedTime::TrackedTime(const base::TimeTicks& time) | 50 TrackedTime::TrackedTime(const base::TimeTicks& time) |
| 49 : ms_(static_cast<int32>((time - base::TimeTicks()).InMilliseconds())) { | 51 : ms_(static_cast<int32_t>((time - base::TimeTicks()).InMilliseconds())) {} |
| 50 } | |
| 51 | 52 |
| 52 // static | 53 // static |
| 53 TrackedTime TrackedTime::Now() { | 54 TrackedTime TrackedTime::Now() { |
| 54 return TrackedTime(base::TimeTicks::Now()); | 55 return TrackedTime(base::TimeTicks::Now()); |
| 55 } | 56 } |
| 56 | 57 |
| 57 Duration TrackedTime::operator-(const TrackedTime& other) const { | 58 Duration TrackedTime::operator-(const TrackedTime& other) const { |
| 58 return Duration(ms_ - other.ms_); | 59 return Duration(ms_ - other.ms_); |
| 59 } | 60 } |
| 60 | 61 |
| 61 TrackedTime TrackedTime::operator+(const Duration& other) const { | 62 TrackedTime TrackedTime::operator+(const Duration& other) const { |
| 62 return TrackedTime(ms_ + other.ms_); | 63 return TrackedTime(ms_ + other.ms_); |
| 63 } | 64 } |
| 64 | 65 |
| 65 bool TrackedTime::is_null() const { return ms_ == 0; } | 66 bool TrackedTime::is_null() const { return ms_ == 0; } |
| 66 | 67 |
| 67 } // namespace tracked_objects | 68 } // namespace tracked_objects |
| OLD | NEW |