servo: Merge #8355 - Cleanup exit messages and related code (from Ms2ger:Exit); r=nox

Source-Repo: https://github.com/servo/servo
Source-Revision: 9a465c58429547b59b8a6e1258eaaea46bf7e5a2
This commit is contained in:
Ms2ger 2015-11-07 22:05:45 +05:01
Родитель 9acccdde15
Коммит d1fefa91f1
8 изменённых файлов: 46 добавлений и 54 удалений

Просмотреть файл

@ -25,7 +25,7 @@ use msg::compositor_msg::Epoch;
use msg::constellation_msg::AnimationState;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::WebDriverCommandMsg;
use msg::constellation_msg::{FrameId, PipelineExitType, PipelineId};
use msg::constellation_msg::{FrameId, PipelineId};
use msg::constellation_msg::{IframeLoadInfo, IFrameSandboxState, MozBrowserEvent, NavigationDirection};
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId};
@ -565,7 +565,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
fn handle_exit(&mut self) {
for (_id, ref pipeline) in &self.pipelines {
pipeline.exit(PipelineExitType::Complete);
pipeline.exit();
}
self.image_cache_task.exit();
self.resource_task.send(net_traits::ControlMsg::Exit).unwrap();
@ -1356,7 +1356,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// Inform script, compositor that this pipeline has exited.
match exit_mode {
ExitPipelineMode::Normal => pipeline.exit(PipelineExitType::PipelineOnly),
ExitPipelineMode::Normal => pipeline.exit(),
ExitPipelineMode::Force => pipeline.force_exit(),
}
}

Просмотреть файл

