B2G/gecko/services/sync/modules/policies.js
/**
   * Set a timer for the next sync
   */
Set a timer for the next sync
Set a timer for the next sync
function scheduleNextSync(interval) {
    if (interval == null) {
      interval = this.syncInterval;
    }
    if (Status.backoffInterval && interval < Status.backoffInterval) {
      this._log.trace("Requested interval " + interval +
                      " ms is smaller than the backoff interval. " + 
                      "Using backoff interval " +
                      Status.backoffInterval + " ms instead.");
      interval = Status.backoffInterval;
    }
    if (this.nextSync != 0) {
      let currentInterval = this.nextSync - Date.now();
      this._log.trace("There's already a sync scheduled in " +
                      currentInterval + " ms.");
      if (currentInterval < interval && this.syncTimer) {
        this._log.trace("Ignoring scheduling request for next sync in " +
                        interval + " ms.");
        return;
      }
    }
    if (interval <= 0) {
      this._log.trace("Requested sync should happen right away.");
      this.syncIfMPUnlocked();
      return;
    }
    this._log.debug("Next sync in " + interval + " ms.");
    Utils.namedTimer(this.syncIfMPUnlocked, interval, this, "syncTimer");
    this.nextSync = Date.now() + interval;
  }
function scheduleNextSync ( interval ) { if ( interval == null ) { interval = this . syncInterval ; } if ( Status . backoffInterval && interval < Status . backoffInterval ) { this . _log . trace ( "Requested interval " + interval + " ms is smaller than the backoff interval. " + "Using backoff interval " + Status . backoffInterval + " ms instead." ) ; interval = Status . backoffInterval ; } if ( this . nextSync != 0 ) { let currentInterval = this . nextSync - Date . now ( ) ; this . _log . trace ( "There's already a sync scheduled in " + currentInterval + " ms." ) ; if ( currentInterval < interval && this . syncTimer ) { this . _log . trace ( "Ignoring scheduling request for next sync in " + interval + " ms." ) ; return ; } } if ( interval <= 0 ) { this . _log . trace ( "Requested sync should happen right away." ) ; this . syncIfMPUnlocked ( ) ; return ; } this . _log . debug ( "Next sync in " + interval + " ms." ) ; Utils . namedTimer ( this . syncIfMPUnlocked , interval , this , "syncTimer" ) ; this . nextSync = Date . now ( ) + interval ; }
Set a timer for the next sync
Set a timer for the next sync
// If no interval was specified, use the current sync interval. // Ensure the interval is set to no less than the backoff. // There's already a sync scheduled. Don't reschedule if there's already // a timer scheduled for sooner than requested. // Start the sync right away if we're already late. // Save the next sync time in-case sync is disabled (logout/offline/etc.)