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

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: 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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized 426 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
427 * default destination selection rules. 427 * default destination selection rules.
428 */ 428 */
429 init: function( 429 init: function(
430 isInAppKioskMode, 430 isInAppKioskMode,
431 systemDefaultDestinationId, 431 systemDefaultDestinationId,
432 serializedDefaultDestinationSelectionRulesStr) { 432 serializedDefaultDestinationSelectionRulesStr) {
433 this.pdfPrinterEnabled_ = !isInAppKioskMode; 433 this.pdfPrinterEnabled_ = !isInAppKioskMode;
434 this.systemDefaultDestinationId_ = systemDefaultDestinationId; 434 this.systemDefaultDestinationId_ = systemDefaultDestinationId;
435 this.createLocalPdfPrintDestination_(); 435 this.createLocalPdfPrintDestination_();
436
437 if (!this.appState_.selectedDestinationId || 436 if (!this.appState_.selectedDestinationId ||
438 !this.appState_.selectedDestinationOrigin) { 437 !this.appState_.selectedDestinationOrigin) {
439 var destinationMatch = this.convertToDestinationMatch_( 438 var destinationMatch = this.convertToDestinationMatch_(
440 serializedDefaultDestinationSelectionRulesStr); 439 serializedDefaultDestinationSelectionRulesStr);
441 if (destinationMatch) { 440 if (destinationMatch) {
442 this.fetchMatchingDestination_(destinationMatch); 441 this.fetchMatchingDestination_(destinationMatch);
443 return; 442 return;
444 } 443 }
445 } 444 }
446 445
447 if (!this.systemDefaultDestinationId_ && 446 if (!this.systemDefaultDestinationId_ &&
448 !(this.appState_.selectedDestinationId && 447 !(this.appState_.selectedDestinationId &&
449 this.appState_.selectedDestinationOrigin)) { 448 this.appState_.selectedDestinationOrigin)) {
450 this.selectPdfDestination_(); 449 this.selectPdfDestination_();
451 return; 450 return;
452 } 451 }
453 452
454 var origin = print_preview.Destination.Origin.LOCAL; 453 var origin = print_preview.Destination.Origin.LOCAL;
455 var id = this.systemDefaultDestinationId_; 454 var id = this.systemDefaultDestinationId_;
456 var account = ''; 455 var account = '';
457 var name = ''; 456 var name = '';
458 var capabilities = null; 457 var capabilities = null;
459 var extensionId = ''; 458 var extensionId = '';
460 var extensionName = ''; 459 var extensionName = '';
461 if (this.appState_.selectedDestinationId && 460 var foundDestination = false;
462 this.appState_.selectedDestinationOrigin) { 461 if (this.appState_.recentDestinationIds &&
463 origin = this.appState_.selectedDestinationOrigin; 462 this.appState_.recentDestinationOrigins) {
464 id = this.appState_.selectedDestinationId; 463 // Run through the destinations backwards the most recently used is set
465 account = this.appState_.selectedDestinationAccount || ''; 464 // as the initially selected destination.
466 name = this.appState_.selectedDestinationName || ''; 465 for (var i = this.appState_.recentDestinationIds.length - 1; i >= 0;
467 capabilities = this.appState_.selectedDestinationCapabilities; 466 i--) {
468 extensionId = this.appState_.selectedDestinationExtensionId || ''; 467 if (this.appState_.recentDestinationIds[i] &&
469 extensionName = this.appState_.selectedDestinationExtensionName || ''; 468 this.appState_.recentDestinationOrigins[i]) {
469 origin = this.appState_.recentDestinationOrigins[i];
470 id = this.appState_.recentDestinationIds[i];
471 account = this.appState_.recentDestinationAccounts[i] || '';
472 name = this.appState_.recentDestinationNames[i] || '';
473 capabilities = this.appState_.recentDestinationCapabilities[i];
474 extensionId = this.appState_.recentDestinationExtensionIds[i] || '';
475 extensionName =
476 this.appState_.recentDestinationExtensionNames[i] || '';
477 }
478 var candidate =
479 this.destinationMap_[this.getDestinationKey_(origin,
480 id, account)];
481 if (candidate != null) {
482 this.selectDestination(candidate);
483 candidate.isRecent = true;
484 foundDestination = true;
485 } else {
486 if (this.fetchPreselectedDestination_(
487 origin,
488 id,
489 account,
490 name,
491 capabilities,
492 extensionId,
493 extensionName)) {
494 foundDestination = true;
495 }
496 }
497 }
470 } 498 }
499 if (foundDestination) return;
500 // Try the system default
471 var candidate = 501 var candidate =
472 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; 502 this.destinationMap_[this.getDestinationKey_(origin, id, account)];
473 if (candidate != null) { 503 if (candidate != null) {
474 this.selectDestination(candidate); 504 this.selectDestination(candidate);
475 return; 505 return;
476 } 506 }
477 507
478 if (this.fetchPreselectedDestination_( 508 if (this.fetchPreselectedDestination_(
479 origin, 509 origin,
480 id, 510 id,
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 } 1148 }
1119 }, 1149 },
1120 1150
1121 /** 1151 /**
1122 * Inserts a destination into the store without dispatching any events. 1152 * Inserts a destination into the store without dispatching any events.
1123 * @return {boolean} Whether the inserted destination was not already in the 1153 * @return {boolean} Whether the inserted destination was not already in the
1124 * store. 1154 * store.
1125 * @private 1155 * @private
1126 */ 1156 */
1127 insertIntoStore_: function(destination) { 1157 insertIntoStore_: function(destination) {
1158
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;
1164 destinationIdNum++) {
1165 if (this.appState_.recentDestinationIds &&
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