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

Unified Diff: remoting/webapp/crd/js/host_list_api_gcd_impl.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/host_list_api.js ('k') | remoting/webapp/crd/js/host_list_api_impl.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_gcd_impl.js
diff --git a/remoting/webapp/crd/js/host_list_api_gcd_impl.js b/remoting/webapp/crd/js/host_list_api_gcd_impl.js
deleted file mode 100644
index 2e6e508c9fdfd5be6f681328837bc7924c060beb..0000000000000000000000000000000000000000
--- a/remoting/webapp/crd/js/host_list_api_gcd_impl.js
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-/**
- * @fileoverview
- * REST API for host-list management.
- */
-
-/** @suppress {duplicate} */
-var remoting = remoting || {};
-
-(function() {
-
-'use strict';
-
-/**
- * @constructor
- * @implements {remoting.HostListApi}
- */
-remoting.HostListApiGcdImpl = function() {
- this.gcd_ = new remoting.gcd.Client({
- apiKey: remoting.settings.GOOGLE_API_KEY
- });
-};
-
-/** @override */
-remoting.HostListApiGcdImpl.prototype.register = function(
- newHostId, hostName, publicKey, hostClientId) {
- var self = this;
- var deviceDraft = {
- channel: {
- supportedType: 'xmpp'
- },
- deviceKind: 'vendor',
- name: newHostId,
- displayName: hostName,
- state: {
- 'publicKey': publicKey
- }
- };
-
- return /** @type {!Promise<remoting.HostListApi.RegisterResult>} */ (
- this.gcd_.insertRegistrationTicket().
- then(function(ticket) {
- return self.gcd_.patchRegistrationTicket(
- ticket.id, deviceDraft, hostClientId);
- }).
- then(function(/**remoting.gcd.RegistrationTicket*/ ticket) {
- return self.gcd_.finalizeRegistrationTicket(ticket.id);
- }).
- then(function(/**remoting.gcd.RegistrationTicket*/ ticket) {
- return {
- authCode: ticket.robotAccountAuthorizationCode,
- email: ticket.robotAccountEmail,
- gcdId: ticket.deviceId
- };
- }).
- catch(function(error) {
- console.error('Error registering device with GCD: ' + error);
- throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED);
- }));
-};
-
-/** @override */
-remoting.HostListApiGcdImpl.prototype.get = function() {
- return this.gcd_.listDevices().
- then(function(devices) {
- var hosts = [];
- devices.forEach(function(device) {
- try {
- hosts.push(deviceToHost(device));
- } catch (/** @type {*} */ error) {
- console.warn('Invalid device spec:', error);
- }
- });
- return hosts;
- });
-};
-
-/** @override */
-remoting.HostListApiGcdImpl.prototype.put =
- function(hostId, hostName, hostPublicKey) {
- // TODO(jrw)
- throw new Error('Not implemented');
-};
-
-/** @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);
- }
- });
-};
-
-/** @override */
-remoting.HostListApiGcdImpl.prototype.getSupportHost = function(supportId) {
- console.error('getSupportHost not supported by HostListApiGclImpl');
- return Promise.reject(remoting.Error.unexpected());
-};
-
-/**
- * Converts a GCD device description to a Host object.
- * @param {!Object} device
- * @return {!remoting.Host}
- */
-function deviceToHost(device) {
- var statusMap = {
- 'online': 'ONLINE',
- 'offline': 'OFFLINE'
- };
- var hostId = base.getStringAttr(device, 'name');
- var host = new remoting.Host(hostId);
- host.hostName = base.getStringAttr(device, 'displayName');
- 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 creationTimeMs = base.getNumberAttr(device, 'creationTimeMs', 0);
- if (creationTimeMs) {
- host.createdTime = new Date(creationTimeMs).toISOString();
- }
- var lastUpdateTimeMs = base.getNumberAttr(device, 'lastUpdateTimeMs', 0);
- if (lastUpdateTimeMs) {
- host.updatedTime = new Date(lastUpdateTimeMs).toISOString();
- }
- return host;
-};
-
-})();
« no previous file with comments | « remoting/webapp/crd/js/host_list_api.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