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

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

Issue 2346153002: Save most recent 3 destinations across multiple sessions (Closed)
Patch Set: Add check for bad struct read in 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
« no previous file with comments | « chrome/browser/resources/print_preview/data/app_state.js ('k') | chrome/test/data/webui/print_preview.js » ('j') | 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 acbfae038781a9008a0fa7ad8cd361e356bff7fd..c049c4f0a001e6e55e33aaa4349d6b701115a47d 100644
--- a/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chrome/browser/resources/print_preview/data/destination_store.js
@@ -458,16 +458,42 @@ 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_.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--) {
+ origin = this.appState_.recentDestinations[i].origin;
+ id = this.appState_.recentDestinations[i].id;
+ account = this.appState_.recentDestinations[i].account || '';
+ name = this.appState_.recentDestinations[i].name || '';
+ capabilities = this.appState_.recentDestinations[i].capabilities;
+ extensionId = this.appState_.recentDestinations[i].extensionId ||
+ '';
+ extensionName =
+ this.appState_.recentDestinations[i].extensionName || '';
+ var candidate =
+ this.destinationMap_[this.getDestinationKey_(origin,
+ id, account)];
+ if (candidate != null) {
+ this.selectDestination(candidate);
+ candidate.isRecent = true;
+ foundDestination = true;
+ } else {
+ foundDestination = this.fetchPreselectedDestination_(
+ origin,
+ id,
+ account,
+ name,
+ capabilities,
+ extensionId,
+ extensionName);
+ }
+ }
}
+ if (foundDestination) return;
+ // Try the system default
var candidate =
this.destinationMap_[this.getDestinationKey_(origin, id, account)];
if (candidate != null) {
@@ -1128,6 +1154,11 @@ cr.define('print_preview', function() {
var key = this.getKey_(destination);
var existingDestination = this.destinationMap_[key];
if (existingDestination == null) {
+ destination.isRecent |= this.appState_.recentDestinations.some(
+ function(recent) {
+ return (destination.id == recent.id &&
+ destination.origin == recent.origin);
+ }, this);
this.destinations_.push(destination);
this.destinationMap_[key] = destination;
return true;
« no previous file with comments | « chrome/browser/resources/print_preview/data/app_state.js ('k') | chrome/test/data/webui/print_preview.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698