glean_ffi/
url.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use std::os::raw::c_char;
6
7use ffi_support::FfiStr;
8
9use crate::{
10    define_metric, ffi_string_ext::FallibleToString, handlemap_ext::HandleMapExtension,
11    with_glean_value, Lifetime,
12};
13
14define_metric!(UrlMetric => URL_METRICS {
15    new           -> glean_new_url_metric(),
16    test_get_num_recorded_errors -> glean_url_test_get_num_recorded_errors,
17    destroy       -> glean_destroy_url_metric,
18});
19
20#[no_mangle]
21pub extern "C" fn glean_url_set(metric_id: u64, value: FfiStr) {
22    with_glean_value(|glean| {
23        URL_METRICS.call_with_log(metric_id, |metric| {
24            let value = value.to_string_fallible()?;
25            metric.set(glean, value);
26            Ok(())
27        })
28    })
29}
30
31#[no_mangle]
32pub extern "C" fn glean_url_test_has_value(metric_id: u64, storage_name: FfiStr) -> u8 {
33    with_glean_value(|glean| {
34        URL_METRICS.call_infallible(metric_id, |metric| {
35            metric
36                .test_get_value(glean, storage_name.as_str())
37                .is_some()
38        })
39    })
40}
41
42#[no_mangle]
43pub extern "C" fn glean_url_test_get_value(metric_id: u64, storage_name: FfiStr) -> *mut c_char {
44    with_glean_value(|glean| {
45        URL_METRICS.call_infallible(metric_id, |metric| {
46            metric.test_get_value(glean, storage_name.as_str()).unwrap()
47        })
48    })
49}