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 #include "content/common/inter_process_time_ticks_converter.h" | 5 #include "content/common/inter_process_time_ticks_converter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 DCHECK_EQ(local_upper_bound.value_, | 45 DCHECK_EQ(local_upper_bound.value_, |
46 ToLocalTimeTicks(remote_upper_bound).value_); | 46 ToLocalTimeTicks(remote_upper_bound).value_); |
47 DCHECK_EQ(target_range, Convert(source_range)); | 47 DCHECK_EQ(target_range, Convert(source_range)); |
48 } | 48 } |
49 | 49 |
50 LocalTimeTicks InterProcessTimeTicksConverter::ToLocalTimeTicks( | 50 LocalTimeTicks InterProcessTimeTicksConverter::ToLocalTimeTicks( |
51 const RemoteTimeTicks& remote_ms) const { | 51 const RemoteTimeTicks& remote_ms) const { |
52 // If input time is "null", return another "null" time. | 52 // If input time is "null", return another "null" time. |
53 if (remote_ms.value_ == 0) | 53 if (remote_ms.value_ == 0) |
54 return LocalTimeTicks(0); | 54 return LocalTimeTicks(0); |
55 DCHECK_LE(remote_lower_bound_, remote_ms.value_); | 55 |
56 DCHECK_GE(remote_upper_bound_, remote_ms.value_); | |
57 RemoteTimeDelta remote_delta = remote_ms - remote_lower_bound_; | 56 RemoteTimeDelta remote_delta = remote_ms - remote_lower_bound_; |
| 57 |
| 58 DCHECK_LE(remote_ms.value_, remote_upper_bound_); |
| 59 // For remote times that come before remote time range, apply just time |
| 60 // offset and ignore scaling, so as to avoid extrapolation error for values |
| 61 // long in the past. |
| 62 if (remote_ms.value_ < remote_lower_bound_) |
| 63 return LocalTimeTicks(local_base_time_ + remote_delta.value_); |
| 64 |
58 return LocalTimeTicks(local_base_time_ + | 65 return LocalTimeTicks(local_base_time_ + |
59 ToLocalTimeDelta(remote_delta).value_); | 66 ToLocalTimeDelta(remote_delta).value_); |
60 } | 67 } |
61 | 68 |
62 LocalTimeDelta InterProcessTimeTicksConverter::ToLocalTimeDelta( | 69 LocalTimeDelta InterProcessTimeTicksConverter::ToLocalTimeDelta( |
63 const RemoteTimeDelta& remote_delta) const { | 70 const RemoteTimeDelta& remote_delta) const { |
64 DCHECK_GE(remote_upper_bound_, remote_lower_bound_ + remote_delta.value_); | 71 DCHECK_GE(remote_upper_bound_, remote_lower_bound_ + remote_delta.value_); |
65 return LocalTimeDelta(Convert(remote_delta.value_)); | 72 return LocalTimeDelta(Convert(remote_delta.value_)); |
66 } | 73 } |
67 | 74 |
68 int64_t InterProcessTimeTicksConverter::Convert(int64_t value) const { | 75 int64_t InterProcessTimeTicksConverter::Convert(int64_t value) const { |
69 if (value <= 0) { | 76 if (value <= 0) { |
70 return value; | 77 return value; |
71 } | 78 } |
72 return numerator_ * value / denominator_; | 79 return numerator_ * value / denominator_; |
73 } | 80 } |
74 | 81 |
75 bool InterProcessTimeTicksConverter::IsSkewAdditiveForMetrics() const { | 82 bool InterProcessTimeTicksConverter::IsSkewAdditiveForMetrics() const { |
76 return numerator_ == 1 && denominator_ == 1; | 83 return numerator_ == 1 && denominator_ == 1; |
77 } | 84 } |
78 | 85 |
79 base::TimeDelta InterProcessTimeTicksConverter::GetSkewForMetrics() const { | 86 base::TimeDelta InterProcessTimeTicksConverter::GetSkewForMetrics() const { |
80 return base::TimeTicks::FromInternalValue(remote_lower_bound_) - | 87 return base::TimeTicks::FromInternalValue(remote_lower_bound_) - |
81 base::TimeTicks::FromInternalValue(local_base_time_); | 88 base::TimeTicks::FromInternalValue(local_base_time_); |
82 } | 89 } |
83 | 90 |
84 } // namespace content | 91 } // namespace content |
OLD | NEW |