forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Bug 1635487) Wired up sync logging for extension pref storage r=lina…
…,markh Differential Revision: https://phabricator.services.mozilla.com/D80975
- Loading branch information
1 parent
375174f
commit 893cb93
Showing
27 changed files
with
316 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
services/common/app_services_logger/AppServicesLoggerComponents.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef mozilla_services_AppServicesLoggerComponents_h_ | ||
#define mozilla_services_AppServicesLoggerComponents_h_ | ||
|
||
#include "mozIAppServicesLogger.h" | ||
#include "nsCOMPtr.h" | ||
|
||
extern "C" { | ||
|
||
// Implemented in Rust, in the `app_services_logger` crate. | ||
nsresult NS_NewAppServicesLogger(mozIAppServicesLogger** aResult); | ||
|
||
} // extern "C" | ||
|
||
namespace mozilla { | ||
namespace appservices { | ||
|
||
// The C++ constructor for a `services.appServicesLogger` service. This wrapper | ||
// exists because `components.conf` requires a component class constructor to | ||
// return an `already_AddRefed<T>`, but Rust doesn't have such a type. So we | ||
// call the Rust constructor using a `nsCOMPtr` (which is compatible with Rust's | ||
// `xpcom::RefPtr`) out param, and return that. | ||
already_AddRefed<mozIAppServicesLogger> NewLogService() { | ||
nsCOMPtr<mozIAppServicesLogger> logger; | ||
nsresult rv = NS_NewAppServicesLogger(getter_AddRefs(logger)); | ||
if (NS_WARN_IF(NS_FAILED(rv))) { | ||
return nullptr; | ||
} | ||
return logger.forget(); | ||
} | ||
|
||
} // namespace appservices | ||
} // namespace mozilla | ||
|
||
#endif // mozilla_services_AppServicesLoggerComponents_h_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "app_services_logger" | ||
version = "0.1.0" | ||
authors = ["lougeniac64 <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
golden_gate = { path = "../../../services/sync/golden_gate" } | ||
log = "0.4" | ||
once_cell = "1.4.0" | ||
nserror = { path = "../../../xpcom/rust/nserror" } | ||
nsstring = { path = "../../../xpcom/rust/nsstring" } | ||
xpcom = { path = "../../../xpcom/rust/xpcom" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- | ||
# vim: set filetype=python: | ||
# 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 http://mozilla.org/MPL/2.0/. | ||
|
||
Classes = [ | ||
{ | ||
'cid': '{d2716568-f5fa-4989-91dd-e11599e932a1}', | ||
'contract_ids': ['@mozilla.org/appservices/logger;1'], | ||
'type': 'mozIAppServicesLogger', | ||
'headers': ['mozilla/appservices/AppServicesLoggerComponents.h'], | ||
'constructor': 'mozilla::appservices::NewLogService', | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* 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/. */ | ||
|
||
//! This provides a XPCOM service to send app services logs to the desktop | ||
#[macro_use] | ||
extern crate xpcom; | ||
|
||
use golden_gate::log::LogSink; | ||
use log; | ||
use nserror::{nsresult, NS_OK}; | ||
use nsstring::nsAString; | ||
use once_cell::sync::Lazy; | ||
use std::{cmp, collections::HashMap, sync::RwLock}; | ||
use xpcom::{ | ||
interfaces::{mozIAppServicesLogger, mozIServicesLogSink}, | ||
RefPtr, | ||
}; | ||
|
||
#[derive(xpcom)] | ||
#[xpimplements(mozIAppServicesLogger)] | ||
#[refcnt = "nonatomic"] | ||
pub struct InitAppServicesLogger {} | ||
|
||
pub static LOGGERS_BY_TARGET: Lazy<RwLock<HashMap<String, LogSink>>> = Lazy::new(|| { | ||
let h: HashMap<String, LogSink> = HashMap::new(); | ||
let m = RwLock::new(h); | ||
m | ||
}); | ||
|
||
impl AppServicesLogger { | ||
xpcom_method!(register => Register(target: *const nsAString, logger: *const mozIServicesLogSink)); | ||
fn register(&self, target: &nsAString, logger: &mozIServicesLogSink) -> Result<(), nsresult> { | ||
let log_sink_logger = LogSink::with_logger(Some(logger))?; | ||
let max_level = cmp::max(log::max_level(), log_sink_logger.max_level); | ||
|
||
// Note: This will only work if the max_level is lower than the compile-time | ||
// max_level_* filter. | ||
log::set_max_level(max_level); | ||
|
||
LOGGERS_BY_TARGET | ||
.write() | ||
.unwrap() | ||
.insert(target.to_string(), log_sink_logger); | ||
Ok(()) | ||
} | ||
|
||
pub fn is_app_services_logger_registered(target: String) -> bool { | ||
match LOGGERS_BY_TARGET.read() { | ||
Ok(loggers_by_target) => loggers_by_target.contains_key(&target), | ||
Err(_e) => false, | ||
} | ||
} | ||
} | ||
|
||
/// The constructor for an `AppServicesLogger` service. This uses C linkage so that it | ||
/// can be called from C++. See `AppServicesLoggerComponents.h` for the C++ | ||
/// constructor that's passed to the component manager. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This function is unsafe because it dereferences `result`. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn NS_NewAppServicesLogger( | ||
result: *mut *const mozIAppServicesLogger, | ||
) -> nsresult { | ||
let logger = AppServicesLogger::allocate(InitAppServicesLogger {}); | ||
RefPtr::new(logger.coerce::<mozIAppServicesLogger>()).forget(&mut *result); | ||
NS_OK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "nsISupports.idl" | ||
#include "mozIServicesLogSink.idl" | ||
|
||
[scriptable, uuid(446dd837-fbb0-41e4-8221-f740f672b20d)] | ||
interface mozIAppServicesLogger : nsISupports { | ||
void register(in AString target, in mozIServicesLogSink logger); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.