From 29137e4627aded587c25e31fe65429ebfcd06026 Mon Sep 17 00:00:00 2001 From: Chris H-C Date: Thu, 30 Jul 2020 16:35:29 +0000 Subject: [PATCH] Bug 1635253 - Pass the about:glean commands to the Glean SDK r=janerik Differential Revision: https://phabricator.services.mozilla.com/D83980 --- .../glean/aboutGlean/AboutGlean.cpp | 12 ++++-- toolkit/components/glean/src/api.rs | 12 ++++++ toolkit/components/glean/src/lib.rs | 38 ++++++++++++++++++- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/toolkit/components/glean/aboutGlean/AboutGlean.cpp b/toolkit/components/glean/aboutGlean/AboutGlean.cpp index f2a997d3a99b..b95eeab5a155 100644 --- a/toolkit/components/glean/aboutGlean/AboutGlean.cpp +++ b/toolkit/components/glean/aboutGlean/AboutGlean.cpp @@ -24,19 +24,25 @@ already_AddRefed AboutGlean::GetSingleton() { return do_AddRef(gAboutGlean); } +extern "C" { +nsresult fog_set_log_pings(bool aEnableLogPings); +nsresult fog_set_debug_view_tag(const nsACString* aDebugTag); +nsresult fog_submit_ping(const nsACString* aPingName); +} + NS_IMETHODIMP AboutGlean::SetLogPings(bool aEnableLogPings) { - return NS_ERROR_NOT_IMPLEMENTED; + return fog_set_log_pings(aEnableLogPings); } NS_IMETHODIMP AboutGlean::SetTagPings(const nsACString& aDebugTag) { - return NS_ERROR_NOT_IMPLEMENTED; + return fog_set_debug_view_tag(&aDebugTag); } NS_IMETHODIMP AboutGlean::SendPing(const nsACString& aPingName) { - return NS_ERROR_NOT_IMPLEMENTED; + return fog_submit_ping(&aPingName); } NS_IMPL_ISUPPORTS(AboutGlean, nsIAboutGlean) diff --git a/toolkit/components/glean/src/api.rs b/toolkit/components/glean/src/api.rs index 603d2070def5..6763fe3e7c82 100644 --- a/toolkit/components/glean/src/api.rs +++ b/toolkit/components/glean/src/api.rs @@ -185,3 +185,15 @@ fn register_uploader() { ); } } + +pub fn set_debug_view_tag(value: &str) -> bool { + with_glean_mut(|glean| glean.set_debug_view_tag(value)) +} + +pub fn submit_ping(ping_name: &str) -> Result { + with_glean_mut(|glean| glean.submit_ping_by_name(ping_name, None)) +} + +pub fn set_log_pings(value: bool) -> bool { + with_glean_mut(|glean| glean.set_log_pings(value)) +} diff --git a/toolkit/components/glean/src/lib.rs b/toolkit/components/glean/src/lib.rs index 5fbcea3a2089..e47b97d1fae2 100644 --- a/toolkit/components/glean/src/lib.rs +++ b/toolkit/components/glean/src/lib.rs @@ -29,7 +29,7 @@ extern crate xpcom; use std::ffi::CStr; use std::os::raw::c_char; -use nserror::{nsresult, NS_ERROR_FAILURE, NS_OK}; +use nserror::{nsresult, NS_ERROR_FAILURE, NS_ERROR_NO_CONTENT, NS_OK}; use nsstring::{nsACString, nsCStr}; use xpcom::interfaces::{mozIViaduct, nsIObserver, nsIPrefBranch, nsISupports}; use xpcom::{RefPtr, XpCom}; @@ -210,3 +210,39 @@ pub unsafe extern "C" fn fog_use_ipc_buf(buf: *const u8, buf_len: usize) { // TODO: Record the error. }*/ } + +#[no_mangle] +/// Sets the debug tag for pings assembled in the future. +/// Returns an error result if the provided value is not a valid tag. +pub unsafe extern "C" fn fog_set_debug_view_tag(value: &nsACString) -> nsresult { + let result = api::set_debug_view_tag(&value.to_string()); + if result { + return NS_OK; + } else { + return NS_ERROR_FAILURE; + } +} + +#[no_mangle] +/// Submits a ping by name. +/// Returns NS_OK if the ping was successfully submitted, NS_ERROR_NO_CONTENT +/// if the ping wasn't sent, or NS_ERROR_FAILURE if some part of the ping +/// submission mechanism failed. +pub unsafe extern "C" fn fog_submit_ping(ping_name: &nsACString) -> nsresult { + match api::submit_ping(&ping_name.to_string()) { + Ok(true) => NS_OK, + Ok(false) => NS_ERROR_NO_CONTENT, + _ => NS_ERROR_FAILURE, + } +} + +#[no_mangle] +/// Turns ping logging on or off. +/// Returns an error if the logging failed to be configured. +pub unsafe extern "C" fn fog_set_log_pings(value: bool) -> nsresult { + if api::set_log_pings(value) { + return NS_OK; + } else { + return NS_ERROR_FAILURE; + } +}