DevTools: Improve resource_available to handle multiple connections (#36933)

This patch improves the `resource_available` trait to handle multiple
connections. In this patch we also remove the redundant
`resource_available` from worker actor

Testing: Existing tests in DevTools already tests for this. We do not
need to add new test
Fixes: part of #36027

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
atbrakhi 2025-05-09 14:06:33 +02:00 committed by GitHub
parent e5347eceac
commit 2aaf9695df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 51 additions and 62 deletions

View file

@ -17,7 +17,7 @@ use servo_url::ServoUrl;
use crate::StreamId;
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::protocol::JsonPacketStream;
use crate::resource::{ResourceAvailable, ResourceAvailableReply};
use crate::resource::ResourceAvailable;
#[derive(Clone, Copy)]
#[allow(dead_code)]
@ -60,10 +60,6 @@ impl ResourceAvailable for WorkerActor {
fn actor_name(&self) -> String {
self.name.clone()
}
fn get_streams(&self) -> &RefCell<HashMap<StreamId, TcpStream>> {
&self.streams
}
}
impl Actor for WorkerActor {
@ -133,28 +129,6 @@ impl Actor for WorkerActor {
}
}
impl WorkerActor {
pub(crate) fn resource_available<T: Serialize>(&self, resource: T, resource_type: String) {
self.resources_available(vec![resource], resource_type);
}
pub(crate) fn resources_available<T: Serialize>(
&self,
resources: Vec<T>,
resource_type: String,
) {
let msg = ResourceAvailableReply::<T> {
from: self.name(),
type_: "resources-available-array".into(),
array: vec![(resource_type, resources)],
};
for stream in self.streams.borrow_mut().values_mut() {
let _ = stream.write_json_packet(&msg);
}
}
}
#[derive(Serialize)]
struct DetachedReply {
from: String,