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

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

Issue 14340003: Rename AuthType to Origin of destination. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename AuthType to Origin. Created 7 years, 8 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 253883f85ddb8d4f280bad32e26368c94b1917d3..e0ea29421204283dd1a690d5165e0fbda108e540 100644
--- a/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chrome/browser/resources/print_preview/data/destination_store.js
@@ -39,7 +39,7 @@ cr.define('print_preview', function() {
this.destinations_ = [];
/**
- * Cache used for constant lookup of destinations by ID.
+ * Cache used for constant lookup of destinations by origin and id.
* @type {object.<string, !print_preview.Destination>}
* @private
*/
@@ -62,11 +62,11 @@ cr.define('print_preview', function() {
this.initialDestinationId_ = null;
/**
- * Whether the initial destination is a local one or not.
- * @type {boolean}
+ * Initial origin used to auto-select destination.
+ * @type {print_preview.Destination.Origin}
* @private
*/
- this.isInitialDestinationLocal_ = true;
+ this.initialDestinationOrigin_ = print_preview.Destination.Origin.LOCAL;
/**
* Whether the destination store will auto select the destination that
@@ -154,7 +154,7 @@ cr.define('print_preview', function() {
var dest = new print_preview.Destination(
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
print_preview.Destination.Type.LOCAL,
- print_preview.Destination.AuthType.LOCAL,
+ print_preview.Destination.Origin.LOCAL,
localStrings.getString('printToPDF'),
false /*isRecent*/,
print_preview.Destination.ConnectionStatus.ONLINE);
@@ -216,25 +216,31 @@ cr.define('print_preview', function() {
* @private
*/
init: function(systemDefaultDestinationId) {
- if (this.appState_.selectedDestinationId) {
+ if (this.appState_.selectedDestinationId &&
+ this.appState_.selectedDestinationOrigin) {
this.initialDestinationId_ = this.appState_.selectedDestinationId;
- this.isInitialDestinationLocal_ =
- this.appState_.isSelectedDestinationLocal;
+ this.initialDestinationOrigin_ =
+ this.appState_.selectedDestinationOrigin_;
} else {
this.initialDestinationId_ = systemDefaultDestinationId;
- this.isInitialDestinationLocal_ = true;
+ this.initialDestinationOrigin_ =
+ print_preview.Destination.Origin.LOCAL;
}
-
this.isInAutoSelectMode_ = true;
- if (this.initialDestinationId_ == null) {
+ if (this.initialDestinationId_ == null ||
+ this.initialDestinationOrigin_ == null) {
assert(this.destinations_.length > 0,
'No destinations available to select');
this.selectDestination(this.destinations_[0]);
} else {
- var candidate = this.destinationMap_[this.initialDestinationId_];
+ var key = this.getDestinationKey_(this.initialDestinationOrigin_,
+ this.initialDestinationId_);
+ var candidate = this.destinationMap_[key];
if (candidate != null) {
this.selectDestination(candidate);
- } else if (!cr.isChromeOS && this.isInitialDestinationLocal_) {
+ } else if (!cr.isChromeOS &&
+ this.initialDestinationOrigin_ ==
+ print_preview.Destination.Origin.LOCAL) {
this.nativeLayer_.startGetLocalDestinationCapabilities(
this.initialDestinationId_);
}
@@ -265,8 +271,10 @@ cr.define('print_preview', function() {
cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED,
this.onCloudPrintPrinterFailed_.bind(this));
// Fetch initial destination if its a cloud destination.
- if (this.isInAutoSelectMode_ && !this.isInitialDestinationLocal_) {
- this.cloudPrintInterface_.printer(this.initialDestinationId_);
+ var origin = this.initialDestinationOrigin_;
+ if (this.isInAutoSelectMode_ &&
+ origin != print_preview.Destination.Origin.LOCAL) {
+ this.cloudPrintInterface_.printer(this.initialDestinationId_, origin);
}
},
@@ -311,7 +319,8 @@ cr.define('print_preview', function() {
assert(this.cloudPrintInterface_ != null,
'Selected destination is a cloud destination, but Google ' +
'Cloud Print is not enabled');
- this.cloudPrintInterface_.printer(destination.id);
+ this.cloudPrintInterface_.printer(destination.id,
+ destination.origin);
}
} else {
cr.dispatchSimpleEvent(
@@ -377,7 +386,8 @@ cr.define('print_preview', function() {
* updated.
*/
updateDestination: function(destination) {
- var existingDestination = this.destinationMap_[destination.id];
+ var key = this.getDestinationKey_(destination.origin, destination.id);
+ var existingDestination = this.destinationMap_[key];
if (existingDestination != null) {
existingDestination.capabilities = destination.capabilities;
return existingDestination;
@@ -416,10 +426,11 @@ cr.define('print_preview', function() {
* @private
*/
insertDestination_: function(destination) {
- var existingDestination = this.destinationMap_[destination.id];
+ var key = this.getDestinationKey_(destination.origin, destination.id);
+ var existingDestination = this.destinationMap_[key];
if (existingDestination == null) {
this.destinations_.push(destination);
- this.destinationMap_[destination.id] = destination;
+ this.destinationMap_[key] = destination;
return true;
} else if (existingDestination.connectionStatus ==
print_preview.Destination.ConnectionStatus.UNKNOWN &&
@@ -497,7 +508,10 @@ cr.define('print_preview', function() {
*/
onLocalDestinationCapabilitiesSet_: function(event) {
var destinationId = event.settingsInfo['printerId'];
- var destination = this.destinationMap_[destinationId];
+ var key =
+ this.getDestinationKey_(print_preview.Destination.Origin.LOCAL,
+ destinationId);
+ var destination = this.destinationMap_[key];
var capabilities = print_preview.LocalCapabilitiesParser.parse(
event.settingsInfo);
if (destination) {
@@ -623,6 +637,16 @@ cr.define('print_preview', function() {
assert(this.destinations_.length > 0,
'No destinations were loaded before auto-select timeout expired');
this.selectDestination(this.destinations_[0]);
+ },
+
+ /**
+ * Returns key to be used with {@code destinationMap_}.
+ * @param {!print_preview.Destination.Origin} origin Destination origin.
+ * @return {!string} id Destination id.
+ * @private
+ */
+ getDestinationKey_: function(origin, id) {
+ return origin + '/' + id;
Toscano 2013/04/18 19:26:41 Wouldn't it be better to move this into destinatio
Vitaly Buka (NO REVIEWS) 2013/04/18 20:48:23 We need to be able create key without instance of
Toscano 2013/04/18 22:45:40 SGTM
}
};

Powered by Google App Engine
This is Rietveld 408576698