Bug 623950: Send startup time measurements along with the metadata requests. r=Unfocused, a=sdwilsh
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 20 Jan 2011 13:45:10 -0800
changeset 61080 4f296157ad3eca6a6662ead36fa7659de76373bb
parent 61079 4d89f48b2abdd9b001728b05f257a5972918da80
child 61081 40b7e12784d5ba27151b6b2f4ca72b79d55b50f2
push idunknown
push userunknown
push dateunknown
reviewersUnfocused, sdwilsh
bugs623950
milestone2.0b10pre
Bug 623950: Send startup time measurements along with the metadata requests. r=Unfocused, a=sdwilsh
browser/app/profile/firefox.js
toolkit/mozapps/extensions/AddonRepository.jsm
toolkit/mozapps/extensions/test/browser/Makefile.in
toolkit/mozapps/extensions/test/browser/browser_bug623950.js
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -54,17 +54,17 @@ pref("browser.chromeURL","chrome://brows
 pref("browser.hiddenWindowChromeURL", "chrome://browser/content/hiddenWindow.xul");
 
 // Enables some extra Extension System Logging (can reduce performance)
 pref("extensions.logging.enabled", false);
 
 // Preferences for AMO integration
 pref("extensions.getAddons.cache.enabled", true);
 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.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%");
 
 // Blocklist preferences
 pref("extensions.blocklist.enabled", true);
 pref("extensions.blocklist.interval", 86400);
 // Controls what level the blocklist switches from warning about items to forcibly
--- a/toolkit/mozapps/extensions/AddonRepository.jsm
+++ b/toolkit/mozapps/extensions/AddonRepository.jsm
@@ -696,21 +696,38 @@ var AddonRepository = {
    * passed to the given callback.
    *
    * @param  aIDs
    *         The array of ids to search for
    * @param  aCallback
    *         The callback to pass results to
    */
   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 url = this._formatURLPref(PREF_GETADDONS_BYIDS, {
+
+    let params = {
       API_VERSION : API_VERSION,
       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;
     function handleResults(aElements, aTotalResults) {
       // Don't use this._parseAddons() so that, for example,
       // incompatible add-ons are not filtered out
       let results = [];
       for (let i = 0; i < aElements.length && results.length < self._maxResults; i++) {
         let result = self._parseAddon(aElements[i]);
@@ -1119,16 +1136,18 @@ var AddonRepository = {
       aCallback.searchFailed();
       return;
     }
 
     this._searching = true;
     this._callback = aCallback;
     this._maxResults = aMaxResults;
 
+    LOG("Requesting " + aURI);
+
     this._request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
                     createInstance(Ci.nsIXMLHttpRequest);
     this._request.open("GET", aURI, true);
     this._request.overrideMimeType("text/xml");
 
     let self = this;
     this._request.onerror = function(aEvent) { self._reportFailure(); };
     this._request.onload = function(aEvent) {
--- a/toolkit/mozapps/extensions/test/browser/Makefile.in
+++ b/toolkit/mozapps/extensions/test/browser/Makefile.in
@@ -82,16 +82,17 @@ include $(DEPTH)/config/autoconf.mk
   browser_updateid.js \
   browser_purchase.js \
   $(NULL)
 
 _TEST_FILES = \
   head.js \
   browser_bug557956.js \
   browser_bug616841.js \
+  browser_bug623950.js \
   browser_updatessl.js \
   browser_installssl.js \
   $(NULL)
 
 _TEST_RESOURCES = \
   addon_prefs.xul \
   browser_bug557956.rdf \
   browser_bug557956_8_2.xpi \
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug623950.js
@@ -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();
+    }
+  });
+}
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -1044,19 +1044,16 @@ Services.prefs.setBoolPref("extensions.l
 Services.prefs.setIntPref("extensions.enabledScopes", AddonManager.SCOPE_PROFILE);
 
 // By default, don't cache add-ons in AddonRepository.jsm
 Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false);
 
 // Disable the compatibility updates window by default
 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
 Services.prefs.setCharPref("extensions.update.url", "http://127.0.0.1/updateURL");
 Services.prefs.setCharPref("extensions.blocklist.url", "http://127.0.0.1/blocklistURL");
 
 // By default ignore bundled add-ons
 Services.prefs.setBoolPref("extensions.installDistroAddons", false);
 
 // Register a temporary directory for the tests.