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

Side by Side Diff: remoting/webapp/crd/js/host_list_api_gcd_impl.js

Issue 1104383002: Added ability to list and delete hosts with GCD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for review Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « remoting/webapp/crd/js/gcd_client.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * REST API for host-list management. 7 * REST API for host-list management.
8 */ 8 */
9 9
10 /** @suppress {duplicate} */ 10 /** @suppress {duplicate} */
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 return ticket.robotAccountAuthorizationCode; 53 return ticket.robotAccountAuthorizationCode;
54 }). 54 }).
55 catch(function(error) { 55 catch(function(error) {
56 console.error('Error registering device with GCD: ' + error); 56 console.error('Error registering device with GCD: ' + error);
57 throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED); 57 throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED);
58 })); 58 }));
59 }; 59 };
60 60
61 /** @override */ 61 /** @override */
62 remoting.HostListApiGcdImpl.prototype.get = function() { 62 remoting.HostListApiGcdImpl.prototype.get = function() {
63 // TODO(jrw) 63 return this.gcd_.listDevices().
64 this.gcd_.listDevices(); 64 then(function(devices) {
65 return Promise.resolve([]); 65 var hosts = [];
66 devices.forEach(function(device) {
67 try {
68 hosts.push(remoting.HostListApiGcdImpl.deviceToHost(device));
69 } catch (/** @type {*} */ error) {
70 console.warn('Invalid device spec:', error);
71 }
72 });
73 return hosts;
74 });
66 }; 75 };
67 76
68 /** @override */ 77 /** @override */
69 remoting.HostListApiGcdImpl.prototype.put = 78 remoting.HostListApiGcdImpl.prototype.put =
70 function(hostId, hostName, hostPublicKey) { 79 function(hostId, hostName, hostPublicKey) {
71 // TODO(jrw) 80 // TODO(jrw)
72 throw new Error('Not implemented'); 81 throw new Error('Not implemented');
73 }; 82 };
74 83
75 /** @override */ 84 /** @override */
76 remoting.HostListApiGcdImpl.prototype.remove = function(hostId) { 85 remoting.HostListApiGcdImpl.prototype.remove = function(hostId) {
77 // TODO(jrw) 86 var that = this;
78 throw new Error('Not implemented'); 87 return this.gcd_.listDevices(hostId).then(function(devices) {
88 var gcdId = null;
89 for (var i = 0; i < devices.length; i++) {
90 var device = devices[i];
91 // The "name" field in GCD holds what Chromoting considers to be
92 // the host ID.
93 if (device.name == hostId) {
94 gcdId = device.id;
95 }
96 }
97 if (gcdId == null) {
98 return false;
99 } else {
100 return that.gcd_.deleteDevice(gcdId);
101 }
102 });
103 };
104
105 /**
106 * @param {!Object} device
107 * @return {!remoting.Host}
108 */
109 remoting.HostListApiGcdImpl.deviceToHost = function(device) {
110 var statusMap = {
111 'online': 'ONLINE',
112 'offline': 'OFFLINE'
113 };
114 var hostId = base.getStringAttr(device, 'name');
115 var host = new remoting.Host(hostId);
116 host.hostName = base.getStringAttr(device, 'displayName');
117 host.status = base.getStringAttr(
118 statusMap, base.getStringAttr(device, 'connectionStatus'));
119 var state = base.getObjectAttr(device, 'state', {});
120 host.publicKey = base.getStringAttr(state, 'publicKey');
121 host.jabberId = base.getStringAttr(state, 'jabberId', '');
122 host.hostVersion = base.getStringAttr(state, 'hostVersion', '');
123 var creationTimeMs = base.getNumberAttr(device, 'creationTimeMs', 0);
124 if (creationTimeMs) {
125 host.createdTime = new Date(creationTimeMs).toISOString();
126 }
127 var lastUpdateTimeMs = base.getNumberAttr(device, 'lastUpdateTimeMs', 0);
128 if (lastUpdateTimeMs) {
129 host.updatedTime = new Date(lastUpdateTimeMs).toISOString();
130 }
131 return host;
79 }; 132 };
80 133
81 })(); 134 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/gcd_client.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698