aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/task_source/file_reading.rs
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/task_source/file_reading.rs
parent2aef518ce672b8037913fb1a33980475e02259f8 (diff)
downloadservo-aa5f34fcd9b83135e46139be50f1e1a199a8b56f.tar.gz
servo-aa5f34fcd9b83135e46139be50f1e1a199a8b56f.zip
Implement file reading task source
And remove superfluous FileReaderEvent enum
Diffstat (limited to 'components/script/task_source/file_reading.rs')
-rw-r--r--components/script/task_source/file_reading.rs71
1 files changed, 62 insertions, 9 deletions
diff --git a/components/script/task_source/file_reading.rs b/components/script/task_source/file_reading.rs
index 7eda4d73ff6..a1732995fcb 100644
--- a/components/script/task_source/file_reading.rs
+++ b/components/script/task_source/file_reading.rs
@@ -2,19 +2,72 @@
* 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/. */
-use script_runtime::{CommonScriptMsg, ScriptChan};
-use script_thread::MainThreadScriptMsg;
-use std::sync::mpsc::Sender;
+use dom::domexception::DOMErrorName;
+use dom::filereader::{FileReader, TrustedFileReader, GenerationId, ReadMetaData};
+use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory, ScriptChan};
+use script_thread::{Runnable, RunnableWrapper};
+use std::sync::Arc;
+use task_source::TaskSource;
#[derive(JSTraceable)]
-pub struct FileReadingTaskSource(pub Sender<MainThreadScriptMsg>);
+pub struct FileReadingTaskSource(pub Box<ScriptChan + Send + 'static>);
-impl ScriptChan for FileReadingTaskSource {
- fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> {
- self.0.send(MainThreadScriptMsg::Common(msg)).map_err(|_| ())
+impl Clone for FileReadingTaskSource {
+ fn clone(&self) -> FileReadingTaskSource {
+ FileReadingTaskSource(self.0.clone())
}
+}
+
+impl TaskSource for FileReadingTaskSource {
+ fn queue_with_wrapper<T>(&self,
+ msg: Box<T>,
+ wrapper: &RunnableWrapper)
+ -> Result<(), ()>
+ where T: Runnable + Send + 'static {
+ self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::FileRead,
+ wrapper.wrap_runnable(msg)))
+ }
+}
+
+pub struct FileReadingRunnable {
+ task: FileReadingTask,
+}
+
+impl FileReadingRunnable {
+ pub fn new(task: FileReadingTask) -> Box<FileReadingRunnable> {
+ box FileReadingRunnable {
+ task: task
+ }
+ }
+}
+
+impl Runnable for FileReadingRunnable {
+ fn handler(self: Box<FileReadingRunnable>) {
+ self.task.handle_task();
+ }
+}
+
+#[allow(dead_code)]
+pub enum FileReadingTask {
+ ProcessRead(TrustedFileReader, GenerationId),
+ ProcessReadData(TrustedFileReader, GenerationId),
+ ProcessReadError(TrustedFileReader, GenerationId, DOMErrorName),
+ ProcessReadEOF(TrustedFileReader, GenerationId, ReadMetaData, Arc<Vec<u8>>),
+}
+
+impl FileReadingTask {
+ pub fn handle_task(self) {
+ use self::FileReadingTask::*;
- fn clone(&self) -> Box<ScriptChan + Send> {
- box FileReadingTaskSource((&self.0).clone())
+ match self {
+ ProcessRead(reader, gen_id) =>
+ FileReader::process_read(reader, gen_id),
+ ProcessReadData(reader, gen_id) =>
+ FileReader::process_read_data(reader, gen_id),
+ ProcessReadError(reader, gen_id, error) =>
+ FileReader::process_read_error(reader, gen_id, error),
+ ProcessReadEOF(reader, gen_id, metadata, blob_contents) =>
+ FileReader::process_read_eof(reader, gen_id, metadata, blob_contents),
+ }
}
}