Bug 1676808 - [devtools] Expose WatcherFront via the TargetList instead of ResourceWatcher. r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D96804
This commit is contained in:
Alexandre Poirot 2020-11-16 21:08:19 +00:00
Родитель 390a288378
Коммит b1bb3196f3
4 изменённых файлов: 54 добавлений и 67 удалений

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

@ -99,15 +99,6 @@ class ProcessDescriptorFront extends FrontClassWithSpec(processDescriptorSpec) {
return this._targetFrontPromise;
}
getCachedWatcher() {
for (const child of this.poolChildren()) {
if (child.typeName == "watcher") {
return child;
}
}
return null;
}
destroy() {
if (this._processTargetFront) {
this._processTargetFront.destroy();

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

@ -210,15 +210,6 @@ class TabDescriptorFront extends FrontClassWithSpec(tabDescriptorSpec) {
return this._targetFrontPromise;
}
getCachedWatcher() {
for (const child of this.poolChildren()) {
if (child.typeName == "watcher") {
return child;
}
}
return null;
}
/**
* Handle tabs events.
*/

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

@ -22,7 +22,6 @@ class ResourceWatcher {
constructor(targetList) {
this.targetList = targetList;
this.descriptorFront = targetList.descriptorFront;
this._onTargetAvailable = this._onTargetAvailable.bind(this);
this._onTargetDestroyed = this._onTargetDestroyed.bind(this);
@ -45,6 +44,10 @@ class ResourceWatcher {
this._throttledNotifyWatchers = throttle(this._notifyWatchers, 100);
}
get watcher() {
return this.targetList.watcher;
}
/**
* Return all specified resources cached in this watcher.
*
@ -103,27 +106,23 @@ class ResourceWatcher {
);
}
// Cache the Watcher once for all, the first time we call `watch()`.
// This `watcher` attribute may be then used in any function of the ResourceWatcher after this.
if (!this.watcher) {
const supportsWatcher = this.descriptorFront?.traits?.watcher;
if (supportsWatcher) {
this.watcher = await this.descriptorFront.getWatcher();
// Resources watched from the parent process will be emitted on the Watcher Actor.
// So that we also have to listen for this event on it, in addition to all targets.
this.watcher.on(
"resource-available-form",
this._onResourceAvailable.bind(this, { watcherFront: this.watcher })
);
this.watcher.on(
"resource-updated-form",
this._onResourceUpdated.bind(this, { watcherFront: this.watcher })
);
this.watcher.on(
"resource-destroyed-form",
this._onResourceDestroyed.bind(this, { watcherFront: this.watcher })
);
}
// Bug 1675763: Watcher actor is not available in all situations yet.
if (!this._listenerRegistered && this.watcher) {
this._listenerRegistered = true;
// Resources watched from the parent process will be emitted on the Watcher Actor.
// So that we also have to listen for this event on it, in addition to all targets.
this.watcher.on(
"resource-available-form",
this._onResourceAvailable.bind(this, { watcherFront: this.watcher })
);
this.watcher.on(
"resource-updated-form",
this._onResourceUpdated.bind(this, { watcherFront: this.watcher })
);
this.watcher.on(
"resource-destroyed-form",
this._onResourceDestroyed.bind(this, { watcherFront: this.watcher })
);
}
// First ensuring enabling listening to targets.

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

@ -229,6 +229,10 @@ class TargetList extends EventEmitter {
return this._listenersStarted.has(type);
}
hasTargetWatcherSupport(type) {
return !!this.watcher?.traits[type];
}
/**
* Start listening for targets from the server
*
@ -245,6 +249,16 @@ class TargetList extends EventEmitter {
* but still register listeners set via Legacy Listeners.
*/
async startListening({ onlyLegacy = false } = {}) {
// Cache the Watcher once for all, the first time we call `startListening()`.
// This `watcher` attribute may be then used in any function in TargetList or ResourceWatcher after this.
if (!this.watcher) {
// Bug 1675763: Watcher actor is not available in all situations yet.
const supportsWatcher = this.descriptorFront?.traits?.watcher;
if (supportsWatcher) {
this.watcher = await this.descriptorFront.getWatcher();
}
}
let types = [];
if (this.targetFront.isParentProcess) {
const fissionBrowserToolboxEnabled = Services.prefs.getBoolPref(
@ -283,24 +297,20 @@ class TargetList extends EventEmitter {
this._setListening(type, true);
// Starting with FF77, we support frames watching via watchTargets for Tab and Process descriptors
const supportsWatcher = this.descriptorFront?.traits?.watcher;
if (supportsWatcher) {
const watcher = await this.descriptorFront.getWatcher();
if (watcher.traits[type]) {
// When we switch to a new top level target, we don't have to stop and restart
// Watcher listener as it is independant from the top level target.
// This isn't the case for some Legacy Listeners, which fetch targets from the top level target
if (onlyLegacy) {
continue;
}
if (!this._startedListeningToWatcher) {
this._startedListeningToWatcher = true;
watcher.on("target-available", this._onTargetAvailable);
watcher.on("target-destroyed", this._onTargetDestroyed);
}
await watcher.watchTargets(type);
if (this.hasTargetWatcherSupport(type)) {
// When we switch to a new top level target, we don't have to stop and restart
// Watcher listener as it is independant from the top level target.
// This isn't the case for some Legacy Listeners, which fetch targets from the top level target
if (onlyLegacy) {
continue;
}
if (!this._startedListeningToWatcher) {
this._startedListeningToWatcher = true;
this.watcher.on("target-available", this._onTargetAvailable);
this.watcher.on("target-destroyed", this._onTargetDestroyed);
}
await this.watcher.watchTargets(type);
continue;
}
if (this.legacyImplementation[type]) {
await this.legacyImplementation[type].listen();
@ -326,18 +336,14 @@ class TargetList extends EventEmitter {
this._setListening(type, false);
// Starting with FF77, we support frames watching via watchTargets for Tab and Process descriptors
const supportsWatcher = this.descriptorFront?.traits?.watcher;
if (supportsWatcher) {
const watcher = this.descriptorFront.getCachedWatcher();
if (watcher && watcher.traits[type]) {
// When we switch to a new top level target, we don't have to stop and restart
// Watcher listener as it is independant from the top level target.
// This isn't the case for some Legacy Listeners, which fetch targets from the top level target
if (!onlyLegacy) {
watcher.unwatchTargets(type);
}
continue;
if (this.hasTargetWatcherSupport(type)) {
// When we switch to a new top level target, we don't have to stop and restart
// Watcher listener as it is independant from the top level target.
// This isn't the case for some Legacy Listeners, which fetch targets from the top level target
if (!onlyLegacy) {
this.watcher.unwatchTargets(type);
}
continue;
}
if (this.legacyImplementation[type]) {
this.legacyImplementation[type].unlisten();