mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Refactor away ScriptThread::alter_resource_utilization().
It's used in two places, one of which already has access to the Window.
This commit is contained in:
parent
c3f0c9054f
commit
a689cf1d34
2 changed files with 21 additions and 24 deletions
|
@ -1270,21 +1270,6 @@ impl ScriptThread {
|
|||
reports_chan.send(reports);
|
||||
}
|
||||
|
||||
/// To slow/speed up timers and manage any other script thread resource based on visibility.
|
||||
/// Returns true if successful.
|
||||
fn alter_resource_utilization(&self, id: PipelineId, visible: bool) -> bool {
|
||||
let window = self.documents.borrow().find_window(id);
|
||||
if let Some(window) = window {
|
||||
if visible {
|
||||
window.upcast::<GlobalScope>().speed_up_timers();
|
||||
} else {
|
||||
window.upcast::<GlobalScope>().slow_down_timers();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Updates iframe element after a change in visibility
|
||||
fn handle_visibility_change_complete_msg(&self, parent_pipeline_id: PipelineId, id: FrameId, visible: bool) {
|
||||
let iframe = self.documents.borrow().find_iframe(parent_pipeline_id, id);
|
||||
|
@ -1295,20 +1280,23 @@ impl ScriptThread {
|
|||
|
||||
/// Handle visibility change message
|
||||
fn handle_visibility_change_msg(&self, id: PipelineId, visible: bool) {
|
||||
let resources_altered = self.alter_resource_utilization(id, visible);
|
||||
|
||||
// Separate message sent since parent script thread could be different (Iframe of different
|
||||
// domain)
|
||||
self.constellation_chan.send(ConstellationMsg::VisibilityChangeComplete(id, visible)).unwrap();
|
||||
|
||||
if !resources_altered {
|
||||
let mut loads = self.incomplete_loads.borrow_mut();
|
||||
if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
|
||||
load.is_visible = visible;
|
||||
let window = self.documents.borrow().find_window(id);
|
||||
match window {
|
||||
Some(window) => {
|
||||
window.alter_resource_utilization(visible);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
None => {
|
||||
let mut loads = self.incomplete_loads.borrow_mut();
|
||||
if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
|
||||
load.is_visible = visible;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
warn!("change visibility message sent to nonexistent pipeline");
|
||||
|
@ -1863,7 +1851,7 @@ impl ScriptThread {
|
|||
}
|
||||
|
||||
if !incomplete.is_visible {
|
||||
self.alter_resource_utilization(incomplete.pipeline_id, false);
|
||||
window.alter_resource_utilization(false);
|
||||
}
|
||||
|
||||
document.get_current_parser().unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue