Bug 1650099 - Unify UrlbarProviders logger boilerplate. r=adw

Differential Revision: https://phabricator.services.mozilla.com/D82939
This commit is contained in:
Marco Bonardo 2020-07-10 09:49:42 +00:00
Родитель 64b33a1eaa
Коммит efd2be2d06
17 изменённых файлов: 72 добавлений и 101 удалений

Просмотреть файл

@ -289,6 +289,9 @@ pref("browser.urlbar.speculativeConnect.enabled", true);
// search for bookmarklets typing "javascript: " followed by the actual query.
pref("browser.urlbar.filter.javascript", true);
// Enable a certain level of urlbar logging to the Browser Console. See Log.jsm.
pref("browser.urlbar.loglevel", "Error");
// the maximum number of results to show in autocomplete when doing richResults
pref("browser.urlbar.maxRichResults", 10);

Просмотреть файл

@ -14,11 +14,11 @@ XPCOMUtils.defineLazyModuleGetters(this, {
clearTimeout: "resource://gre/modules/Timer.jsm",
Services: "resource://gre/modules/Services.jsm",
setTimeout: "resource://gre/modules/Timer.jsm",
Log: "resource://gre/modules/Log.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.EventBufferer")
UrlbarUtils.getLogger({ prefix: "EventBufferer" })
);
// Maximum time events can be deferred for.

Просмотреть файл

