compositing: Split Servo up into multiple sandboxed processes.

Multiprocess mode is enabled with the `-M` switch, and sandboxing is
enabled with the `-S` switch.
This commit is contained in:
Patrick Walton 2015-07-24 17:00:10 -07:00 committed by Josh Matthews
parent ff4171170d
commit 1c130819ca
33 changed files with 688 additions and 265 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use font_template::{FontTemplate, FontTemplateDescriptor};
use ipc_channel::ipc;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use net_traits::{AsyncResponseTarget, PendingAsyncLoad, ResourceTask, ResponseAction};
use platform::font_context::FontContextHandle;
@ -15,7 +15,7 @@ use platform::font_template::FontTemplateData;
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::mem;
use std::sync::mpsc::{Sender, Receiver, channel};
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use style::font_face::Source;
@ -77,15 +77,17 @@ impl FontFamily {
}
/// Commands that the FontContext sends to the font cache task.
#[derive(Deserialize, Serialize)]
pub enum Command {
GetFontTemplate(String, FontTemplateDescriptor, Sender<Reply>),
GetLastResortFontTemplate(FontTemplateDescriptor, Sender<Reply>),
AddWebFont(Atom, Source, Sender<()>),
AddDownloadedWebFont(LowercaseString, Url, Vec<u8>, Sender<()>),
Exit(Sender<()>),
GetFontTemplate(String, FontTemplateDescriptor, IpcSender<Reply>),
GetLastResortFontTemplate(FontTemplateDescriptor, IpcSender<Reply>),
AddWebFont(Atom, Source, IpcSender<()>),
AddDownloadedWebFont(LowercaseString, Url, Vec<u8>, IpcSender<()>),
Exit(IpcSender<()>),
}
/// Reply messages sent from the font cache task to the FontContext caller.
#[derive(Deserialize, Serialize)]
pub enum Reply {
GetFontTemplateReply(Option<Arc<FontTemplateData>>),
}
@ -93,8 +95,8 @@ pub enum Reply {
/// The font cache task itself. It maintains a list of reference counted
/// font templates that are currently in use.
struct FontCache {
port: Receiver<Command>,
channel_to_self: Sender<Command>,
port: IpcReceiver<Command>,
channel_to_self: IpcSender<Command>,
generic_fonts: HashMap<LowercaseString, LowercaseString>,
local_families: HashMap<LowercaseString, FontFamily>,
web_families: HashMap<LowercaseString, FontFamily>,
@ -269,14 +271,14 @@ impl FontCache {
/// The public interface to the font cache task, used exclusively by
/// the per-thread/task FontContext structures.
#[derive(Clone)]
#[derive(Clone, Deserialize, Serialize)]
pub struct FontCacheTask {
chan: Sender<Command>,
chan: IpcSender<Command>,
}
impl FontCacheTask {
pub fn new(resource_task: ResourceTask) -> FontCacheTask {
let (chan, port) = channel();
let (chan, port) = ipc::channel().unwrap();
let channel_to_self = chan.clone();
spawn_named("FontCacheTask".to_owned(), move || {
@ -310,7 +312,7 @@ impl FontCacheTask {
pub fn find_font_template(&self, family: String, desc: FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
let (response_chan, response_port) = channel();
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::GetFontTemplate(family, desc, response_chan)).unwrap();
let reply = response_port.recv().unwrap();
@ -325,7 +327,7 @@ impl FontCacheTask {
pub fn last_resort_font_template(&self, desc: FontTemplateDescriptor)
-> Arc<FontTemplateData> {
let (response_chan, response_port) = channel();
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::GetLastResortFontTemplate(desc, response_chan)).unwrap();
let reply = response_port.recv().unwrap();
@ -337,12 +339,12 @@ impl FontCacheTask {
}
}
pub fn add_web_font(&self, family: Atom, src: Source, sender: Sender<()>) {
pub fn add_web_font(&self, family: Atom, src: Source, sender: IpcSender<()>) {
self.chan.send(Command::AddWebFont(family, src, sender)).unwrap();
}
pub fn exit(&self) {
let (response_chan, response_port) = channel();
let (response_chan, response_port) = ipc::channel().unwrap();
self.chan.send(Command::Exit(response_chan)).unwrap();
response_port.recv().unwrap();
}