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

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

Issue 2346153002: Save most recent 3 destinations across multiple sessions (Closed)
Patch Set: Fix errors, remove commented code Created 4 years, 3 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 acbfae038781a9008a0fa7ad8cd361e356bff7fd..1becd0c47211d80c0b565f49af79974fbd35ad4b 100644
--- a/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chrome/browser/resources/print_preview/data/destination_store.js
@@ -458,16 +458,47 @@ cr.define('print_preview', function() {
var capabilities = null;
var extensionId = '';
var extensionName = '';
- if (this.appState_.selectedDestinationId &&
- this.appState_.selectedDestinationOrigin) {
- origin = this.appState_.selectedDestinationOrigin;
- id = this.appState_.selectedDestinationId;
- account = this.appState_.selectedDestinationAccount || '';
- name = this.appState_.selectedDestinationName || '';
- capabilities = this.appState_.selectedDestinationCapabilities;
- extensionId = this.appState_.selectedDestinationExtensionId || '';
- extensionName = this.appState_.selectedDestinationExtensionName || '';
+ var foundDestination = false;
+ if (this.appState_.recentDestinationIds &&
+ this.appState_.recentDestinationOrigins) {
+ // Run through the destinations backwards the most recently used is set
+ // as the initially selected destination.
+ for (var i = this.appState_.recentDestinationIds.length - 1; i >= 0;
+ i--) {
+ if (this.appState_.recentDestinationIds[i] &&
+ this.appState_.recentDestinationOrigins[i]) {
dpapad 2016/09/21 00:34:30 Are those two checks necessary?
rbpotter 2016/09/21 01:43:07 Done.
+ origin = this.appState_.recentDestinationOrigins[i];
+ id = this.appState_.recentDestinationIds[i];
+ account = this.appState_.recentDestinationAccounts[i] || '';
+ name = this.appState_.recentDestinationNames[i] || '';
+ capabilities = this.appState_.recentDestinationCapabilities[i];
+ extensionId = this.appState_.recentDestinationExtensionIds[i] || '';
+ extensionName =
+ this.appState_.recentDestinationExtensionNames[i] || '';
+ }
+ var candidate =
+ this.destinationMap_[this.getDestinationKey_(origin,
+ id, account)];
+ if (candidate != null) {
+ this.selectDestination(candidate);
+ candidate.isRecent = true;
+ foundDestination = true;
+ } else {
dpapad 2016/09/21 00:34:30 Can this be simplified as follows? } else { fou
rbpotter 2016/09/21 01:43:07 Done.
+ if (this.fetchPreselectedDestination_(
+ origin,
+ id,
+ account,
+ name,
+ capabilities,
+ extensionId,
+ extensionName)) {
+ foundDestination = true;
+ }
+ }
+ }
}
+ if (foundDestination) return;
+ // Try the system default
var candidate =
this.destinationMap_[this.getDestinationKey_(origin, id, account)];
if (candidate != null) {
@@ -1128,6 +1159,18 @@ cr.define('print_preview', function() {
var key = this.getKey_(destination);
var existingDestination = this.destinationMap_[key];
if (existingDestination == null) {
+ for (var destinationIdNum = 0;
+ destinationIdNum < this.appState_.recentDestinationIds.length;
dpapad 2016/09/21 00:34:30 Probably more readable to simply name the iteratio
rbpotter 2016/09/21 01:43:07 Done.
+ destinationIdNum++) {
+ if (this.appState_.recentDestinationIds &&
dpapad 2016/09/21 00:34:30 Is this check necessary? Does this.appState_.recen
rbpotter 2016/09/21 01:43:07 Done.
+ this.appState_.recentDestinationIds[destinationIdNum] &&
+ (destination.id ==
+ this.appState_.recentDestinationIds[destinationIdNum]) &&
+ (destination.origin ==
+ this.appState_.recentDestinationOrigins[destinationIdNum])) {
+ destination.isRecent = true;
+ }
+ }
this.destinations_.push(destination);
this.destinationMap_[key] = destination;
return true;

Powered by Google App Engine
This is Rietveld 408576698