diff --git a/mobile/android/chrome/geckoview/geckoview.js b/mobile/android/chrome/geckoview/geckoview.js index fe3e0b747791..22da8f5dc572 100644 --- a/mobile/android/chrome/geckoview/geckoview.js +++ b/mobile/android/chrome/geckoview/geckoview.js @@ -774,6 +774,13 @@ function startup() { SafeBrowsing.init(); }); + InitLater(() => { + // It's enough to run this once to set up FOG. + // (See also bug 1730026.) + const FOG = Cc["@mozilla.org/toolkit/glean;1"].createInstance(Ci.nsIFOG); + FOG.registerCustomPings(); + }); + // This should always go last, since the idle tasks (except for the ones with // timeouts) should execute in order. Note that this observer notification is // not guaranteed to fire, since the window could close before we get here. diff --git a/toolkit/components/glean/ipc/FOGIPC.cpp b/toolkit/components/glean/ipc/FOGIPC.cpp index d046152ce3be..f76d62b20339 100644 --- a/toolkit/components/glean/ipc/FOGIPC.cpp +++ b/toolkit/components/glean/ipc/FOGIPC.cpp @@ -27,7 +27,6 @@ namespace glean { * serialized payload that the Rust impl hands you. */ void FlushFOGData(std::function&& aResolver) { -#ifndef MOZ_GLEAN_ANDROID ByteBuf buf; uint32_t ipcBufferSize = impl::fog_serialize_ipc_buf(); bool ok = buf.Allocate(ipcBufferSize); @@ -39,7 +38,6 @@ void FlushFOGData(std::function&& aResolver) { return; } aResolver(std::move(buf)); -#endif } /** @@ -49,7 +47,6 @@ void FlushFOGData(std::function&& aResolver) { */ void FlushAllChildData( std::function&&)>&& aResolver) { -#ifndef MOZ_GLEAN_ANDROID nsTArray parents; ContentParent::GetAll(parents); if (parents.Length() == 0) { @@ -79,7 +76,6 @@ void FlushAllChildData( aResolver(std::move(results)); } }); -#endif } /** @@ -87,10 +83,8 @@ void FlushAllChildData( * @param buf - a bincoded serialized payload that the Rust impl understands. */ void FOGData(ipc::ByteBuf&& buf) { -#ifndef MOZ_GLEAN_ANDROID fog_ipc::buffer_sizes.Accumulate(buf.mLen); impl::fog_use_ipc_buf(buf.mData, buf.mLen); -#endif } /** @@ -98,7 +92,6 @@ void FOGData(ipc::ByteBuf&& buf) { * @param buf - a bincoded serialized payload that the Rust impl understands. */ void SendFOGData(ipc::ByteBuf&& buf) { -#ifndef MOZ_GLEAN_ANDROID switch (XRE_GetProcessType()) { case GeckoProcessType_Content: mozilla::dom::ContentChild::GetSingleton()->SendFOGData(std::move(buf)); @@ -106,7 +99,6 @@ void SendFOGData(ipc::ByteBuf&& buf) { default: MOZ_ASSERT_UNREACHABLE("Unsuppored process type"); } -#endif } /** diff --git a/toolkit/components/glean/src/lib.rs b/toolkit/components/glean/src/lib.rs index 43e060d096a8..621d27c555a7 100644 --- a/toolkit/components/glean/src/lib.rs +++ b/toolkit/components/glean/src/lib.rs @@ -46,6 +46,11 @@ pub extern "C" fn fog_shutdown() { glean::shutdown(); } +#[no_mangle] +pub extern "C" fn fog_register_pings() { + fog::pings::register_pings(); +} + static mut PENDING_BUF: Vec = Vec::new(); // IPC serialization/deserialization methods diff --git a/toolkit/components/glean/xpcom/FOG.cpp b/toolkit/components/glean/xpcom/FOG.cpp index ca529265a35c..762e17bed4a2 100644 --- a/toolkit/components/glean/xpcom/FOG.cpp +++ b/toolkit/components/glean/xpcom/FOG.cpp @@ -28,6 +28,9 @@ using glean::LogToBrowserConsole; // Defined by `glean_ffi`. We reexport it here for later use. extern "C" NS_EXPORT void glean_enable_logging(void); +// Defined by `glean`. We reexport it here for use by the Glean Core SDK. +extern "C" NS_EXPORT void rlb_flush_dispatcher(void); + // Workaround to force a re-export of the `no_mangle` symbols from `glean_ffi` // // Due to how linking works and hides symbols the symbols from `glean_ffi` might @@ -80,20 +83,18 @@ already_AddRefed FOG::GetSingleton() { return do_AddRef(gFOG); } -void FOG::Shutdown() { -#ifndef MOZ_GLEAN_ANDROID - glean::impl::fog_shutdown(); -#endif -} +void FOG::Shutdown() { glean::impl::fog_shutdown(); } NS_IMETHODIMP FOG::InitializeFOG(const nsACString& aDataPathOverride, const nsACString& aAppIdOverride) { -#ifdef MOZ_GLEAN_ANDROID - return NS_OK; -#else return glean::impl::fog_init(&aDataPathOverride, &aAppIdOverride); -#endif +} + +NS_IMETHODIMP +FOG::RegisterCustomPings() { + glean::impl::fog_register_pings(); + return NS_OK; } NS_IMETHODIMP diff --git a/toolkit/components/glean/xpcom/nsIFOG.idl b/toolkit/components/glean/xpcom/nsIFOG.idl index 7811b98fb4fb..4637cce9bbf9 100644 --- a/toolkit/components/glean/xpcom/nsIFOG.idl +++ b/toolkit/components/glean/xpcom/nsIFOG.idl @@ -22,6 +22,13 @@ interface nsIFOG : nsISupports */ void initializeFOG([optional] in AUTF8String aDataPathOverride, [optional] in AUTF8String aAppIdOverride); + /** + * Register custom pings. + * + * Ensure all custom pings are registered with Glean. + */ + void registerCustomPings(); + /** * Enable or Disable the logging of pings in the Glean SDK. * See https://firefox-source-docs.mozilla.org/toolkit/components/glean/testing.html