Send response for image requests progressively to image cache.

This commit is contained in:
Josh Matthews 2017-01-05 21:57:20 -05:00
parent 21118f0a8a
commit 0d2ec852ac
5 changed files with 59 additions and 58 deletions

View file

@ -396,8 +396,11 @@ impl ImageCache {
// TODO(#15501): look for opportunities to clean up cache if this send fails.
let _ = consumer.send(result);
}
ImageCacheCommand::StoreDecodeImage(id, image_vector) => {
self.store_decode_image(id, image_vector);
ImageCacheCommand::StoreDecodeImage(id, data) => {
self.handle_progress(ResourceLoadInfo {
action: data,
key: id
});
}
};
@ -409,7 +412,7 @@ impl ImageCache {
match (msg.action, msg.key) {
(FetchResponseMsg::ProcessRequestBody, _) |
(FetchResponseMsg::ProcessRequestEOF, _) => return,
(FetchResponseMsg::ProcessResponse(_), _) => {}
(FetchResponseMsg::ProcessResponse(_response), _) => {}
(FetchResponseMsg::ProcessResponseChunk(data), _) => {
let pending_load = self.pending_loads.get_by_key_mut(&msg.key).unwrap();
pending_load.bytes.extend_from_slice(&data);
@ -581,21 +584,6 @@ impl ImageCache {
None => Err(ImageState::LoadError),
}
}
fn store_decode_image(&mut self,
id: PendingImageId,
loaded_bytes: Vec<u8>) {
let action = FetchResponseMsg::ProcessResponseChunk(loaded_bytes);
self.handle_progress(ResourceLoadInfo {
action: action,
key: id,
});
let action = FetchResponseMsg::ProcessResponseEOF(Ok(()));
self.handle_progress(ResourceLoadInfo {
action: action,
key: id,
});
}
}
/// Create a new image cache.