Commit 40323c0a authored by Hongbo Song's avatar Hongbo Song Committed by Commit Bot

Create a function that converts MonotonicTime To TimeDelta.


Bug: 852061
Change-Id: Id5b3aa5a7d0b2e7e676b1ac09c96cf27550d9794
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148827
Commit-Queue: Hongbo Song <hbsong@google.com>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759825}
parent 6fee242d
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
namespace blink { namespace blink {
LargestContentfulPaint::LargestContentfulPaint(double start_time, LargestContentfulPaint::LargestContentfulPaint(double start_time,
double render_time, base::TimeDelta render_time,
uint64_t size, uint64_t size,
double load_time, base::TimeDelta load_time,
const AtomicString& id, const AtomicString& id,
const String& url, const String& url,
Element* element) Element* element)
...@@ -51,8 +51,8 @@ Element* LargestContentfulPaint::element() const { ...@@ -51,8 +51,8 @@ Element* LargestContentfulPaint::element() const {
void LargestContentfulPaint::BuildJSONValue(V8ObjectBuilder& builder) const { void LargestContentfulPaint::BuildJSONValue(V8ObjectBuilder& builder) const {
PerformanceEntry::BuildJSONValue(builder); PerformanceEntry::BuildJSONValue(builder);
builder.Add("size", size_); builder.Add("size", size_);
builder.Add("renderTime", render_time_); builder.Add("renderTime", render_time_.InMillisecondsF());
builder.Add("loadTime", load_time_); builder.Add("loadTime", load_time_.InMillisecondsF());
builder.Add("id", id_); builder.Add("id", id_);
builder.Add("url", url_); builder.Add("url", url_);
builder.Add("element", element()); builder.Add("element", element());
......
...@@ -18,9 +18,9 @@ class CORE_EXPORT LargestContentfulPaint final : public PerformanceEntry { ...@@ -18,9 +18,9 @@ class CORE_EXPORT LargestContentfulPaint final : public PerformanceEntry {
public: public:
LargestContentfulPaint(double start_time, LargestContentfulPaint(double start_time,
double render_time, base::TimeDelta render_time,
uint64_t size, uint64_t size,
double load_time, base::TimeDelta load_time,
const AtomicString& id, const AtomicString& id,
const String& url, const String& url,
Element*); Element*);
...@@ -30,8 +30,10 @@ class CORE_EXPORT LargestContentfulPaint final : public PerformanceEntry { ...@@ -30,8 +30,10 @@ class CORE_EXPORT LargestContentfulPaint final : public PerformanceEntry {
PerformanceEntryType EntryTypeEnum() const override; PerformanceEntryType EntryTypeEnum() const override;
uint64_t size() const { return size_; } uint64_t size() const { return size_; }
DOMHighResTimeStamp renderTime() const { return render_time_; } DOMHighResTimeStamp renderTime() const {
DOMHighResTimeStamp loadTime() const { return load_time_; } return render_time_.InMillisecondsF();
}
DOMHighResTimeStamp loadTime() const { return load_time_.InMillisecondsF(); }
const AtomicString& id() const { return id_; } const AtomicString& id() const { return id_; }
const String& url() const { return url_; } const String& url() const { return url_; }
Element* element() const; Element* element() const;
...@@ -42,8 +44,8 @@ class CORE_EXPORT LargestContentfulPaint final : public PerformanceEntry { ...@@ -42,8 +44,8 @@ class CORE_EXPORT LargestContentfulPaint final : public PerformanceEntry {
void BuildJSONValue(V8ObjectBuilder&) const override; void BuildJSONValue(V8ObjectBuilder&) const override;
uint64_t size_; uint64_t size_;
DOMHighResTimeStamp render_time_; base::TimeDelta render_time_;
DOMHighResTimeStamp load_time_; base::TimeDelta load_time_;
AtomicString id_; AtomicString id_;
String url_; String url_;
WeakMember<Element> element_; WeakMember<Element> element_;
......
...@@ -996,12 +996,27 @@ DOMHighResTimeStamp Performance::MonotonicTimeToDOMHighResTimeStamp( ...@@ -996,12 +996,27 @@ DOMHighResTimeStamp Performance::MonotonicTimeToDOMHighResTimeStamp(
return ConvertSecondsToDOMHighResTimeStamp(clamped_time_in_seconds); return ConvertSecondsToDOMHighResTimeStamp(clamped_time_in_seconds);
} }
// static
base::TimeDelta Performance::MonotonicTimeToTimeDelta(
base::TimeTicks time_origin,
base::TimeTicks monotonic_time,
bool allow_negative_value) {
return base::TimeDelta::FromMillisecondsD(MonotonicTimeToDOMHighResTimeStamp(
time_origin, monotonic_time, allow_negative_value));
}
DOMHighResTimeStamp Performance::MonotonicTimeToDOMHighResTimeStamp( DOMHighResTimeStamp Performance::MonotonicTimeToDOMHighResTimeStamp(
base::TimeTicks monotonic_time) const { base::TimeTicks monotonic_time) const {
return MonotonicTimeToDOMHighResTimeStamp(time_origin_, monotonic_time, return MonotonicTimeToDOMHighResTimeStamp(time_origin_, monotonic_time,
false /* allow_negative_value */); false /* allow_negative_value */);
} }
base::TimeDelta Performance::MonotonicTimeToTimeDelta(
base::TimeTicks monotonic_time) const {
return MonotonicTimeToTimeDelta(time_origin_, monotonic_time,
false /* allow_negative_value */);
}
DOMHighResTimeStamp Performance::now() const { DOMHighResTimeStamp Performance::now() const {
return MonotonicTimeToDOMHighResTimeStamp(unified_clock_->NowTicks()); return MonotonicTimeToDOMHighResTimeStamp(unified_clock_->NowTicks());
} }
......
...@@ -109,6 +109,11 @@ class CORE_EXPORT Performance : public EventTargetWithInlineData { ...@@ -109,6 +109,11 @@ class CORE_EXPORT Performance : public EventTargetWithInlineData {
base::TimeTicks monotonic_time, base::TimeTicks monotonic_time,
bool allow_negative_value); bool allow_negative_value);
static base::TimeDelta MonotonicTimeToTimeDelta(
base::TimeTicks time_origin,
base::TimeTicks monotonic_time,
bool allow_negative_value);
// Translate given platform monotonic time in seconds into a high resolution // Translate given platform monotonic time in seconds into a high resolution
// DOMHighResTimeStamp in milliseconds. The result timestamp is relative to // DOMHighResTimeStamp in milliseconds. The result timestamp is relative to
// document's time origin and has a time resolution that is safe for // document's time origin and has a time resolution that is safe for
...@@ -116,6 +121,12 @@ class CORE_EXPORT Performance : public EventTargetWithInlineData { ...@@ -116,6 +121,12 @@ class CORE_EXPORT Performance : public EventTargetWithInlineData {
DOMHighResTimeStamp MonotonicTimeToDOMHighResTimeStamp(base::TimeTicks) const; DOMHighResTimeStamp MonotonicTimeToDOMHighResTimeStamp(base::TimeTicks) const;
DOMHighResTimeStamp now() const; DOMHighResTimeStamp now() const;
// Translate given platform monotonic time in seconds into base::TimeDelta.
// The result timestamp is relative to document's time origin and is
// equivalent to the timestamp returned by the function
// MonotonicTimeToDOMHighResTimeStamp.
base::TimeDelta MonotonicTimeToTimeDelta(base::TimeTicks) const;
// High Resolution Time Level 3 timeOrigin. // High Resolution Time Level 3 timeOrigin.
// (https://www.w3.org/TR/hr-time-3/#dom-performance-timeorigin) // (https://www.w3.org/TR/hr-time-3/#dom-performance-timeorigin)
DOMHighResTimeStamp timeOrigin() const; DOMHighResTimeStamp timeOrigin() const;
......
...@@ -458,13 +458,13 @@ void WindowPerformance::OnLargestContentfulPaintUpdated( ...@@ -458,13 +458,13 @@ void WindowPerformance::OnLargestContentfulPaintUpdated(
const AtomicString& id, const AtomicString& id,
const String& url, const String& url,
Element* element) { Element* element) {
double render_timestamp = MonotonicTimeToDOMHighResTimeStamp(paint_time); base::TimeDelta render_timestamp = MonotonicTimeToTimeDelta(paint_time);
double load_timestamp = MonotonicTimeToDOMHighResTimeStamp(load_time); base::TimeDelta load_timestamp = MonotonicTimeToTimeDelta(load_time);
double start_timestamp = base::TimeDelta start_timestamp =
render_timestamp != 0.0 ? render_timestamp : load_timestamp; render_timestamp.is_zero() ? load_timestamp : render_timestamp;
auto* entry = MakeGarbageCollected<LargestContentfulPaint>( auto* entry = MakeGarbageCollected<LargestContentfulPaint>(
start_timestamp, render_timestamp, paint_size, load_timestamp, id, url, start_timestamp.InMillisecondsF(), render_timestamp, paint_size,
element); load_timestamp, id, url, element);
if (HasObserverFor(PerformanceEntry::kLargestContentfulPaint)) if (HasObserverFor(PerformanceEntry::kLargestContentfulPaint))
NotifyObserversOfEntry(*entry); NotifyObserversOfEntry(*entry);
AddLargestContentfulPaint(entry); AddLargestContentfulPaint(entry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment