| 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 4c40894b00a7246f83e64d3426ed83593c4883db..c84ad7046d775e634e12e7a694362d5931544cf2 100644
|
| --- a/chrome/browser/resources/print_preview/cloud_print_interface.js
|
| +++ b/chrome/browser/resources/print_preview/cloud_print_interface.js
|
| @@ -100,15 +100,6 @@ cr.define('cloudprint', function() {
|
| * @private
|
| */
|
| this.outstandingCloudSearchRequests_ = [];
|
| -
|
| - /**
|
| - * Event tracker used to keep track of native layer events.
|
| - * @type {!EventTracker}
|
| - * @private
|
| - */
|
| - this.tracker_ = new EventTracker();
|
| -
|
| - this.addEventListeners_();
|
| }
|
|
|
| /**
|
| @@ -340,17 +331,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.
|
| @@ -430,7 +410,8 @@ cr.define('cloudprint', function() {
|
| return this.sendRequest_(request);
|
| } else {
|
| this.requestQueue_.push(request);
|
| - this.nativeLayer_.startGetAccessToken(request.origin);
|
| + this.nativeLayer_.getAccessToken(request.origin).then(
|
| + this.onAccessTokenReady_.bind(this, request.origin));
|
| }
|
| },
|
|
|
| @@ -504,20 +485,27 @@ 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 {!print_preview.AccessTokenResponse} response Contains the access
|
| + * token and an indicator of whether the token request is complete (if
|
| + * not, another request for this authentication type was already in
|
| + * progress).
|
| * @private
|
| */
|
| - onAccessTokenReady_: function(event) {
|
| + onAccessTokenReady_: function(authType, response) {
|
| + if (!response.completed)
|
| + return;
|
| // TODO(vitalybuka): remove when other Origins implemented.
|
| - assert(event.authType == print_preview.DestinationOrigin.DEVICE);
|
| + assert(authType == print_preview.DestinationOrigin.DEVICE);
|
| 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 (response.accessToken) {
|
| request.xhr.setRequestHeader('Authorization',
|
| - 'Bearer ' + event.accessToken);
|
| + 'Bearer ' + response.accessToken);
|
| this.sendRequest_(request);
|
| } else { // No valid token.
|
| // Without abort status does not exist.
|
|
|