aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSagar Muchhal <muchhalsagar88@gmail.com>2016-04-20 21:07:03 -0400
committerSagar Muchhal <muchhalsagar88@gmail.com>2016-04-26 03:05:15 -0400
commit5b9251ed3b1ecff165043bf69a333540406aa147 (patch)
treed1faa18db3a829a54d06b54b829a401787db52c9
parent81f6e70a623a6f11535322ed2ef954eafaf8c70c (diff)
downloadservo-5b9251ed3b1ecff165043bf69a333540406aa147.tar.gz
servo-5b9251ed3b1ecff165043bf69a333540406aa147.zip
Added Store Command to ImageCache Task
-rw-r--r--components/net/image_cache_thread.rs20
-rw-r--r--components/net_traits/image_cache_thread.rs13
2 files changed, 32 insertions, 1 deletions
diff --git a/components/net/image_cache_thread.rs b/components/net/image_cache_thread.rs
index 15f3bd93c38..3ca281761d4 100644
--- a/components/net/image_cache_thread.rs
+++ b/components/net/image_cache_thread.rs
@@ -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
@@ -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.
diff --git a/components/net_traits/image_cache_thread.rs b/components/net_traits/image_cache_thread.rs
index 0011cab8e9f..4b17cce7309 100644
--- a/components/net_traits/image_cache_thread.rs
+++ b/components/net_traits/image_cache_thread.rs
@@ -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();
}
}
-