mirror of
https://github.com/servo/servo
synced 2026-04-26 01:25:32 +02:00
script: Have FetchResponseListener::process_response_eof consume the listener (#40556)
The goal of this change is to prevent having to copy so much data out of listeners when a fetch completes, which will be particularly important for off-the-main thread parsing of CSS (see #22478). This change has pros and cons: Pros: - This makes the design of the `FetchResponseListener` a great deal simpler. They no longer individually store a dummy `ResourceFetchTiming` that is only replaced right before `process_response_eof`. - The creation of the `Arc<Mutex<FetchResponseListener>>` in the `NetworkListener` is abstracted away from clients and now they just pass the `FetchResponseListener` to the fetch methods in the global. Cons: - Now each `FetchResponseListener` must explicitly call `submit_timing` instead of having the `NetworkListener` do it. This is arguably a bit easier to follow in the code. - Since the internal data of the `NetworkListener` is now an `Arc<Mutex<Option<FetchResponseListener>>>`, when the fetching code needs to share state with the `NetworkListener` it either needs to share an `Option` or some sort of internal state. In one case I've stored the `Option` and in another case, I've stored a new inner shared value. Testing: This should not change observable behavior and is thus covered by existing tests. Fixes: #22550 --------- Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
@@ -1901,7 +1901,7 @@ impl Document {
|
||||
.insecure_requests_policy(self.insecure_requests_policy())
|
||||
.has_trustworthy_ancestor_origin(self.has_trustworthy_ancestor_or_current_origin());
|
||||
let callback = NetworkListener {
|
||||
context: std::sync::Arc::new(Mutex::new(listener)),
|
||||
context: std::sync::Arc::new(Mutex::new(Some(listener))),
|
||||
task_source: self
|
||||
.owner_global()
|
||||
.task_manager()
|
||||
@@ -1922,7 +1922,7 @@ impl Document {
|
||||
.insecure_requests_policy(self.insecure_requests_policy())
|
||||
.has_trustworthy_ancestor_origin(self.has_trustworthy_ancestor_or_current_origin());
|
||||
let callback = NetworkListener {
|
||||
context: std::sync::Arc::new(Mutex::new(listener)),
|
||||
context: std::sync::Arc::new(Mutex::new(Some(listener))),
|
||||
task_source: self
|
||||
.owner_global()
|
||||
.task_manager()
|
||||
|
||||
Reference in New Issue
Block a user