diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-04-17 15:56:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 15:56:30 -0400 |
commit | c9480c8e07a89c1bd40b29438f90e76dd8757edc (patch) | |
tree | 7aa0d74d54408eab95961e61c0ae4048f2b36208 /components/script/canvas_state.rs | |
parent | aa37904bbdb3c17d80a1b39f315977295d636d0f (diff) | |
parent | d4e85f9a904d4469b65bf73f7e465464eddb5cec (diff) | |
download | servo-c9480c8e07a89c1bd40b29438f90e76dd8757edc.tar.gz servo-c9480c8e07a89c1bd40b29438f90e76dd8757edc.zip |
Auto merge of #23661 - julientregoat:i-21289, r=jdm
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}
<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).
As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289 (GitHub issue number if applicable)
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/canvas_state.rs')
-rw-r--r-- | components/script/canvas_state.rs | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index d0dca9b2d15..2376d6f8d85 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -38,12 +38,7 @@ use euclid::{ vec2, }; use ipc_channel::ipc::{self, IpcSender}; -use net_traits::image_cache::CanRequestImages; -use net_traits::image_cache::ImageCache; -use net_traits::image_cache::ImageOrMetadataAvailable; -use net_traits::image_cache::ImageResponse; -use net_traits::image_cache::ImageState; -use net_traits::image_cache::UsePlaceholder; +use net_traits::image_cache::{ImageCache, ImageResponse}; use net_traits::request::CorsSettings; use pixels::PixelFormat; use profile_traits::ipc as profiled_ipc; @@ -261,19 +256,12 @@ impl CanvasState { url: ServoUrl, cors_setting: Option<CorsSettings>, ) -> ImageResponse { - let response = self.image_cache.find_image_or_metadata( - url.clone(), - self.origin.clone(), - cors_setting, - UsePlaceholder::No, - CanRequestImages::No, - ); - match response { - Ok(ImageOrMetadataAvailable::ImageAvailable(image, url)) => { - ImageResponse::Loaded(image, url) - }, - Err(ImageState::Pending(_)) => ImageResponse::None, - _ => { + match self + .image_cache + .get_image(url.clone(), self.origin.clone(), cors_setting) + { + Some(image) => ImageResponse::Loaded(image, url), + None => { // Rather annoyingly, we get the same response back from // A load which really failed and from a load which hasn't started yet. self.missing_image_urls.borrow_mut().push(url); |