Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRefactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image} #23661
Conversation
highfive
commented
Jun 30, 2019
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon. |
highfive
commented
Jun 30, 2019
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jun 30, 2019
|
@jdm re:
I explored this, but it seemed like every way I thought of refactoring it would add the same amount of code, or duplicate functionality. I was looking into areas that called these functions, disallowing placeholder images.From what I can tell, the |
|
Good start! I've left some suggestions that I think will reduce some of the duplicated code and make it easier to understand the intentions of the code using the image cache. |
|
thanks so much for the thorough review, will get on this ASAP! |
214c84d
to
3427dc1
|
This is much improved! I think we can still simplify the rules of the API a little bit more by ensuring that the callers cannot forget to add an image cache listener. |
| } | ||
|
|
||
| let (sender, _receiver) = ipc::channel().unwrap(); |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 19, 2019
Member
This looks suspicious to me - I believe callers of track_image should be passing a sender as an argument so they can make use of the receiver. Right now any notifications go into the void because the receiver is ignored completely.
This comment has been minimized.
This comment has been minimized.
|
|
||
| Err(ImageState::NotRequested(id)) => { | ||
| ImageCacheResult::Pending(id) => add_cache_listener_for_element(image_cache, id, self), | ||
| ImageCacheResult::ReadyForRequest(id) => { | ||
| add_cache_listener_for_element(image_cache, id, self); |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 19, 2019
Member
I think the idea I had is that the track_image API would automatically call ImageCache::add_listener so that users of the API would not have to do that.
| // See if the image is already available | ||
| let result = | ||
| // Check for available image or start tracking. | ||
| let sender; // FIXME |
This comment has been minimized.
This comment has been minimized.
julientregoat
Jul 28, 2019
Author
Contributor
@jdm I left this broken for the moment. I wasn't sure where & how I should generate the IpcSender for the call to track_image here, since the LayoutContext isn't an element like the other callers of track_image. Based on the comments in the code above I imagined what I would want to do would be to add a route to the ipc_channel::router::ROUTER with a callback that would trigger the reflow. However I also realized that it might make more sense to have the caller of get_or_request_image_or_meta pass a sender in. This would ultimately be Fragements and ImageFragmentInfos. any advice?
This comment has been minimized.
This comment has been minimized.
jdm
Sep 4, 2019
Member
Ok, I spent a while looking at this, and I think we don't actually want to call track_image here, because it doesn't really fit the model of the other consumers of that API. This code cares about three states:
- is there an image/metadata already?
- is there an image cache entry pending?
- is there no image cache entry?
We only want to add a cache listener in states 2 and 3, and that listener is added in separate code in components/script/dom/window.rs (in Window::force_reflow). I think we should add a new image cache API called get_cached_image_status which returns ImageCacheResult and does not take a Sender argument. Hopefully we can find a good way to avoid duplicating the implementation of track_image.
|
I'm really sorry for forgetting about this PR! |
|
@bors-servo r+ |
|
|
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 -->
|
|
|
@bors-servo retry |
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 -->
|
|
|
@bors-servo retry |
|
|
julientregoat commentedJun 30, 2019
•
edited by SimonSapin
Updated the
ImageCachetrait to replacefind_image_or_metadatawith two new functionstrack_imageandget_image, as well as a new enum (ImageCacheResult).As a result, I was able to refactor the functions that previously called
find_image_or_metadatapretty cleanly. For a list of these functions, please see the commit information../mach build -ddoes not report any errors./mach test-tidydoes not report any errorscargo testinnet,net_traits,layout, andscriptsuccessfully.This change is