init(
        isInAppKioskMode, systemDefaultDestinationId,
        serializedDefaultDestinationSelectionRulesStr, recentDestinations) {
      this.pdfPrinterEnabled_ = !isInAppKioskMode;
      this.systemDefaultDestinationId_ = systemDefaultDestinationId;
      this.createLocalPdfPrintDestination_();

      const isRecentDestinationValid = recentDestinations.length > 0 &&
          this.isDestinationValid(recentDestinations[0]);

      if (!isRecentDestinationValid) {
        const destinationMatch = this.convertToDestinationMatch_(
            serializedDefaultDestinationSelectionRulesStr);
        if (destinationMatch) {
          this.fetchMatchingDestination_(destinationMatch);
          return;
        }
      }

      if (this.systemDefaultDestinationId_.length == 0 &&
          !isRecentDestinationValid) {
        this.selectPdfDestination_();
        return;
      }

      this.recentDestinations_ = recentDestinations;
      let origin = null;
      let id = '';
      let account = '';
      let name = '';
      let capabilities = null;
      let extensionId = '';
      let extensionName = '';
      let foundDestination = false;
      // Run through the destinations forward. As soon as we find a
      // destination, don't select any future destinations, just mark
      // them recent. Otherwise, there is a race condition between selecting
      // destinations/updating the print ticket and this selecting a new
      // destination that causes random print preview errors.
      for (let destination of recentDestinations) {
        origin = destination.origin;
        id = destination.id;
        account = destination.account || '';
        name = destination.displayName || '';
        capabilities = destination.capabilities;
        extensionId = destination.extensionId || '';
        extensionName = destination.extensionName || '';
        const candidate =
            this.destinationMap_[this.getDestinationKey_(origin, id, account)];
        if (candidate != null) {
          candidate.isRecent = true;
          if (!foundDestination && !this.useSystemDefaultAsDefault_)
            this.selectDestination(candidate);
          foundDestination = true;
        } else if (!foundDestination && !this.useSystemDefaultAsDefault_) {
          foundDestination = this.fetchPreselectedDestination_(
              origin, id, account, name, capabilities, extensionId,
              extensionName);
        }
      }

      if (foundDestination && !this.useSystemDefaultAsDefault_)
        return;

      // Try the system default
      id = this.systemDefaultDestinationId_;
      origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
          print_preview.DestinationOrigin.LOCAL :
          this.platformOrigin_;
      account = '';
      const systemDefaultCandidate =
          this.destinationMap_[this.getDestinationKey_(origin, id, account)];
      if (systemDefaultCandidate != null) {
        this.selectDestination(systemDefaultCandidate);
        return;
      }

      if (this.fetchPreselectedDestination_(
              origin, id, account, name, capabilities, extensionId,
              extensionName)) {
        return;
      }

      this.selectPdfDestination_();
    }
/**
     * Initializes the destination store. Sets the initially selected
     * destination. If any inserted destinations match this ID, that destination
     * will be automatically selected.
     * @param {boolean} isInAppKioskMode Whether the print preview is in App
     *     Kiosk mode.
     * @param {string} systemDefaultDestinationId ID of the system default
     *     destination.
     * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
     *     default destination selection rules.
     * @param {!Array<!print_preview.RecentDestination>}
     *     recentDestinations The recent print destinations.
     */
