B2G/gecko/services/aitc/modules/storage.js
/**
   * Determine the set of changes needed to reconcile local with remote data.
   *
   * The return value is a mapping describing the actions that need to be
   * performed. It has the following keys:
   *
   *   deleteIDs
   *     (Array) String app IDs of applications that need to be uninstalled.
   *   installs
   *     (Object) Maps app ID to the remote app record. The app ID may exist
   *       locally. If the app did not exist previously, a new ID will be
   *       generated and used here.
   *
   * @param localApps
   *        (Object) Mapping of App ID to minimal application record (from
   *        DOMApplicationRegistry.getAllWithoutManifests()).
   * @param remoteApps
   *        (Array) Application records from the server.
   */
Determine the set of changes needed to reconcile local with remote data.
The return value is a mapping describing the actions that need to be
performed. It has the following keys.

deleteIDs
(Array) String app IDs of applications that need to be uninstalled.
installs
(Object) Maps app ID to the remote app record. The app ID may exist
locally. If the app did not exist previously, a new ID will be
generated and used here.

@param localApps
(Object) Mapping of App ID to minimal application record (from
DOMApplicationRegistry.getAllWithoutManifests()).
@param remoteApps
(Array) Application records from the server.
Determine the set of changes needed to reconcile local with remote data . The return value is a mapping describing the actions that need to be performed . It has the following keys . deleteIDs ( Array ) String app IDs of applications that need to be uninstalled . installs ( Object ) Maps app ID to the remote app record . The app ID may exist locally . If the app did not exist previously a new ID will be generated and used here . @param localApps ( Object ) Mapping of App ID to minimal application record ( from DOMApplicationRegistry . getAllWithoutManifests () ) . @param remoteApps ( Array ) Application records from the server .
function _determineChanges(localApps, remoteApps) {
    let changes = new Map();
    changes.deleteIDs = [];
    changes.installs  = {};
     Arguably, the correct thing to do is to delete all local apps. The
     server is the authoritative source, after all. But, we play it safe.
    if (!Object.keys(remoteApps).length) {
      this._log.warn("Empty set of remote apps. Not taking any action.");
      return changes;
    }
     This is all to avoid potential duplicates. Once JS Sets are iterable, we
     should switch everything to use them.
    let deletes       = {};
    let remoteOrigins = {};
    let localOrigins = {};
    for (let [id, app] in Iterator(localApps)) {
      localOrigins[app.origin] = id;
    }
    for (let remoteApp of remoteApps) {
      let origin = remoteApp.origin;
      remoteOrigins[origin] = true;
       If the app is hidden on the remote server, that translates to a local
       delete/uninstall, but only if the app is present locally.
      if (remoteApp.hidden) {
        if (origin in localOrigins) {
          deletes[localOrigins[origin]] = true;
        }
        continue;
      }
       If the remote app isn't present locally, we install it under a
       newly-generated ID.
      if (!localApps[origin]) {
        changes.installs[DOMApplicationRegistry.makeAppId()] = remoteApp;
        continue;
      }
       If the remote app is newer, we force a re-install using the existing
       ID.
      if (localApps[origin].installTime < remoteApp.installTime) {
        changes.installs[localApps[origin]] = remoteApp;
        continue;
      }
    }
     If we have local apps not on the server, we need to delete them, as the
     server is authoritative.
    for (let [id, app] in Iterator(localApps)) {
      if (!(app.origin in remoteOrigins)) {
        deletes[id] = true;
      }
    }
    changes.deleteIDs = Object.keys(deletes);
    return changes;
  }
function _determineChanges ( localApps , remoteApps ) { let changes = new Map ( ) ; changes . deleteIDs = [ ] ; changes . installs = { } ; if ( ! Object . keys ( remoteApps ) . length ) { this . _log . warn ( "Empty set of remote apps. Not taking any action." ) ; return changes ; } let deletes = { } ; let remoteOrigins = { } ; let localOrigins = { } ; for ( let [ id , app ] in Iterator ( localApps ) ) { localOrigins [ app . origin ] = id ; } for ( let remoteApp of remoteApps ) { let origin = remoteApp . origin ; remoteOrigins [ origin ] = true ; if ( remoteApp . hidden ) { if ( origin in localOrigins ) { deletes [ localOrigins [ origin ] ] = true ; } continue ; } if ( ! localApps [ origin ] ) { changes . installs [ DOMApplicationRegistry . makeAppId ( ) ] = remoteApp ; continue ; } if ( localApps [ origin ] . installTime < remoteApp . installTime ) { changes . installs [ localApps [ origin ] ] = remoteApp ; continue ; } } for ( let [ id , app ] in Iterator ( localApps ) ) { if ( ! ( app . origin in remoteOrigins ) ) { deletes [ id ] = true ; } } changes . deleteIDs = Object . keys ( deletes ) ; return changes ; }
Determine the set of changes needed to reconcile local with remote data.
Determine the set of changes needed to reconcile local with remote data .
// If there are no remote apps, do nothing. // // Arguably, the correct thing to do is to delete all local apps. The // server is the authoritative source, after all. But, we play it safe. // This is all to avoid potential duplicates. Once JS Sets are iterable, we // should switch everything to use them. // If the app is hidden on the remote server, that translates to a local // delete/uninstall, but only if the app is present locally. // If the remote app isn't present locally, we install it under a // newly-generated ID. // If the remote app is newer, we force a re-install using the existing // ID. // If we have local apps not on the server, we need to delete them, as the // server is authoritative.