Bug 1591564 - Determine from the pref whether Glean upload is enabled r=janerik,emilio

Since we're the only one sending data, and we're doing so infrequently, let's
get the pref value before each ping send instead of building a pref observer
right this second.

Differential Revision: https://phabricator.services.mozilla.com/D57107

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris H-C 2020-01-06 16:19:44 +00:00
Родитель a0c9e18a50
Коммит 3e39cc6eea
6 изменённых файлов: 21 добавлений и 3 удалений

1
Cargo.lock сгенерированный
Просмотреть файл

@ -1204,6 +1204,7 @@ dependencies = [
"glean-preview 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "glean-preview 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"nserror 0.1.0", "nserror 0.1.0",
"nsstring 0.1.0", "nsstring 0.1.0",
"static_prefs 0.1.0",
] ]
[[package]] [[package]]

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

@ -1190,6 +1190,16 @@
value: 0 value: 0
mirror: always mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "datareporting."
#---------------------------------------------------------------------------
- name: datareporting.healthreport.uploadEnabled
type: RelaxedAtomicBool
value: false
mirror: always
rust: true
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Prefs starting with "device." # Prefs starting with "device."
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------

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

@ -34,6 +34,7 @@ pref_groups = [
'channelclassifier', 'channelclassifier',
'clipboard', 'clipboard',
'content', 'content',
'datareporting',
'device', 'device',
'devtools', 'devtools',
'docshell', 'docshell',

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

@ -1171,7 +1171,7 @@ TelemetryImpl::GetIsOfficialTelemetry(bool* ret) {
// C functions with the "fog_" prefix. // C functions with the "fog_" prefix.
// See toolkit/components/telemetry/fog/*. // See toolkit/components/telemetry/fog/*.
extern "C" { extern "C" {
nsresult fog_init(bool useTelemetry, const nsAString* dataDir); nsresult fog_init(const nsAString* dataDir);
} }
static void internal_initFogotype(bool aUseTelemetry) { static void internal_initFogotype(bool aUseTelemetry) {
@ -1187,7 +1187,7 @@ static void internal_initFogotype(bool aUseTelemetry) {
NS_WARNING("Couldn't get data path. Bailing on FOGotype."); NS_WARNING("Couldn't get data path. Bailing on FOGotype.");
return; return;
} }
NS_WARN_IF(NS_FAILED(fog_init(aUseTelemetry, &path))); NS_WARN_IF(NS_FAILED(fog_init(&path)));
} }
#endif // defined(MOZ_FOGOTYPE) #endif // defined(MOZ_FOGOTYPE)

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

@ -11,3 +11,4 @@ license = "MPL-2.0"
glean-preview = "0.0.2" glean-preview = "0.0.2"
nserror = { path = "../../../../xpcom/rust/nserror" } nserror = { path = "../../../../xpcom/rust/nserror" }
nsstring = { path = "../../../../xpcom/rust/nsstring" } nsstring = { path = "../../../../xpcom/rust/nsstring" }
static_prefs = { path = "../../../../modules/libpref/init/static_prefs" }

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

@ -11,7 +11,10 @@ use std::io::Error;
use std::thread::JoinHandle; use std::thread::JoinHandle;
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn fog_init(upload_enabled: bool, data_dir: &nsAString) -> nsresult { pub unsafe extern "C" fn fog_init(data_dir: &nsAString) -> nsresult {
let upload_enabled = static_prefs::pref!("datareporting.healthreport.uploadEnabled");
let cfg = Configuration { let cfg = Configuration {
data_path: data_dir.to_string(), data_path: data_dir.to_string(),
application_id: "org.mozilla.fogotype".into(), application_id: "org.mozilla.fogotype".into(),
@ -41,6 +44,8 @@ fn prototype_ping_init() -> Result<JoinHandle<()>, Error> {
let an_hour = time::Duration::from_secs(60 * 60); let an_hour = time::Duration::from_secs(60 * 60);
loop { loop {
thread::sleep(an_hour); thread::sleep(an_hour);
let upload_enabled = static_prefs::pref!("datareporting.healthreport.uploadEnabled");
glean_preview::set_upload_enabled(upload_enabled);
prototype_ping.send(); prototype_ping.send();
} }
}) })