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

Side by Side 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 unified diff | Download patch
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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 return; 451 return;
452 } 452 }
453 453
454 var origin = print_preview.Destination.Origin.LOCAL; 454 var origin = print_preview.Destination.Origin.LOCAL;
455 var id = this.systemDefaultDestinationId_; 455 var id = this.systemDefaultDestinationId_;
456 var account = ''; 456 var account = '';
457 var name = ''; 457 var name = '';
458 var capabilities = null; 458 var capabilities = null;
459 var extensionId = ''; 459 var extensionId = '';
460 var extensionName = ''; 460 var extensionName = '';
461 if (this.appState_.selectedDestinationId && 461 var foundDestination = false;
462 this.appState_.selectedDestinationOrigin) { 462 if (this.appState_.recentDestinations) {
463 origin = this.appState_.selectedDestinationOrigin; 463 // Run through the destinations backwards the most recently used is set
464 id = this.appState_.selectedDestinationId; 464 // as the initially selected destination.
465 account = this.appState_.selectedDestinationAccount || ''; 465 for (var i = this.appState_.recentDestinations.length - 1; i >= 0;
466 name = this.appState_.selectedDestinationName || ''; 466 i--) {
467 capabilities = this.appState_.selectedDestinationCapabilities; 467 origin = this.appState_.recentDestinations[i].origin;
468 extensionId = this.appState_.selectedDestinationExtensionId || ''; 468 id = this.appState_.recentDestinations[i].id;
469 extensionName = this.appState_.selectedDestinationExtensionName || ''; 469 account = this.appState_.recentDestinations[i].account || '';
470 name = this.appState_.recentDestinations[i].name || '';
471 capabilities = this.appState_.recentDestinations[i].capabilities;
472 extensionId = this.appState_.recentDestinations[i].extensionId ||
473 '';
474 extensionName =
475 this.appState_.recentDestinations[i].extensionName || '';
476 var candidate =
477 this.destinationMap_[this.getDestinationKey_(origin,
478 id, account)];
479 if (candidate != null) {
480 this.selectDestination(candidate);
481 candidate.isRecent = true;
482 foundDestination = true;
483 } else {
484 foundDestination = this.fetchPreselectedDestination_(
485 origin,
486 id,
487 account,
488 name,
489 capabilities,
490 extensionId,
491 extensionName);
492 }
493 }
470 } 494 }
495 if (foundDestination) return;
496 // Try the system default
471 var candidate = 497 var candidate =
472 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; 498 this.destinationMap_[this.getDestinationKey_(origin, id, account)];
473 if (candidate != null) { 499 if (candidate != null) {
474 this.selectDestination(candidate); 500 this.selectDestination(candidate);
475 return; 501 return;
476 } 502 }
477 503
478 if (this.fetchPreselectedDestination_( 504 if (this.fetchPreselectedDestination_(
479 origin, 505 origin,
480 id, 506 id,
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 /** 1147 /**
1122 * Inserts a destination into the store without dispatching any events. 1148 * Inserts a destination into the store without dispatching any events.
1123 * @return {boolean} Whether the inserted destination was not already in the 1149 * @return {boolean} Whether the inserted destination was not already in the
1124 * store. 1150 * store.
1125 * @private 1151 * @private
1126 */ 1152 */
1127 insertIntoStore_: function(destination) { 1153 insertIntoStore_: function(destination) {
1128 var key = this.getKey_(destination); 1154 var key = this.getKey_(destination);
1129 var existingDestination = this.destinationMap_[key]; 1155 var existingDestination = this.destinationMap_[key];
1130 if (existingDestination == null) { 1156 if (existingDestination == null) {
1157 destination.isRecent |= this.appState_.recentDestinations.some(
1158 function(recent) {
1159 return (destination.id == recent.id &&
1160 destination.origin == recent.origin);
1161 }, this);
1131 this.destinations_.push(destination); 1162 this.destinations_.push(destination);
1132 this.destinationMap_[key] = destination; 1163 this.destinationMap_[key] = destination;
1133 return true; 1164 return true;
1134 } else if (existingDestination.connectionStatus == 1165 } else if (existingDestination.connectionStatus ==
1135 print_preview.Destination.ConnectionStatus.UNKNOWN && 1166 print_preview.Destination.ConnectionStatus.UNKNOWN &&
1136 destination.connectionStatus != 1167 destination.connectionStatus !=
1137 print_preview.Destination.ConnectionStatus.UNKNOWN) { 1168 print_preview.Destination.ConnectionStatus.UNKNOWN) {
1138 existingDestination.connectionStatus = destination.connectionStatus; 1169 existingDestination.connectionStatus = destination.connectionStatus;
1139 return true; 1170 return true;
1140 } else { 1171 } else {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 return this.getDestinationKey_( 1503 return this.getDestinationKey_(
1473 destination.origin, destination.id, destination.account); 1504 destination.origin, destination.id, destination.account);
1474 } 1505 }
1475 }; 1506 };
1476 1507
1477 // Export 1508 // Export
1478 return { 1509 return {
1479 DestinationStore: DestinationStore 1510 DestinationStore: DestinationStore
1480 }; 1511 };
1481 }); 1512 });
OLDNEW
« 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