Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the dependency of fetch on filemanager_thread::UIProvider. #14275

Merged
merged 5 commits into from Nov 22, 2016

Factor out FileManager::read_file().

  • Loading branch information
Ms2ger committed Nov 21, 2016
commit 5ce869d58a82f792cf1572014c84e7ed3058933d
@@ -12,7 +12,7 @@ use mime_classifier::MimeClassifier;
use net_traits::{LoadConsumer, LoadData, Metadata, NetworkError};
use net_traits::ProgressMsg::{Done, Payload};
use net_traits::blob_url_store::parse_blob_url;
use net_traits::filemanager_thread::{FileManagerThreadMsg, ReadFileProgress};
use net_traits::filemanager_thread::ReadFileProgress;
use net_traits::response::HttpsState;
use resource_thread::{send_error, start_sending_sniffed_opt};
use resource_thread::CancellationListener;
@@ -41,8 +41,7 @@ fn load_blob<UI: 'static + UIProvider>
let (chan, recv) = ipc::channel().unwrap();
if let Ok((id, origin, _fragment)) = parse_blob_url(&load_data.url.clone()) {
let check_url_validity = true;
let msg = FileManagerThreadMsg::ReadFile(chan, id, check_url_validity, origin);
let _ = filemanager.handle(msg, Some(cancel_listener));
filemanager.read_file(chan, id, check_url_validity, origin, Some(cancel_listener));

// Receive first chunk
match recv.recv().unwrap() {
@@ -137,8 +136,7 @@ pub fn load_blob_sync<UI: 'static + UIProvider>

let (sender, receiver) = ipc::channel().unwrap();
let check_url_validity = true;
let msg = FileManagerThreadMsg::ReadFile(sender, id, check_url_validity, origin);
let _ = filemanager.handle(msg, None);
filemanager.read_file(sender, id, check_url_validity, origin, None);

let blob_buf = match receiver.recv().unwrap() {
Ok(ReadFileProgress::Meta(blob_buf)) => blob_buf,
@@ -135,6 +135,21 @@ impl<UI: 'static + UIProvider> FileManager<UI> {
}
}

pub fn read_file(&self,
sender: IpcSender<FileManagerResult<ReadFileProgress>>,
id: Uuid,
check_url_validity: bool,
origin: FileOrigin,
cancel_listener: Option<CancellationListener>) {
let store = self.store.clone();
spawn_named("read file".to_owned(), move || {
if let Err(e) = store.try_read_file(&sender, id, check_url_validity,
origin, cancel_listener) {
let _ = sender.send(Err(FileManagerThreadError::BlobURLStoreError(e)));
}
})
}

/// Message handler
pub fn handle(&self, msg: FileManagerThreadMsg, cancel_listener: Option<CancellationListener>) {
match msg {
@@ -153,13 +168,7 @@ impl<UI: 'static + UIProvider> FileManager<UI> {
})
}
FileManagerThreadMsg::ReadFile(sender, id, check_url_validity, origin) => {
let store = self.store.clone();
spawn_named("read file".to_owned(), move || {
if let Err(e) = store.try_read_file(&sender, id, check_url_validity,
origin, cancel_listener) {
let _ = sender.send(Err(FileManagerThreadError::BlobURLStoreError(e)));
}
})
self.read_file(sender, id, check_url_validity, origin, cancel_listener);
}
FileManagerThreadMsg::PromoteMemory(blob_buf, set_valid, sender, origin) => {
let store = self.store.clone();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.