Initializes the destination store. Sets the initially selected
destination. If any inserted destinations match this ID, that destination
will be automatically selected.
@param {boolean} isInAppKioskMode Whether the print preview is in App
Kiosk mode.
@param {string} systemDefaultDestinationId ID of the system default
destination.
@param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
default destination selection rules.
@param {!Array}
recentDestinations The recent print destinations.
Initializes the destination store . Sets the initially selected destination . If any inserted destinations match this ID that destination will be automatically selected . @param { boolean } isInAppKioskMode Whether the print preview is in App Kiosk mode . @param { string } systemDefaultDestinationId ID of the system default destination . @param { ?string } serializedDefaultDestinationSelectionRulesStr Serialized default destination selection rules . @param { !Array } recentDestinations The recent print destinations .
init(
        isInAppKioskMode, systemDefaultDestinationId,
        serializedDefaultDestinationSelectionRulesStr, recentDestinations) {
      this.pdfPrinterEnabled_ = !isInAppKioskMode;
      this.systemDefaultDestinationId_ = systemDefaultDestinationId;
      this.createLocalPdfPrintDestination_();
      const isRecentDestinationValid = recentDestinations.length > 0 &&
          this.isDestinationValid(recentDestinations[0]);
      if (!isRecentDestinationValid) {
        const destinationMatch = this.convertToDestinationMatch_(
            serializedDefaultDestinationSelectionRulesStr);
        if (destinationMatch) {
          this.fetchMatchingDestination_(destinationMatch);
          return;
        }
      }
      if (this.systemDefaultDestinationId_.length == 0 &&
          !isRecentDestinationValid) {
        this.selectPdfDestination_();
        return;
      }
      this.recentDestinations_ = recentDestinations;
      let origin = null;
      let id = '';
      let account = '';
      let name = '';
      let capabilities = null;
      let extensionId = '';
      let extensionName = '';
      let foundDestination = false;
      for (let destination of recentDestinations) {
        origin = destination.origin;
        id = destination.id;
        account = destination.account || '';
        name = destination.displayName || '';
        capabilities = destination.capabilities;
        extensionId = destination.extensionId || '';
        extensionName = destination.extensionName || '';
        const candidate =
            this.destinationMap_[this.getDestinationKey_(origin, id, account)];
        if (candidate != null) {
          candidate.isRecent = true;
          if (!foundDestination && !this.useSystemDefaultAsDefault_)
            this.selectDestination(candidate);
          foundDestination = true;
        } else if (!foundDestination && !this.useSystemDefaultAsDefault_) {
          foundDestination = this.fetchPreselectedDestination_(
              origin, id, account, name, capabilities, extensionId,
              extensionName);
        }
      }
      if (foundDestination && !this.useSystemDefaultAsDefault_)
        return;
      id = this.systemDefaultDestinationId_;
      origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
          print_preview.DestinationOrigin.LOCAL :
          this.platformOrigin_;
      account = '';
      const systemDefaultCandidate =
          this.destinationMap_[this.getDestinationKey_(origin, id, account)];
      if (systemDefaultCandidate != null) {
        this.selectDestination(systemDefaultCandidate);
        return;
      }
      if (this.fetchPreselectedDestination_(
              origin, id, account, name, capabilities, extensionId,
              extensionName)) {
        return;
      }
      this.selectPdfDestination_();
    }
init ( isInAppKioskMode , systemDefaultDestinationId , serializedDefaultDestinationSelectionRulesStr , recentDestinations ) { this . pdfPrinterEnabled_ = ! isInAppKioskMode ; this . systemDefaultDestinationId_ = systemDefaultDestinationId ; this . createLocalPdfPrintDestination_ ( ) ; const isRecentDestinationValid = recentDestinations . length > 0 && this . isDestinationValid ( recentDestinations [ 0 ] ) ; if ( ! isRecentDestinationValid ) { const destinationMatch = this . convertToDestinationMatch_ ( serializedDefaultDestinationSelectionRulesStr ) ; if ( destinationMatch ) { this . fetchMatchingDestination_ ( destinationMatch ) ; return ; } } if ( this . systemDefaultDestinationId_ . length == 0 && ! isRecentDestinationValid ) { this . selectPdfDestination_ ( ) ; return ; } this . recentDestinations_ = recentDestinations ; let origin = null ; let id = '' ; let account = '' ; let name = '' ; let capabilities = null ; let extensionId = '' ; let extensionName = '' ; let foundDestination = false ; for ( let destination of recentDestinations ) { origin = destination . origin ; id = destination . id ; account = destination . account || '' ; name = destination . displayName || '' ; capabilities = destination . capabilities ; extensionId = destination . extensionId || '' ; extensionName = destination . extensionName || '' ; const candidate = this . destinationMap_ [ this . getDestinationKey_ ( origin , id , account ) ] ; if ( candidate != null ) { candidate . isRecent = true ; if ( ! foundDestination && ! this . useSystemDefaultAsDefault_ ) this . selectDestination ( candidate ) ; foundDestination = true ; } else if ( ! foundDestination && ! this . useSystemDefaultAsDefault_ ) { foundDestination = this . fetchPreselectedDestination_ ( origin , id , account , name , capabilities , extensionId , extensionName ) ; } } if ( foundDestination && ! this . useSystemDefaultAsDefault_ ) return ; id = this . systemDefaultDestinationId_ ; origin = id == print_preview . Destination . GooglePromotedId . SAVE_AS_PDF ? print_preview . DestinationOrigin . LOCAL : this . platformOrigin_ ; account = '' ; const systemDefaultCandidate = this . destinationMap_ [ this . getDestinationKey_ ( origin , id , account ) ] ; if ( systemDefaultCandidate != null ) { this . selectDestination ( systemDefaultCandidate ) ; return ; } if ( this . fetchPreselectedDestination_ ( origin , id , account , name , capabilities , extensionId , extensionName ) ) { return ; } this . selectPdfDestination_ ( ) ; }
Initializes the destination store.
Initializes the destination store .
// Run through the destinations forward. As soon as we find a // destination, don't select any future destinations, just mark // them recent. Otherwise, there is a race condition between selecting // destinations/updating the print ticket and this selecting a new // destination that causes random print preview errors. // Try the system default