mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1614777 - Part 1: collect bandwidth in search telemetry; r=Ehsan,Standard8
Differential Revision: https://phabricator.services.mozilla.com/D63096 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ff87ae3aec
commit
3c3eb0c74e
@ -149,6 +149,7 @@ class TelemetryHandler {
|
||||
browserInfoByURL: this._browserInfoByURL,
|
||||
findBrowserItemForURL: (...args) => this._findBrowserItemForURL(...args),
|
||||
getProviderInfoForURL: (...args) => this._getProviderInfoForURL(...args),
|
||||
checkURLForSerpMatch: (...args) => this._checkURLForSerpMatch(...args),
|
||||
});
|
||||
}
|
||||
|
||||
@ -583,6 +584,7 @@ class ContentHandler {
|
||||
this._browserInfoByURL = options.browserInfoByURL;
|
||||
this._findBrowserItemForURL = options.findBrowserItemForURL;
|
||||
this._getProviderInfoForURL = options.getProviderInfoForURL;
|
||||
this._checkURLForSerpMatch = options.checkURLForSerpMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -598,6 +600,8 @@ class ContentHandler {
|
||||
Cc["@mozilla.org/network/http-activity-distributor;1"]
|
||||
.getService(Ci.nsIHttpActivityDistributor)
|
||||
.addObserver(this);
|
||||
|
||||
Services.obs.addObserver(this, "http-on-stop-request");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -607,6 +611,8 @@ class ContentHandler {
|
||||
Cc["@mozilla.org/network/http-activity-distributor;1"]
|
||||
.getService(Ci.nsIHttpActivityDistributor)
|
||||
.removeObserver(this);
|
||||
|
||||
Services.obs.removeObserver(this, "http-on-stop-request");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -633,6 +639,69 @@ class ContentHandler {
|
||||
Services.ppmm.sharedData.set("SearchTelemetry:ProviderInfo", providerInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports bandwidth used by the given channel if it is used by search requests.
|
||||
*
|
||||
* @param {object} aChannel The channel that generated the activity.
|
||||
*/
|
||||
_reportChannelBandwidth(aChannel) {
|
||||
if (!(aChannel instanceof Ci.nsIChannel)) {
|
||||
return;
|
||||
}
|
||||
let wrappedChannel = ChannelWrapper.get(aChannel);
|
||||
|
||||
let getTopURL = channel => {
|
||||
// top-level document
|
||||
if (
|
||||
channel.loadInfo.externalContentPolicyType ==
|
||||
Ci.nsIContentPolicy.TYPE_DOCUMENT
|
||||
) {
|
||||
return channel.finalURL;
|
||||
}
|
||||
|
||||
// iframe
|
||||
if (channel.frameAncestors) {
|
||||
let ancestor = channel.frameAncestors.find(obj => obj.frameId == 0);
|
||||
if (ancestor) {
|
||||
return ancestor.url;
|
||||
}
|
||||
}
|
||||
|
||||
// top-level resource
|
||||
if (
|
||||
channel.loadInfo.loadingPrincipal &&
|
||||
channel.loadInfo.loadingPrincipal.URI
|
||||
) {
|
||||
return channel.loadInfo.loadingPrincipal.URI.spec;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
let topUrl = getTopURL(wrappedChannel);
|
||||
if (!topUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
let info = this._checkURLForSerpMatch(topUrl);
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
|
||||
let bytesTransferred =
|
||||
wrappedChannel.requestSize + wrappedChannel.responseSize;
|
||||
let { provider } = info;
|
||||
LOG(`provider=${provider} size=${bytesTransferred}`);
|
||||
}
|
||||
|
||||
observe(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "http-on-stop-request":
|
||||
this._reportChannelBandwidth(aSubject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener that observes network activity, so that we can determine if a link
|
||||
* from a search provider page was followed, and if then if that link was an
|
||||
@ -760,7 +829,7 @@ class ContentHandler {
|
||||
*/
|
||||
function LOG(msg) {
|
||||
if (loggingEnabled) {
|
||||
dump(`*** SearchTelemetry: ${msg}\n"`);
|
||||
dump(`*** SearchTelemetry: ${msg}\n`);
|
||||
Services.console.logStringMessage(msg);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user