Bug 1591564 - Initialize the FOGotype when Telemetry inits r=janerik,emilio

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

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

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

@ -1202,6 +1202,8 @@ name = "fog"
version = "0.1.0"
dependencies = [
"glean-preview 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"nserror 0.1.0",
"nsstring 0.1.0",
]
[[package]]

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

@ -56,6 +56,7 @@
#include "nsDataHashtable.h"
#include "nsHashKeys.h"
#include "nsIDirectoryEnumerator.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIFileStreams.h"
#include "nsIMemoryReporter.h"
#include "nsISeekableStream.h"
@ -1165,6 +1166,31 @@ TelemetryImpl::GetIsOfficialTelemetry(bool* ret) {
return NS_OK;
}
#if defined(MOZ_FOGOTYPE)
// The FOGotype API is implemented in Rust and exposed to C++ via a set of
// C functions with the "fog_" prefix.
// See toolkit/components/telemetry/fog/*.
extern "C" {
nsresult fog_init(bool useTelemetry, const nsAString* dataDir);
}
static void internal_initFogotype(bool aUseTelemetry) {
nsCOMPtr<nsIFile> dataDir;
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(dataDir));
if (NS_FAILED(rv)) {
NS_WARNING("Couldn't get data dir. Bailing on FOGotype.");
return;
}
nsAutoString path;
rv = dataDir->GetPath(path);
if (NS_FAILED(rv)) {
NS_WARNING("Couldn't get data path. Bailing on FOGotype.");
return;
}
NS_WARN_IF(NS_FAILED(fog_init(aUseTelemetry, &path)));
}
#endif // defined(MOZ_FOGOTYPE)
already_AddRefed<nsITelemetry> TelemetryImpl::CreateTelemetryInstance() {
{
auto lock = sTelemetry.Lock();
@ -1222,6 +1248,12 @@ already_AddRefed<nsITelemetry> TelemetryImpl::CreateTelemetryInstance() {
}
#endif
#if defined(MOZ_FOGOTYPE)
if (XRE_IsParentProcess()) {
internal_initFogotype(useTelemetry);
}
#endif
return ret.forget();
}

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

@ -9,3 +9,5 @@ license = "MPL-2.0"
[dependencies]
glean-preview = "0.0.2"
nserror = { path = "../../../../xpcom/rust/nserror" }
nsstring = { path = "../../../../xpcom/rust/nsstring" }

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

@ -2,10 +2,23 @@
* 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/. */
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
use glean_preview::Configuration;
use nserror::{nsresult, NS_ERROR_FAILURE, NS_OK};
use nsstring::nsAString;
#[no_mangle]
pub unsafe extern "C" fn fog_init(upload_enabled: bool, data_dir: &nsAString) -> nsresult {
let cfg = Configuration {
data_path: data_dir.to_string(),
application_id: "org.mozilla.fogotype".into(),
upload_enabled: upload_enabled,
max_events: None,
delay_ping_lifetime_io: false, // We will want this eventually.
};
if glean_preview::initialize(cfg).is_err() {
return NS_ERROR_FAILURE
}
NS_OK
}