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

Side by Side Diff: chrome/browser/resources/print_preview/data/destination_store.js

Issue 2516523002: Fix CrOS reverting to Save as PDF and random PDF preview fail (Closed)
Patch Set: Fix occasional PDF error problem 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * A data store that stores destinations and dispatches events when the data 9 * A data store that stores destinations and dispatches events when the data
10 * store changes. 10 * store changes.
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 * default destination selection rules. 662 * default destination selection rules.
663 */ 663 */
664 init: function( 664 init: function(
665 isInAppKioskMode, 665 isInAppKioskMode,
666 systemDefaultDestinationId, 666 systemDefaultDestinationId,
667 serializedDefaultDestinationSelectionRulesStr) { 667 serializedDefaultDestinationSelectionRulesStr) {
668 this.pdfPrinterEnabled_ = !isInAppKioskMode; 668 this.pdfPrinterEnabled_ = !isInAppKioskMode;
669 this.systemDefaultDestinationId_ = systemDefaultDestinationId; 669 this.systemDefaultDestinationId_ = systemDefaultDestinationId;
670 this.createLocalPdfPrintDestination_(); 670 this.createLocalPdfPrintDestination_();
671 671
672 if (!this.appState_.selectedDestinationId || 672 if (!this.appState_.selectedDestination ||
673 !this.appState_.selectedDestinationOrigin) { 673 !this.appState_.selectedDestination.id ||
674 !this.appState_.selectedDestination.origin) {
674 var destinationMatch = this.convertToDestinationMatch_( 675 var destinationMatch = this.convertToDestinationMatch_(
675 serializedDefaultDestinationSelectionRulesStr); 676 serializedDefaultDestinationSelectionRulesStr);
676 if (destinationMatch) { 677 if (destinationMatch) {
677 this.fetchMatchingDestination_(destinationMatch); 678 this.fetchMatchingDestination_(destinationMatch);
678 return; 679 return;
679 } 680 }
680 } 681 }
681 682
682 if (!this.systemDefaultDestinationId_ && 683 if (!this.systemDefaultDestinationId_ &&
683 !(this.appState_.selectedDestinationId && 684 (!this.appState_.selectedDestination ||
684 this.appState_.selectedDestinationOrigin)) { 685 !this.appState_.selectedDestination.id ||
686 !this.appState_.selectedDestination.origin)) {
685 this.selectPdfDestination_(); 687 this.selectPdfDestination_();
686 return; 688 return;
687 } 689 }
688 690
689 var origin = print_preview.Destination.Origin.LOCAL; 691 var origin = print_preview.Destination.Origin.LOCAL;
690 var id = this.systemDefaultDestinationId_; 692 var id = this.systemDefaultDestinationId_;
691 var account = ''; 693 var account = '';
692 var name = ''; 694 var name = '';
693 var capabilities = null; 695 var capabilities = null;
694 var extensionId = ''; 696 var extensionId = '';
695 var extensionName = ''; 697 var extensionName = '';
696 var foundDestination = false; 698 var foundDestination = false;
697 if (this.appState_.recentDestinations) { 699 if (this.appState_.recentDestinations) {
698 // Run through the destinations backwards the most recently used is set 700 // Run through the destinations forward. As soon as we find a
699 // as the initially selected destination. 701 // destination, don't select any future destinations, just mark
700 for (var i = this.appState_.recentDestinations.length - 1; i >= 0; 702 // them recent. Otherwise, there is a race condition between selecting
701 i--) { 703 // destinations/updating the print ticket and this selecting a new
704 // destination that causes random print preview errors.
705 for (var i = 0; i < this.appState_.recentDestinations.length; i++) {
702 origin = this.appState_.recentDestinations[i].origin; 706 origin = this.appState_.recentDestinations[i].origin;
703 id = this.appState_.recentDestinations[i].id; 707 id = this.appState_.recentDestinations[i].id;
704 account = this.appState_.recentDestinations[i].account || ''; 708 account = this.appState_.recentDestinations[i].account || '';
705 name = this.appState_.recentDestinations[i].name || ''; 709 name = this.appState_.recentDestinations[i].name || '';
706 capabilities = this.appState_.recentDestinations[i].capabilities; 710 capabilities = this.appState_.recentDestinations[i].capabilities;
707 extensionId = this.appState_.recentDestinations[i].extensionId || 711 extensionId = this.appState_.recentDestinations[i].extensionId ||
708 ''; 712 '';
709 extensionName = 713 extensionName =
710 this.appState_.recentDestinations[i].extensionName || ''; 714 this.appState_.recentDestinations[i].extensionName || '';
711 var candidate = 715 var candidate =
712 this.destinationMap_[this.getDestinationKey_(origin, 716 this.destinationMap_[this.getDestinationKey_(origin,
713 id, account)]; 717 id, account)];
714 if (candidate != null) { 718 if (candidate != null) {
715 this.selectDestination(candidate); 719 if (!foundDestination)
720 this.selectDestination(candidate);
716 candidate.isRecent = true; 721 candidate.isRecent = true;
717 foundDestination = true; 722 foundDestination = true;
718 } else { 723 } else if (!foundDestination) {
719 foundDestination = this.fetchPreselectedDestination_( 724 foundDestination = this.fetchPreselectedDestination_(
720 origin, 725 origin,
721 id, 726 id,
722 account, 727 account,
723 name, 728 name,
724 capabilities, 729 capabilities,
725 extensionId, 730 extensionId,
726 extensionName); 731 extensionName);
727 } 732 }
728 } 733 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 displayNameRegExp, 931 displayNameRegExp,
927 true /*skipVirtualDestinations*/); 932 true /*skipVirtualDestinations*/);
928 }, 933 },
929 934
930 /** 935 /**
931 * @return {print_preview.DestinationMatch} Creates rules matching 936 * @return {print_preview.DestinationMatch} Creates rules matching
932 * previously selected destination. 937 * previously selected destination.
933 * @private 938 * @private
934 */ 939 */
935 convertPreselectedToDestinationMatch_: function() { 940 convertPreselectedToDestinationMatch_: function() {
936 if (this.appState_.selectedDestinationId && 941 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.
937 this.appState_.selectedDestinationOrigin) { 942 this.appState_.selectedDestination.id &&
943 this.appState_.selectedDestination.origin) {
938 return this.createExactDestinationMatch_( 944 return this.createExactDestinationMatch_(
939 this.appState_.selectedDestinationOrigin, 945 this.appState_.selectedDestination.origin,
940 this.appState_.selectedDestinationId); 946 this.appState_.selectedDestination.id);
941 } 947 }
942 if (this.systemDefaultDestinationId_) { 948 if (this.systemDefaultDestinationId_) {
943 return this.createExactDestinationMatch_( 949 return this.createExactDestinationMatch_(
944 print_preview.Destination.Origin.LOCAL, 950 print_preview.Destination.Origin.LOCAL,
945 this.systemDefaultDestinationId_); 951 this.systemDefaultDestinationId_);
946 } 952 }
947 return null; 953 return null;
948 }, 954 },
949 955
950 /** 956 /**
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 destination.capabilities_); 1337 destination.capabilities_);
1332 destination.capabilities_ = DestinationStore.sortMediaSizes_( 1338 destination.capabilities_ = DestinationStore.sortMediaSizes_(
1333 destination.capabilities_); 1339 destination.capabilities_);
1334 var existingDestination = this.destinationMap_[this.getKey_(destination)]; 1340 var existingDestination = this.destinationMap_[this.getKey_(destination)];
1335 if (existingDestination != null) { 1341 if (existingDestination != null) {
1336 existingDestination.capabilities = destination.capabilities; 1342 existingDestination.capabilities = destination.capabilities;
1337 } else { 1343 } else {
1338 this.insertDestination_(destination); 1344 this.insertDestination_(destination);
1339 } 1345 }
1340 1346
1341 if (existingDestination == this.selectedDestination_ || 1347 if (this.selectedDestination_ &&
1342 destination == this.selectedDestination_) { 1348 (existingDestination == this.selectedDestination_ ||
1349 destination == this.selectedDestination_)) {
1343 this.appState_.persistSelectedDestination(this.selectedDestination_); 1350 this.appState_.persistSelectedDestination(this.selectedDestination_);
1344 cr.dispatchSimpleEvent( 1351 cr.dispatchSimpleEvent(
1345 this, 1352 this,
1346 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); 1353 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
1347 } 1354 }
1348 }, 1355 },
1349 1356
1350 /** 1357 /**
1351 * Called when the search for Privet printers is done. 1358 * Called when the search for Privet printers is done.
1352 * @private 1359 * @private
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 return this.getDestinationKey_( 1745 return this.getDestinationKey_(
1739 destination.origin, destination.id, destination.account); 1746 destination.origin, destination.id, destination.account);
1740 } 1747 }
1741 }; 1748 };
1742 1749
1743 // Export 1750 // Export
1744 return { 1751 return {
1745 DestinationStore: DestinationStore 1752 DestinationStore: DestinationStore
1746 }; 1753 };
1747 }); 1754 });
OLDNEW
« 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