servo: Merge #15179 - Refactor away ScriptThread::alter_resource_utilization() (from servo:alter_resource_utilization); r=nox
authorMs2ger <Ms2ger@gmail.com>
Thu, 26 Jan 2017 08:30:56 -0800
changeset 340654 80d62feb3262939587dd7f4d5eb4e0b0ef26187f
parent 340653 59941ce59674a6465cb2a7fd666e312cf92c93ec
child 340655 e124867d362cbdbc1a6151819545218da83657e3
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
servo: Merge #15179 - Refactor away ScriptThread::alter_resource_utilization() (from servo:alter_resource_utilization); r=nox It's used in two places, one of which already has access to the Window. Source-Repo: https://github.com/servo/servo Source-Revision: 88cd8a3cf0d299a4dc066059d454fdbc395dbfeb
servo/components/script/dom/window.rs
servo/components/script/script_thread.rs
--- a/servo/components/script/dom/window.rs
+++ b/servo/components/script/dom/window.rs
@@ -1578,16 +1578,25 @@ impl Window {
         assert!(PREFS.is_mozbrowser_enabled());
         let custom_event = build_mozbrowser_custom_event(&self, event);
         custom_event.upcast::<Event>().fire(self.upcast());
     }
 
     pub fn evaluate_media_queries_and_report_changes(&self) {
         self.media_query_lists.evaluate_and_report_changes();
     }
+
+    /// Slow down/speed up timers based on visibility.
+    pub fn alter_resource_utilization(&self, visible: bool) {
+        if visible {
+            self.upcast::<GlobalScope>().speed_up_timers();
+        } else {
+            self.upcast::<GlobalScope>().slow_down_timers();
+        }
+    }
 }
 
 impl Window {
     #[allow(unsafe_code)]
     pub fn new(runtime: Rc<Runtime>,
                script_chan: MainThreadScriptChan,
                dom_task_source: DOMManipulationTaskSource,
                user_task_source: UserInteractionTaskSource,
--- a/servo/components/script/script_thread.rs
+++ b/servo/components/script/script_thread.rs
@@ -1269,55 +1269,43 @@ impl ScriptThread {
             });
         }
 
         path_seg.push_str(")");
         reports.extend(get_reports(self.get_cx(), path_seg));
         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);
         if let Some(iframe) = iframe {
             iframe.change_visibility_status(visible);
         }
     }
 
     /// 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");
     }
 
     /// Handles freeze message
     fn handle_freeze_msg(&self, id: PipelineId) {
         let document = self.documents.borrow().find_document(id);
@@ -1862,17 +1850,17 @@ impl ScriptThread {
                 Some(incomplete.pipeline_id));
         }
 
         if incomplete.is_frozen {
             window.upcast::<GlobalScope>().suspend();
         }
 
         if !incomplete.is_visible {
-            self.alter_resource_utilization(incomplete.pipeline_id, false);
+            window.alter_resource_utilization(false);
         }
 
         document.get_current_parser().unwrap()
     }
 
     fn notify_devtools(&self, title: DOMString, url: ServoUrl, ids: (PipelineId, Option<WorkerId>)) {
         if let Some(ref chan) = self.devtools_chan {
             let page_info = DevtoolsPageInfo {