Bug 623950: Send startup time measurements along with the metadata requests. r=Unfocused, a=sdwilsh

This commit is contained in:
Dave Townsend 2011-01-20 13:45:10 -08:00
Родитель fcb4b30f93
Коммит 7f0d7c58d0
5 изменённых файлов: 91 добавлений и 6 удалений

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

@ -59,7 +59,7 @@ pref("extensions.logging.enabled", false);
// Preferences for AMO integration // Preferences for AMO integration
pref("extensions.getAddons.cache.enabled", true); pref("extensions.getAddons.cache.enabled", true);
pref("extensions.getAddons.maxResults", 15); pref("extensions.getAddons.maxResults", 15);
pref("extensions.getAddons.get.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/guid:%IDS%?src=firefox"); pref("extensions.getAddons.get.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/guid:%IDS%?src=firefox&appOS=%OS%&appVersion=%VERSION%&tMain=%TIME_MAIN%&tFirstPaint=%TIME_FIRST_PAINT%&tSessionRestored=%TIME_SESSION_RESTORED%");
pref("extensions.getAddons.search.browseURL", "https://addons.mozilla.org/%LOCALE%/%APP%/search?q=%TERMS%"); pref("extensions.getAddons.search.browseURL", "https://addons.mozilla.org/%LOCALE%/%APP%/search?q=%TERMS%");
pref("extensions.getAddons.search.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/%TERMS%/all/%MAX_RESULTS%/%OS%/%VERSION%?src=firefox"); pref("extensions.getAddons.search.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/%TERMS%/all/%MAX_RESULTS%/%OS%/%VERSION%?src=firefox");
pref("extensions.webservice.discoverURL", "https://services.addons.mozilla.org/%LOCALE%/%APP%/discovery/%VERSION%/%OS%"); pref("extensions.webservice.discoverURL", "https://services.addons.mozilla.org/%LOCALE%/%APP%/discovery/%VERSION%/%OS%");

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

@ -701,11 +701,28 @@ var AddonRepository = {
* The callback to pass results to * The callback to pass results to
*/ */
getAddonsByIDs: function(aIDs, aCallback) { getAddonsByIDs: function(aIDs, aCallback) {
let startupInfo = Cc["@mozilla.org/toolkit/app-startup;1"].
getService(Ci.nsIAppStartup_MOZILLA_2_0).
getStartupInfo();
let ids = aIDs.slice(0); let ids = aIDs.slice(0);
let url = this._formatURLPref(PREF_GETADDONS_BYIDS, {
let params = {
API_VERSION : API_VERSION, API_VERSION : API_VERSION,
IDS : ids.map(encodeURIComponent).join(',') IDS : ids.map(encodeURIComponent).join(',')
}); };
if (startupInfo.process) {
if (startupInfo.main)
params.TIME_MAIN = startupInfo.main - startupInfo.process;
if (startupInfo.firstPaint)
params.TIME_FIRST_PAINT = startupInfo.firstPaint - startupInfo.process;
if (startupInfo.sessionRestored)
params.TIME_SESSION_RESTORED = startupInfo.sessionRestored -
startupInfo.process;
};
let url = this._formatURLPref(PREF_GETADDONS_BYIDS, params);
let self = this; let self = this;
function handleResults(aElements, aTotalResults) { function handleResults(aElements, aTotalResults) {
@ -1124,6 +1141,8 @@ var AddonRepository = {
this._callback = aCallback; this._callback = aCallback;
this._maxResults = aMaxResults; this._maxResults = aMaxResults;
LOG("Requesting " + aURI);
this._request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. this._request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
createInstance(Ci.nsIXMLHttpRequest); createInstance(Ci.nsIXMLHttpRequest);
this._request.open("GET", aURI, true); this._request.open("GET", aURI, true);

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

@ -87,6 +87,7 @@ _TEST_FILES = \
head.js \ head.js \
browser_bug557956.js \ browser_bug557956.js \
browser_bug616841.js \ browser_bug616841.js \
browser_bug623950.js \
browser_updatessl.js \ browser_updatessl.js \
browser_installssl.js \ browser_installssl.js \
$(NULL) $(NULL)

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

@ -0,0 +1,68 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests that the metadata request includes startup time measurements
Components.utils.import("resource://gre/modules/AddonRepository.jsm");
var gManagerWindow;
var gProvider;
function parseParams(aQuery) {
let params = {};
aQuery.split("&").forEach(function(aParam) {
let [key, value] = aParam.split("=");
params[key] = value;
});
return params;
}
function test() {
waitForExplicitFinish();
var gSeenRequest = false;
gProvider = new MockProvider();
gProvider.createAddons([{
id: "test1@tests.mozilla.org",
name: "Test add-on"
}]);
function observe(aSubject, aTopic, aData) {
aSubject.QueryInterface(Ci.nsIChannel);
let url = aSubject.URI.QueryInterface(Ci.nsIURL);
if (url.filePath != "/extensions-dummy/metadata")
return;
info(url.query);
let params = parseParams(url.query);
is(params.appOS, Services.appinfo.OS, "OS should be correct");
is(params.appVersion, Services.appinfo.version, "Version should be correct");
ok(params.tMain >= 0, "Should be a sensible tMain");
ok(params.tFirstPaint >= 0, "Should be a sensible tFirstPaint");
ok(params.tSessionRestored >= 0, "Should be a sensible tSessionRestored");
gSeenRequest = true;
}
// Watch HTTP requests
Services.obs.addObserver(observe, "http-on-modify-request", false);
Services.prefs.setCharPref("extensions.getAddons.get.url",
"http://127.0.0.1:8888/extensions-dummy/metadata?appOS=%OS%&appVersion=%VERSION%&tMain=%TIME_MAIN%&tFirstPaint=%TIME_FIRST_PAINT%&tSessionRestored=%TIME_SESSION_RESTORED%");
registerCleanupFunction(function() {
Services.obs.removeObserver(observe, "http-on-modify-request");
Services.prefs.clearUserPref("extensions.getAddons.get.url");
});
AddonRepository.getAddonsByIDs(["test1@tests.mozilla.org"], {
searchFailed: function() {
ok(gSeenRequest, "Should have seen metadata request");
finish();
}
});
}

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

@ -1049,9 +1049,6 @@ Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
// Disable the compatibility updates window by default // Disable the compatibility updates window by default
Services.prefs.setBoolPref("extensions.showMismatchUI", false); Services.prefs.setBoolPref("extensions.showMismatchUI", false);
// By default, don't cache add-ons in AddonRepository.jsm
Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
// Point update checks to the local machine for fast failures // Point update checks to the local machine for fast failures
Services.prefs.setCharPref("extensions.update.url", "http://127.0.0.1/updateURL"); Services.prefs.setCharPref("extensions.update.url", "http://127.0.0.1/updateURL");
Services.prefs.setCharPref("extensions.blocklist.url", "http://127.0.0.1/blocklistURL"); Services.prefs.setCharPref("extensions.blocklist.url", "http://127.0.0.1/blocklistURL");