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

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

Issue 1161813006: Updated handling of GCD devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for review; fixed broken host reg. algorithm Created 5 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: 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 a3ae6e6640545606d13f934a7a98c5f6fbd919a1..ce2ce5cc9b96fb636fc015bb61284d4a37bad19c 100644
--- a/remoting/webapp/crd/js/host_controller.js
+++ b/remoting/webapp/crd/js/host_controller.js
@@ -163,8 +163,6 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
return null;
}
});
- var newHostId = base.generateUuid();
- var pinHashPromise = this.hostDaemonFacade_.getPinHash(newHostId, hostPin);
var hostOwnerPromise = this.getClientBaseJid_();
/** @type {boolean} */
@@ -183,12 +181,24 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
var keyPair = /** @type {remoting.KeyPair} */ (a[2]);
return remoting.HostListApi.getInstance().register(
- newHostId, hostName, keyPair.publicKey, hostClientId);
+ hostName, keyPair.publicKey, hostClientId);
}).then(function(/** remoting.HostListApi.RegisterResult */ result) {
hostRegistered = true;
return result;
});
+ // For convenience, make the host ID available as a separate promise.
+ /** @type {!Promise<string>} */
+ var hostIdPromise = registerResultPromise.then(function(registerResult) {
+ return registerResult.hostId;
+ });
+
+ // Get the PIN hash based on the host ID.
+ /** @type {!Promise<string>} */
+ var pinHashPromise = hostIdPromise.then(function(hostId) {
+ return that.hostDaemonFacade_.getPinHash(hostId, hostPin);
+ });
+
// Get XMPP creditials.
var xmppCredsPromise = registerResultPromise.then(function(registerResult) {
base.debug.assert(registerResult.authCode != '');
@@ -230,7 +240,6 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
var hostConfig = {
xmpp_login: xmppCreds.userEmail,
oauth_refresh_token: xmppCreds.refreshToken,
- host_id: newHostId,
host_name: hostName,
host_secret_hash: hostSecretHash,
private_key: keyPair.privateKey,
@@ -239,8 +248,11 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
if (hostOwnerEmail != hostOwner) {
hostConfig['host_owner_email'] = hostOwnerEmail;
}
- if (registerResult.gcdId) {
- hostConfig['gcd_device_id'] = registerResult.gcdId;
+ if (registerResult.isLegacy) {
+ hostConfig['host_id'] = registerResult.hostId;
+ }
+ else {
+ hostConfig['gcd_device_id'] = registerResult.hostId;
}
return hostConfig;
});
@@ -253,24 +265,26 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
});
// Update the UI or report an error.
- return startDaemonResultPromise.then(function(result) {
- if (result == remoting.HostController.AsyncResult.OK) {
- return hostNamePromise.then(function(hostName) {
- return keyPairPromise.then(function(keyPair) {
- remoting.hostList.onLocalHostStarted(
- hostName, newHostId, keyPair.publicKey);
+ return hostIdPromise.then(function(hostId) {
+ return startDaemonResultPromise.then(function(result) {
+ if (result == remoting.HostController.AsyncResult.OK) {
+ return hostNamePromise.then(function(hostName) {
+ return keyPairPromise.then(function(keyPair) {
+ remoting.hostList.onLocalHostStarted(
+ hostName, hostId, keyPair.publicKey);
+ });
});
- });
- } else if (result == remoting.HostController.AsyncResult.CANCELLED) {
- throw new remoting.Error(remoting.Error.Tag.CANCELLED);
- } else {
- throw remoting.Error.unexpected();
- }
- }).catch(function(error) {
- if (hostRegistered) {
- remoting.hostList.unregisterHostById(newHostId);
- }
- throw error;
+ } else if (result == remoting.HostController.AsyncResult.CANCELLED) {
+ throw new remoting.Error(remoting.Error.Tag.CANCELLED);
+ } else {
+ throw remoting.Error.unexpected();
+ }
+ }).catch(function(error) {
+ if (hostId) {
+ remoting.hostList.unregisterHostById(hostId);
+ }
+ throw error;
+ });
});
};
@@ -399,7 +413,8 @@ remoting.HostController.prototype.getLocalHostId = function(onDone) {
function onConfig(config) {
var hostId = null;
if (isHostConfigValid_(config)) {
- hostId = /** @type {string} */ (config['host_id']);
+ hostId = base.getStringAttr(
Jamie 2015/06/08 21:44:34 Add a comment along the lines of "Use the gcd_devi
John Williams 2015/06/09 19:46:30 Done. Didn't go for bonus points because this cod
+ config, 'gcd_device_id', base.getStringAttr(config, 'host_id'));
}
onDone(hostId);
};

Powered by Google App Engine
This is Rietveld 408576698