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

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: 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 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_.recentDestinationIds &&
463 origin = this.appState_.selectedDestinationOrigin; 463 this.appState_.recentDestinationOrigins) {
464 id = this.appState_.selectedDestinationId; 464 // Run through the destinations backwards the most recently used is set
465 account = this.appState_.selectedDestinationAccount || ''; 465 // as the initially selected destination.
466 name = this.appState_.selectedDestinationName || ''; 466 for (var i = this.appState_.recentDestinationIds.length - 1; i >= 0;
467 capabilities = this.appState_.selectedDestinationCapabilities; 467 i--) {
468 extensionId = this.appState_.selectedDestinationExtensionId || ''; 468 if (this.appState_.recentDestinationIds[i] &&
469 extensionName = this.appState_.selectedDestinationExtensionName || ''; 469 this.appState_.recentDestinationOrigins[i]) {
dpapad 2016/09/21 00:34:30 Are those two checks necessary?
rbpotter 2016/09/21 01:43:07 Done.
470 origin = this.appState_.recentDestinationOrigins[i];
471 id = this.appState_.recentDestinationIds[i];
472 account = this.appState_.recentDestinationAccounts[i] || '';
473 name = this.appState_.recentDestinationNames[i] || '';
474 capabilities = this.appState_.recentDestinationCapabilities[i];
475 extensionId = this.appState_.recentDestinationExtensionIds[i] || '';
476 extensionName =
477 this.appState_.recentDestinationExtensionNames[i] || '';
478 }
479 var candidate =
480 this.destinationMap_[this.getDestinationKey_(origin,
481 id, account)];
482 if (candidate != null) {
483 this.selectDestination(candidate);
484 candidate.isRecent = true;
485 foundDestination = true;
486 } else {
dpapad 2016/09/21 00:34:30 Can this be simplified as follows? } else { fou
rbpotter 2016/09/21 01:43:07 Done.
487 if (this.fetchPreselectedDestination_(
488 origin,
489 id,
490 account,
491 name,
492 capabilities,
493 extensionId,
494 extensionName)) {
495 foundDestination = true;
496 }
497 }
498 }
470 } 499 }
500 if (foundDestination) return;
501 // Try the system default
471 var candidate = 502 var candidate =
472 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; 503 this.destinationMap_[this.getDestinationKey_(origin, id, account)];
473 if (candidate != null) { 504 if (candidate != null) {
474 this.selectDestination(candidate); 505 this.selectDestination(candidate);
475 return; 506 return;
476 } 507 }
477 508
478 if (this.fetchPreselectedDestination_( 509 if (this.fetchPreselectedDestination_(
479 origin, 510 origin,
480 id, 511 id,
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 /** 1152 /**
1122 * Inserts a destination into the store without dispatching any events. 1153 * Inserts a destination into the store without dispatching any events.
1123 * @return {boolean} Whether the inserted destination was not already in the 1154 * @return {boolean} Whether the inserted destination was not already in the
1124 * store. 1155 * store.
1125 * @private 1156 * @private
1126 */ 1157 */
1127 insertIntoStore_: function(destination) { 1158 insertIntoStore_: function(destination) {
1128 var key = this.getKey_(destination); 1159 var key = this.getKey_(destination);
1129 var existingDestination = this.destinationMap_[key]; 1160 var existingDestination = this.destinationMap_[key];
1130 if (existingDestination == null) { 1161 if (existingDestination == null) {
1162 for (var destinationIdNum = 0;
1163 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.
1164 destinationIdNum++) {
1165 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.
1166 this.appState_.recentDestinationIds[destinationIdNum] &&
1167 (destination.id ==
1168 this.appState_.recentDestinationIds[destinationIdNum]) &&
1169 (destination.origin ==
1170 this.appState_.recentDestinationOrigins[destinationIdNum])) {
1171 destination.isRecent = true;
1172 }
1173 }
1131 this.destinations_.push(destination); 1174 this.destinations_.push(destination);
1132 this.destinationMap_[key] = destination; 1175 this.destinationMap_[key] = destination;
1133 return true; 1176 return true;
1134 } else if (existingDestination.connectionStatus == 1177 } else if (existingDestination.connectionStatus ==
1135 print_preview.Destination.ConnectionStatus.UNKNOWN && 1178 print_preview.Destination.ConnectionStatus.UNKNOWN &&
1136 destination.connectionStatus != 1179 destination.connectionStatus !=
1137 print_preview.Destination.ConnectionStatus.UNKNOWN) { 1180 print_preview.Destination.ConnectionStatus.UNKNOWN) {
1138 existingDestination.connectionStatus = destination.connectionStatus; 1181 existingDestination.connectionStatus = destination.connectionStatus;
1139 return true; 1182 return true;
1140 } else { 1183 } else {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 return this.getDestinationKey_( 1515 return this.getDestinationKey_(
1473 destination.origin, destination.id, destination.account); 1516 destination.origin, destination.id, destination.account);
1474 } 1517 }
1475 }; 1518 };
1476 1519
1477 // Export 1520 // Export
1478 return { 1521 return {
1479 DestinationStore: DestinationStore 1522 DestinationStore: DestinationStore
1480 }; 1523 };
1481 }); 1524 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698