Bug 1662906 - Dispatch set_upload_enabled r=janerik

Differential Revision: https://phabricator.services.mozilla.com/D92766
This commit is contained in:
Chris H-C 2020-10-09 13:31:10 +00:00
Родитель 8058b36a11
Коммит 9a659f29d0
2 изменённых файлов: 20 добавлений и 17 удалений

Просмотреть файл

@ -20,7 +20,7 @@ pub mod ping_upload;
pub mod pings;
pub mod private;
pub(crate) mod dispatcher;
pub mod dispatcher;
pub mod ipc;
/// Run a closure with a mutable reference to the locked global Glean object.

Просмотреть файл

@ -20,6 +20,7 @@
// FIXME: Remove when code gets actually used eventually (by initializing Glean).
#![allow(dead_code)]
use fog::dispatcher;
use fog::ping_upload::{self, UploadResult};
use glean_core::{global_glean, setup_glean, Configuration, Glean, Result};
use once_cell::sync::OnceCell;
@ -139,24 +140,26 @@ fn initialize_core_metrics(glean: &Glean, client_info: &ClientInfo) {
/// Set whether upload is enabled or not.
///
/// See `glean_core::Glean.set_upload_enabled`.
pub fn set_upload_enabled(enabled: bool) -> bool {
with_glean_mut(|glean| {
let state = global_state();
let old_enabled = glean.is_upload_enabled();
glean.set_upload_enabled(enabled);
pub fn set_upload_enabled(enabled: bool) {
dispatcher::launch(move || {
with_glean_mut(|glean| {
let state = global_state();
let old_enabled = glean.is_upload_enabled();
glean.set_upload_enabled(enabled);
if !old_enabled && enabled {
// If uploading is being re-enabled, we have to restore the
// application-lifetime metrics.
initialize_core_metrics(&glean, &state.client_info);
} else if old_enabled && !enabled {
// If upload is being disabled, check for pings to send.
ping_upload::check_for_uploads();
}
if !old_enabled && enabled {
// If uploading is being re-enabled, we have to restore the
// application-lifetime metrics.
initialize_core_metrics(&glean, &state.client_info);
} else if old_enabled && !enabled {
// If upload is being disabled, check for pings to send.
ping_upload::check_for_uploads();
}
enabled
})
.expect("Setting upload enabled failed!")
enabled
})
.expect("Setting upload enabled failed!");
});
}
fn register_uploader() {