Skip to content

Commit

Permalink
#24468 Performance::queue_entries return the index of the added perfo…
Browse files Browse the repository at this point in the history
…rmance entry
  • Loading branch information
shnmorimoto authored and jdm committed Dec 13, 2019
1 parent faee09f commit 9128721
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
35 changes: 15 additions & 20 deletions components/script/dom/performance.rs
Expand Up @@ -233,10 +233,10 @@ impl Performance {
/// <https://w3c.github.io/performance-timeline/#queue-a-performanceentry>
/// Also this algorithm has been extented according to :
/// <https://w3c.github.io/resource-timing/#sec-extensions-performance-interface>
pub fn queue_entry(&self, entry: &PerformanceEntry, add_to_performance_entries_buffer: bool) {
pub fn queue_entry(&self, entry: &PerformanceEntry) -> Option<usize> {
// https://w3c.github.io/performance-timeline/#dfn-determine-eligibility-for-adding-a-performance-entry
if entry.entry_type() == "resource" && !self.should_queue_resource_entry(entry) {
return;
return None;
}

// Steps 1-3.
Expand All @@ -253,26 +253,27 @@ impl Performance {
}

// Step 4.
// If the "add to performance entry buffer flag" is set, add the
// new entry to the buffer.
if add_to_performance_entries_buffer {
self.buffer
.borrow_mut()
.entries
.push(DomRoot::from_ref(entry));
}
//add the new entry to the buffer.
self.buffer
.borrow_mut()
.entries
.push(DomRoot::from_ref(entry));

let entry_last_index = self.buffer.borrow_mut().entries.len() - 1;

// Step 5.
// If there is already a queued notification task, we just bail out.
if self.pending_notification_observers_task.get() {
return;
return None;
}

// Step 6.
// Queue a new notification task.
self.pending_notification_observers_task.set(true);
let task_source = self.global().performance_timeline_task_source();
task_source.queue_notification(&self.global());

Some(entry_last_index)
}

/// Observers notifications task.
Expand Down Expand Up @@ -321,7 +322,7 @@ impl Performance {
.borrow_mut()
.pop_front();
if let Some(ref entry) = entry {
self.queue_entry(entry, true);
self.queue_entry(entry);
} else {
break;
}
Expand Down Expand Up @@ -438,10 +439,7 @@ impl PerformanceMethods for Performance {
// Steps 2 to 6.
let entry = PerformanceMark::new(&global, mark_name, self.now(), 0.);
// Steps 7 and 8.
self.queue_entry(
&entry.upcast::<PerformanceEntry>(),
true, /* buffer performance entry */
);
self.queue_entry(&entry.upcast::<PerformanceEntry>());

// Step 9.
Ok(())
Expand Down Expand Up @@ -488,10 +486,7 @@ impl PerformanceMethods for Performance {
);

// Step 9 and 10.
self.queue_entry(
&entry.upcast::<PerformanceEntry>(),
true, /* buffer performance entry */
);
self.queue_entry(&entry.upcast::<PerformanceEntry>());

// Step 11.
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/servoparser/mod.rs
Expand Up @@ -913,7 +913,7 @@ impl FetchResponseListener for ParserContext {
document
.global()
.performance()
.queue_entry(performance_entry.upcast::<PerformanceEntry>(), true);
.queue_entry(performance_entry.upcast::<PerformanceEntry>());
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/network_listener.rs
Expand Up @@ -62,7 +62,7 @@ pub fn submit_timing_data(
PerformanceResourceTiming::new(global, url, initiator_type, None, resource_timing);
global
.performance()
.queue_entry(performance_entry.upcast::<PerformanceEntry>(), true);
.queue_entry(performance_entry.upcast::<PerformanceEntry>());
}

impl<Listener: PreInvoke + Send + 'static> NetworkListener<Listener> {
Expand Down
7 changes: 3 additions & 4 deletions components/script/script_thread.rs
Expand Up @@ -3889,10 +3889,9 @@ impl ScriptThread {
metric_type,
metric_value,
);
window.Performance().queue_entry(
&entry.upcast::<PerformanceEntry>(),
true, /* buffer performance entry */
);
window
.Performance()
.queue_entry(&entry.upcast::<PerformanceEntry>());
}
}

Expand Down

0 comments on commit 9128721

Please sign in to comment.