Chromium Code Reviews| 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 a96778fcea849646b4df90b85660bf85ce4884fd..35705eb3f8bd6bc32c14b746b8e7a4a2b91e72de 100644 |
| --- a/chrome/browser/resources/print_preview/data/destination_store.js |
| +++ b/chrome/browser/resources/print_preview/data/destination_store.js |
| @@ -669,8 +669,9 @@ cr.define('print_preview', function() { |
| this.systemDefaultDestinationId_ = systemDefaultDestinationId; |
| this.createLocalPdfPrintDestination_(); |
| - if (!this.appState_.selectedDestinationId || |
| - !this.appState_.selectedDestinationOrigin) { |
| + if (!this.appState_.selectedDestination || |
| + !this.appState_.selectedDestination.id || |
| + !this.appState_.selectedDestination.origin) { |
| var destinationMatch = this.convertToDestinationMatch_( |
| serializedDefaultDestinationSelectionRulesStr); |
| if (destinationMatch) { |
| @@ -680,8 +681,9 @@ cr.define('print_preview', function() { |
| } |
| if (!this.systemDefaultDestinationId_ && |
| - !(this.appState_.selectedDestinationId && |
| - this.appState_.selectedDestinationOrigin)) { |
| + (!this.appState_.selectedDestination || |
| + !this.appState_.selectedDestination.id || |
| + !this.appState_.selectedDestination.origin)) { |
| this.selectPdfDestination_(); |
| return; |
| } |
| @@ -695,10 +697,12 @@ cr.define('print_preview', function() { |
| var extensionName = ''; |
| var foundDestination = false; |
| if (this.appState_.recentDestinations) { |
| - // Run through the destinations backwards the most recently used is set |
| - // as the initially selected destination. |
| - for (var i = this.appState_.recentDestinations.length - 1; i >= 0; |
| - i--) { |
| + // 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 (var i = 0; i < this.appState_.recentDestinations.length; i++) { |
| origin = this.appState_.recentDestinations[i].origin; |
| id = this.appState_.recentDestinations[i].id; |
| account = this.appState_.recentDestinations[i].account || ''; |
| @@ -712,10 +716,11 @@ cr.define('print_preview', function() { |
| this.destinationMap_[this.getDestinationKey_(origin, |
| id, account)]; |
| if (candidate != null) { |
| - this.selectDestination(candidate); |
| + if (!foundDestination) |
| + this.selectDestination(candidate); |
| candidate.isRecent = true; |
| foundDestination = true; |
| - } else { |
| + } else if (!foundDestination) { |
| foundDestination = this.fetchPreselectedDestination_( |
| origin, |
| id, |
| @@ -933,11 +938,12 @@ cr.define('print_preview', function() { |
| * @private |
| */ |
| convertPreselectedToDestinationMatch_: function() { |
| - if (this.appState_.selectedDestinationId && |
| - this.appState_.selectedDestinationOrigin) { |
| + if (this.appState_.selectedDestination && |
|
dpapad
2016/11/19 01:37:58
Can you package these three checks in a helper and
rbpotter
2016/11/19 02:44:58
Done.
|
| + this.appState_.selectedDestination.id && |
| + this.appState_.selectedDestination.origin) { |
| return this.createExactDestinationMatch_( |
| - this.appState_.selectedDestinationOrigin, |
| - this.appState_.selectedDestinationId); |
| + this.appState_.selectedDestination.origin, |
| + this.appState_.selectedDestination.id); |
| } |
| if (this.systemDefaultDestinationId_) { |
| return this.createExactDestinationMatch_( |
| @@ -1338,8 +1344,9 @@ cr.define('print_preview', function() { |
| this.insertDestination_(destination); |
| } |
| - if (existingDestination == this.selectedDestination_ || |
| - destination == this.selectedDestination_) { |
| + if (this.selectedDestination_ && |
| + (existingDestination == this.selectedDestination_ || |
| + destination == this.selectedDestination_)) { |
| this.appState_.persistSelectedDestination(this.selectedDestination_); |
| cr.dispatchSimpleEvent( |
| this, |