Refactor FileAPI implementation

This commit is contained in:
Zhen Zhang 2016-07-12 14:13:57 +08:00
parent 9b01a4cc97
commit aea99e081b
8 changed files with 224 additions and 178 deletions

View file

@ -2,7 +2,7 @@
* 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 blob_url_store::{BlobURLStoreEntry, BlobURLStoreError};
use blob_url_store::{BlobBuf, BlobURLStoreError};
use ipc_channel::ipc::IpcSender;
use num_traits::ToPrimitive;
use std::cmp::{max, min};
@ -10,7 +10,8 @@ use std::ops::Range;
use std::path::PathBuf;
use super::{LoadConsumer, LoadData};
// HACK: We should send Origin directly instead of this in future, blocked on #11722
// HACK: Not really process-safe now, we should send Origin
// directly instead of this in future, blocked on #11722
/// File manager store entry's origin
pub type FileOrigin = String;
@ -33,7 +34,7 @@ impl RelativePos {
pub fn full_range() -> RelativePos {
RelativePos {
start: 0,
end: Some(0),
end: None,
}
}
@ -98,20 +99,24 @@ impl RelativePos {
}
}
// XXX: We should opt to Uuid once it implements `Deserialize` and `Serialize`
/// FileID used in inter-process message
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SelectedFileId(pub String);
/// Response to file selection request
#[derive(Debug, Deserialize, Serialize)]
pub struct SelectedFile {
pub id: SelectedFileId,
pub filename: PathBuf,
pub modified: u64,
pub size: u64,
// https://w3c.github.io/FileAPI/#dfn-type
pub type_string: String,
}
/// Filter for file selection
/// the content is expected to be extension (e.g, "doc", without the prefixing ".")
/// Filter for file selection;
/// the `String` content is expected to be extension (e.g, "doc", without the prefixing ".")
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FilterPattern(pub String);
@ -131,7 +136,7 @@ pub enum FileManagerThreadMsg {
/// Add an entry as promoted memory-based blob and send back the associated FileID
/// as part of a valid Blob URL
PromoteMemory(BlobURLStoreEntry, IpcSender<Result<SelectedFileId, BlobURLStoreError>>, FileOrigin),
PromoteMemory(BlobBuf, IpcSender<Result<SelectedFileId, BlobURLStoreError>>, FileOrigin),
/// Add a sliced entry pointing to the parent FileID, and send back the associated FileID
/// as part of a valid Blob URL
@ -161,8 +166,8 @@ pub enum FileManagerThreadError {
InvalidSelection,
/// The selection action is cancelled by user
UserCancelled,
/// Failure to process file information such as file name, modified time etc.
FileInfoProcessingError,
/// Failure to read the file content
ReadFileError,
/// Errors returned from file system request
FileSystemError(String),
/// Blob URL Store error
BlobURLStoreError(BlobURLStoreError),
}