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 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 // Set up scaling factors, and then deduce shift. | 35 // Set up scaling factors, and then deduce shift. |
36 numerator_ = target_range; | 36 numerator_ = target_range; |
37 denominator_ = source_range; | 37 denominator_ = source_range; |
38 // Find out what we need to shift by to make this really work. | 38 // Find out what we need to shift by to make this really work. |
39 offset_ = local_lower_bound.value_ - Convert(remote_lower_bound.value_); | 39 offset_ = local_lower_bound.value_ - Convert(remote_lower_bound.value_); |
40 DCHECK_GE(local_upper_bound.value_, Convert(remote_upper_bound.value_)); | 40 DCHECK_GE(local_upper_bound.value_, Convert(remote_upper_bound.value_)); |
41 } | 41 } |
42 | 42 |
43 LocalTimeTicks InterProcessTimeTicksConverter::ToLocalTimeTicks( | 43 LocalTimeTicks InterProcessTimeTicksConverter::ToLocalTimeTicks( |
44 const RemoteTimeTicks& remote_ms) { | 44 const RemoteTimeTicks& remote_ms) const { |
| 45 if (!remote_ms.value_) |
| 46 return LocalTimeTicks(0); |
45 DCHECK_LE(remote_lower_bound_, remote_ms.value_); | 47 DCHECK_LE(remote_lower_bound_, remote_ms.value_); |
46 DCHECK_GE(remote_upper_bound_, remote_ms.value_); | 48 DCHECK_GE(remote_upper_bound_, remote_ms.value_); |
47 RemoteTimeDelta remote_delta = remote_ms - remote_lower_bound_; | 49 RemoteTimeDelta remote_delta = remote_ms - remote_lower_bound_; |
48 return LocalTimeTicks(remote_lower_bound_ + offset_ + | 50 return LocalTimeTicks(remote_lower_bound_ + offset_ + |
49 ToLocalTimeDelta(remote_delta).value_); | 51 ToLocalTimeDelta(remote_delta).value_); |
50 } | 52 } |
51 | 53 |
52 LocalTimeDelta InterProcessTimeTicksConverter::ToLocalTimeDelta( | 54 LocalTimeDelta InterProcessTimeTicksConverter::ToLocalTimeDelta( |
53 const RemoteTimeDelta& remote_delta) { | 55 const RemoteTimeDelta& remote_delta) const { |
54 DCHECK_GE(remote_upper_bound_, remote_lower_bound_ + remote_delta.value_); | 56 DCHECK_GE(remote_upper_bound_, remote_lower_bound_ + remote_delta.value_); |
55 return LocalTimeDelta(Convert(remote_delta.value_)); | 57 return LocalTimeDelta(Convert(remote_delta.value_)); |
56 } | 58 } |
57 | 59 |
58 int64 InterProcessTimeTicksConverter::Convert(int64 value) { | 60 int64 InterProcessTimeTicksConverter::Convert(int64 value) const { |
59 if (value <= 0) { | 61 if (value <= 0) { |
60 return value; | 62 return value; |
61 } | 63 } |
62 return numerator_ * value / denominator_; | 64 return numerator_ * value / denominator_; |
63 } | 65 } |
64 | 66 |
65 } // namespace content | 67 } // namespace content |
OLD | NEW |