| 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 #ifndef CONTENT_COMMON_INTER_PROCESS_TIME_TICKS_CONVERTER_H_ | 5 #ifndef CONTENT_COMMON_INTER_PROCESS_TIME_TICKS_CONVERTER_H_ |
| 6 #define CONTENT_COMMON_INTER_PROCESS_TIME_TICKS_CONVERTER_H_ | 6 #define CONTENT_COMMON_INTER_PROCESS_TIME_TICKS_CONVERTER_H_ |
| 7 | 7 |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "content/common/content_export.h" |
| 9 | 10 |
| 10 namespace content { | 11 namespace content { |
| 11 | 12 |
| 12 class LocalTimeDelta; | 13 class LocalTimeDelta; |
| 13 class LocalTimeTicks; | 14 class LocalTimeTicks; |
| 14 class RemoteTimeDelta; | 15 class RemoteTimeDelta; |
| 15 class RemoteTimeTicks; | 16 class RemoteTimeTicks; |
| 16 | 17 |
| 17 // On Windows, TimeTicks are not consistent between processes. Often, the values | 18 // On Windows, TimeTicks are not consistent between processes. Often, the values |
| 18 // on one process have a static offset relative to another. Occasionally, these | 19 // on one process have a static offset relative to another. Occasionally, these |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 // | 39 // |
| 39 // Once these bounds are determined, values within the remote process's range | 40 // Once these bounds are determined, values within the remote process's range |
| 40 // can be converted to the local process's range. The values are converted as | 41 // can be converted to the local process's range. The values are converted as |
| 41 // follows: | 42 // follows: |
| 42 // | 43 // |
| 43 // 1. If the remote's range exceeds the local's range, it is scaled to fit. | 44 // 1. If the remote's range exceeds the local's range, it is scaled to fit. |
| 44 // Any values converted will have the same scale factor applied. | 45 // Any values converted will have the same scale factor applied. |
| 45 // | 46 // |
| 46 // 2. The remote's range is shifted so that it is centered within the | 47 // 2. The remote's range is shifted so that it is centered within the |
| 47 // local's range. Any values converted will be shifted the same amount. | 48 // local's range. Any values converted will be shifted the same amount. |
| 48 class InterProcessTimeTicksConverter { | 49 class CONTENT_EXPORT InterProcessTimeTicksConverter { |
| 49 public: | 50 public: |
| 50 InterProcessTimeTicksConverter(const LocalTimeTicks& local_lower_bound, | 51 InterProcessTimeTicksConverter(const LocalTimeTicks& local_lower_bound, |
| 51 const LocalTimeTicks& local_upper_bound, | 52 const LocalTimeTicks& local_upper_bound, |
| 52 const RemoteTimeTicks& remote_lower_bound, | 53 const RemoteTimeTicks& remote_lower_bound, |
| 53 const RemoteTimeTicks& remote_upper_bound); | 54 const RemoteTimeTicks& remote_upper_bound); |
| 54 | 55 |
| 55 // Returns the value within the local's bounds that correlates to | 56 // Returns the value within the local's bounds that correlates to |
| 56 // |remote_ms|. | 57 // |remote_ms|. |
| 57 LocalTimeTicks ToLocalTimeTicks(const RemoteTimeTicks& remote_ms); | 58 LocalTimeTicks ToLocalTimeTicks(const RemoteTimeTicks& remote_ms); |
| 58 | 59 |
| 59 // Returns the equivalent delta after applying remote-to-local scaling to | 60 // Returns the equivalent delta after applying remote-to-local scaling to |
| 60 // |remote_delta|. | 61 // |remote_delta|. |
| 61 LocalTimeDelta ToLocalTimeDelta(const RemoteTimeDelta& remote_delta); | 62 LocalTimeDelta ToLocalTimeDelta(const RemoteTimeDelta& remote_delta); |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 int64 Convert(int64 value); | 65 int64 Convert(int64 value); |
| 65 | 66 |
| 66 int64 offset_; | 67 int64 offset_; |
| 67 int64 numerator_; | 68 int64 numerator_; |
| 68 int64 denominator_; | 69 int64 denominator_; |
| 69 | 70 |
| 70 int64 remote_lower_bound_; | 71 int64 remote_lower_bound_; |
| 71 int64 remote_upper_bound_; | 72 int64 remote_upper_bound_; |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 class LocalTimeDelta { | 75 class CONTENT_EXPORT LocalTimeDelta { |
| 75 public: | 76 public: |
| 76 int ToInt32() const { return value_; } | 77 int ToInt32() const { return value_; } |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 friend class InterProcessTimeTicksConverter; | 80 friend class InterProcessTimeTicksConverter; |
| 80 friend class LocalTimeTicks; | 81 friend class LocalTimeTicks; |
| 81 | 82 |
| 82 LocalTimeDelta(int value) : value_(value) {} | 83 LocalTimeDelta(int value) : value_(value) {} |
| 83 | 84 |
| 84 int value_; | 85 int value_; |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 class LocalTimeTicks { | 88 class CONTENT_EXPORT LocalTimeTicks { |
| 88 public: | 89 public: |
| 89 static LocalTimeTicks FromTimeTicks(const base::TimeTicks& value) { | 90 static LocalTimeTicks FromTimeTicks(const base::TimeTicks& value) { |
| 90 return LocalTimeTicks(value.ToInternalValue()); | 91 return LocalTimeTicks(value.ToInternalValue()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 base::TimeTicks ToTimeTicks() { | 94 base::TimeTicks ToTimeTicks() { |
| 94 return base::TimeTicks::FromInternalValue(value_); | 95 return base::TimeTicks::FromInternalValue(value_); |
| 95 } | 96 } |
| 96 | 97 |
| 97 LocalTimeTicks operator+(const LocalTimeDelta& delta) { | 98 LocalTimeTicks operator+(const LocalTimeDelta& delta) { |
| 98 return LocalTimeTicks(value_ + delta.value_); | 99 return LocalTimeTicks(value_ + delta.value_); |
| 99 } | 100 } |
| 100 | 101 |
| 101 private: | 102 private: |
| 102 friend class InterProcessTimeTicksConverter; | 103 friend class InterProcessTimeTicksConverter; |
| 103 | 104 |
| 104 LocalTimeTicks(int64 value) : value_(value) {} | 105 LocalTimeTicks(int64 value) : value_(value) {} |
| 105 | 106 |
| 106 int64 value_; | 107 int64 value_; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 class RemoteTimeDelta { | 110 class CONTENT_EXPORT RemoteTimeDelta { |
| 110 public: | 111 public: |
| 111 static RemoteTimeDelta FromRawDelta(int delta) { | 112 static RemoteTimeDelta FromRawDelta(int delta) { |
| 112 return RemoteTimeDelta(delta); | 113 return RemoteTimeDelta(delta); |
| 113 } | 114 } |
| 114 | 115 |
| 115 private: | 116 private: |
| 116 friend class InterProcessTimeTicksConverter; | 117 friend class InterProcessTimeTicksConverter; |
| 117 friend class RemoteTimeTicks; | 118 friend class RemoteTimeTicks; |
| 118 | 119 |
| 119 RemoteTimeDelta(int value) : value_(value) {} | 120 RemoteTimeDelta(int value) : value_(value) {} |
| 120 | 121 |
| 121 int value_; | 122 int value_; |
| 122 }; | 123 }; |
| 123 | 124 |
| 124 class RemoteTimeTicks { | 125 class CONTENT_EXPORT RemoteTimeTicks { |
| 125 public: | 126 public: |
| 126 static RemoteTimeTicks FromTimeTicks(const base::TimeTicks& ticks) { | 127 static RemoteTimeTicks FromTimeTicks(const base::TimeTicks& ticks) { |
| 127 return RemoteTimeTicks(ticks.ToInternalValue()); | 128 return RemoteTimeTicks(ticks.ToInternalValue()); |
| 128 } | 129 } |
| 129 | 130 |
| 130 RemoteTimeDelta operator-(const RemoteTimeTicks& rhs) const { | 131 RemoteTimeDelta operator-(const RemoteTimeTicks& rhs) const { |
| 131 return RemoteTimeDelta(value_ - rhs.value_); | 132 return RemoteTimeDelta(value_ - rhs.value_); |
| 132 } | 133 } |
| 133 | 134 |
| 134 private: | 135 private: |
| 135 friend class InterProcessTimeTicksConverter; | 136 friend class InterProcessTimeTicksConverter; |
| 136 | 137 |
| 137 RemoteTimeTicks(int64 value) : value_(value) {} | 138 RemoteTimeTicks(int64 value) : value_(value) {} |
| 138 | 139 |
| 139 int64 value_; | 140 int64 value_; |
| 140 }; | 141 }; |
| 141 | 142 |
| 142 } // namespace content | 143 } // namespace content |
| 143 | 144 |
| 144 #endif // CONTENT_COMMON_INTER_PROCESS_TIME_TICKS_CONVERTER_H_ | 145 #endif // CONTENT_COMMON_INTER_PROCESS_TIME_TICKS_CONVERTER_H_ |
| OLD | NEW |