зеркало из https://github.com/mozilla/glean.git
Add handleBackgroundEvent (#22)
This commit is contained in:
Родитель
474848394c
Коммит
701549c96b
|
@ -63,6 +63,15 @@ open class GleanInternalAPI internal constructor () {
|
|||
val s = LibGleanFFI.INSTANCE.glean_ping_collect(handle, ping_name, e)!!
|
||||
LibGleanFFI.INSTANCE.glean_str_free(s)
|
||||
}
|
||||
|
||||
fun handleBackgroundEvent() {
|
||||
sendPing("baseline")
|
||||
sendPing("events")
|
||||
}
|
||||
|
||||
private fun sendPing(pingName: String) {
|
||||
LibGleanFFI.INSTANCE.glean_send_ping(handle, pingName)
|
||||
}
|
||||
}
|
||||
|
||||
object Glean : GleanInternalAPI()
|
||||
|
|
|
@ -42,6 +42,8 @@ internal interface LibGleanFFI : Library {
|
|||
|
||||
fun glean_is_upload_enabled(glean_handle: Long): Byte
|
||||
|
||||
fun glean_send_ping(glean_handle: Long, ping_name: String)
|
||||
|
||||
fun glean_new_boolean_metric(category: String, name: String, send_in_pings: StringArray, send_in_pings_len: Int, lifetime: Int, err: RustError.ByReference): Long
|
||||
|
||||
fun glean_new_counter_metric(category: String, name: String, send_in_pings: StringArray, send_in_pings_len: Int, lifetime: Int, err: RustError.ByReference): Long
|
||||
|
|
|
@ -4,15 +4,29 @@
|
|||
|
||||
package mozilla.telemetry.glean
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class GleanTest {
|
||||
@Test
|
||||
fun `simple smoke test`() {
|
||||
Glean.initialize(ApplicationProvider.getApplicationContext())
|
||||
GleanInternalAPI().initialize(ApplicationProvider.getApplicationContext())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `send a ping`() {
|
||||
val context: Context = ApplicationProvider.getApplicationContext()
|
||||
val glean = GleanInternalAPI()
|
||||
glean.initialize(context)
|
||||
glean.handleBackgroundEvent()
|
||||
val pingPath = File(context.applicationInfo.dataDir, "glean_data/pings")
|
||||
val path = pingPath.toString()
|
||||
assertEquals(2, pingPath.listFiles()?.size)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,6 +174,8 @@ uint8_t glean_is_initialized(uint64_t glean_handle);
|
|||
|
||||
uint8_t glean_is_upload_enabled(uint64_t glean_handle);
|
||||
|
||||
void glean_send_ping(uint64_t glean_handle, FfiStr ping_name);
|
||||
|
||||
uint64_t glean_new_boolean_metric(FfiStr category,
|
||||
FfiStr name,
|
||||
RawStringArray send_in_pings,
|
||||
|
|
|
@ -80,6 +80,15 @@ pub extern "C" fn glean_set_upload_enabled(glean_handle: u64, flag: u8) {
|
|||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glean_send_ping(glean_handle: u64, ping_name: FfiStr) {
|
||||
let mut err = ExternError::success();
|
||||
GLEAN.call_with_output(&mut err, glean_handle, |glean| {
|
||||
// FIXME: Error handling
|
||||
let _ = glean.send_ping(ping_name.as_str());
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn glean_new_boolean_metric(
|
||||
category: FfiStr,
|
||||
|
|
|
@ -129,6 +129,8 @@ impl Glean {
|
|||
let url_path = self.make_path(ping_name, &doc_id);
|
||||
let ping_content =
|
||||
::serde_json::to_string_pretty(&ping_maker.collect(self.storage(), ping_name)).unwrap();
|
||||
// FIXME: Logging ping content for now. Eventually this should be controlled by a flag
|
||||
log::info!("{}", ping_content);
|
||||
ping_maker.store_ping(&doc_id, &self.get_data_path(), &url_path, &ping_content)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче