/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/// Parse the telemetry enablement pref from the prefs file. /// /// For example: /// ```rust /// let input = r#"user_pref("datareporting.healthreport.uploadEnabled", false);"#; /// assert_eq!(parse_telemetry_enabled_pref(input), Some(false)); /// let input = r#"user_pref("datareporting.healthreport.uploadEnabled", true);"#; /// assert_eq!(parse_telemetry_enabled_pref(input), Some(true)); /// ``` fn parse_telemetry_enabled_pref(prefs_content: &str) -> Option<bool> {
find_bool_pref(prefs_content, TELEMETRY_ENABLED_PREF_KEY)
}
/// Determine whether telemetry should be enabled based on the profile. pubfn determine_telemetry_enabled(profile_dir: Option<&Path>) -> bool { // If there is no profile dir, we cannot determine whether telemetry is enabled or not. However, // disabling telemetry in this case will cause us to entirely miss the class of crashes that // occur before the profile is set up, so we leave it enabled. let Some(profile_dir) = profile_dir else { returntrue;
};
let prefs = profile_dir.join("prefs.js");
// If there is no pref file, default to true. if !prefs.exists() { returntrue;
}
matchcrate::std::fs::read_to_string(&prefs) {
Ok(prefs_contents) => {
parse_telemetry_enabled_pref(&prefs_contents) // If there is no pref, default to true
.unwrap_or(true)
}
Err(e) => { // Like the no-profile-dir case, if we can't read the prefs file, this might be the // cause of some crash that we are trying to report. So disabling telemetry in this case // would make us blind to the issue.
log::error!( "failed to read prefs file at {} for disabling telemetry: {e}",
prefs.display()
); true
}
}
}
impl InitOptions { /// Initialize glean based on the given configuration. pubfn from_config(cfg: &Config) -> Self { let locale = cfg.strings.as_ref().map(|s| s.locale()); let data_dir = cfg.data_dir().to_owned(); #[cfg(mock)] let data_dir = (&data_dir).into();
let upload_enabled = determine_telemetry_enabled(cfg.profile_dir.as_deref());
/// Initialize glean. /// /// When mocking, this should be called on a thread where the mock data is present. pubfn init(self) -> std::io::Result<crashping::GleanHandle> { self.init_glean().initialize()
}
impl GleanTest { fn new(cfg: &Config) -> Self { // Tests using glean can only run serially as glean is initialized as a global static. static GLOBAL_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
impl Drop for GleanTest { fn drop(&mutself) { // `shutdown` ensures any uploads are executed and threads are joined. // `test_reset_glean` does not do the same (found by source inspection).
glean::shutdown();
glean::test_reset_glean(
glean::ConfigurationBuilder::new(false, ::std::env::temp_dir(), "none.none")
.build(),
glean::ClientInfoMetrics::unknown(), true,
);
}
}
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.