B2G/gecko/services/aitc/modules/manager.js
/**
   * Initial schedule for the manager. It is the responsibility of the
   * caller who created this object to call this function if it wants to
   * do an initial sync (i.e. upload local apps on a device that has never
   * communicated with AITC before).
   *
   * The callback will be invoked with the number of local apps that were
   * queued to be uploaded, or -1 if this client has already synced and a
   * local upload is not required.
   *
   * Try to schedule PUTs but only if we can get a silent assertion, and if
   * the queue in non-empty, or we've never done a GET (first run).
   */
Initial schedule for the manager. It is the responsibility of the
caller who created this object to call this function if it wants to
do an initial sync .

The callback will be invoked with the number of local apps that were
queued to be uploaded, or -1 if this client has already synced and a
local upload is not required.

Try to schedule PUTs but only if we can get a silent assertion, and if
the queue in non-empty, or we've never done a GET (first run).
Initial schedule for the manager . It is the responsibility of the caller who created this object to call this function if it wants to do an initial sync . The callback will be invoked with the number of local apps that were queued to be uploaded or - 1 if this client has already synced and a local upload is not required . Try to schedule PUTs but only if we can get a silent assertion and if the queue in non - empty or we ' ve never done a GET ( first run ) .
function initialSchedule(cb) {
    let self = this;
    function startProcessQueue(num) {
      self._makeClient(function(err, client) {
        if (!err && client) {
          self._client = client;
          self._processQueue();
          return;
        }
      });
      cb(num);
    }
    if (Preferences.get("services.aitc.client.lastModified", "0") != "0") {
      if (this._pending.length) {
        startProcessQueue(-1);
      } else {
        cb(-1);
      }
      return;
    }
    DOMApplicationRegistry.getAllWithoutManifests(function gotAllApps(apps) {
      let done = 0;
      let appids = Object.keys(apps);
      let total = appids.length;
      self._log.info("First run, queuing all local apps: " + total + " found");
      function appQueued(err) {
        if (err) {
          self._log.error("Error queuing app " + apps[appids[done]].origin);
        }
        if (done == total) {
          self._log.info("Finished queuing all initial local apps");
          startProcessQueue(total);
          return;
        }
        let app = apps[appids[done]];
        let obj = {type: "install", app: app, retries: 0, lastTime: 0};
        done += 1;
        self._pending.enqueue(obj, appQueued);
      }
      appQueued();
    });
  }
function initialSchedule ( cb ) { let self = this ; function startProcessQueue ( num ) { self . _makeClient ( function ( err , client ) { if ( ! err && client ) { self . _client = client ; self . _processQueue ( ) ; return ; } } ) ; cb ( num ) ; } if ( Preferences . get ( "services.aitc.client.lastModified" , "0" ) != "0" ) { if ( this . _pending . length ) { startProcessQueue ( - 1 ) ; } else { cb ( - 1 ) ; } return ; } DOMApplicationRegistry . getAllWithoutManifests ( function gotAllApps ( apps ) { let done = 0 ; let appids = Object . keys ( apps ) ; let total = appids . length ; self . _log . info ( "First run, queuing all local apps: " + total + " found" ) ; function appQueued ( err ) { if ( err ) { self . _log . error ( "Error queuing app " + apps [ appids [ done ] ] . origin ) ; } if ( done == total ) { self . _log . info ( "Finished queuing all initial local apps" ) ; startProcessQueue ( total ) ; return ; } let app = apps [ appids [ done ] ] ; let obj = { type : "install" , app : app , retries : 0 , lastTime : 0 } ; done += 1 ; self . _pending . enqueue ( obj , appQueued ) ; } appQueued ( ) ; } ) ; }
Initial schedule for the manager.
Initial schedule for the manager .
// If we've already done a sync with AITC, it means we've already done // an initial upload. Resume processing the queue, if there are items in it.