This source file includes following definitions.
- remote_upper_bound_
- ToLocalTimeTicks
- ToLocalTimeDelta
#include "content/common/inter_process_time_ticks_converter.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
namespace content {
InterProcessTimeTicksConverter::InterProcessTimeTicksConverter(
const LocalTimeTicks& local_lower_bound,
const LocalTimeTicks& local_upper_bound,
const RemoteTimeTicks& remote_lower_bound,
const RemoteTimeTicks& remote_upper_bound)
: remote_lower_bound_(remote_lower_bound.value_),
remote_upper_bound_(remote_upper_bound.value_) {
int64 target_range = local_upper_bound.value_ - local_lower_bound.value_;
int64 source_range = remote_upper_bound.value_ - remote_lower_bound.value_;
DCHECK_GE(target_range, 0);
DCHECK_GE(source_range, 0);
if (source_range <= target_range) {
numerator_ = 1;
denominator_ = 1;
local_base_time_ =
local_lower_bound.value_ + (target_range - source_range) / 2;
DCHECK_LE(local_lower_bound.value_,
ToLocalTimeTicks(remote_lower_bound).value_);
DCHECK_GE(local_upper_bound.value_,
ToLocalTimeTicks(remote_upper_bound).value_);
return;
}
numerator_ = target_range;
denominator_ = source_range;
local_base_time_ = local_lower_bound.value_;
DCHECK_EQ(local_lower_bound.value_,
ToLocalTimeTicks(remote_lower_bound).value_);
DCHECK_EQ(local_upper_bound.value_,
ToLocalTimeTicks(remote_upper_bound).value_);
DCHECK_EQ(target_range, Convert(source_range));
}
LocalTimeTicks InterProcessTimeTicksConverter::ToLocalTimeTicks(
const RemoteTimeTicks& remote_ms) const {
if (remote_ms.value_ == 0)
return LocalTimeTicks(0);
DCHECK_LE(remote_lower_bound_, remote_ms.value_);
DCHECK_GE(remote_upper_bound_, remote_ms.value_);
RemoteTimeDelta remote_delta = remote_ms - remote_lower_bound_;
return LocalTimeTicks(local_base_time_ +
ToLocalTimeDelta(remote_delta).value_);
}
LocalTimeDelta InterProcessTimeTicksConverter::ToLocalTimeDelta(
const RemoteTimeDelta& remote_delta) const {
DCHECK_GE(remote_upper_bound_, remote_lower_bound_ + remote_delta.value_);
return LocalTimeDelta(Convert(remote_delta.value_));
}
int64 InterProcessTimeTicksConverter::Convert(int64 value) const {
if (value <= 0) {
return value;
}
return numerator_ * value / denominator_;
}
}