@ -14,7 +14,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
Services: "resource://gre/modules/Services.jsm",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarMuxer: "resource:///modules/UrlbarUtils.jsm",
@ -22,7 +21,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Muxer.UnifiedComplete")
UrlbarUtils.getLogger({ prefix: "MuxerUnifiedComplete" })
);
function groupFromResult(result) {

Просмотреть файл

@ -286,6 +286,7 @@ class UrlbarProviderExtension extends UrlbarProvider {
name: "UrlbarProviderExtension notification timer",
time: UrlbarProviderExtension.notificationTimeout,
reportErrorOnTimeout: true,
logger: this.logger,
});
result = await Promise.race([
timer.promise,

Просмотреть файл

@ -16,7 +16,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
Services: "resource://gre/modules/Services.jsm",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
@ -25,10 +24,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.HeuristicFallback")
);
/**
* Class used to create the provider.
*/
@ -83,7 +78,6 @@ class ProviderHeuristicFallback extends UrlbarProvider {
* @returns {Promise} resolved when the query stops.
*/
async startQuery(queryContext, addCallback) {
logger.info(`Starting query for ${queryContext.searchString}`);
let instance = {};
this.queries.set(queryContext, instance);
@ -131,7 +125,6 @@ class ProviderHeuristicFallback extends UrlbarProvider {
* @param {object} queryContext The query context object
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
this.queries.delete(queryContext);
}

Просмотреть файл

@ -14,7 +14,6 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
AppUpdater: "resource:///modules/AppUpdater.jsm",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
Log: "resource://gre/modules/Log.jsm",
NLP: "resource://gre/modules/NLP.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
ResetProfile: "resource://gre/modules/ResetProfile.jsm",
@ -25,10 +24,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.Interventions")
);
XPCOMUtils.defineLazyGetter(this, "appUpdater", () => new AppUpdater());
// The possible tips to show. These names (except NONE) are used in the names
@ -666,7 +661,6 @@ class ProviderInterventions extends UrlbarProvider {
* query for.
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
this.queries.delete(queryContext);
// If we're waiting for appUpdater to finish its update check,

Просмотреть файл

@ -15,7 +15,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
ExtensionSearchHandler: "resource://gre/modules/ExtensionSearchHandler.jsm",
SkippableTimer: "resource:///modules/UrlbarUtils.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
@ -23,10 +22,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.Omnibox")
);
// After this time, we'll give up waiting for the extension to return matches.
const MAXIMUM_ALLOWED_EXTENSION_TIME_MS = 3000;
@ -116,7 +111,6 @@ class ProviderOmnibox extends UrlbarProvider {
* The callback invoked by this method to add each result.
*/
async startQuery(queryContext, addCallback) {
logger.info(`Starting query for ${queryContext.searchString}`);
let instance = {};
this.queries.set(queryContext, instance);
@ -173,7 +167,7 @@ class ProviderOmnibox extends UrlbarProvider {
let timeoutPromise = new SkippableTimer({
name: "ProviderOmnibox",
time: MAXIMUM_ALLOWED_EXTENSION_TIME_MS,
logger,
logger: this.logger,
}).promise;
await Promise.race([timeoutPromise, this._resultsPromise]).catch(
Cu.reportError

Просмотреть файл

@ -15,7 +15,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm",
@ -23,10 +22,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.OpenTabs")
);
/**
* Class used to create the provider.
*/
@ -156,7 +151,6 @@ class ProviderOpenTabs extends UrlbarProvider {
// temp table to return proper frecency.
// TODO:
// * properly search and handle tokens, this is just a mock for now.
logger.info(`Starting query for ${queryContext.searchString}`);
let instance = {};
this.queries.set(queryContext, instance);
let conn = await this.promiseDb();
@ -193,7 +187,6 @@ class ProviderOpenTabs extends UrlbarProvider {
* @param {object} queryContext The query context object
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
this.queries.delete(queryContext);
}
}

Просмотреть файл

@ -14,7 +14,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
Services: "resource://gre/modules/Services.jsm",
SkippableTimer: "resource:///modules/UrlbarUtils.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
@ -23,10 +22,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.PrivateSearch")
);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"separatePrivateDefaultUIEnabled",
@ -92,8 +87,6 @@ class ProviderPrivateSearch extends UrlbarProvider {
* @returns {Promise} resolved when the query stops.
*/
async startQuery(queryContext, addCallback) {
logger.info(`Starting query for ${queryContext.searchString}`);
let searchString = queryContext.searchString.trim();
if (
queryContext.tokens.some(
@ -119,7 +112,7 @@ class ProviderPrivateSearch extends UrlbarProvider {
: await Services.search.getDefaultPrivate();
let isPrivateEngine =
separatePrivateDefault && engine != (await Services.search.getDefault());
logger.info(`isPrivateEngine: ${isPrivateEngine}`);
this.logger.info(`isPrivateEngine: ${isPrivateEngine}`);
// This is a delay added before returning results, to avoid flicker.
// Our result must appear only when all results are searches, but if search
@ -128,7 +121,7 @@ class ProviderPrivateSearch extends UrlbarProvider {
await new SkippableTimer({
name: "ProviderPrivateSearch",
time: 100,
logger,
logger: this.logger,
}).promise;
let result = new UrlbarResult(
@ -152,7 +145,6 @@ class ProviderPrivateSearch extends UrlbarProvider {
* @param {object} queryContext The query context object
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
this.queries.delete(queryContext);
}
}

Просмотреть файл

@ -14,7 +14,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
SearchSuggestionController:
"resource://gre/modules/SearchSuggestionController.jsm",
Services: "resource://gre/modules/Services.jsm",
@ -27,10 +26,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.SearchSuggestions")
);
/**
* Returns whether the passed in string looks like a url.
* @param {string} str
@ -215,7 +210,6 @@ class ProviderSearchSuggestions extends UrlbarProvider {
* @returns {Promise} resolved when the query stops.
*/
async startQuery(queryContext, addCallback) {
logger.info(`Starting query for ${queryContext.searchString}`);
let instance = {};
this.queries.set(queryContext, instance);
@ -327,8 +321,6 @@ class ProviderSearchSuggestions extends UrlbarProvider {
* @param {object} queryContext The query context object
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
if (this._suggestionsController) {
this._suggestionsController.stop();
this._suggestionsController = null;
@ -434,7 +426,7 @@ class ProviderSearchSuggestions extends UrlbarProvider {
let tailTimer = new SkippableTimer({
name: "ProviderSearchSuggestions",
time: 100,
logger,
logger: this.logger,
});
for (let entry of fetchData.remote) {

Просмотреть файл

@ -19,7 +19,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.jsm",
DefaultBrowserCheck: "resource:///modules/BrowserGlue.jsm",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
Log: "resource://gre/modules/Log.jsm",
ProfileAge: "resource://gre/modules/ProfileAge.jsm",
Services: "resource://gre/modules/Services.jsm",
setTimeout: "resource://gre/modules/Timer.jsm",
@ -30,10 +29,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.SearchTips")
);
XPCOMUtils.defineLazyServiceGetter(
this,
"updateManager",
@ -230,7 +225,6 @@ class ProviderSearchTips extends UrlbarProvider {
* query for.
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
this.queries.delete(queryContext);
}

Просмотреть файл

@ -14,17 +14,12 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
UrlbarResult: "resource:///modules/UrlbarResult.jsm",
UrlbarSearchUtils: "resource:///modules/UrlbarSearchUtils.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.TokenAliasEngines")
);
/**
* Class used to create the provider.
*/
@ -80,7 +75,6 @@ class ProviderTokenAliasEngines extends UrlbarProvider {
* result.
*/
async startQuery(queryContext, addCallback) {
logger.info(`Starting query for ${queryContext.searchString}`);
let instance = {};
this.queries.set(queryContext, instance);
@ -127,7 +121,6 @@ class ProviderTokenAliasEngines extends UrlbarProvider {
* @param {object} queryContext The query context object
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
this.queries.delete(queryContext);
}
}

Просмотреть файл

@ -12,7 +12,6 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
AboutNewTab: "resource:///modules/AboutNewTab.jsm",
Log: "resource://gre/modules/Log.jsm",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
@ -25,10 +24,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
TOP_SITES_DEFAULT_ROWS: "resource://activity-stream/common/Reducers.jsm",
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.TopSites")
);
/**
* This module exports a provider returning the user's newtab Top Sites.
*/
@ -247,7 +242,6 @@ class ProviderTopSites extends UrlbarProvider {
* query for.
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
this.queries.delete(queryContext);
}
}

Просмотреть файл

@ -16,7 +16,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
@ -31,10 +30,6 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIAutoCompleteSearch"
);
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Provider.UnifiedComplete")
);
/**
* Class used to create the provider.
*/
@ -80,7 +75,6 @@ class ProviderUnifiedComplete extends UrlbarProvider {
* @returns {Promise} resolved when the query stops.
*/
async startQuery(queryContext, addCallback) {
logger.info(`Starting query for ${queryContext.searchString}`);
let instance = {};
this.queries.set(queryContext, instance);
let urls = new Set();
@ -111,7 +105,6 @@ class ProviderUnifiedComplete extends UrlbarProvider {
* @param {object} queryContext The query context object
*/
cancelQuery(queryContext) {
logger.info(`Canceling query for ${queryContext.searchString}`);
// This doesn't properly support being used concurrently by multiple fields.
this.queries.delete(queryContext);
unifiedComplete.stopSearch();

Просмотреть файл

@ -15,7 +15,6 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
Log: "resource://gre/modules/Log.jsm",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
SkippableTimer: "resource:///modules/UrlbarUtils.jsm",
UrlbarMuxer: "resource:///modules/UrlbarUtils.jsm",
@ -27,7 +26,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
});
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.ProvidersManager")
UrlbarUtils.getLogger({ prefix: "ProvidersManager" })
);
// List of available local providers, each is implemented in its own jsm module
@ -234,7 +233,7 @@ class ProvidersManager {
* @param {object} queryContext
*/
cancelQuery(queryContext) {
logger.info(`Query cancel ${queryContext.searchString}`);
logger.info(`Query cancel "${queryContext.searchString}"`);
let query = this.queries.get(queryContext);
if (!query) {
throw new Error("Couldn't find a matching query for the given context");
@ -363,13 +362,21 @@ class Query {
}
// Start querying active providers.
let queryPromises = [];
let startQuery = provider => {
provider.logger.info(`Starting query for "${this.context.searchString}"`);
return provider.tryMethod(
"startQuery",
this.context,
this.add.bind(this)
);
};
for (let provider of activeProviders) {
if (provider.type == UrlbarUtils.PROVIDER_TYPE.HEURISTIC) {
this.context.pendingHeuristicProviders.add(provider.name);
queryPromises.push(
provider.tryMethod("startQuery", this.context, this.add.bind(this))
);
queryPromises.push(startQuery(provider));
continue;
}
if (!this._sleepTimer) {
@ -379,20 +386,13 @@ class Query {
this._sleepTimer = new SkippableTimer({
name: "Query provider timer",
time: UrlbarPrefs.get("delay"),
logger,
logger: provider.logger,
});
}
queryPromises.push(
this._sleepTimer.promise.then(() => {
if (this.canceled) {
return undefined;
}
return provider.tryMethod(
"startQuery",
this.context,
this.add.bind(this)
);
})
this._sleepTimer.promise.then(() =>
this.canceled ? undefined : startQuery(provider)
)
);
}
@ -418,6 +418,9 @@ class Query {
}
this.canceled = true;
for (let provider of this.providers) {
provider.logger.info(
`Canceling query for "${this.context.searchString}"`
);
provider.tryMethod("cancelQuery", this.context);
}
if (this._chunkTimer) {
@ -518,7 +521,7 @@ class Query {
name: "Heuristic provider timer",
callback: () => this._notifyResults(),
time: CHUNK_RESULTS_DELAY_MS,
logger,
logger: provider.logger,
});
}
} else if (!this._chunkTimer) {
@ -526,7 +529,7 @@ class Query {
name: "Query chunk timer",
callback: () => this._notifyResults(),
time: CHUNK_RESULTS_DELAY_MS,
logger,
logger: provider.logger,
});
}
// If all active heuristic providers have returned results, we can skip the
@ -570,13 +573,13 @@ class Query {
// Crop results to the requested number, taking their result spans into
// account.
logger.debug(
`Cropping ${this.context.results.length} results to ${this.context.maxResults}`
);
let resultCount = this.context.maxResults;
for (let i = 0; i < this.context.results.length; i++) {
resultCount -= UrlbarUtils.getSpanForResult(this.context.results[i]);
if (resultCount < 0) {
logger.debug(
`Splicing results from ${i} to crop results to ${this.context.maxResults}`
);
this.context.results.splice(i, this.context.results.length - i);
break;
}

Просмотреть файл

@ -15,11 +15,13 @@ var EXPORTED_SYMBOLS = ["UrlbarTokenizer"];
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
ChromeUtils.defineModuleGetter(this, "Log", "resource://gre/modules/Log.jsm");
XPCOMUtils.defineLazyGetter(this, "logger", () =>
Log.repository.getLogger("Urlbar.Tokenizer")
UrlbarUtils.getLogger({ prefix: "Tokenizer" })
);
var UrlbarTokenizer = {

Просмотреть файл

@ -23,6 +23,7 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
Log: "resource://gre/modules/Log.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
PlacesUIUtils: "resource:///modules/PlacesUIUtils.jsm",
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
@ -659,6 +660,30 @@ var UrlbarUtils = {
}
return context.heuristicResult;
},
/**
* Creates a logger.
* Logging level can be controlled through browser.urlbar.loglevel.
* @param {string} [prefix] Prefix to use for the logged messages, "::" will
* be appended automatically to the prefix.
* @returns {object} The logger.
*/
getLogger({ prefix = "" } = {}) {
if (!this._logger) {
this._logger = Log.repository.getLogger("urlbar");
this._logger.manageLevelFromPref("browser.urlbar.loglevel");
this._logger.addAppender(
new Log.ConsoleAppender(new Log.BasicFormatter())
);
}
if (prefix) {
// This is not an early return because it is necessary to invoke getLogger
// at least once before getLoggerWithMessagePrefix; it replaces a
// method of the original logger, rather than using an actual Proxy.
return Log.repository.getLoggerWithMessagePrefix("urlbar", prefix + "::");
}
return this._logger;
},
};
XPCOMUtils.defineLazyGetter(UrlbarUtils.ICON, "DEFAULT", () => {
@ -1100,6 +1125,12 @@ class UrlbarMuxer {
* The provider scope is to query a datasource and return results from it.
*/
class UrlbarProvider {
constructor() {
XPCOMUtils.defineLazyGetter(this, "logger", () =>
UrlbarUtils.getLogger({ prefix: `Provider.${this.name}` })
);
}
/**
* Unique name for the provider, used by the context to filter on providers.
* Not using a unique name will cause the newest registration to win.