mirror of
https://github.com/servo/servo.git
synced 2025-10-11 22:10:18 +01:00
Messages that are sent to the `Constellation` have pretty ambiguous names. This change does two renames: - `ConstellationMsg` → `EmbedderToConstellationMessage` - `ScriptMsg` → `ScriptToConstellationMessage` This naming reflects that the `Constellation` stands in between the embedding layer and the script layer and can receive messages from both. Soon both of these message types will live in `constellation_traits`, reflecting the idea that the `_traits` variant for a crate is responsible for exposing the API for that crate. Testing: No new tests are necessary here as this just renames two enums. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com>
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use std::sync::Arc;
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
use constellation_traits::EmbedderToConstellationMessage;
|
|
use crossbeam_channel::{SendError, Sender};
|
|
use log::warn;
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct ConstellationProxy {
|
|
sender: Sender<EmbedderToConstellationMessage>,
|
|
disconnected: Arc<AtomicBool>,
|
|
}
|
|
|
|
impl ConstellationProxy {
|
|
pub fn new(sender: Sender<EmbedderToConstellationMessage>) -> Self {
|
|
Self {
|
|
sender,
|
|
disconnected: Arc::default(),
|
|
}
|
|
}
|
|
|
|
pub fn disconnected(&self) -> bool {
|
|
self.disconnected.load(Ordering::SeqCst)
|
|
}
|
|
|
|
pub fn send(&self, msg: EmbedderToConstellationMessage) {
|
|
if self.try_send(msg).is_err() {
|
|
warn!("Lost connection to Constellation. Will report to embedder.")
|
|
}
|
|
}
|
|
|
|
fn try_send(
|
|
&self,
|
|
msg: EmbedderToConstellationMessage,
|
|
) -> Result<(), SendError<EmbedderToConstellationMessage>> {
|
|
if self.disconnected() {
|
|
return Err(SendError(msg));
|
|
}
|
|
if let Err(error) = self.sender.send(msg) {
|
|
self.disconnected.store(true, Ordering::SeqCst);
|
|
return Err(error);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn sender(&self) -> Sender<EmbedderToConstellationMessage> {
|
|
self.sender.clone()
|
|
}
|
|
}
|