Bug 1353897 - Only destroy preference front if used. r=ochameau
The toolbox can get a preference front for toggling various prefs on the server.
The toolbox destruction code path was written in such a way that it would
request a preference front during toolbox destroy, only to immediately destroy
the front right after. This is extra painful, since we send a `listTabs`
request and other fun things as part of this.
With this change, we cache the preference front when it is first used, and we
only attempt to destroy it if it was previously used.
MozReview-Commit-ID: 9repQSXjdRj
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -1798,45 +1798,46 @@ Toolbox.prototype = {
}
this.postMessage({
name: "set-host-title",
title
});
},
// Returns an instance of the preference actor
- get _preferenceFront() {
+ get preferenceFront() {
+ if (this._preferenceFront) {
+ return Promise.resolve(this._preferenceFront);
+ }
return this.isOpen.then(() => {
return this.target.root.then(rootForm => {
- return getPreferenceFront(this.target.client, rootForm);
+ let front = getPreferenceFront(this.target.client, rootForm);
+ this._preferenceFront = front;
+ return front;
});
});
},
_toggleNoAutohide: Task.async(function* () {
- let front = yield this._preferenceFront;
- let toggledValue = !(yield this._isDisableAutohideEnabled(front));
+ let front = yield this.preferenceFront;
+ let toggledValue = !(yield this._isDisableAutohideEnabled());
front.setBoolPref(DISABLE_AUTOHIDE_PREF, toggledValue);
this.autohideButton.isChecked = toggledValue;
}),
- _isDisableAutohideEnabled: Task.async(function* (prefFront) {
+ _isDisableAutohideEnabled: Task.async(function* () {
// Ensure that the tools are open, and the button is visible.
yield this.isOpen;
if (!this.autohideButton.isVisible) {
return false;
}
- // If no prefFront was provided, then get one.
- if (!prefFront) {
- prefFront = yield this._preferenceFront;
- }
-
+ let prefFront = yield this.preferenceFront;
return yield prefFront.getBoolPref(DISABLE_AUTOHIDE_PREF);
}),
_listFrames: function (event) {
if (!this._target.activeTab || !this._target.activeTab.traits.frames) {
// We are not targetting a regular TabActor
// it can be either an addon or browser toolbox actor
return promise.resolve();
@@ -2510,18 +2511,21 @@ Toolbox.prototype = {
yield this.performance.destroy();
this._performance = null;
}),
/**
* Destroy the preferences actor when the toolbox is unloaded.
*/
destroyPreference: Task.async(function* () {
- let front = yield this._preferenceFront;
- front.destroy();
+ if (!this._preferenceFront) {
+ return;
+ }
+ this._preferenceFront.destroy();
+ this._preferenceFront = null;
}),
/**
* Called when any event comes from the PerformanceFront. If the performance tool is
* already loaded when the first event comes in, immediately unbind this handler, as
* this is only used to queue up observed recordings before the performance tool can
* handle them, which will only occur when `console.profile()` recordings are started
* before the tool loads.