Bug 1053745 - Add GMP plugin data to FHR. r=gfritzsche, a=lmandel
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 05 Sep 2014 11:17:00 -0400
changeset 216702 02474d192901
parent 216701 18ba9aece9bd
child 216703 46abad0899f9
push id3883
push userryanvm@gmail.com
push date2014-09-11 20:34 +0000
treeherdermozilla-beta@d4082d3a082c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, lmandel
bugs1053745
milestone33.0
Bug 1053745 - Add GMP plugin data to FHR. r=gfritzsche, a=lmandel
services/healthreport/providers.jsm
services/healthreport/tests/xpcshell/test_provider_addons.js
toolkit/mozapps/extensions/internal/OpenH264Provider.jsm
--- a/services/healthreport/providers.jsm
+++ b/services/healthreport/providers.jsm
@@ -753,16 +753,46 @@ ActivePluginsMeasurement.prototype = Obj
 
     // Exceptions are caught in the caller.
     let result = JSON.parse(data.get("plugins")[1]);
     result._v = this.version;
     return result;
   },
 });
 
+function ActiveGMPluginsMeasurement() {
+  Metrics.Measurement.call(this);
+
+  this._serializers = {};
+  this._serializers[this.SERIALIZE_JSON] = {
+    singular: this._serializeJSONSingular.bind(this),
+  };
+}
+
+ActiveGMPluginsMeasurement.prototype = Object.freeze({
+  __proto__: Metrics.Measurement.prototype,
+
+  name: "gm-plugins",
+  version: 1,
+
+  fields: {
+    "gm-plugins": LAST_TEXT_FIELD,
+  },
+
+  _serializeJSONSingular: function (data) {
+    if (!data.has("gm-plugins")) {
+      this._log.warn("Don't have GM plugins info. Weird.");
+      return null;
+    }
+
+    let result = JSON.parse(data.get("gm-plugins")[1]);
+    result._v = this.version;
+    return result;
+  },
+});
 
 function AddonCountsMeasurement() {
   Metrics.Measurement.call(this);
 }
 
 AddonCountsMeasurement.prototype = Object.freeze({
   __proto__: Metrics.Measurement.prototype,
 
@@ -829,16 +859,17 @@ AddonsProvider.prototype = Object.freeze
     "service",
   ],
 
   name: "org.mozilla.addons",
 
   measurementTypes: [
     ActiveAddonsMeasurement,
     ActivePluginsMeasurement,
+    ActiveGMPluginsMeasurement,
     AddonCountsMeasurement1,
     AddonCountsMeasurement,
   ],
 
   postInit: function () {
     let listener = {};
 
     for (let method of this.ADDON_LISTENER_CALLBACKS) {
@@ -864,30 +895,33 @@ AddonsProvider.prototype = Object.freeze
 
   _collectAndStoreAddons: function () {
     let deferred = Promise.defer();
 
     AddonManager.getAllAddons(function onAllAddons(addons) {
       let data;
       let addonsField;
       let pluginsField;
+      let gmPluginsField;
       try {
         data = this._createDataStructure(addons);
         addonsField = JSON.stringify(data.addons);
         pluginsField = JSON.stringify(data.plugins);
+        gmPluginsField = JSON.stringify(data.gmPlugins);
       } catch (ex) {
         this._log.warn("Exception when populating add-ons data structure: " +
                        CommonUtils.exceptionStr(ex));
         deferred.reject(ex);
         return;
       }
 
       let now = new Date();
       let addons = this.getMeasurement("addons", 2);
       let plugins = this.getMeasurement("plugins", 1);
+      let gmPlugins = this.getMeasurement("gm-plugins", 1);
       let counts = this.getMeasurement(AddonCountsMeasurement.prototype.name,
                                        AddonCountsMeasurement.prototype.version);
 
       this.enqueueStorageOperation(function storageAddons() {
         for (let type in data.counts) {
           try {
             counts.fieldID(type);
           } catch (ex) {
@@ -896,17 +930,25 @@ AddonsProvider.prototype = Object.freeze
           }
 
           counts.setDailyLastNumeric(type, data.counts[type], now);
         }
 
         return addons.setLastText("addons", addonsField).then(
           function onSuccess() {
             return plugins.setLastText("plugins", pluginsField).then(
-              function onSuccess() { deferred.resolve(); },
+              function onSuccess() {
+                return gmPlugins.setLastText("gm-plugins", gmPluginsField).then(
+                  function onSuccess() {
+                    deferred.resolve();
+                  },
+                  function onError(error) {
+                    deferred.reject(error);
+                  });
+              },
               function onError(error) { deferred.reject(error); }
             );
           },
           function onError(error) { deferred.reject(error); }
         );
       }.bind(this));
     }.bind(this));
 
@@ -933,25 +975,34 @@ AddonsProvider.prototype = Object.freeze
     "disabled",
     "clicktoplay",
   ],
 
   _createDataStructure: function (addons) {
     let data = {
       addons: {},
       plugins: {},
+      gmPlugins: {},
       counts: {}
     };
 
     for (let addon of addons) {
       let type = addon.type;
 
       // We count plugins separately below.
-      if (addon.type == "plugin")
+      if (addon.type == "plugin") {
+        if (addon.gmPlugin) {
+          data.gmPlugins[addon.id] = {
+            version: addon.version,
+            userDisabled: addon.userDisabled,
+            applyBackgroundUpdates: addon.applyBackgroundUpdates,
+          };
+        }
         continue;
+      }
 
       data.counts[type] = (data.counts[type] || 0) + 1;
 
       if (this.FULL_DETAIL_TYPES.indexOf(addon.type) == -1) {
         continue;
       }
 
       let obj = {};
--- a/services/healthreport/tests/xpcshell/test_provider_addons.js
+++ b/services/healthreport/tests/xpcshell/test_provider_addons.js
@@ -111,16 +111,31 @@ add_task(function test_collect() {
       type: "service",
       scope: 1,
       foreignInstall: false,
       hasBinaryComponents: false,
       installDate: now,
       updateDate: now,
       description: "addon3 description"
     },
+    {
+      // Should be excluded from the report completely
+      id: "pluginfake",
+      type: "plugin",
+      userDisabled: false,
+      appDisabled: false,
+    },
+    {
+      // Should be in gm-plugins
+      id: "gmp-testgmp",
+      type: "plugin",
+      userDisabled: false,
+      version: "7.2",
+      gmPlugin: true,
+    },
   ];
 
   monkeypatchAddons(provider, testAddons);
 
   let testPlugins = {
     "Test Plug-in":
     {
       "version": "1.0.0.0",
@@ -181,16 +196,18 @@ add_task(function test_collect() {
   let json = data.singular.get("addons")[1];
   let value = JSON.parse(json);
   do_check_eq(typeof(value), "object");
   do_check_eq(Object.keys(value).length, 2);
   do_check_true("addon0" in value);
   do_check_true(!("addon1" in value));
   do_check_true(!("addon2" in value));
   do_check_true("addon3" in value);
+  do_check_true(!("pluginfake" in value));
+  do_check_true(!("gmp-testgmp" in value));
 
   let serializer = addons.serializer(addons.SERIALIZE_JSON);
   let serialized = serializer.singular(data.singular);
   do_check_eq(typeof(serialized), "object");
   do_check_eq(Object.keys(serialized).length, 3); // Our entries, plus _v.
   do_check_true("addon0" in serialized);
   do_check_true("addon3" in serialized);
   do_check_eq(serialized._v, 2);
@@ -232,16 +249,40 @@ add_task(function test_collect() {
   serialized = serializer.singular(data.singular);
   do_check_eq(typeof(serialized), "object");
   do_check_eq(Object.keys(serialized).length, pluginTags.length+1); // Our entries, plus _v.
   for (let name in testPlugins) {
     do_check_true(testPlugins[name].id in serialized);
   }
   do_check_eq(serialized._v, 1);
 
+  // Test GMP plugins measurement.
+
+  let gmPlugins = provider.getMeasurement("gm-plugins", 1);
+  data = yield gmPlugins.getValues();
+
+  do_check_eq(data.days.size, 0);
+  do_check_eq(data.singular.size, 1);
+  do_check_true(data.singular.has("gm-plugins"));
+
+  json = data.singular.get("gm-plugins")[1];
+  value = JSON.parse(json);
+  do_print("value: " + json);
+  do_check_eq(typeof(value), "object");
+  do_check_eq(Object.keys(value).length, 1);
+
+  do_check_eq(value["gmp-testgmp"].version, "7.2");
+  do_check_eq(value["gmp-testgmp"].userDisabled, false);
+
+  serializer = gmPlugins.serializer(plugins.SERIALIZE_JSON);
+  serialized = serializer.singular(data.singular);
+  do_check_eq(typeof(serialized), "object");
+  do_check_eq(serialized["gmp-testgmp"].version, "7.2");
+  do_check_eq(serialized._v, 1);
+
   // Test counts measurement.
 
   let counts = provider.getMeasurement("counts", 2);
   data = yield counts.getValues();
   do_check_eq(data.days.size, 1);
   do_check_eq(data.singular.size, 0);
   do_check_true(data.days.hasDay(now));
 
--- a/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm
+++ b/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm
@@ -82,16 +82,17 @@ let OpenH264Wrapper = {
 
   _log: null,
 
   optionsType: AddonManager.OPTIONS_TYPE_INLINE,
   optionsURL: OPENH264_OPTIONS_URL,
 
   get id() { return OPENH264_PLUGIN_ID; },
   get type() { return "plugin"; },
+  get isGMPlugin() { return true; },
   get name() { return pluginsBundle.GetStringFromName("openH264_name"); },
   get creator() { return null; },
   get homepageURL() { return OPENH264_HOMEPAGE_URL; },
 
   get description() { return pluginsBundle.GetStringFromName("openH264_description"); },
 
   get version() { return prefs.get(OPENH264_PREF_VERSION, ""); },