Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: content/common/inter_process_time_ticks_converter.cc

Issue 7602023: Use a monotonic clock (TimeTicks) to report network times to WebCore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync & Merge Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "content/common/inter_process_time_ticks_converter.h"
6
7 #include "base/logging.h"
8
9 namespace content {
10
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;
27 }
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_));
34 }
35
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_);
43 }
44
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_));
49 }
50
51 int64 InterProcessTimeTicksConverter::Convert(int64 value) {
52 if (value <= 0) {
53 return value;
54 }
55 return numerator_ * value / denominator_;
56 }
57
58 } // namespace content
OLDNEW
« no previous file with comments | « content/common/inter_process_time_ticks_converter.h ('k') | content/common/inter_process_time_ticks_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698