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

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

Issue 2514303002: M56: Fix CrOS reverting to Save as PDF and random PDF preview fail (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/resources/print_preview/data/app_state.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..785ca4c194cecbbc1e659e18394ea004e272b61b 100644
--- a/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chrome/browser/resources/print_preview/data/destination_store.js
@@ -650,6 +650,15 @@ cr.define('print_preview', function() {
},
/**
+ * @return {boolean} Whether the selected destination is valid.
+ */
+ selectedDestinationValid_: function() {
+ return this.appState_.selectedDestination &&
+ this.appState_.selectedDestination.id &&
+ this.appState_.selectedDestination.origin;
+ },
+
+ /*
* Initializes the destination store. Sets the initially selected
* destination. If any inserted destinations match this ID, that destination
* will be automatically selected. This method must be called after the
@@ -669,8 +678,7 @@ cr.define('print_preview', function() {
this.systemDefaultDestinationId_ = systemDefaultDestinationId;
this.createLocalPdfPrintDestination_();
- if (!this.appState_.selectedDestinationId ||
- !this.appState_.selectedDestinationOrigin) {
+ if (!this.selectedDestinationValid_()) {
var destinationMatch = this.convertToDestinationMatch_(
serializedDefaultDestinationSelectionRulesStr);
if (destinationMatch) {
@@ -680,8 +688,7 @@ cr.define('print_preview', function() {
}
if (!this.systemDefaultDestinationId_ &&
- !(this.appState_.selectedDestinationId &&
- this.appState_.selectedDestinationOrigin)) {
+ !this.selectedDestinationValid_()) {
this.selectPdfDestination_();
return;
}
@@ -695,10 +702,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 +721,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 +943,10 @@ cr.define('print_preview', function() {
* @private
*/
convertPreselectedToDestinationMatch_: function() {
- if (this.appState_.selectedDestinationId &&
- this.appState_.selectedDestinationOrigin) {
+ if (this.selectedDestinationValid_()) {
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 +1347,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,
« no previous file with comments | « chrome/browser/resources/print_preview/data/app_state.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698