aboutsummaryrefslogtreecommitdiffstats
path: root/components/net_traits/image_cache.rs
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-04-17 15:56:30 -0400
committerGitHub <noreply@github.com>2020-04-17 15:56:30 -0400
commitc9480c8e07a89c1bd40b29438f90e76dd8757edc (patch)
tree7aa0d74d54408eab95961e61c0ae4048f2b36208 /components/net_traits/image_cache.rs
parentaa37904bbdb3c17d80a1b39f315977295d636d0f (diff)
parentd4e85f9a904d4469b65bf73f7e465464eddb5cec (diff)
downloadservo-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/net_traits/image_cache.rs')
-rw-r--r--components/net_traits/image_cache.rs46
1 files changed, 33 insertions, 13 deletions
diff --git a/components/net_traits/image_cache.rs b/components/net_traits/image_cache.rs
index e640ca5b292..9c5ca0b1455 100644
--- a/components/net_traits/image_cache.rs
+++ b/components/net_traits/image_cache.rs
@@ -73,14 +73,6 @@ pub enum ImageResponse {
None,
}
-/// The current state of an image in the cache.
-#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
-pub enum ImageState {
- Pending(PendingImageId),
- LoadError,
- NotRequested(PendingImageId),
-}
-
/// The unique id for an image that has previously been requested.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
pub struct PendingImageId(pub u64);
@@ -101,22 +93,50 @@ pub enum UsePlaceholder {
// ImageCache public API.
// ======================================================================
+pub enum ImageCacheResult {
+ Available(ImageOrMetadataAvailable),
+ LoadError,
+ Pending(PendingImageId),
+ ReadyForRequest(PendingImageId),
+}
+
pub trait ImageCache: Sync + Send {
fn new(webrender_api: WebrenderIpcSender) -> Self
where
Self: Sized;
- /// Return any available metadata or image for the given URL,
- /// or an indication that the image is not yet available if it is in progress,
- /// or else reserve a slot in the cache for the URL if the consumer can request images.
- fn find_image_or_metadata(
+ /// Definitively check whether there is a cached, fully loaded image available.
+ fn get_image(
+ &self,
+ url: ServoUrl,
+ origin: ImmutableOrigin,
+ cors_setting: Option<CorsSettings>,
+ ) -> Option<Arc<Image>>;
+
+ fn get_cached_image_status(
+ &self,
+ url: ServoUrl,
+ origin: ImmutableOrigin,
+ cors_setting: Option<CorsSettings>,
+ use_placeholder: UsePlaceholder,
+ can_request: CanRequestImages,
+ ) -> ImageCacheResult;
+
+ /// Add a listener for the provided pending image id, eventually called by
+ /// ImageCacheStore::complete_load.
+ /// If only metadata is available, Available(ImageOrMetadataAvailable) will
+ /// be returned.
+ /// If Available(ImageOrMetadataAvailable::Image) or LoadError is the final value,
+ /// the provided listener will be dropped (consumed & not added to PendingLoad).
+ fn track_image(
&self,
url: ServoUrl,
origin: ImmutableOrigin,
cors_setting: Option<CorsSettings>,
+ sender: IpcSender<PendingImageResponse>,
use_placeholder: UsePlaceholder,
can_request: CanRequestImages,
- ) -> Result<ImageOrMetadataAvailable, ImageState>;
+ ) -> ImageCacheResult;
/// Add a new listener for the given pending image id. If the image is already present,
/// the responder will still receive the expected response.