* destinations.
* @param {!print_preview.UserInfo} userInfo User information repository.
* @param {!print_preview.AppState} appState Application state.
- * @param {!print_preview.Metrics} metrics Metrics.
* @constructor
* @extends {cr.EventTarget}
*/
- function DestinationStore(nativeLayer, userInfo, appState, metrics) {
+ function DestinationStore(nativeLayer, userInfo, appState) {
cr.EventTarget.call(this);
/**
/**
* Used to track metrics.
- * @type {!print_preview.AppState}
+ * @type {!print_preview.DestinationSearchMetricsContext}
* @private
*/
- this.metrics_ = metrics;
+ this.metrics_ = new print_preview.DestinationSearchMetricsContext();
/**
* Internal backing store for the data store.
this.tracker_ = new EventTracker();
/**
+ * Whether PDF printer is enabled. It's disabled, for example, in App Kiosk
+ * mode.
+ * @type {boolean}
+ * @private
+ */
+ this.pdfPrinterEnabled_ = false;
+
+ /**
* Used to fetch cloud-based print destinations.
* @type {print_preview.CloudPrintInterface}
* @private
return this.selectedDestination_;
},
+ /** @return {boolean} Whether destination selection is pending or not. */
+ get isAutoSelectDestinationInProgress() {
+ return this.selectedDestination_ == null &&
+ this.autoSelectTimeout_ != null;
+ },
+
/**
* @return {boolean} Whether a search for local destinations is in progress.
*/
* destination. If any inserted destinations match this ID, that destination
* will be automatically selected. This method must be called after the
* print_preview.AppState has been initialized.
- * @private
+ * @param {boolean} isInAppKioskMode Whether the print preview is in App
+ * Kiosk mode.
*/
- init: function() {
+ init: function(isInAppKioskMode) {
+ this.pdfPrinterEnabled_ = !isInAppKioskMode;
this.isInAutoSelectMode_ = true;
+ this.createLocalPdfPrintDestination_();
if (!this.appState_.selectedDestinationId ||
!this.appState_.selectedDestinationOrigin) {
- this.onAutoSelectFailed_();
+ this.selectDefaultDestination_();
} else {
var key = this.getDestinationKey_(
this.appState_.selectedDestinationOrigin,
cr.dispatchSimpleEvent(
this,
DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY);
-
} else {
- this.onAutoSelectFailed_();
+ this.selectDefaultDestination_();
}
}
},
/** @param {!print_preview.Destination} Destination to select. */
selectDestination: function(destination) {
this.isInAutoSelectMode_ = false;
- this.cancelAutoSelectTimeout_();
- if (destination == this.selectedDestination_) {
+ // When auto select expires, DESTINATION_SELECT event has to be dispatched
+ // anyway (see isAutoSelectDestinationInProgress() logic).
+ if (this.autoSelectTimeout_) {
+ clearTimeout(this.autoSelectTimeout_);
+ this.autoSelectTimeout_ = null;
+ } else if (destination == this.selectedDestination_) {
return;
}
if (destination == null) {
return otherDestination.cloudID == destination.cloudID &&
otherDestination != destination;
})) {
- if (destination.isPrivet) {
- this.metrics_.incrementDestinationSearchBucket(
- print_preview.Metrics.DestinationSearchBucket.
- PRIVET_DUPLICATE_SELECTED);
- } else {
- this.metrics_.incrementDestinationSearchBucket(
- print_preview.Metrics.DestinationSearchBucket.
- CLOUD_DUPLICATE_SELECTED);
- }
+ this.metrics_.record(destination.isPrivet ?
+ print_preview.Metrics.DestinationSearchBucket.
+ PRIVET_DUPLICATE_SELECTED :
+ print_preview.Metrics.DestinationSearchBucket.
+ CLOUD_DUPLICATE_SELECTED);
}
// Notify about selected destination change.
cr.dispatchSimpleEvent(
* @private
*/
selectDefaultDestination_: function() {
- var destination = this.destinationMap_[this.getDestinationKey_(
+ var saveToPdfKey = this.getDestinationKey_(
print_preview.Destination.Origin.LOCAL,
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
- '')] || null;
- assert(destination != null, 'Save to PDF printer not found');
- this.selectDestination(destination);
+ '');
+ this.selectDestination(
+ this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null);
},
/** Initiates loading of local print destinations. */
* @private
*/
createLocalPdfPrintDestination_: function() {
- return new print_preview.Destination(
- print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
- print_preview.Destination.Type.LOCAL,
- print_preview.Destination.Origin.LOCAL,
- localStrings.getString('printToPDF'),
- false /*isRecent*/,
- print_preview.Destination.ConnectionStatus.ONLINE);
+ // TODO(alekseys): Create PDF printer in the native code and send its
+ // capabilities back with other local printers.
+ if (this.pdfPrinterEnabled_) {
+ this.insertDestination_(new print_preview.Destination(
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
+ print_preview.Destination.Type.LOCAL,
+ print_preview.Destination.Origin.LOCAL,
+ localStrings.getString('printToPDF'),
+ false /*isRecent*/,
+ print_preview.Destination.ConnectionStatus.ONLINE));
+ }
},
/**
this.selectDestination(null);
this.loadedCloudOrigins_ = {};
this.hasLoadedAllLocalDestinations_ = false;
- // TODO(alekseys): Create PDF printer in the native code and send its
- // capabilities back with other local printers.
- this.insertDestination_(this.createLocalPdfPrintDestination_());
- this.resetAutoSelectTimeout_();
- },
-
- /**
- * Resets destination auto selection timeout.
- * @private
- */
- resetAutoSelectTimeout_: function() {
- this.cancelAutoSelectTimeout_();
- this.autoSelectTimeout_ =
- setTimeout(this.onAutoSelectFailed_.bind(this),
- DestinationStore.AUTO_SELECT_TIMEOUT_);
- },
- /**
- * Cancels destination auto selection timeout.
- * @private
- */
- cancelAutoSelectTimeout_: function() {
- if (this.autoSelectTimeout_ != null) {
- clearTimeout(this.autoSelectTimeout_);
- this.autoSelectTimeout_ = null;
- }
+ clearTimeout(this.autoSelectTimeout_);
+ this.autoSelectTimeout_ = setTimeout(
+ this.selectDefaultDestination_.bind(this),
+ DestinationStore.AUTO_SELECT_TIMEOUT_);
},
/**
onDestinationsReload_: function() {
this.reset_();
this.isInAutoSelectMode_ = true;
+ this.createLocalPdfPrintDestination_();
this.startLoadLocalDestinations();
this.startLoadCloudDestinations();
this.startLoadPrivetDestinations();
},
- /**
- * Called when auto-selection fails. Selects the first destination in store.
- * @private
- */
- onAutoSelectFailed_: function() {
- this.cancelAutoSelectTimeout_();
- this.selectDefaultDestination_();
- },
-
// TODO(vitalybuka): Remove three next functions replacing Destination.id
// and Destination.origin by complex ID.
/**