Bug 645860 - "Studies should have a way to write metadata" [r=mark.finkle]
authorJono X <jdicarlo@mozilla.com>
Mon, 11 Apr 2011 16:16:00 -0400
changeset 67884 64b8491e8833c4aa0b48069124745790cff4d09a
parent 67883 62c358785d4c9ec9542bc181ed9c1e1da72a5515
child 67885 09fd357938210f4d6b416698d714d9a574106757
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmark
bugs645860
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 645860 - "Studies should have a way to write metadata" [r=mark.finkle]
browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js
--- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js
+++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js
@@ -547,16 +547,31 @@ TestPilotExperiment.prototype = {
 
   onExitPrivateBrowsing: function TestPilotExperiment_onExitPrivate() {
     this._logger.trace("Task is exiting private browsing.");
     if (this.experimentIsRunning()) {
       this._handlers.onExitPrivateBrowsing();
     }
   },
 
+  getStudyMetadata: function TestPilotExperiment_getStudyMetadata() {
+    try {
+      if (this._handlers.getStudyMetadata) {
+        let metadata = this._handlers.getStudyMetadata();
+        if (metadata.length) {
+          // getStudyMetadata must return an array, otherwise it is invalid.
+          return metadata;
+        }
+      }
+    } catch(e) {
+      this._logger.warn("Error in getStudyMetadata: " + e);
+    }
+    return null;
+  },
+
   _reschedule: function TestPilotExperiment_reschedule() {
     // Schedule next run of test:
     // add recurrence interval to start date and store!
     let ms = this._recurrenceInterval * (24 * 60 * 60 * 1000);
     // recurrenceInterval is in days, convert to milliseconds:
     this._startDate += ms;
     this._endDate += ms;
     let prefName = START_DATE_PREF_PREFIX + this._id;
@@ -748,16 +763,25 @@ TestPilotExperiment.prototype = {
 
   _prependMetadataToJSON: function TestPilotExperiment__prependToJson(callback) {
     let json = {};
     let self = this;
     MetadataCollector.getMetadata(function(md) {
       json.metadata = md;
       json.metadata.task_guid = self.getGuid(self._id);
       json.metadata.event_headers = self._dataStore.getPropertyNames();
+      let moreMd = self.getStudyMetadata();
+      if (moreMd) {
+        for (let i = 0; i < moreMd.length; i++) {
+          if (moreMd[i].name && moreMd[i].value) {
+            json.metadata[ moreMd[i].name ] = moreMd[i].value; // TODO sanitize strings?
+            // TODO handle case where name or value are something other than strings?
+          }
+        }
+      }
       self._dataStore.getJSONRows(function(rows) {
                                     json.events = rows;
                                     callback( JSON.stringify(json) );
                                   });
     });
   },
 
   // Note: When we have multiple experiments running, the uploads