srpcgen: Use 'const char*' for string parameters
[chromium-blink-merge.git] / content / common / inter_process_time_ticks_converter.cc
blob09c14f0ec62585df5631076dfed515745bfefe92
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
3 // found in the LICENSE file.
5 #include "content/common/inter_process_time_ticks_converter.h"
7 #include "base/logging.h"
9 namespace content {
11 InterProcessTimeTicksConverter::InterProcessTimeTicksConverter(
12 const LocalTimeTicks& local_lower_bound,
13 const LocalTimeTicks& local_upper_bound,
14 const RemoteTimeTicks& remote_lower_bound,
15 const RemoteTimeTicks& remote_upper_bound)
16 : remote_lower_bound_(remote_lower_bound.value_),
17 remote_upper_bound_(remote_upper_bound.value_) {
18 int64 target_range = local_upper_bound.value_ - local_lower_bound.value_;
19 int64 source_range = remote_upper_bound.value_ - remote_lower_bound.value_;
20 if (source_range <= target_range) {
21 // We fit! Just shift the midpoints to match.
22 numerator_ = 1;
23 denominator_ = 1;
24 offset_ = ((local_upper_bound.value_ + local_lower_bound.value_) -
25 (remote_upper_bound.value_ + remote_lower_bound.value_)) / 2;
26 return;
28 // Set up scaling factors, and then deduce shift.
29 numerator_ = target_range;
30 denominator_ = source_range;
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_);
33 DCHECK_GE(local_upper_bound.value_, Convert(remote_upper_bound.value_));
36 LocalTimeTicks InterProcessTimeTicksConverter::ToLocalTimeTicks(
37 const RemoteTimeTicks& remote_ms) {
38 DCHECK_LE(remote_lower_bound_, remote_ms.value_);
39 DCHECK_GE(remote_upper_bound_, remote_ms.value_);
40 RemoteTimeDelta remote_delta = remote_ms - remote_lower_bound_;
41 return LocalTimeTicks(remote_lower_bound_ + offset_ +
42 ToLocalTimeDelta(remote_delta).value_);
45 LocalTimeDelta InterProcessTimeTicksConverter::ToLocalTimeDelta(
46 const RemoteTimeDelta& remote_delta) {
47 DCHECK_GE(remote_upper_bound_, remote_lower_bound_ + remote_delta.value_);
48 return LocalTimeDelta(Convert(remote_delta.value_));
51 int64 InterProcessTimeTicksConverter::Convert(int64 value) {
52 if (value <= 0) {
53 return value;
55 return numerator_ * value / denominator_;
58 } // namespace content