B2G/gaia/apps/email/js/ext/mailapi/worker-bootstrap.js
/**
   * Update an existing mesage header in the database, generating slice
   * notifications and dirtying its containing block to cause eventual database
   * writeback.
   *
   * A message header gets updated ONLY because of a change in its flags.  We
   * don't consider this change large enough to cause us to need to split a
   * block.
   *
   * This function can either be used to replace the header or to look it up
   * and then call a function to manipulate the header.
   */
Update an existing mesage header in the database, generating slice
notifications and dirtying its containing block to cause eventual database
writeback.

A message header gets updated ONLY because of a change in its flags.  We
don't consider this change large enough to cause us to need to split a
block.

This function can either be used to replace the header or to look it up
and then call a function to manipulate the header.
Update an existing mesage header in the database generating slice notifications and dirtying its containing block to cause eventual database writeback . A message header gets updated ONLY because of a change in its flags . We don ' t consider this change large enough to cause us to need to split a block . This function can either be used to replace the header or to look it up and then call a function to manipulate the header .
function ifs_updateMessageHeader(date, id, partOfSync,
                                                        headerOrMutationFunc,
                                                        callback) {
    if (this._pendingLoads.length) {
      this._deferredCalls.push(this.updateMessageHeader.bind(
                                 this, date, id, partOfSync,
                                 headerOrMutationFunc, callback));
      return;
    }
    var infoTuple = this._findRangeObjIndexForDateAndID(
                      this._headerBlockInfos, date, id),
        iInfo = infoTuple[0], info = infoTuple[1], self = this;
    function doUpdateHeader(block) {
      var idx = block.ids.indexOf(id), header;
      if (idx === -1) {
        if (headerOrMutationFunc instanceof Function)
          headerOrMutationFunc(null);
        else
          throw new Error('Failed to find ID ' + id + '!');
      }
      else if (headerOrMutationFunc instanceof Function) {
        if (!headerOrMutationFunc((header = block.headers[idx])))
          header = null;
      }
      else {
        header = block.headers[idx] = headerOrMutationFunc;
      }
      if (header) {
        self._dirty = true;
        self._dirtyHeaderBlocks[info.blockId] = block;
        self._LOG.updateMessageHeader(header.date, header.id, header.srvid);
        if (self._slices.length > (self._curSyncSlice ? 1 : 0)) {
          for (var iSlice = 0; iSlice < self._slices.length; iSlice++) {
            var slice = self._slices[iSlice];
            if (partOfSync && slice === self._curSyncSlice)
              continue;
            if (BEFORE(date, slice.startTS) ||
                STRICTLY_AFTER(date, slice.endTS))
              continue;
            if ((date === slice.startTS &&
                 id < slice.startUID) ||
                (date === slice.endTS &&
                 id > slice.endUID))
              continue;
            slice.onHeaderModified(header);
          }
        }
      }
      if (callback)
        callback();
    }
    if (!info) {
      if (headerOrMutationFunc instanceof Function)
        headerOrMutationFunc(null);
      else
        throw new Error('Failed to find block containing header with date: ' +
                        date + ' id: ' + id);
    }
    else if (!this._headerBlocks.hasOwnProperty(info.blockId))
      this._loadBlock('header', info, doUpdateHeader);
    else
      doUpdateHeader(this._headerBlocks[info.blockId]);
  }
function ifs_updateMessageHeader ( date , id , partOfSync , headerOrMutationFunc , callback ) { if ( this . _pendingLoads . length ) { this . _deferredCalls . push ( this . updateMessageHeader . bind ( this , date , id , partOfSync , headerOrMutationFunc , callback ) ) ; return ; } var infoTuple = this . _findRangeObjIndexForDateAndID ( this . _headerBlockInfos , date , id ) , iInfo = infoTuple [ 0 ] , info = infoTuple [ 1 ] , self = this ; function doUpdateHeader ( block ) { var idx = block . ids . indexOf ( id ) , header ; if ( idx === - 1 ) { if ( headerOrMutationFunc instanceof Function ) headerOrMutationFunc ( null ) ; else throw new Error ( 'Failed to find ID ' + id + '!' ) ; } else if ( headerOrMutationFunc instanceof Function ) { if ( ! headerOrMutationFunc ( ( header = block . headers [ idx ] ) ) ) header = null ; } else { header = block . headers [ idx ] = headerOrMutationFunc ; } if ( header ) { self . _dirty = true ; self . _dirtyHeaderBlocks [ info . blockId ] = block ; self . _LOG . updateMessageHeader ( header . date , header . id , header . srvid ) ; if ( self . _slices . length > ( self . _curSyncSlice ? 1 : 0 ) ) { for ( var iSlice = 0 ; iSlice < self . _slices . length ; iSlice ++ ) { var slice = self . _slices [ iSlice ] ; if ( partOfSync && slice === self . _curSyncSlice ) continue ; if ( BEFORE ( date , slice . startTS ) || STRICTLY_AFTER ( date , slice . endTS ) ) continue ; if ( ( date === slice . startTS && id < slice . startUID ) || ( date === slice . endTS && id > slice . endUID ) ) continue ; slice . onHeaderModified ( header ) ; } } } if ( callback ) callback ( ) ; } if ( ! info ) { if ( headerOrMutationFunc instanceof Function ) headerOrMutationFunc ( null ) ; else throw new Error ( 'Failed to find block containing header with date: ' + date + ' id: ' + id ) ; } else if ( ! this . _headerBlocks . hasOwnProperty ( info . blockId ) ) this . _loadBlock ( 'header' , info , doUpdateHeader ) ; else doUpdateHeader ( this . _headerBlocks [ info . blockId ] ) ; }
Update an existing mesage header in the database, generating slice
 notifications and dirtying its containing block to cause eventual database
 writeback.
Update an existing mesage header in the database generating slice notifications and dirtying its containing block to cause eventual database writeback .
// (While this method can complete synchronously, we want to maintain its // perceived ordering relative to those that cannot be.) // We need to deal with the potential for the block having been discarded // from memory thanks to the potential asynchrony due to pending loads or // on the part of the caller. // Call the mutation func with null to let it know we couldn't find the // header. // If it returns false it means that the header did not change and so // there is no need to mark anything dirty and we can leave without // notifying anyone. // only dirty us and generate notifications if there is a header