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