Bug 1107686 - Remove redundant task cache check in DataReportingService. r=gps
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Mon, 08 Dec 2014 12:38:20 +0100
changeset 219071 7365b7551ee32932b7a495e5d7564be67854c1ec
parent 219070 411d617e59a0f598a8246d9e4a82659624a1f642
child 219072 25bf672286235637580671a30a4241110f2070a9
push id27954
push userryanvm@gmail.com
push dateWed, 10 Dec 2014 21:10:24 +0000
treeherdermozilla-central@0cf461e62ce5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1107686
milestone37.0a1
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 1107686 - Remove redundant task cache check in DataReportingService. r=gps
services/datareporting/DataReportingService.js
--- a/services/datareporting/DataReportingService.js
+++ b/services/datareporting/DataReportingService.js
@@ -293,89 +293,88 @@ DataReportingService.prototype = Object.
 
     // Wait for initialization to finish so if a shutdown occurs before init
     // has finished we don't adversely affect app startup on next run.
     this._healthReporter.init().then(function onInit() {
       this._prefs.set("service.firstRun", true);
     }.bind(this));
   },
 
-  _loadClientID: Task.async(function* () {
+  _loadClientID: function () {
     if (this._loadClientIdTask) {
       return this._loadClientIdTask;
     }
 
-    // Previously we had the stable client ID managed in FHR.
-    // As we want to start correlating FHR and telemetry data (and moving towards
-    // unifying the two), we moved the ID management to the datareporting
-    // service. Consequently, we try to import the FHR ID first, so we can keep
-    // using it.
+    this._loadClientIdTask = Task.spawn(function* () {
+      // Previously we had the stable client ID managed in FHR.
+      // As we want to start correlating FHR and telemetry data (and moving towards
+      // unifying the two), we moved the ID management to the datareporting
+      // service. Consequently, we try to import the FHR ID first, so we can keep
+      // using it.
 
-    // Try to load the client id from the DRS state file first.
-    try {
-      let state = yield CommonUtils.readJSON(this._stateFilePath);
-      if (state && 'clientID' in state && typeof(state.clientID) == 'string') {
-        this._clientID = state.clientID;
-        this._loadClientIdTask = null;
-        return this._clientID;
+      // Try to load the client id from the DRS state file first.
+      try {
+        let state = yield CommonUtils.readJSON(this._stateFilePath);
+        if (state && 'clientID' in state && typeof(state.clientID) == 'string') {
+          this._clientID = state.clientID;
+          this._loadClientIdTask = null;
+          return this._clientID;
+        }
+      } catch (e) {
+        // fall through to next option
       }
-    } catch (e) {
-      // fall through to next option
-    }
 
-    // If we dont have DRS state yet, try to import from the FHR state.
-    try {
-      let fhrStatePath = OS.Path.join(OS.Constants.Path.profileDir, "healthreport", "state.json");
-      let state = yield CommonUtils.readJSON(fhrStatePath);
-      if (state && 'clientID' in state && typeof(state.clientID) == 'string') {
-        this._clientID = state.clientID;
-        this._loadClientIdTask = null;
-        this._saveClientID();
-        return this._clientID;
+      // If we dont have DRS state yet, try to import from the FHR state.
+      try {
+        let fhrStatePath = OS.Path.join(OS.Constants.Path.profileDir, "healthreport", "state.json");
+        let state = yield CommonUtils.readJSON(fhrStatePath);
+        if (state && 'clientID' in state && typeof(state.clientID) == 'string') {
+          this._clientID = state.clientID;
+          this._loadClientIdTask = null;
+          this._saveClientID();
+          return this._clientID;
+        }
+      } catch (e) {
+        // fall through to next option
       }
-    } catch (e) {
-      // fall through to next option
-    }
 
-    // We dont have an id from FHR yet, generate a new ID.
-    this._clientID = CommonUtils.generateUUID();
-    this._loadClientIdTask = null;
-    this._saveClientIdTask = this._saveClientID();
+      // We dont have an id from FHR yet, generate a new ID.
+      this._clientID = CommonUtils.generateUUID();
+      this._loadClientIdTask = null;
+      this._saveClientIdTask = this._saveClientID();
 
-    // Wait on persisting the id. Otherwise failure to save the ID would result in
-    // the client creating and subsequently sending multiple IDs to the server.
-    // This would appear as multiple clients submitting similar data, which would
-    // result in orphaning.
-    yield this._saveClientIdTask;
+      // Wait on persisting the id. Otherwise failure to save the ID would result in
+      // the client creating and subsequently sending multiple IDs to the server.
+      // This would appear as multiple clients submitting similar data, which would
+      // result in orphaning.
+      yield this._saveClientIdTask;
 
-    return this._clientID;
-  }),
+      return this._clientID;
+    }.bind(this));
+
+    return this._loadClientIdTask;
+  },
 
   _saveClientID: Task.async(function* () {
     let obj = { clientID: this._clientID };
     yield OS.File.makeDir(this._stateDir);
     yield CommonUtils.writeJSON(obj, this._stateFilePath);
     this._saveClientIdTask = null;
   }),
 
   /**
    * This returns a promise resolving to the the stable client ID we use for
    * data reporting (FHR & Telemetry). Previously exising FHR client IDs are
    * migrated to this.
    *
    * @return Promise<string> The stable client ID.
    */
   getClientID: function() {
-    if (this._loadClientIdTask) {
-      return this._loadClientIdTask;
-    }
-
     if (!this._clientID) {
-      this._loadClientIdTask = this._loadClientID();
-      return this._loadClientIdTask;
+      return this._loadClientID();
     }
 
     return Promise.resolve(this._clientID);
   },
 
   /**
    * Reset the stable client id.
    *