Skip to content

Commit

Permalink
Added Store Command to ImageCache Task
Browse files Browse the repository at this point in the history
  • Loading branch information
srm09 committed Apr 26, 2016
1 parent 81f6e70 commit 5b9251e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 20 additions & 0 deletions components/net/image_cache_thread.rs
Expand Up @@ -394,6 +394,9 @@ impl ImageCache {
let result = self.get_image_or_meta_if_available(url, use_placeholder);
consumer.send(result).unwrap();
}
ImageCacheCommand::StoreDecodeImage(url, image_vector) => {
self.store_decode_image(url, image_vector);
}
};

None
Expand Down Expand Up @@ -588,6 +591,23 @@ impl ImageCache {
}
}
}

fn store_decode_image(&mut self,
ref_url: Url,
loaded_bytes: Vec<u8>) {
let (cache_result, load_key, _) = self.pending_loads.get_cached(Arc::new(ref_url));
assert!(cache_result == CacheResult::Miss);
let action = ResponseAction::DataAvailable(loaded_bytes);
let _ = self.progress_sender.send(ResourceLoadInfo {
action: action,
key: load_key,
});
let action = ResponseAction::ResponseComplete(Ok(()));
let _ = self.progress_sender.send(ResourceLoadInfo {
action: action,
key: load_key,
});
}
}

/// Create a new image cache.
Expand Down
13 changes: 12 additions & 1 deletion components/net_traits/image_cache_thread.rs
Expand Up @@ -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<()>),
}
Expand Down Expand Up @@ -157,11 +161,18 @@ 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();
self.chan.send(ImageCacheCommand::Exit(response_chan)).unwrap();
response_port.recv().unwrap();
}
}

0 comments on commit 5b9251e

Please sign in to comment.