Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: chrome/browser/resources/print_preview/data/destination_store.js

Issue 10870114: Merge 153263 - Fixes cloud-printer being treated as local-printer problem. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1229/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/data/destination_store.js
===================================================================
--- chrome/browser/resources/print_preview/data/destination_store.js (revision 153561)
+++ chrome/browser/resources/print_preview/data/destination_store.js (working copy)
@@ -31,7 +31,7 @@
this.destinations_ = [];
/**
- * Cache used for constant lookup of printers.
+ * Cache used for constant lookup of destinations.
* @type {object.<string, !print_preview.Destination>}
* @private
*/
@@ -54,6 +54,13 @@
this.initialDestinationId_ = null;
/**
+ * Whether the initial destination is a local one or not.
+ * @type {boolean}
+ * @private
+ */
+ this.isInitialDestinationLocal_ = true;
+
+ /**
* Whether the destination store will auto select the destination that
* matches the initial destination.
* @type {boolean}
@@ -169,12 +176,16 @@
* match this ID, that destination will be automatically selected. This
* occurs only once for every time this setter is called or if the store is
* cleared.
- * @param {?string} ID of the destination that should be selected
- * automatically when added to the store or {@code null} if the first
- * destination that is inserted should be selected.
+ * @param {?string} initialDestinationId ID of the destination that should
+ * be selected automatically when added to the store or {@code null} if
+ * the first destination that is inserted should be selected.
+ * @param {boolean} isLocalDestination Whether the initial destination is
+ * local.
*/
- setInitialDestinationId: function(initialDestinationId) {
+ setInitialDestinationId: function(
+ initialDestinationId, isLocalDestination) {
this.initialDestinationId_ = initialDestinationId;
+ this.isInitialDestinationLocal_ = isLocalDestination;
this.isInAutoSelectMode_ = true;
if (this.initialDestinationId_ == null) {
assert(this.destinations_.length > 0,
@@ -184,17 +195,9 @@
var candidate = this.destinationMap_[this.initialDestinationId_];
if (candidate != null) {
this.selectDestination(candidate);
- } else {
- // Try and fetch the destination
- // TODO(rltoscano): Since we don't know if the initialDestinationId is
- // a local printer or a cloud printer, we are going to assume based on
- // platform. The C++ layer should be modified to return more
- // information about the initially selected printer so this assumption
- // does not have to be made. See http://crbug.com/132831.
- if (!cr.isChromeOS) {
- this.nativeLayer_.startGetLocalDestinationCapabilities(
- initialDestinationId);
- }
+ } else if (!cr.isChromeOS && isLocalDestination) {
+ this.nativeLayer_.startGetLocalDestinationCapabilities(
+ initialDestinationId);
}
}
},
@@ -214,6 +217,14 @@
this.cloudPrintInterface_,
cloudprint.CloudPrintInterface.EventType.PRINTER_DONE,
this.onCloudPrintPrinterDone_.bind(this));
+ this.tracker_.add(
+ this.cloudPrintInterface_,
+ cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED,
+ this.onPrinterFailed_.bind(this));
+ // Fetch initial destination if its a cloud destination.
+ if (this.isInAutoSelectMode_ && !this.isInitialDestinationLocal_) {
+ this.cloudPrintInterface_.printer(this.initialDestinationId_);
+ }
},
/** @param {!print_preview.Destination} Destination to select. */
@@ -378,6 +389,10 @@
this.onLocalDestinationCapabilitiesSet_.bind(this));
this.tracker_.add(
this.nativeLayer_,
+ print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL,
+ this.onGetCapabilitiesFail_.bind(this));
+ this.tracker_.add(
+ this.nativeLayer_,
print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD,
this.onDestinationsReload_.bind(this));
},
@@ -444,11 +459,30 @@
},
/**
- * Called when the /search call completes. Adds the fetched printers to the
- * destination store.
- * @param {cr.Event} event Contains the fetched printers.
+ * Called when a request to get a local destination's print capabilities
+ * fails. If the destination is the initial destination, auto-select another
+ * destination instead.
+ * @param {cr.Event} event Contains the destination ID that failed.
* @private
*/
+ onGetCapabilitiesFail_: function(event) {
+ console.error('Failed to get print capabilities for printer ' +
+ event.destinationId);
+ if (this.isInAutoSelectMode_ &&
+ this.initialDestinationId_ == event.destinationId) {
+ assert(this.destinations_.length > 0,
+ 'No destinations were loaded when failed to get initial ' +
+ 'destination');
+ this.selectDestination(this.destinations_[0]);
+ }
+ },
+
+ /**
+ * Called when the /search call completes. Adds the fetched destinations to
+ * the destination store.
+ * @param {cr.Event} event Contains the fetched destinations.
+ * @private
+ */
onCloudPrintSearchDone_: function(event) {
this.insertDestinations(event.printers);
},
@@ -492,6 +526,26 @@
assert(this.destinations_.length > 0,
'No destinations were loaded before auto-select timeout expired');
this.selectDestination(this.destinations_[0]);
+ },
+
+ /**
+ * Called when the Google Cloud Print interface fails to lookup a
+ * destination. Selects another destination if the failed destination was
+ * the initial destination.
+ * @param {object} event Contains the ID of the destination that was failed
+ * to be looked up.
+ * @private
+ */
+ onPrinterFailed_: function(event) {
+ if (event.errorCode == '111' &&
+ this.isInAutoSelectMode_ &&
+ this.initialDestinationId_ == event.destinationId) {
+ console.error('Could not find initial printer: ' + event.destinationId);
+ assert(this.destinations_.length > 0,
+ 'No destinations were loaded when failed to get initial ' +
+ 'destination');
+ this.selectDestination(this.destinations_[0]);
+ }
}
};

Powered by Google App Engine
This is Rietveld 408576698