mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
remove unnecessary proc from resource loader factory
This commit is contained in:
parent
f3653342df
commit
b8b51b6dd8
4 changed files with 35 additions and 52 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use resource_task::{Done, Payload, Metadata, LoadData, LoadResponse, LoaderTask, start_sending};
|
use resource_task::{Done, Payload, Metadata, LoadData, LoadResponse, start_sending};
|
||||||
|
|
||||||
use serialize::base64::FromBase64;
|
use serialize::base64::FromBase64;
|
||||||
|
|
||||||
|
@ -13,13 +13,12 @@ use http::headers::content_type::MediaType;
|
||||||
use url::{percent_decode, NonRelativeSchemeData};
|
use url::{percent_decode, NonRelativeSchemeData};
|
||||||
|
|
||||||
|
|
||||||
pub fn factory() -> LoaderTask {
|
pub fn factory(load_data: LoadData, start_chan: Sender<LoadResponse>) {
|
||||||
proc(url, start_chan) {
|
|
||||||
// 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.
|
||||||
|
// Left in separate function to allow easy moving to a task, if desired.
|
||||||
load(url, start_chan)
|
load(url, start_chan)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(load_data: LoadData, start_chan: Sender<LoadResponse>) {
|
fn load(load_data: LoadData, start_chan: Sender<LoadResponse>) {
|
||||||
|
|
|
@ -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 resource_task::{ProgressMsg, Metadata, Payload, Done, LoaderTask, start_sending};
|
use resource_task::{ProgressMsg, Metadata, Payload, Done, start_sending};
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::File;
|
use std::io::File;
|
||||||
|
@ -29,8 +29,7 @@ fn read_all(reader: &mut io::Stream, progress_chan: &Sender<ProgressMsg>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn factory() -> LoaderTask {
|
pub fn factory(load_data: LoadData, start_chan: Sender<LoadResponse>) {
|
||||||
let f: LoaderTask = proc(load_data, start_chan) {
|
|
||||||
let url = load_data.url;
|
let url = load_data.url;
|
||||||
assert!("file" == url.scheme.as_slice());
|
assert!("file" == url.scheme.as_slice());
|
||||||
let progress_chan = start_sending(start_chan, Metadata::default(url.clone()));
|
let progress_chan = start_sending(start_chan, Metadata::default(url.clone()));
|
||||||
|
@ -53,6 +52,4 @@ pub fn factory() -> LoaderTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
|
||||||
f
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 resource_task::{Metadata, Payload, Done, LoadResponse, LoadData, LoaderTask, start_sending_opt};
|
use resource_task::{Metadata, Payload, Done, LoadResponse, LoadData, start_sending_opt};
|
||||||
|
|
||||||
use std::collections::hashmap::HashSet;
|
use std::collections::hashmap::HashSet;
|
||||||
use http::client::{RequestWriter, NetworkStream};
|
use http::client::{RequestWriter, NetworkStream};
|
||||||
|
@ -11,11 +11,8 @@ use std::io::Reader;
|
||||||
use servo_util::task::spawn_named;
|
use servo_util::task::spawn_named;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub fn factory() -> LoaderTask {
|
pub fn factory(load_data: LoadData, start_chan: Sender<LoadResponse>) {
|
||||||
let f: LoaderTask = proc(url, start_chan) {
|
|
||||||
spawn_named("http_loader", proc() load(url, start_chan))
|
spawn_named("http_loader", proc() load(url, start_chan))
|
||||||
};
|
|
||||||
f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_error(url: Url, err: String, start_chan: Sender<LoadResponse>) {
|
fn send_error(url: Url, err: String, start_chan: Sender<LoadResponse>) {
|
||||||
|
|
|
@ -163,16 +163,6 @@ pub fn load_whole_resource(resource_task: &ResourceTask, url: Url)
|
||||||
/// Handle to a resource task
|
/// Handle to a resource task
|
||||||
pub type ResourceTask = Sender<ControlMsg>;
|
pub type ResourceTask = Sender<ControlMsg>;
|
||||||
|
|
||||||
pub type LoaderTask = proc(load_data: LoadData, Sender<LoadResponse>);
|
|
||||||
|
|
||||||
/**
|
|
||||||
Creates a task to load a specific resource
|
|
||||||
|
|
||||||
The ResourceManager delegates loading to a different type of loader task for
|
|
||||||
each URL scheme
|
|
||||||
*/
|
|
||||||
type LoaderTaskFactory = extern "Rust" fn() -> LoaderTask;
|
|
||||||
|
|
||||||
/// Create a ResourceTask
|
/// Create a ResourceTask
|
||||||
pub fn new_resource_task() -> ResourceTask {
|
pub fn new_resource_task() -> ResourceTask {
|
||||||
let (setup_chan, setup_port) = channel();
|
let (setup_chan, setup_port) = channel();
|
||||||
|
@ -213,9 +203,9 @@ impl ResourceManager {
|
||||||
|
|
||||||
fn load(&self, mut load_data: LoadData, start_chan: Sender<LoadResponse>) {
|
fn load(&self, mut load_data: LoadData, start_chan: Sender<LoadResponse>) {
|
||||||
let loader = match load_data.url.scheme.as_slice() {
|
let loader = match load_data.url.scheme.as_slice() {
|
||||||
"file" => file_loader::factory(),
|
"file" => file_loader::factory,
|
||||||
"http" | "https" => http_loader::factory(),
|
"http" | "https" => http_loader::factory,
|
||||||
"data" => data_loader::factory(),
|
"data" => data_loader::factory,
|
||||||
"about" => {
|
"about" => {
|
||||||
match load_data.url.non_relative_scheme_data().unwrap() {
|
match load_data.url.non_relative_scheme_data().unwrap() {
|
||||||
"crash" => fail!("Loading the about:crash URL."),
|
"crash" => fail!("Loading the about:crash URL."),
|
||||||
|
@ -225,7 +215,7 @@ impl ResourceManager {
|
||||||
path.pop();
|
path.pop();
|
||||||
path.push_many(["src", "test", "html", "failure.html"]);
|
path.push_many(["src", "test", "html", "failure.html"]);
|
||||||
load_data.url = Url::from_file_path(&path).unwrap();
|
load_data.url = Url::from_file_path(&path).unwrap();
|
||||||
file_loader::factory()
|
file_loader::factory
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
start_sending(start_chan, Metadata::default(load_data.url))
|
start_sending(start_chan, Metadata::default(load_data.url))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue