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

Unified Diff: remoting/webapp/crd/js/host_list_api_impl.js

Issue 945033002: Updated XHR API so call sites are more descriptive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@xhr-test
Patch Set: Created 5 years, 9 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
« no previous file with comments | « remoting/webapp/crd/js/host_controller.js ('k') | remoting/webapp/crd/js/oauth2.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/host_list_api_impl.js
diff --git a/remoting/webapp/crd/js/host_list_api_impl.js b/remoting/webapp/crd/js/host_list_api_impl.js
index 838bafa9e6d0a46b9cb7eac776a1e7452f73f149..f82ad1a1a9fbf08c3b1817600988987adb1c45a2 100644
--- a/remoting/webapp/crd/js/host_list_api_impl.js
+++ b/remoting/webapp/crd/js/host_list_api_impl.js
@@ -26,17 +26,16 @@ remoting.HostListApiImpl = function() {
* @param {function(!remoting.Error):void} onError
*/
remoting.HostListApiImpl.prototype.get = function(onDone, onError) {
- /** @type {function(XMLHttpRequest):void} */
+ /** @type {function(remoting.Xhr.Response):void} */
var parseHostListResponse =
this.parseHostListResponse_.bind(this, onDone, onError);
/** @param {string} token */
var onToken = function(token) {
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'GET',
url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts',
- onDone: parseHostListResponse,
oauthToken: token
- });
+ }).then(parseHostListResponse);
};
remoting.identity.getToken().then(onToken, remoting.Error.handler(onError));
};
@@ -61,13 +60,12 @@ remoting.HostListApiImpl.prototype.put =
'publicKey': hostPublicKey
}
};
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'PUT',
url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId,
- onDone: remoting.xhr.defaultResponse(onDone, onError),
jsonContent: newHostDetails,
oauthToken: token
- });
+ }).then(remoting.Xhr.defaultResponse(onDone, onError));
};
remoting.identity.getToken().then(onToken, remoting.Error.handler(onError));
};
@@ -82,12 +80,11 @@ remoting.HostListApiImpl.prototype.put =
remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) {
/** @param {string} token */
var onToken = function(token) {
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'DELETE',
url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId,
- onDone: remoting.xhr.defaultResponse(onDone, onError),
oauthToken: token
- });
+ }).then(remoting.Xhr.defaultResponse(onDone, onError));
};
remoting.identity.getToken().then(onToken, remoting.Error.handler(onError));
};
@@ -99,14 +96,14 @@ remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) {
*
* @param {function(Array<remoting.Host>):void} onDone
* @param {function(!remoting.Error):void} onError
- * @param {XMLHttpRequest} xhr
+ * @param {remoting.Xhr.Response} xhrr
* @private
*/
remoting.HostListApiImpl.prototype.parseHostListResponse_ =
- function(onDone, onError, xhr) {
- if (xhr.status == 200) {
+ function(onDone, onError, xhrr) {
+ if (xhrr.status == 200) {
var response = /** @type {{data: {items: Array}}} */
- (base.jsonParseSafe(xhr.responseText));
+ (base.jsonParseSafe(xhrr.responseText));
if (!response || !response.data) {
console.error('Invalid "hosts" response from server.');
onError(remoting.Error.UNEXPECTED);
@@ -129,7 +126,7 @@ remoting.HostListApiImpl.prototype.parseHostListResponse_ =
onDone(hosts);
}
} else {
- onError(remoting.Error.fromHttpStatus(xhr.status));
+ onError(remoting.Error.fromHttpStatus(xhrr.status));
}
};
« no previous file with comments | « remoting/webapp/crd/js/host_controller.js ('k') | remoting/webapp/crd/js/oauth2.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698