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

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

Issue 1161813006: Updated handling of GCD devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: oops--ignore 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
« no previous file with comments | « remoting/webapp/crd/js/gcd_client.js ('k') | remoting/webapp/crd/js/host_controller.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/gcd_host_list_api.js
diff --git a/remoting/webapp/crd/js/host_list_api_gcd_impl.js b/remoting/webapp/crd/js/gcd_host_list_api.js
similarity index 54%
rename from remoting/webapp/crd/js/host_list_api_gcd_impl.js
rename to remoting/webapp/crd/js/gcd_host_list_api.js
index 2e6e508c9fdfd5be6f681328837bc7924c060beb..a904c9dce511d61c20df792183bb485d2475b36e 100644
--- a/remoting/webapp/crd/js/host_list_api_gcd_impl.js
+++ b/remoting/webapp/crd/js/gcd_host_list_api.js
@@ -18,26 +18,34 @@ var remoting = remoting || {};
* @constructor
* @implements {remoting.HostListApi}
*/
-remoting.HostListApiGcdImpl = function() {
+remoting.GcdHostListApi = function() {
this.gcd_ = new remoting.gcd.Client({
apiKey: remoting.settings.GOOGLE_API_KEY
});
};
/** @override */
-remoting.HostListApiGcdImpl.prototype.register = function(
- newHostId, hostName, publicKey, hostClientId) {
+remoting.GcdHostListApi.prototype.register = function(
+ hostName, publicKey, hostClientId) {
var self = this;
var deviceDraft = {
channel: {
supportedType: 'xmpp'
},
deviceKind: 'vendor',
- name: newHostId,
- displayName: hostName,
+ name: hostName,
state: {
- 'publicKey': publicKey
- }
+ base: {
+ firmwareVersion: 'none',
+ localDiscoveryEnabled: false,
+ localAnonymousAccessMaxRole: 'none',
+ localPairingEnabled: false,
+ // The leading underscore is necessary for |_publicKey|
+ // because it's not a standard key defined by GCD.
+ _publicKey: publicKey
+ }
+ },
+ 'tags': [CHROMOTING_DEVICE_TAG]
};
return /** @type {!Promise<remoting.HostListApi.RegisterResult>} */ (
@@ -53,7 +61,8 @@ remoting.HostListApiGcdImpl.prototype.register = function(
return {
authCode: ticket.robotAccountAuthorizationCode,
email: ticket.robotAccountEmail,
- gcdId: ticket.deviceId
+ hostId: ticket.deviceId,
+ isLegacy: false
};
}).
catch(function(error) {
@@ -63,13 +72,15 @@ remoting.HostListApiGcdImpl.prototype.register = function(
};
/** @override */
-remoting.HostListApiGcdImpl.prototype.get = function() {
+remoting.GcdHostListApi.prototype.get = function() {
return this.gcd_.listDevices().
then(function(devices) {
var hosts = [];
devices.forEach(function(device) {
try {
- hosts.push(deviceToHost(device));
+ if (isChromotingHost(device)) {
+ hosts.push(deviceToHost(device));
+ }
} catch (/** @type {*} */ error) {
console.warn('Invalid device spec:', error);
}
@@ -79,41 +90,64 @@ remoting.HostListApiGcdImpl.prototype.get = function() {
};
/** @override */
-remoting.HostListApiGcdImpl.prototype.put =
+remoting.GcdHostListApi.prototype.put =
function(hostId, hostName, hostPublicKey) {
- // TODO(jrw)
- throw new Error('Not implemented');
+ return this.gcd_.patchDevice(hostId, {
+ 'name': hostName
+ }).then(function(device) {
+ if (device.name != hostName) {
+ console.error('error updating host name');
+ throw remoting.Error.unexpected();
+ }
+ if (!device.state || device.state['_publicKey'] != hostPublicKey) {
+ // TODO(jrw): Is there any reason to believe this would ever be
+ // happen?
+ console.error('unexpected host public key');
+ throw remoting.Error.unexpected();
+ }
+ // Don't return anything.
+ });
};
/** @override */
-remoting.HostListApiGcdImpl.prototype.remove = function(hostId) {
- var that = this;
- return this.gcd_.listDevices(hostId).then(function(devices) {
- var gcdId = null;
- for (var i = 0; i < devices.length; i++) {
- var device = devices[i];
- // The "name" field in GCD holds what Chromoting considers to be
- // the host ID.
- if (device.name == hostId) {
- gcdId = device.id;
- }
- }
- if (gcdId == null) {
- return false;
- } else {
- return that.gcd_.deleteDevice(gcdId);
+remoting.GcdHostListApi.prototype.remove = function(hostId) {
+ return this.gcd_.deleteDevice(hostId).then(function(deleted) {
+ if (!deleted) {
+ console.error('error deleting host from GCD');
+ throw remoting.Error.unexpected();
}
+ // Don't return anything.
});
};
/** @override */
-remoting.HostListApiGcdImpl.prototype.getSupportHost = function(supportId) {
+remoting.GcdHostListApi.prototype.getSupportHost = function(supportId) {
console.error('getSupportHost not supported by HostListApiGclImpl');
return Promise.reject(remoting.Error.unexpected());
};
/**
+ * Tag for distinguishing Chromoting hosts from other devices stored
+ * in GCD.
+ *
+ * @const
+ */
+var CHROMOTING_DEVICE_TAG = '1ce4542c-dd87-4320-ba19-ac173f98c04e';
+
+/**
+ * Check whether a GCD device entry is a Chromoting host.
+ *
+ * @param {remoting.gcd.Device} device
+ * @return {boolean}
+ */
+function isChromotingHost(device) {
+ return device.tags != null &&
+ device.tags.indexOf(CHROMOTING_DEVICE_TAG) != -1;
+}
+
+/**
* Converts a GCD device description to a Host object.
+ *
* @param {!Object} device
* @return {!remoting.Host}
*/
@@ -122,15 +156,16 @@ function deviceToHost(device) {
'online': 'ONLINE',
'offline': 'OFFLINE'
};
- var hostId = base.getStringAttr(device, 'name');
+ var hostId = base.getStringAttr(device, 'id');
var host = new remoting.Host(hostId);
- host.hostName = base.getStringAttr(device, 'displayName');
+ host.hostName = base.getStringAttr(device, 'name');
host.status = base.getStringAttr(
statusMap, base.getStringAttr(device, 'connectionStatus'));
var state = base.getObjectAttr(device, 'state', {});
- host.publicKey = base.getStringAttr(state, 'publicKey');
- host.jabberId = base.getStringAttr(state, 'jabberId', '');
- host.hostVersion = base.getStringAttr(state, 'hostVersion', '');
+ var baseState = base.getObjectAttr(state, 'base', {});
+ host.publicKey = base.getStringAttr(baseState, '_publicKey');
+ host.jabberId = base.getStringAttr(baseState, '_jabberId', '');
+ host.hostVersion = base.getStringAttr(baseState, '_hostVersion', '');
var creationTimeMs = base.getNumberAttr(device, 'creationTimeMs', 0);
if (creationTimeMs) {
host.createdTime = new Date(creationTimeMs).toISOString();
« no previous file with comments | « remoting/webapp/crd/js/gcd_client.js ('k') | remoting/webapp/crd/js/host_controller.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698