/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! This provides a XPCOM service to send app services logs to the desktop
#[macro_use] externcrate cstr;
#[macro_use] externcrate xpcom;
use golden_gate::log::LogSink; use nserror::{nsresult, NS_OK}; use nsstring::nsAString; use once_cell::sync::Lazy; use std::os::raw::c_char; use std::{
collections::HashMap,
sync::{
atomic::{AtomicBool, Ordering},
RwLock,
},
}; use xpcom::{
interfaces::{mozIAppServicesLogger, mozIServicesLogSink, nsIObserverService, nsISupports},
RefPtr,
};
/// A flag that's set after we register our observer to clear the map of loggers /// on shutdown. static SHUTDOWN_OBSERVED: AtomicBool = AtomicBool::new(false);
pubstatic LOGGERS_BY_TARGET: Lazy<RwLock<HashMap<String, LogSink>>> = Lazy::new(|| { let h: HashMap<String, LogSink> = HashMap::new(); let m = RwLock::new(h);
m
});
// Import the `NS_IsMainThread` symbol from Gecko... extern"C" { fn NS_IsMainThread() -> bool;
}
/// Registers an observer to clear the loggers map on `xpcom-shutdown`. This /// function must be called from the main thread, because the observer service //// is main thread-only. fn ensure_observing_shutdown() {
assert!(unsafe { NS_IsMainThread() }); // If we've already registered our observer, bail. Relaxed ordering is safe // here and below, because we've asserted we're only called from the main // thread, and only check the flag here. if SHUTDOWN_OBSERVED.load(Ordering::Relaxed) { return;
} iflet Ok(service) = xpcom::components::Observer::service::<nsIObserverService>() { let observer = ShutdownObserver::allocate(InitShutdownObserver {}); let rv = unsafe {
service.AddObserver(observer.coerce(), cstr!("xpcom-shutdown").as_ptr(), false)
}; // If we fail to register the observer now, or fail to get the observer // service, the flag will remain `false`, and we'll try again on the // next call to `ensure_observing_shutdown`.
SHUTDOWN_OBSERVED.store(rv.succeeded(), Ordering::Relaxed);
}
}
/// The constructor for an `AppServicesLogger` service. This uses C linkage so that it /// can be called from C++. See `AppServicesLoggerComponents.h` for the C++ /// constructor that's passed to the component manager. /// /// # Safety /// /// This function is unsafe because it dereferences `result`. #[no_mangle] pubunsafeextern"C"fn NS_NewAppServicesLogger(
result: *mut *const mozIAppServicesLogger,
) -> nsresult { let logger = AppServicesLogger::allocate(InitAppServicesLogger {});
RefPtr::new(logger.coerce::<mozIAppServicesLogger>()).forget(&mut *result);
NS_OK
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-20)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.