B2G/gecko/services/aitc/modules/storage.js
/**
   * Process changes so local client is in sync with server.
   *
   * This takes the output from _determineLocalChanges() and applies it.
   *
   * The supplied callback is invoked with no arguments when all operations
   * have completed.
   */
Process changes so local client is in sync with server.
This takes the output from _determineLocalChanges() and applies it.

The supplied callback is invoked with no arguments when all operations
have completed.
Process changes so local client is in sync with server . This takes the output from _determineLocalChanges () and applies it . The supplied callback is invoked with no arguments when all operations have completed .
function _processChanges(changes, cb) {
    if (!changes.deleteIDs.length && !Object.keys(changes.installs).length) {
      this._log.info("No changes to be applied.");
      cb();
      return;
    }
    let installs = [];
    for (let [id, record] in Iterator(changes.installs)) {
      installs.push({id: id, value: record});
    }
    let uninstalls = [];
    for (let id of changes.deleteIDs) {
      this._log.info("Uninstalling app: " + id);
      uninstalls.push({id: id, hidden: true});
    }
     We want to perform all the uninstalls followed by all the installs.
     However, this is somewhat complicated because uninstalls are
     asynchronous and there may not even be any uninstalls. So, we simply
     define a clojure to invoke installation and we call it whenever we're
     ready.
    let doInstalls = function doInstalls() {
      if (!installs.length) {
        if (cb) {
          try {
            cb();
          } catch (ex) {
            this._log.warn("Exception when invoking callback: " +
                           CommonUtils.exceptionStr(ex));
          } finally {
            cb = null;
          }
        }
        return;
      }
      this._applyInstalls(installs, cb);
       Prevent double invoke, just in case.
      installs = [];
      cb       = null;
    }.bind(this);
    if (uninstalls.length) {
      DOMApplicationRegistry.updateApps(uninstalls, function onComplete() {
        doInstalls();
        return;
      });
    } else {
      doInstalls();
    }
  }
function _processChanges ( changes , cb ) { if ( ! changes . deleteIDs . length && ! Object . keys ( changes . installs ) . length ) { this . _log . info ( "No changes to be applied." ) ; cb ( ) ; return ; } let installs = [ ] ; for ( let [ id , record ] in Iterator ( changes . installs ) ) { installs . push ( { id : id , value : record } ) ; } let uninstalls = [ ] ; for ( let id of changes . deleteIDs ) { this . _log . info ( "Uninstalling app: " + id ) ; uninstalls . push ( { id : id , hidden : true } ) ; } let doInstalls = function doInstalls ( ) { if ( ! installs . length ) { if ( cb ) { try { cb ( ) ; } catch ( ex ) { this . _log . warn ( "Exception when invoking callback: " + CommonUtils . exceptionStr ( ex ) ) ; } finally { cb = null ; } } return ; } this . _applyInstalls ( installs , cb ) ; installs = [ ] ; cb = null ; } . bind ( this ) ; if ( uninstalls . length ) { DOMApplicationRegistry . updateApps ( uninstalls , function onComplete ( ) { doInstalls ( ) ; return ; } ) ; } else { doInstalls ( ) ; } }
Process changes so local client is in sync with server.
Process changes so local client is in sync with server .
// First, we assemble all the changes in the right format. // Now we need to perform actions. // // We want to perform all the uninstalls followed by all the installs. // However, this is somewhat complicated because uninstalls are // asynchronous and there may not even be any uninstalls. So, we simply // define a clojure to invoke installation and we call it whenever we're // ready. // Prevent double invoke, just in case.