зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 4 changesets (bug 1623304) for android build bustages. CLOSED TREE
Backed out changeset 28e076bc443b (bug 1623304) Backed out changeset e7470ab5ae58 (bug 1623304) Backed out changeset 932d51ae751e (bug 1623304) Backed out changeset 1845fca9e3ec (bug 1623304)
This commit is contained in:
Родитель
f2901dc886
Коммит
d6f1fb7bff
|
@ -1481,7 +1481,6 @@ checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
|||
name = "fog"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cstr",
|
||||
"glean",
|
||||
"glean-core",
|
||||
"log",
|
||||
|
@ -1489,8 +1488,6 @@ dependencies = [
|
|||
"nsstring",
|
||||
"once_cell",
|
||||
"static_prefs",
|
||||
"url",
|
||||
"viaduct",
|
||||
"xpcom",
|
||||
]
|
||||
|
||||
|
|
|
@ -14,6 +14,3 @@ static_prefs = { path = "../../../modules/libpref/init/static_prefs" }
|
|||
xpcom = { path = "../../../xpcom/rust/xpcom" }
|
||||
once_cell = "1.2.0"
|
||||
glean = { path = "./api" }
|
||||
cstr = "0.1"
|
||||
viaduct = { git = "https://github.com/mozilla/application-services", rev = "57a07e89e9ac92756b60b67c4a6ee06975b86288" } # Copied from toolkit/library/rust/shared/Cargo.toml
|
||||
url = "2.1" # Copied from viaduct's deps, see https://github.com/mozilla/application-services/issues/3062
|
||||
|
|
|
@ -16,7 +16,6 @@ pub extern crate once_cell;
|
|||
pub extern crate uuid;
|
||||
|
||||
pub mod metrics;
|
||||
pub mod ping_upload;
|
||||
|
||||
/// Run a closure with a mutable reference to the locked global Glean object.
|
||||
fn with_glean<F, R>(f: F) -> R
|
||||
|
|
|
@ -61,10 +61,6 @@ impl Ping {
|
|||
///
|
||||
/// Returns true if a ping was assembled and queued, false otherwise.
|
||||
pub fn submit(&self, reason: Option<&str>) -> bool {
|
||||
let res = crate::with_glean(|glean| self.0.submit(glean, reason).unwrap_or(false));
|
||||
if res {
|
||||
crate::ping_upload::check_for_uploads();
|
||||
}
|
||||
res
|
||||
crate::with_glean(|glean| self.0.submit(glean, reason).unwrap_or(false))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//! The Ping Upload Scheduler logic.
|
||||
//!
|
||||
//! Register your application's PingUploader to upload pings when scheduled.
|
||||
//!
|
||||
//! ## Example:
|
||||
//!
|
||||
//! ```rust,ignore
|
||||
//! fn during_init() {
|
||||
//! ping_upload::register_uploader(Box::new(|ping_request| do_the_thing(ping_request)));
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use glean_core::upload::PingUploadTask::*;
|
||||
pub use glean_core::upload::{PingRequest, UploadResult};
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
use std::sync::Mutex;
|
||||
use std::thread;
|
||||
|
||||
pub type UploadFn = dyn (FnMut(&PingRequest) -> UploadResult) + Send;
|
||||
static UPLOADER: OnceCell<Mutex<Box<UploadFn>>> = OnceCell::new();
|
||||
|
||||
/// Threadsafe. Set the uploader to be used for all pings.
|
||||
/// Subsequent calls fail.
|
||||
pub fn register_uploader(uploader: Box<UploadFn>) -> Result<(), ()> {
|
||||
UPLOADER.set(Mutex::new(uploader)).map_err(|_| ())
|
||||
}
|
||||
|
||||
/// Called occasionally on any thread to nudge the Scheduler to ask Glean for
|
||||
/// ping requests.
|
||||
pub(crate) fn check_for_uploads() {
|
||||
if UPLOADER.get().is_none() {
|
||||
return;
|
||||
}
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
if let Some(mutex) = UPLOADER.get() {
|
||||
let uploader = &mut *mutex.lock().unwrap();
|
||||
if let Upload(request) = crate::with_glean(|glean| glean.get_upload_task(false)) {
|
||||
let response = (*uploader)(&request);
|
||||
crate::with_glean(|glean| {
|
||||
glean.process_ping_upload_response(&request.document_id, response)
|
||||
});
|
||||
} else {
|
||||
// For now, don't bother distinguishing between Wait and Done.
|
||||
// Either mean there's no task to execute right now.
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// No uploader? Weird.
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -20,11 +20,8 @@
|
|||
// FIXME: Remove when code gets actually used eventually (by initializing Glean).
|
||||
#![allow(dead_code)]
|
||||
|
||||
use glean::ping_upload::{self, UploadResult};
|
||||
use glean_core::{global_glean, setup_glean, Configuration, Glean, Result};
|
||||
use once_cell::sync::OnceCell;
|
||||
use url::Url;
|
||||
use viaduct::Request;
|
||||
|
||||
use crate::client_info::ClientInfo;
|
||||
use crate::core_metrics::InternalMetrics;
|
||||
|
@ -81,9 +78,6 @@ pub fn initialize(cfg: Configuration, client_info: ClientInfo) -> Result<()> {
|
|||
// Now make this the global object available to others.
|
||||
setup_glean(glean)?;
|
||||
|
||||
// Register the uploader so we can upload pings.
|
||||
register_uploader();
|
||||
|
||||
Ok(AppState { client_info })
|
||||
})
|
||||
.map(|_| ())
|
||||
|
@ -136,42 +130,3 @@ pub fn set_upload_enabled(enabled: bool) -> bool {
|
|||
enabled
|
||||
})
|
||||
}
|
||||
|
||||
fn register_uploader() {
|
||||
let result = ping_upload::register_uploader(Box::new(|ping_request| {
|
||||
log::trace!(
|
||||
"FOG Ping Uploader uploading ping {}",
|
||||
ping_request.document_id
|
||||
);
|
||||
let result: std::result::Result<UploadResult, viaduct::Error> = (move || {
|
||||
const SERVER: &str = "https://incoming.telemetry.mozilla.org";
|
||||
let url = Url::parse(SERVER)?.join(&ping_request.path)?;
|
||||
let mut req = Request::post(url).body(ping_request.body.clone());
|
||||
for (&header_key, header_value) in ping_request.headers.iter() {
|
||||
req = req.header(header_key, header_value)?;
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
"FOG Ping Uploader sending ping {}",
|
||||
ping_request.document_id
|
||||
);
|
||||
let res = req.send()?;
|
||||
Ok(UploadResult::HttpStatus(res.status.into()))
|
||||
})();
|
||||
log::trace!(
|
||||
"FOG Ping Uploader completed uploading ping {} (Result {:?})",
|
||||
ping_request.document_id,
|
||||
result
|
||||
);
|
||||
match result {
|
||||
Ok(result) => result,
|
||||
_ => UploadResult::UnrecoverableFailure,
|
||||
}
|
||||
}));
|
||||
if result.is_err() {
|
||||
log::warn!(
|
||||
"Couldn't register uploader because one's already in there. {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,11 @@
|
|||
// compiled.
|
||||
pub extern crate glean;
|
||||
|
||||
#[macro_use]
|
||||
extern crate cstr;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
use nserror::{nsresult, NS_OK};
|
||||
use nsstring::nsACString;
|
||||
use xpcom::interfaces::mozIViaduct;
|
||||
|
||||
use client_info::ClientInfo;
|
||||
use glean_core::Configuration;
|
||||
|
@ -83,19 +79,6 @@ pub unsafe extern "C" fn fog_init(
|
|||
|
||||
log::debug!("Configuration: {:#?}", configuration);
|
||||
|
||||
// Ensure Viaduct is initialized for networking unconditionally so we don't
|
||||
// need to check again if upload is later enabled.
|
||||
if let Some(viaduct) =
|
||||
xpcom::create_instance::<mozIViaduct>(cstr!("@mozilla.org/toolkit/viaduct;1"))
|
||||
{
|
||||
let result = viaduct.EnsureInitialized();
|
||||
if result.failed() {
|
||||
log::error!("Failed to ensure viaduct was initialized due to {}. Ping upload may not be available.", result.error_name());
|
||||
}
|
||||
} else {
|
||||
log::error!("Failed to create Viaduct via XPCOM. Ping upload may not be available.");
|
||||
}
|
||||
|
||||
if configuration.data_path.len() > 0 {
|
||||
if let Err(e) = api::initialize(configuration, client_info) {
|
||||
log::error!("Failed to init FOG due to {:?}", e);
|
||||
|
|
Загрузка…
Ссылка в новой задаче