aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorKeith Yeung <kungfukeith11@gmail.com>2016-06-06 16:57:15 -0400
committerJosh Matthews <josh@joshmatthews.net>2016-07-14 13:27:42 -0400
commitaa5f34fcd9b83135e46139be50f1e1a199a8b56f (patch)
treefbda66d7307649ef7057d7d5e3e2bf4f08206a4b /components/script/dom
parent2aef518ce672b8037913fb1a33980475e02259f8 (diff)
downloadservo-aa5f34fcd9b83135e46139be50f1e1a199a8b56f.tar.gz
servo-aa5f34fcd9b83135e46139be50f1e1a199a8b56f.zip
Implement file reading task source
And remove superfluous FileReaderEvent enum
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/global.rs5
-rw-r--r--components/script/dom/filereader.rs62
-rw-r--r--components/script/dom/window.rs2
-rw-r--r--components/script/dom/workerglobalscope.rs5
4 files changed, 27 insertions, 47 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs
index 6593fc36b8f..22cb256bd04 100644
--- a/components/script/dom/bindings/global.rs
+++ b/components/script/dom/bindings/global.rs
@@ -26,6 +26,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
use script_thread::{MainThreadScriptChan, ScriptThread, RunnableWrapper};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest};
use task_source::dom_manipulation::DOMManipulationTaskSource;
+use task_source::file_reading::FileReadingTaskSource;
use timers::{OneshotTimerCallback, OneshotTimerHandle};
use url::Url;
@@ -219,10 +220,10 @@ impl<'a> GlobalRef<'a> {
/// `ScriptChan` used to send messages to the event loop of this global's
/// thread.
- pub fn file_reading_task_source(&self) -> Box<ScriptChan + Send> {
+ pub fn file_reading_task_source(&self) -> FileReadingTaskSource {
match *self {
GlobalRef::Window(ref window) => window.file_reading_task_source(),
- GlobalRef::Worker(ref worker) => worker.script_chan(),
+ GlobalRef::Worker(ref worker) => worker.file_reading_task_source(),
}
}
diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs
index be57d67f7c0..a82e4dc47bc 100644
--- a/components/script/dom/filereader.rs
+++ b/components/script/dom/filereader.rs
@@ -23,12 +23,12 @@ use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, EncodingRef};
use hyper::mime::{Attr, Mime};
use rustc_serialize::base64::{CharacterSet, Config, Newline, ToBase64};
-use script_runtime::ScriptThreadEventCategory::FileRead;
-use script_runtime::{ScriptChan, CommonScriptMsg};
-use script_thread::Runnable;
+use script_thread::RunnableWrapper;
use std::cell::Cell;
use std::sync::Arc;
use string_cache::Atom;
+use task_source::TaskSource;
+use task_source::file_reading::{FileReadingTaskSource, FileReadingRunnable, FileReadingTask};
use util::thread::spawn_named;
#[derive(PartialEq, Clone, Copy, JSTraceable, HeapSizeOf)]
@@ -358,10 +358,11 @@ impl FileReader {
let fr = Trusted::new(self);
let gen_id = self.generation_id.get();
- let script_chan = self.global().r().file_reading_task_source();
+ let wrapper = self.global().r().get_runnable_wrapper();
+ let task_source = self.global().r().file_reading_task_source();
spawn_named("file reader async operation".to_owned(), move || {
- perform_annotated_read_operation(gen_id, load_data, blob_contents, fr, script_chan)
+ perform_annotated_read_operation(gen_id, load_data, blob_contents, fr, task_source, wrapper)
});
Ok(())
}
@@ -371,47 +372,20 @@ impl FileReader {
}
}
-#[derive(Clone)]
-pub enum FileReaderEvent {
- ProcessRead(TrustedFileReader, GenerationId),
- ProcessReadData(TrustedFileReader, GenerationId),
- ProcessReadError(TrustedFileReader, GenerationId, DOMErrorName),
- ProcessReadEOF(TrustedFileReader, GenerationId, ReadMetaData, Arc<Vec<u8>>)
-}
-
-impl Runnable for FileReaderEvent {
- fn name(&self) -> &'static str { "FileReaderEvent" }
-
- fn handler(self: Box<FileReaderEvent>) {
- let file_reader_event = *self;
- match file_reader_event {
- FileReaderEvent::ProcessRead(filereader, gen_id) => {
- FileReader::process_read(filereader, gen_id);
- },
- FileReaderEvent::ProcessReadData(filereader, gen_id) => {
- FileReader::process_read_data(filereader, gen_id);
- },
- FileReaderEvent::ProcessReadError(filereader, gen_id, error) => {
- FileReader::process_read_error(filereader, gen_id, error);
- },
- FileReaderEvent::ProcessReadEOF(filereader, gen_id, data, blob_contents) => {
- FileReader::process_read_eof(filereader, gen_id, data, blob_contents);
- }
- }
- }
-}
-
// https://w3c.github.io/FileAPI/#thread-read-operation
-fn perform_annotated_read_operation(gen_id: GenerationId, data: ReadMetaData, blob_contents: Arc<Vec<u8>>,
- filereader: TrustedFileReader, script_chan: Box<ScriptChan + Send>) {
- let chan = &script_chan;
+fn perform_annotated_read_operation(gen_id: GenerationId,
+ data: ReadMetaData,
+ blob_contents: Arc<Vec<u8>>,
+ filereader: TrustedFileReader,
+ task_source: FileReadingTaskSource,
+ wrapper: RunnableWrapper) {
// Step 4
- let thread = box FileReaderEvent::ProcessRead(filereader.clone(), gen_id);
- chan.send(CommonScriptMsg::RunnableMsg(FileRead, thread)).unwrap();
+ let task = FileReadingRunnable::new(FileReadingTask::ProcessRead(filereader.clone(), gen_id));
+ task_source.queue_with_wrapper(task, &wrapper).unwrap();
- let thread = box FileReaderEvent::ProcessReadData(filereader.clone(), gen_id);
- chan.send(CommonScriptMsg::RunnableMsg(FileRead, thread)).unwrap();
+ let task = FileReadingRunnable::new(FileReadingTask::ProcessReadData(filereader.clone(), gen_id));
+ task_source.queue_with_wrapper(task, &wrapper).unwrap();
- let thread = box FileReaderEvent::ProcessReadEOF(filereader, gen_id, data, blob_contents);
- chan.send(CommonScriptMsg::RunnableMsg(FileRead, thread)).unwrap();
+ let task = FileReadingRunnable::new(FileReadingTask::ProcessReadEOF(filereader, gen_id, data, blob_contents));
+ task_source.queue_with_wrapper(task, &wrapper).unwrap();
}
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 9401eae5a46..30ab695f9b7 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -302,7 +302,7 @@ impl Window {
self.history_traversal_task_source.clone()
}
- pub fn file_reading_task_source(&self) -> Box<ScriptChan + Send> {
+ pub fn file_reading_task_source(&self) -> FileReadingTaskSource {
self.file_reading_task_source.clone()
}
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index b04663bbd08..67b7a54951d 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -39,6 +39,7 @@ use std::rc::Rc;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::Receiver;
+use task_source::file_reading::FileReadingTaskSource;
use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle, OneshotTimers, TimerCallback};
use url::Url;
@@ -460,6 +461,10 @@ impl WorkerGlobalScope {
}
}
+ pub fn file_reading_task_source(&self) -> FileReadingTaskSource {
+ FileReadingTaskSource(self.script_chan())
+ }
+
pub fn pipeline(&self) -> PipelineId {
let dedicated = self.downcast::<DedicatedWorkerGlobalScope>();
let service_worker = self.downcast::<ServiceWorkerGlobalScope>();