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

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

Issue 10545181: Optimizes loading initial printer on non-chromeos platforms. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add bug reference to TODOs. Created 8 years, 6 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
diff --git a/chrome/browser/resources/print_preview/data/destination_store.js b/chrome/browser/resources/print_preview/data/destination_store.js
index 17d6d7e8df25d67f8d1126322128c1e2cfaef7f3..94dab6eb186322618bd4d6761ea03b152a93efec 100644
--- a/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chrome/browser/resources/print_preview/data/destination_store.js
@@ -184,6 +184,17 @@ cr.define('print_preview', function() {
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);
+ }
}
}
},
@@ -392,25 +403,34 @@ cr.define('print_preview', function() {
/**
* Called when the native layer retrieves the capabilities for the selected
- * local destination.
+ * local destination. Updates the destination with new capabilities if the
+ * destination already exists, otherwise it creates a new destination and
+ * then updates its capabilities.
* @param {cr.Event} event Contains the capabilities of the local print
* destination.
* @private
*/
onLocalDestinationCapabilitiesSet_: function(event) {
- // TODO(rltoscano): There may be a race condition here. This method is
- // assumed to return capabilities for the currently selected printer. But
- // between the time the local printer was selected and the capabilities
- // were retrieved, the selected printer can change. One way to address
- // this is to include the destination ID in the event.settingsInfo
- // parameter.
- if (this.selectedDestination_ && this.selectedDestination_.isLocal) {
- var capabilities = print_preview.LocalCapabilitiesParser.parse(
+ var destinationId = event.settingsInfo['printerId'];
+ var destination = this.destinationMap_[destinationId];
+ var capabilities = print_preview.LocalCapabilitiesParser.parse(
event.settingsInfo);
- this.selectedDestination_.capabilities = capabilities;
- cr.dispatchSimpleEvent(
- this,
- DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
+ if (destination) {
+ destination.capabilities = capabilities;
+ if (this.selectedDestination_ &&
+ this.selectedDestination_.id == destinationId) {
+ cr.dispatchSimpleEvent(this,
+ DestinationStore.EventType.
+ SELECTED_DESTINATION_CAPABILITIES_READY);
+ }
+ } else {
+ // TODO(rltoscano): This makes the assumption that the "deviceName" is
+ // the same as "printerName". We should include the "printerName" in the
+ // response. See http://crbug.com/132831.
+ destination = print_preview.LocalDestinationParser.parse(
+ {deviceName: destinationId, printerName: destinationId});
+ destination.capabilities = capabilities;
+ this.insertDestination(destination);
}
},

Powered by Google App Engine
This is Rietveld 408576698