mirror of
https://github.com/servo/servo.git
synced 2025-07-25 16:20:36 +01:00
Replace usage of ResponseSenders by LoadConsumer
This commit is contained in:
parent
40ee41ca92
commit
c1f25bbfe4
8 changed files with 28 additions and 43 deletions
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use net_traits::{LoadData, Metadata,ResponseSenders};
|
use net_traits::{LoadData, Metadata, LoadConsumer};
|
||||||
use net_traits::ProgressMsg::Done;
|
use net_traits::ProgressMsg::Done;
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MIMEClassifier;
|
||||||
use resource_task::start_sending;
|
use resource_task::start_sending;
|
||||||
|
@ -18,7 +18,7 @@ use std::borrow::IntoCow;
|
||||||
use std::fs::PathExt;
|
use std::fs::PathExt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub fn factory(mut load_data: LoadData, start_chan: ResponseSenders, classifier: Arc<MIMEClassifier>) {
|
pub fn factory(mut load_data: LoadData, start_chan: LoadConsumer, classifier: Arc<MIMEClassifier>) {
|
||||||
match load_data.url.non_relative_scheme_data().unwrap() {
|
match load_data.url.non_relative_scheme_data().unwrap() {
|
||||||
"blank" => {
|
"blank" => {
|
||||||
let chan = start_sending(start_chan, Metadata {
|
let chan = start_sending(start_chan, Metadata {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use net_traits::{LoadData, Metadata, ResponseSenders};
|
use net_traits::{LoadData, Metadata, LoadConsumer};
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MIMEClassifier;
|
||||||
use resource_task::start_sending;
|
use resource_task::start_sending;
|
||||||
|
@ -13,7 +13,7 @@ use hyper::mime::Mime;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use url::{percent_decode, SchemeData};
|
use url::{percent_decode, SchemeData};
|
||||||
|
|
||||||
pub fn factory(load_data: LoadData, senders: ResponseSenders, _classifier: Arc<MIMEClassifier>) {
|
pub fn factory(load_data: LoadData, senders: LoadConsumer, _classifier: Arc<MIMEClassifier>) {
|
||||||
// NB: we don't spawn a new task.
|
// NB: we don't spawn a new task.
|
||||||
// Hypothesis: data URLs are too small for parallel base64 etc. to be worth it.
|
// Hypothesis: data URLs are too small for parallel base64 etc. to be worth it.
|
||||||
// Should be tested at some point.
|
// Should be tested at some point.
|
||||||
|
@ -21,7 +21,7 @@ pub fn factory(load_data: LoadData, senders: ResponseSenders, _classifier: Arc<M
|
||||||
load(load_data, senders)
|
load(load_data, senders)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(load_data: LoadData, start_chan: ResponseSenders) {
|
pub fn load(load_data: LoadData, start_chan: LoadConsumer) {
|
||||||
let url = load_data.url;
|
let url = load_data.url;
|
||||||
assert!(&*url.scheme == "data");
|
assert!(&*url.scheme == "data");
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use net_traits::{LoadData, Metadata, ResponseSenders};
|
use net_traits::{LoadData, Metadata, LoadConsumer};
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MIMEClassifier;
|
||||||
use resource_task::{start_sending, start_sending_sniffed, ProgressSender};
|
use resource_task::{start_sending, start_sending_sniffed, ProgressSender};
|
||||||
|
@ -43,7 +43,7 @@ fn read_all(reader: &mut File, progress_chan: &ProgressSender)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn factory(load_data: LoadData, senders: ResponseSenders, classifier: Arc<MIMEClassifier>) {
|
pub fn factory(load_data: LoadData, senders: LoadConsumer, classifier: Arc<MIMEClassifier>) {
|
||||||
let url = load_data.url;
|
let url = load_data.url;
|
||||||
assert!(&*url.scheme == "file");
|
assert!(&*url.scheme == "file");
|
||||||
spawn_named("file_loader".to_owned(), move || {
|
spawn_named("file_loader".to_owned(), move || {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use net_traits::{ControlMsg, CookieSource, LoadData, Metadata, ResponseSenders};
|
use net_traits::{ControlMsg, CookieSource, LoadData, Metadata, LoadConsumer};
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MIMEClassifier;
|
||||||
use resource_task::{start_sending_opt, start_sending_sniffed_opt};
|
use resource_task::{start_sending_opt, start_sending_sniffed_opt};
|
||||||
|
@ -32,13 +32,13 @@ use url::{Url, UrlParser};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
|
||||||
pub fn factory(cookies_chan: Sender<ControlMsg>)
|
pub fn factory(cookies_chan: Sender<ControlMsg>)
|
||||||
-> Box<Invoke<(LoadData, ResponseSenders, Arc<MIMEClassifier>)> + Send> {
|
-> Box<Invoke<(LoadData, LoadConsumer, Arc<MIMEClassifier>)> + Send> {
|
||||||
box move |(load_data, senders, classifier)| {
|
box move |(load_data, senders, classifier)| {
|
||||||
spawn_named("http_loader".to_owned(), move || load(load_data, senders, classifier, cookies_chan))
|
spawn_named("http_loader".to_owned(), move || load(load_data, senders, classifier, cookies_chan))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_error(url: Url, err: String, start_chan: ResponseSenders) {
|
fn send_error(url: Url, err: String, start_chan: LoadConsumer) {
|
||||||
let mut metadata: Metadata = Metadata::default(url);
|
let mut metadata: Metadata = Metadata::default(url);
|
||||||
metadata.status = None;
|
metadata.status = None;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ fn read_block<R: Read>(reader: &mut R) -> Result<ReadResult, ()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(mut load_data: LoadData, start_chan: ResponseSenders, classifier: Arc<MIMEClassifier>, cookies_chan: Sender<ControlMsg>) {
|
fn load(mut load_data: LoadData, start_chan: LoadConsumer, classifier: Arc<MIMEClassifier>, cookies_chan: Sender<ControlMsg>) {
|
||||||
// FIXME: At the time of writing this FIXME, servo didn't have any central
|
// FIXME: At the time of writing this FIXME, servo didn't have any central
|
||||||
// location for configuration. If you're reading this and such a
|
// location for configuration. If you're reading this and such a
|
||||||
// repository DOES exist, please update this constant to use it.
|
// repository DOES exist, please update this constant to use it.
|
||||||
|
@ -339,7 +339,7 @@ reason: \"certificate verify failed\" }]";
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_data<R: Read>(reader: &mut R,
|
fn send_data<R: Read>(reader: &mut R,
|
||||||
start_chan: ResponseSenders,
|
start_chan: LoadConsumer,
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
classifier: Arc<MIMEClassifier>) {
|
classifier: Arc<MIMEClassifier>) {
|
||||||
let (progress_chan, mut chunk) = {
|
let (progress_chan, mut chunk) = {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use cookie_storage::CookieStorage;
|
||||||
use cookie;
|
use cookie;
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MIMEClassifier;
|
||||||
|
|
||||||
use net_traits::{ControlMsg, LoadData, LoadResponse, ResponseSenders, LoadConsumer};
|
use net_traits::{ControlMsg, LoadData, LoadResponse, LoadConsumer};
|
||||||
use net_traits::{Metadata, ProgressMsg, ResourceTask, AsyncResponseTarget, ResponseAction};
|
use net_traits::{Metadata, ProgressMsg, ResourceTask, AsyncResponseTarget, ResponseAction};
|
||||||
use net_traits::ProgressMsg::Done;
|
use net_traits::ProgressMsg::Done;
|
||||||
use util::opts;
|
use util::opts;
|
||||||
|
@ -81,19 +81,19 @@ impl ProgressSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For use by loaders in responding to a Load message.
|
/// For use by loaders in responding to a Load message.
|
||||||
pub fn start_sending(start_chan: ResponseSenders, metadata: Metadata) -> ProgressSender {
|
pub fn start_sending(start_chan: LoadConsumer, metadata: Metadata) -> ProgressSender {
|
||||||
start_sending_opt(start_chan, metadata).ok().unwrap()
|
start_sending_opt(start_chan, metadata).ok().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For use by loaders in responding to a Load message that allows content sniffing.
|
/// For use by loaders in responding to a Load message that allows content sniffing.
|
||||||
pub fn start_sending_sniffed(start_chan: ResponseSenders, metadata: Metadata,
|
pub fn start_sending_sniffed(start_chan: LoadConsumer, metadata: Metadata,
|
||||||
classifier: Arc<MIMEClassifier>, partial_body: &Vec<u8>)
|
classifier: Arc<MIMEClassifier>, partial_body: &Vec<u8>)
|
||||||
-> ProgressSender {
|
-> ProgressSender {
|
||||||
start_sending_sniffed_opt(start_chan, metadata, classifier, partial_body).ok().unwrap()
|
start_sending_sniffed_opt(start_chan, metadata, classifier, partial_body).ok().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For use by loaders in responding to a Load message that allows content sniffing.
|
/// For use by loaders in responding to a Load message that allows content sniffing.
|
||||||
pub fn start_sending_sniffed_opt(start_chan: ResponseSenders, mut metadata: Metadata,
|
pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadata,
|
||||||
classifier: Arc<MIMEClassifier>, partial_body: &Vec<u8>)
|
classifier: Arc<MIMEClassifier>, partial_body: &Vec<u8>)
|
||||||
-> Result<ProgressSender, ()> {
|
-> Result<ProgressSender, ()> {
|
||||||
if opts::get().sniff_mime_types {
|
if opts::get().sniff_mime_types {
|
||||||
|
@ -116,9 +116,9 @@ pub fn start_sending_sniffed_opt(start_chan: ResponseSenders, mut metadata: Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For use by loaders in responding to a Load message.
|
/// For use by loaders in responding to a Load message.
|
||||||
pub fn start_sending_opt(start_chan: ResponseSenders, metadata: Metadata) -> Result<ProgressSender, ()> {
|
pub fn start_sending_opt(start_chan: LoadConsumer, metadata: Metadata) -> Result<ProgressSender, ()> {
|
||||||
match start_chan {
|
match start_chan {
|
||||||
ResponseSenders::Channel(start_chan) => {
|
LoadConsumer::Channel(start_chan) => {
|
||||||
let (progress_chan, progress_port) = channel();
|
let (progress_chan, progress_port) = channel();
|
||||||
let result = start_chan.send(LoadResponse {
|
let result = start_chan.send(LoadResponse {
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
|
@ -129,7 +129,7 @@ pub fn start_sending_opt(start_chan: ResponseSenders, metadata: Metadata) -> Res
|
||||||
Err(_) => Err(())
|
Err(_) => Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResponseSenders::Listener(target) => {
|
LoadConsumer::Listener(target) => {
|
||||||
target.invoke_with_listener(ResponseAction::HeadersAvailable(metadata));
|
target.invoke_with_listener(ResponseAction::HeadersAvailable(metadata));
|
||||||
Ok(ProgressSender::Listener(target))
|
Ok(ProgressSender::Listener(target))
|
||||||
}
|
}
|
||||||
|
@ -238,14 +238,13 @@ impl ResourceManager {
|
||||||
|
|
||||||
self.user_agent.as_ref().map(|ua| load_data.headers.set(UserAgent(ua.clone())));
|
self.user_agent.as_ref().map(|ua| load_data.headers.set(UserAgent(ua.clone())));
|
||||||
|
|
||||||
fn from_factory(factory: fn(LoadData, ResponseSenders, Arc<MIMEClassifier>))
|
fn from_factory(factory: fn(LoadData, LoadConsumer, Arc<MIMEClassifier>))
|
||||||
-> Box<Invoke<(LoadData, ResponseSenders, Arc<MIMEClassifier>)> + Send> {
|
-> Box<Invoke<(LoadData, LoadConsumer, Arc<MIMEClassifier>)> + Send> {
|
||||||
box move |(load_data, senders, classifier)| {
|
box move |(load_data, senders, classifier)| {
|
||||||
factory(load_data, senders, classifier)
|
factory(load_data, senders, classifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let senders = ResponseSenders::from_consumer(consumer);
|
|
||||||
let loader = match &*load_data.url.scheme {
|
let loader = match &*load_data.url.scheme {
|
||||||
"file" => from_factory(file_loader::factory),
|
"file" => from_factory(file_loader::factory),
|
||||||
"http" | "https" | "view-source" => http_loader::factory(self.resource_task.clone()),
|
"http" | "https" | "view-source" => http_loader::factory(self.resource_task.clone()),
|
||||||
|
@ -253,13 +252,13 @@ impl ResourceManager {
|
||||||
"about" => from_factory(about_loader::factory),
|
"about" => from_factory(about_loader::factory),
|
||||||
_ => {
|
_ => {
|
||||||
debug!("resource_task: no loader for scheme {}", load_data.url.scheme);
|
debug!("resource_task: no loader for scheme {}", load_data.url.scheme);
|
||||||
start_sending(senders, Metadata::default(load_data.url))
|
start_sending(consumer, Metadata::default(load_data.url))
|
||||||
.send(ProgressMsg::Done(Err("no loader for scheme".to_string()))).unwrap();
|
.send(ProgressMsg::Done(Err("no loader for scheme".to_string()))).unwrap();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
debug!("resource_task: loading url: {}", load_data.url.serialize());
|
debug!("resource_task: loading url: {}", load_data.url.serialize());
|
||||||
|
|
||||||
loader.invoke((load_data, senders, self.mime_classifier.clone()));
|
loader.invoke((load_data, consumer, self.mime_classifier.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,20 +203,6 @@ pub enum CookieSource {
|
||||||
NonHTTP,
|
NonHTTP,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ResponseSenders {
|
|
||||||
Channel(Sender<LoadResponse>),
|
|
||||||
Listener(Box<AsyncResponseTarget+ Send>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResponseSenders {
|
|
||||||
pub fn from_consumer(consumer: LoadConsumer) -> ResponseSenders {
|
|
||||||
match consumer {
|
|
||||||
LoadConsumer::Channel(c) => ResponseSenders::Channel(c),
|
|
||||||
LoadConsumer::Listener(l) => ResponseSenders::Listener(l),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Messages sent in response to a `Load` message
|
/// Messages sent in response to a `Load` message
|
||||||
#[derive(PartialEq,Debug)]
|
#[derive(PartialEq,Debug)]
|
||||||
pub enum ProgressMsg {
|
pub enum ProgressMsg {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
|
|
||||||
use net_traits::ResponseSenders::Channel;
|
use net_traits::LoadConsumer::Channel;
|
||||||
use net_traits::LoadData;
|
use net_traits::LoadData;
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
use self::hyper::header::ContentType;
|
use self::hyper::header::ContentType;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use net_traits::image_cache_task::ImageResponseMsg::*;
|
||||||
use net_traits::image_cache_task::Msg::*;
|
use net_traits::image_cache_task::Msg::*;
|
||||||
|
|
||||||
use net::resource_task::{start_sending, ProgressSender};
|
use net::resource_task::{start_sending, ProgressSender};
|
||||||
use net_traits::{ControlMsg, Metadata, ResourceTask, ResponseSenders};
|
use net_traits::{ControlMsg, Metadata, ResourceTask};
|
||||||
use net_traits::image_cache_task::{ImageCacheTask, ImageCacheTaskClient, ImageResponseMsg, Msg};
|
use net_traits::image_cache_task::{ImageCacheTask, ImageCacheTaskClient, ImageResponseMsg, Msg};
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
use profile::time;
|
use profile::time;
|
||||||
|
@ -111,7 +111,7 @@ fn mock_resource_task<T: Closure + Send + 'static>(on_load: Box<T>) -> ResourceT
|
||||||
loop {
|
loop {
|
||||||
match port.recv().unwrap() {
|
match port.recv().unwrap() {
|
||||||
ControlMsg::Load(_, consumer) => {
|
ControlMsg::Load(_, consumer) => {
|
||||||
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
|
let chan = start_sending(consumer, Metadata::default(
|
||||||
Url::parse("file:///fake").unwrap()));
|
Url::parse("file:///fake").unwrap()));
|
||||||
on_load.invoke(chan);
|
on_load.invoke(chan);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() {
|
||||||
loop {
|
loop {
|
||||||
match port.recv().unwrap() {
|
match port.recv().unwrap() {
|
||||||
ControlMsg::Load(_, consumer) => {
|
ControlMsg::Load(_, consumer) => {
|
||||||
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
|
let chan = start_sending(consumer, Metadata::default(
|
||||||
Url::parse("file:///fake").unwrap()));
|
Url::parse("file:///fake").unwrap()));
|
||||||
chan.send(Payload(test_image_bin())).unwrap();
|
chan.send(Payload(test_image_bin())).unwrap();
|
||||||
chan.send(Done(Ok(()))).unwrap();
|
chan.send(Done(Ok(()))).unwrap();
|
||||||
|
@ -330,7 +330,7 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() {
|
||||||
loop {
|
loop {
|
||||||
match port.recv().unwrap() {
|
match port.recv().unwrap() {
|
||||||
ControlMsg::Load(_, consumer) => {
|
ControlMsg::Load(_, consumer) => {
|
||||||
let chan = start_sending(ResponseSenders::from_consumer(consumer), Metadata::default(
|
let chan = start_sending(consumer, Metadata::default(
|
||||||
Url::parse("file:///fake").unwrap()));
|
Url::parse("file:///fake").unwrap()));
|
||||||
chan.send(Payload(test_image_bin())).unwrap();
|
chan.send(Payload(test_image_bin())).unwrap();
|
||||||
chan.send(Done(Err("".to_string()))).unwrap();
|
chan.send(Done(Err("".to_string()))).unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue