Auto merge of #11029 - izgzhen:filemanager_thread, r=Manishearth

Add FileManagerThread

This is intended to support the File API implementation. Basically an event loop with three kinds of messages:

+ Select a file
+ Read a file with ID
+ Delete the ID from manager-owned map

The design decision in this PR is not the final (or best I think) version, welcome reviews :)

TODOs:

- [x] Add multiple file selection

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11029)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-11 04:28:58 -07:00
commit b61ad4190f
8 changed files with 182 additions and 0 deletions

View file

@ -22,3 +22,4 @@ serde = "0.7"
serde_macros = "0.7"
url = {version = "1.0.0", features = ["heap_size"]}
websocket = "0.17"
uuid = { version = "0.2.2", features = ["v4", "serde"] }

View file

@ -0,0 +1,34 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 ipc_channel::ipc::IpcSender;
use std::path::PathBuf;
use uuid::Uuid;
#[derive(Deserialize, Serialize)]
pub enum FileManagerThreadMsg {
/// Select a single file, return triple (FileID, FileName, lastModified)
SelectFile(IpcSender<FileManagerResult<(Uuid, PathBuf, u64)>>),
/// Select multiple files, return a vector of triples
SelectFiles(IpcSender<FileManagerResult<Vec<(Uuid, PathBuf, u64)>>>),
/// Read file, return the bytes
ReadFile(IpcSender<FileManagerResult<Vec<u8>>>, Uuid),
/// Delete the FileID entry
DeleteFileID(Uuid),
}
pub type FileManagerResult<T> = Result<T, FileManagerThreadError>;
#[derive(Deserialize, Serialize)]
pub enum FileManagerThreadError {
/// The selection action is invalid, nothing is selected
InvalidSelection,
/// Failure to process file information such as file name, modified time etc.
FileInfoProcessingError,
/// Failure to read the file content
ReadFileError,
}

View file

@ -26,6 +26,7 @@ extern crate msg;
extern crate serde;
extern crate url;
extern crate util;
extern crate uuid;
extern crate websocket;
use hyper::header::{ContentType, Headers};
@ -42,6 +43,7 @@ use websocket::header;
pub mod bluetooth_scanfilter;
pub mod bluetooth_thread;
pub mod filemanager_thread;
pub mod hosts;
pub mod image_cache_thread;
pub mod net_error_list;