Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions toolkit/crashreporter/client/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mozilla-central-workspace-hack = { version = "0.1", features = ["crashreporter"]
once_cell = "1"
phf = "0.13"
rand = "0.8.5"
rust-ini = "0.10"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "^0.10.7"
Expand Down Expand Up @@ -61,6 +62,7 @@ features = [
]

[features]
enterprise = []
# Required for tests
mock = []

Expand Down
7 changes: 6 additions & 1 deletion toolkit/crashreporter/client/app/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

RustProgram("crashreporter")
crashreporter_features = []

if CONFIG["MOZ_ENTERPRISE"]:
crashreporter_features += ["enterprise"]

RustProgram("crashreporter", crashreporter_features)

COMPILE_FLAGS["BASE_INCLUDES"] = []
HOST_COMPILE_FLAGS["BASE_INCLUDES"] = []
25 changes: 19 additions & 6 deletions toolkit/crashreporter/client/app/src/glean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

//! Glean telemetry integration.

use crate::config::{buildid, Config};
use crate::config::{buildid, Config, installation_resource_path};
use ini::Ini;

const APP_DISPLAY_VERSION: &str = env!("CARGO_PKG_VERSION");

Expand All @@ -27,17 +28,18 @@ impl InitOptions {
/// Initialize glean.
///
/// When mocking, this should be called on a thread where the mock data is present.
pub fn init(self) -> std::io::Result<crashping::GleanHandle> {
self.init_glean().initialize()
pub fn init(self) -> anyhow::Result<crashping::GleanHandle> {
let glean_handle = self.init_glean()?.initialize()?;
Ok(glean_handle)
}

/// Initialize glean for tests.
#[cfg(test)]
fn test_init(self) {
self.init_glean().test_reset_glean(true)
self.init_glean().expect("Mock initialization should succeed").test_reset_glean(true)
}

fn init_glean(self) -> crashping::InitGlean {
fn init_glean(self) -> anyhow::Result<crashping::InitGlean> {
let mut data_dir = if cfg!(mock) {
// Use a (non-mocked) temp directory since glean won't access our mocked API.
::std::env::temp_dir().join("crashreporter-mock")
Expand Down Expand Up @@ -68,8 +70,19 @@ impl InitOptions {
init_glean.configuration.server_endpoint =
Some("https://incoming.glean.example.com".to_owned());
}
else if cfg!(feature = "enterprise") {
let console_url = Self::read_enterprise_console_endpoint()?;
init_glean.configuration.server_endpoint = Some(console_url);
}

Ok(init_glean)
}

init_glean
fn read_enterprise_console_endpoint() -> anyhow::Result<String> {
let inipath = installation_resource_path().join("distribution").join("distribution.ini");
let conf = Ini::load_from_file(inipath)?;
let console_url = conf.get_from(Some("Preferences"), "enterprise.console.address").ok_or(anyhow::anyhow!("Failed to find console address preference"))?.to_owned();
Ok(console_url)
}
}

Expand Down