@ -15,7 +15,7 @@ use ipc_channel::router::ROUTER;
use layers::geometry::DevicePixel;
use layout_traits::{LayoutControlChan, LayoutTaskFactory};
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
use msg::constellation_msg::{LoadData, MozBrowserEvent, PipelineExitType, WindowSizeData};
use msg::constellation_msg::{LoadData, MozBrowserEvent, WindowSizeData};
use msg::constellation_msg::{PipelineNamespaceId};
use net_traits::ResourceTask;
use net_traits::image_cache_task::ImageCacheTask;
@ -248,13 +248,13 @@ impl Pipeline {
let _ = self.chrome_to_paint_chan.send(ChromeToPaintMsg::PaintPermissionRevoked);
}
pub fn exit(&self, exit_type: PipelineExitType) {
pub fn exit(&self) {
debug!("pipeline {:?} exiting", self.id);
// Script task handles shutting down layout, and layout handles shutting down the painter.
// For now, if the script task has failed, we give up on clean shutdown.
if self.script_chan
.send(ConstellationControlMsg::ExitPipeline(self.id, exit_type))
.send(ConstellationControlMsg::ExitPipeline(self.id))
.is_ok() {
// Wait until all slave tasks have terminated and run destructors
// NOTE: We don't wait for script task as we don't always own it
@ -275,15 +275,10 @@ impl Pipeline {
}
pub fn force_exit(&self) {
let _ = self.script_chan.send(
ConstellationControlMsg::ExitPipeline(self.id,
PipelineExitType::PipelineOnly)).unwrap();
let _ = self.chrome_to_paint_chan.send(ChromeToPaintMsg::Exit(
None,
PipelineExitType::PipelineOnly));
let _ = self.script_chan.send(ConstellationControlMsg::ExitPipeline(self.id)).unwrap();
let _ = self.chrome_to_paint_chan.send(ChromeToPaintMsg::Exit);
let LayoutControlChan(ref layout_channel) = self.layout_chan;
let _ = layout_channel.send(
LayoutControlMsg::ExitNow(PipelineExitType::PipelineOnly)).unwrap();
let _ = layout_channel.send(LayoutControlMsg::ExitNow).unwrap();
}
pub fn to_sendable(&self) -> CompositionPipeline {

Просмотреть файл

@ -22,7 +22,7 @@ use layers::platform::surface::{NativeDisplay, NativeSurface};
use msg::compositor_msg::{Epoch, FrameTreeId, LayerId, LayerKind, LayerProperties};
use msg::compositor_msg::{PaintListener, ScrollPolicy};
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, PipelineId};
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
use paint_context::PaintContext;
use profile_traits::mem::{self, ReportsChan};
use profile_traits::time::{self, profile};
@ -197,7 +197,7 @@ pub enum Msg {
pub enum LayoutToPaintMsg {
PaintInit(Epoch, PaintLayer),
CanvasLayer(LayerId, IpcSender<CanvasMsg>),
Exit(Option<IpcSender<()>>, PipelineExitType),
Exit(IpcSender<()>),
}
pub enum ChromeToPaintMsg {
@ -205,7 +205,7 @@ pub enum ChromeToPaintMsg {
PaintPermissionGranted,
PaintPermissionRevoked,
CollectReports(ReportsChan),
Exit(Option<IpcSender<()>>, PipelineExitType),
Exit,
}
pub struct PaintTask<C> {
@ -382,14 +382,21 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
// FIXME(njn): should eventually measure the paint task.
channel.send(Vec::new())
}
Msg::FromLayout(LayoutToPaintMsg::Exit(ref response_channel, _)) |
Msg::FromChrome(ChromeToPaintMsg::Exit(ref response_channel, _)) => {
Msg::FromLayout(LayoutToPaintMsg::Exit(ref response_channel)) => {
// Ask the compositor to remove any layers it is holding for this paint task.
// FIXME(mrobinson): This can probably move back to the constellation now.
self.compositor.notify_paint_task_exiting(self.id);
debug!("PaintTask: Exiting.");
let _ = response_channel.send(());
break;
}
Msg::FromChrome(ChromeToPaintMsg::Exit) => {
// Ask the compositor to remove any layers it is holding for this paint task.
// FIXME(mrobinson): This can probably move back to the constellation now.
self.compositor.notify_paint_task_exiting(self.id);
debug!("PaintTask: Exiting.");
response_channel.as_ref().map(|channel| channel.send(()));
break;
}
}

Просмотреть файл

@ -40,7 +40,7 @@ use layout_traits::LayoutTaskFactory;
use log;
use msg::compositor_msg::{Epoch, LayerId, ScrollPolicy};
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, PipelineId};
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheResult, ImageCacheTask};
use net_traits::{PendingAsyncLoad, load_bytes_iter};
use opaque_node::OpaqueNodeMethods;
@ -493,8 +493,8 @@ impl LayoutTask {
self.handle_request_helper(Msg::GetWebFontLoadState(sender),
possibly_locked_rw_data)
}
LayoutControlMsg::ExitNow(exit_type) => {
self.handle_request_helper(Msg::ExitNow(exit_type),
LayoutControlMsg::ExitNow => {
self.handle_request_helper(Msg::ExitNow,
possibly_locked_rw_data)
}
}
@ -632,9 +632,9 @@ impl LayoutTask {
self.prepare_to_exit(response_chan, possibly_locked_rw_data);
return false
},
Msg::ExitNow(exit_type) => {
Msg::ExitNow => {
debug!("layout: ExitNow received");
self.exit_now(possibly_locked_rw_data, exit_type);
self.exit_now(possibly_locked_rw_data);
return false
}
}
@ -712,9 +712,9 @@ impl LayoutTask {
self.handle_reap_layout_data(dead_layout_data)
}
}
Msg::ExitNow(exit_type) => {
Msg::ExitNow => {
debug!("layout task is exiting...");
self.exit_now(possibly_locked_rw_data, exit_type);
self.exit_now(possibly_locked_rw_data);
break
}
Msg::CollectReports(_) => {
@ -730,10 +730,7 @@ impl LayoutTask {
/// Shuts down the layout task now. If there are any DOM nodes left, layout will now (safely)
/// crash.
fn exit_now<'a>(&'a self,
possibly_locked_rw_data: &mut Option<MutexGuard<'a, LayoutTaskData>>,
exit_type: PipelineExitType) {
let (response_chan, response_port) = ipc::channel().unwrap();
possibly_locked_rw_data: &mut Option<MutexGuard<'a, LayoutTaskData>>) {
{
let mut rw_data = self.lock_rw_data(possibly_locked_rw_data);
if let Some(ref mut traversal) = (&mut *rw_data).parallel_traversal {
@ -742,7 +739,8 @@ impl LayoutTask {
LayoutTask::return_rw_data(possibly_locked_rw_data, rw_data);
}
self.paint_chan.send(LayoutToPaintMsg::Exit(Some(response_chan), exit_type)).unwrap();
let (response_chan, response_port) = ipc::channel().unwrap();
self.paint_chan.send(LayoutToPaintMsg::Exit(response_chan)).unwrap();
response_port.recv().unwrap()
}

Просмотреть файл

@ -517,11 +517,3 @@ impl fmt::Display for PipelineId {
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize, HeapSizeOf)]
pub struct SubpageId(pub u32);
// The type of pipeline exit. During complete shutdowns, pipelines do not have to
// release resources automatically released on process termination.
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
pub enum PipelineExitType {
PipelineOnly,
Complete,
}

Просмотреть файл

@ -14,7 +14,7 @@ use ipc_channel::ipc::{IpcReceiver, IpcSender};
use libc::uintptr_t;
use msg::compositor_msg::Epoch;
use msg::compositor_msg::LayerId;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, PipelineId};
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
use msg::constellation_msg::{WindowSizeData};
use net_traits::PendingAsyncLoad;
use net_traits::image_cache_task::ImageCacheTask;
@ -78,7 +78,7 @@ pub enum Msg {
/// Requests that the layout task immediately shut down. There must be no more nodes left after
/// this, or layout will crash.
ExitNow(PipelineExitType),
ExitNow,
/// Get the last epoch counter for this layout task.
GetCurrentEpoch(IpcSender<Epoch>),

Просмотреть файл

@ -64,7 +64,7 @@ use mem::heap_size_of_self_and_children;
use msg::compositor_msg::{EventResult, LayerId, ScriptToCompositorMsg};
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, FocusType, LoadData};
use msg::constellation_msg::{MozBrowserEvent, PipelineExitType, PipelineId};
use msg::constellation_msg::{MozBrowserEvent, PipelineId};
use msg::constellation_msg::{PipelineNamespace};
use msg::constellation_msg::{SubpageId, WindowSizeData, WorkerId};
use msg::webdriver_msg::WebDriverScriptCommand;
@ -871,8 +871,8 @@ impl ScriptTask {
let result = self.profile_event(category, move || {
match msg {
MixedMessage::FromConstellation(ConstellationControlMsg::ExitPipeline(id, exit_type)) => {
if self.handle_exit_pipeline_msg(id, exit_type) {
MixedMessage::FromConstellation(ConstellationControlMsg::ExitPipeline(id)) => {
if self.handle_exit_pipeline_msg(id) {
return Some(false)
}
},
@ -1472,7 +1472,7 @@ impl ScriptTask {
/// Handles a request to exit the script task and shut down layout.
/// Returns true if the script task should shut down and false otherwise.
fn handle_exit_pipeline_msg(&self, id: PipelineId, exit_type: PipelineExitType) -> bool {
fn handle_exit_pipeline_msg(&self, id: PipelineId) -> bool {
self.closed_pipelines.borrow_mut().insert(id);
// Check if the exit message is for an in progress load.
@ -1490,7 +1490,7 @@ impl ScriptTask {
if chan.send(layout_interface::Msg::PrepareToExit(response_chan)).is_ok() {
debug!("shutting down layout for page {:?}", id);
response_port.recv().unwrap();
chan.send(layout_interface::Msg::ExitNow(exit_type)).ok();
chan.send(layout_interface::Msg::ExitNow).ok();
}
let has_pending_loads = self.incomplete_loads.borrow().len() > 0;
@ -1505,13 +1505,13 @@ impl ScriptTask {
let window = page.window();
if window.pipeline() == id {
debug!("shutting down layout for root page {:?}", id);
shut_down_layout(&page, exit_type);
shut_down_layout(&page);
return true
}
// otherwise find just the matching page and exit all sub-pages
if let Some(ref mut child_page) = page.remove(id) {
shut_down_layout(&*child_page, exit_type);
shut_down_layout(&*child_page);
}
false
}
@ -2027,7 +2027,7 @@ impl Drop for ScriptTask {
}
/// Shuts down layout for the given page tree.
fn shut_down_layout(page_tree: &Rc<Page>, exit_type: PipelineExitType) {
fn shut_down_layout(page_tree: &Rc<Page>) {
let mut channels = vec!();
for page in page_tree.iter() {
@ -2052,7 +2052,7 @@ fn shut_down_layout(page_tree: &Rc<Page>, exit_type: PipelineExitType) {
// Destroy the layout task. If there were node leaks, layout will now crash safely.
for chan in channels {
chan.send(layout_interface::Msg::ExitNow(exit_type)).ok();
chan.send(layout_interface::Msg::ExitNow).ok();
}
}

Просмотреть файл

@ -33,7 +33,7 @@ use libc::c_void;
use msg::compositor_msg::{Epoch, LayerId, ScriptToCompositorMsg};
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, WindowSizeData};
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, SubpageId};
use msg::constellation_msg::{MozBrowserEvent, PipelineExitType, PipelineNamespaceId};
use msg::constellation_msg::{MozBrowserEvent, PipelineNamespaceId};
use msg::webdriver_msg::WebDriverScriptCommand;
use net_traits::ResourceTask;
use net_traits::image_cache_task::ImageCacheTask;
@ -55,7 +55,7 @@ unsafe impl Send for UntrustedNodeAddress {}
#[derive(Deserialize, Serialize)]
pub enum LayoutControlMsg {
/// Requests that this layout task exit.
ExitNow(PipelineExitType),
ExitNow,
/// Requests the current epoch (layout counter) from this layout.
GetCurrentEpoch(IpcSender<Epoch>),
/// Asks layout to run another step in its animation.
@ -115,7 +115,7 @@ pub enum ConstellationControlMsg {
/// Notifies script that window has been resized but to not take immediate action.
ResizeInactive(PipelineId, WindowSizeData),
/// Notifies the script that a pipeline should be closed.
ExitPipeline(PipelineId, PipelineExitType),
ExitPipeline(PipelineId),
/// Sends a DOM event.
SendEvent(PipelineId, CompositorEvent),
/// Notifies script of the viewport.