B2G/gecko/services/aitc/modules/manager.js
/**
   * Poll the AITC server for any changes and process them. It is safe to call
   * this function multiple times. Last caller wins. The function will
   * grab the current user state from _state and act accordingly.
   *
   * Invalid states will cause this function to throw.
   */
Poll the AITC server for any changes and process them. It is safe to call
this function multiple times. Last caller wins. The function will
grab the current user state from _state and act accordingly.

Invalid states will cause this function to throw.
Poll the AITC server for any changes and process them . It is safe to call this function multiple times . Last caller wins . The function will grab the current user state from _state and act accordingly . Invalid states will cause this function to throw .
function _setPoll() {
    if (this._state == this._ACTIVE && !this._client) {
      throw new Error("_setPoll(ACTIVE) called without client");
    }
    if (this._state != this._ACTIVE && this._state != this._PASSIVE) {
      throw new Error("_state is invalid " + this._state);
    }
    if (!this._client) {
      self._log.warn("_setPoll called but user not logged in, ignoring");
      return;
    }
    if (this._pending.length && !(this._putTimer)) {
      this._processQueue();
      return;
    }
    let getFreq;
    if (this._state == this._ACTIVE) {
      CommonUtils.nextTick(this._checkServer, this);
      getFreq = PREFS.get("manager.getActiveFreq");
    } else {
      getFreq = PREFS.get("manager.getPassiveFreq");
    }
    if (this._getTimer) {
      this._getTimer.cancel();
      this._getTimer = null;
    }
    let self = this;
    this._log.info("Starting GET timer");
    this._getTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
    this._getTimer.initWithCallback({notify: this._checkServer.bind(this)},
                                    getFreq, Ci.nsITimer.TYPE_REPEATING_SLACK);
    this._log.info("GET timer set, next attempt in " + getFreq + "ms");
  }
function _setPoll ( ) { if ( this . _state == this . _ACTIVE && ! this . _client ) { throw new Error ( "_setPoll(ACTIVE) called without client" ) ; } if ( this . _state != this . _ACTIVE && this . _state != this . _PASSIVE ) { throw new Error ( "_state is invalid " + this . _state ) ; } if ( ! this . _client ) { self . _log . warn ( "_setPoll called but user not logged in, ignoring" ) ; return ; } if ( this . _pending . length && ! ( this . _putTimer ) ) { this . _processQueue ( ) ; return ; } let getFreq ; if ( this . _state == this . _ACTIVE ) { CommonUtils . nextTick ( this . _checkServer , this ) ; getFreq = PREFS . get ( "manager.getActiveFreq" ) ; } else { getFreq = PREFS . get ( "manager.getPassiveFreq" ) ; } if ( this . _getTimer ) { this . _getTimer . cancel ( ) ; this . _getTimer = null ; } let self = this ; this . _log . info ( "Starting GET timer" ) ; this . _getTimer = Cc [ "@mozilla.org/timer;1" ] . createInstance ( Ci . nsITimer ) ; this . _getTimer . initWithCallback ( { notify : this . _checkServer . bind ( this ) } , getFreq , Ci . nsITimer . TYPE_REPEATING_SLACK ) ; this . _log . info ( "GET timer set, next attempt in " + getFreq + "ms" ) ; }
Poll the AITC server for any changes and process them.
Poll the AITC server for any changes and process them .
// User is not logged in, we cannot do anything. // Check if there are any PUTs pending first. // There are pending PUTs and no timer, so let's process them. GETs will // resume after the PUTs finish (see processQueue) // Do one GET soon, but only if user is active. // Cancel existing timer, if any. // Start the timer for GETs.