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

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

Issue 1003433002: Updated remoting.xhr API to use promises. Removed access to the native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@spy-promise
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
Index: remoting/webapp/crd/js/host_controller.js
diff --git a/remoting/webapp/crd/js/host_controller.js b/remoting/webapp/crd/js/host_controller.js
index 61529f2b637529c8270f3785e8e82fe34b091704..162cb2a498fea15099dd1f084de08abca793d2f8 100644
--- a/remoting/webapp/crd/js/host_controller.js
+++ b/remoting/webapp/crd/js/host_controller.js
@@ -234,14 +234,14 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone,
* @param {string} hostName
* @param {string} publicKey
* @param {string} privateKey
- * @param {XMLHttpRequest} xhr
+ * @param {!remoting.Xhr.Response} response
*/
function onRegistered(
- hostName, publicKey, privateKey, xhr) {
- var success = (xhr.status == 200);
+ hostName, publicKey, privateKey, response) {
+ var success = (response.status == 200);
if (success) {
- var result = base.jsonParseSafe(xhr.responseText);
+ var result = base.jsonParseSafe(response.getText());
if ('data' in result && 'authorizationCode' in result['data']) {
that.hostDaemonFacade_.getCredentialsFromAuthCode(
result['data']['authorizationCode'],
@@ -260,8 +260,8 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone,
});
}
} else {
- console.log('Failed to register the host. Status: ' + xhr.status +
- ' response: ' + xhr.responseText);
+ console.log('Failed to register the host. Status: ' + response.status +
+ ' response: ' + response.getText());
onError(new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED));
}
}
@@ -281,16 +281,15 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone,
publicKey: publicKey
} };
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'POST',
url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts',
urlParams: {
hostClientId: hostClientId
},
- onDone: onRegistered.bind(null, hostName, publicKey, privateKey),
jsonContent: newHostDetails,
oauthToken: oauthToken
- });
+ }).start().then(onRegistered.bind(null, hostName, publicKey, privateKey));
}
/**
« no previous file with comments | « remoting/webapp/crd/js/dns_blackhole_checker_unittest.js ('k') | remoting/webapp/crd/js/host_list_api_impl.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698