Added Store Command to ImageCache Task

This commit is contained in:
Sagar Muchhal 2016-04-20 21:07:03 -04:00
parent 81f6e70a62
commit 5b9251ed3b
2 changed files with 32 additions and 1 deletions

View file

@ -92,6 +92,10 @@ pub enum ImageCacheCommand {
/// state and but its metadata has been made available, it will be sent as a response.
GetImageOrMetadataIfAvailable(Url, UsePlaceholder, IpcSender<Result<ImageOrMetadataAvailable, ImageState>>),
/// Instruct the cache to store this data as a newly-complete network request and continue
/// decoding the result into pixel data
StoreDecodeImage(Url, Vec<u8>),
/// Clients must wait for a response before shutting down the ResourceThread
Exit(IpcSender<()>),
}
@ -157,6 +161,14 @@ impl ImageCacheThread {
receiver.recv().unwrap()
}
/// Decode the given image bytes and cache the result for the given URL.
pub fn store_complete_image_bytes(&self,
url: Url,
image_data: Vec<u8>) {
let msg = ImageCacheCommand::StoreDecodeImage(url, image_data);
self.chan.send(msg).unwrap();
}
/// Shutdown the image cache thread.
pub fn exit(&self) {
let (response_chan, response_port) = ipc::channel().unwrap();
@ -164,4 +176,3 @@ impl ImageCacheThread {
response_port.recv().unwrap();
}
}