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

Unified Diff: chrome/browser/resources/print_preview/cloud_print_interface.js

Issue 2938073003: Change getAccessToken and getExtensionPrinterAccess to sendWithPromise (Closed)
Patch Set: Remove map and extra dest type Created 3 years, 6 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/cloud_print_interface.js
diff --git a/chrome/browser/resources/print_preview/cloud_print_interface.js b/chrome/browser/resources/print_preview/cloud_print_interface.js
index cce11fc68825334b07bcd224c6b48a06639809b9..3a61778ce8f90307470152cf49eb543f7b124413 100644
--- a/chrome/browser/resources/print_preview/cloud_print_interface.js
+++ b/chrome/browser/resources/print_preview/cloud_print_interface.js
@@ -101,13 +101,13 @@ cr.define('cloudprint', function() {
this.outstandingCloudSearchRequests_ = [];
/**
- * Event tracker used to keep track of native layer events.
- * @type {!EventTracker}
- * @private
+ * Promise that will be resolved when the access token for
+ * DestinationOrigin.DEVICE is available. Null if there is no request
+ * currently pending.
+ * @private {?Promise}
*/
- this.tracker_ = new EventTracker();
+ this.accessTokenRequestPromise_ = null;
- this.addEventListeners_();
}
/**
@@ -163,8 +163,6 @@ cr.define('cloudprint', function() {
CloudPrintInterface.CLOUD_ORIGINS_ = [
print_preview.DestinationOrigin.COOKIES,
print_preview.DestinationOrigin.DEVICE
- // TODO(vitalybuka): Enable when implemented.
- // ready print_preview.DestinationOrigin.PROFILE
];
CloudPrintInterface.prototype = {
@@ -315,17 +313,6 @@ cr.define('cloudprint', function() {
this.onPrinterDone_.bind(this, printerId)));
},
- /**
- * Adds event listeners to relevant events.
- * @private
- */
- addEventListeners_: function() {
- this.tracker_.add(
- this.nativeLayer_.getEventTarget(),
- print_preview.NativeLayer.EventType.ACCESS_TOKEN_READY,
- this.onAccessTokenReady_.bind(this));
- },
-
/**
* Builds request to the Google Cloud Print API.
* @param {string} method HTTP method of the request.
@@ -404,7 +391,9 @@ cr.define('cloudprint', function() {
return this.sendRequest_(request);
} else {
this.requestQueue_.push(request);
- this.nativeLayer_.startGetAccessToken(request.origin);
+ this.accessTokenRequestPromise_ = this.accessTokenRequestPromise_ ||
dpapad 2017/06/20 01:36:21 A bit confused by this line. Is the intention to b
rbpotter 2017/06/20 02:47:54 Yes, that was the intent. That is much clearer, so
+ this.nativeLayer_.getAccessToken(request.origin).then(
+ this.onAccessTokenReady_.bind(this, request.origin));
}
},
@@ -478,20 +467,22 @@ cr.define('cloudprint', function() {
/**
* Called when a native layer receives access token.
- * @param {Event} event Contains the authentication type and access token.
+ * @param {!print_preview.DestinationOrigin} authType The authentication
+ * type.
+ * @param {string} accessToken The access token obtained for |authType|.
* @private
*/
- onAccessTokenReady_: function(event) {
+ onAccessTokenReady_: function(authType, accessToken) {
// TODO(vitalybuka): remove when other Origins implemented.
- assert(event.authType == print_preview.DestinationOrigin.DEVICE);
+ assert(authType == print_preview.DestinationOrigin.DEVICE);
dpapad 2017/06/20 01:36:21 Do we need those assertions (here and line 479 bel
rbpotter 2017/06/20 02:47:54 Removed assertions. Also removed authType from fun
this.requestQueue_ = this.requestQueue_.filter(function(request) {
assert(request.origin == print_preview.DestinationOrigin.DEVICE);
- if (request.origin != event.authType) {
+ if (request.origin != authType) {
return true;
}
- if (event.accessToken) {
+ if (accessToken) {
request.xhr.setRequestHeader(
- 'Authorization', 'Bearer ' + event.accessToken);
+ 'Authorization', 'Bearer ' + accessToken);
this.sendRequest_(request);
} else { // No valid token.
// Without abort status does not exist.
@@ -500,6 +491,7 @@ cr.define('cloudprint', function() {
}
return false;
}, this);
+ this.accessTokenRequestPromise_ = null;
},
/**

Powered by Google App Engine
This is Rietveld 408576698