Auto merge of #25205 - shnmorimoto:fix_performance_interface_timing_member, r=jdm

Fix performance interface timing member

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #23330 and #24468 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2019-12-14 10:42:16 -05:00 committed by GitHub
commit 226b341078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 87 additions and 402 deletions

View file

@ -96,10 +96,10 @@ impl PerformanceEntryList {
entry_type: Option<DOMString>,
) {
self.entries.retain(|e| {
name.as_ref().map_or(true, |name_| *e.name() == *name_) &&
name.as_ref().map_or(true, |name_| *e.name() != *name_) &&
entry_type
.as_ref()
.map_or(true, |type_| *e.entry_type() == *type_)
.map_or(true, |type_| *e.entry_type() != *type_)
});
}
@ -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.
@ -253,19 +253,18 @@ 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.
@ -273,6 +272,8 @@ impl Performance {
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.
@ -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;
}
@ -370,6 +371,12 @@ impl Performance {
.push_back(DomRoot::from_ref(entry));
false
}
pub fn update_entry(&self, index: usize, entry: &PerformanceEntry) {
if let Some(e) = self.buffer.borrow_mut().entries.get_mut(index) {
*e = DomRoot::from_ref(entry);
}
}
}
impl PerformanceMethods for Performance {
@ -438,10 +445,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(())
@ -488,10 +492,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(())

View file

@ -689,6 +689,8 @@ pub struct ParserContext {
url: ServoUrl,
/// timing data for this resource
resource_timing: ResourceFetchTiming,
/// pushed entry index
pushed_entry_index: Option<usize>,
}
impl ParserContext {
@ -699,6 +701,7 @@ impl ParserContext {
id: id,
url: url,
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Navigation),
pushed_entry_index: None,
}
}
}
@ -774,6 +777,8 @@ impl FetchResponseListener for ParserContext {
self.parser = Some(Trusted::new(&*parser));
self.submit_resource_timing();
match content_type {
Some(ref mime) if mime.type_() == mime::IMAGE => {
self.is_synthesized_document = true;
@ -881,8 +886,16 @@ impl FetchResponseListener for ParserContext {
parser.parse_sync();
}
//TODO only submit if this is the current document resource
self.submit_resource_timing();
//TODO only update if this is the current document resource
if let Some(pushed_index) = self.pushed_entry_index {
let document = &parser.document;
let performance_entry =
PerformanceNavigationTiming::new(&document.global(), 0, 0, &document);
document
.global()
.performance()
.update_entry(pushed_index, performance_entry.upcast::<PerformanceEntry>());
}
}
fn resource_timing_mut(&mut self) -> &mut ResourceFetchTiming {
@ -908,10 +921,10 @@ impl FetchResponseListener for ParserContext {
//TODO nav_start and nav_start_precise
let performance_entry =
PerformanceNavigationTiming::new(&document.global(), 0, 0, &document);
document
self.pushed_entry_index = document
.global()
.performance()
.queue_entry(performance_entry.upcast::<PerformanceEntry>(), true);
.queue_entry(performance_entry.upcast::<PerformanceEntry>());
}
}

View file

@ -34,23 +34,20 @@ partial interface Performance {
[Throws]
void measure(DOMString measureName, optional DOMString startMark, optional DOMString endMark);
void clearMeasures(optional DOMString measureName);
};
//https://w3c.github.io/resource-timing/#sec-extensions-performance-interface
partial interface Performance {
void clearResourceTimings ();
void setResourceTimingBufferSize (unsigned long maxSize);
attribute EventHandler onresourcetimingbufferfull;
};
// FIXME(avada): this should be deprecated, but is currently included for web compat
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#performance-timing-attribute
[Exposed=(Window)]
partial interface Performance {
PerformanceNavigationTiming timing();
};
// https://w3c.github.io/navigation-timing/#extensions-to-the-performance-interface
[Exposed=Window]
partial interface Performance {
[SameObject, Exposed=Window]
[SameObject]
readonly attribute PerformanceNavigationTiming timing;
[SameObject]
readonly attribute PerformanceNavigation navigation;
};

View file

@ -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> {

View file

@ -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>());
}
}