Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * The deserialized form of the chromoting host as returned by Apiary. | 7 * The deserialized form of the chromoting host as returned by Apiary. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 var remoting = remoting || {}; | |
| 11 | |
| 12 (function() { | |
| 13 | |
| 10 'use strict'; | 14 'use strict'; |
| 11 | 15 |
| 12 /** @suppress {duplicate} */ | |
| 13 var remoting = remoting || {}; | |
| 14 | |
| 15 /** | 16 /** |
| 16 * Note that the object has more fields than are detailed below--these | 17 * Note that the object has more fields than are detailed below--these |
| 17 * are just the ones that we refer to directly. | 18 * are just the ones that we refer to directly. |
| 19 * | |
| 20 * TODO(kelvinp):Make fields private and expose them via getters. | |
|
Jamie
2015/02/18 00:33:10
This is basically a struct; I don't think there's
| |
| 18 * @constructor | 21 * @constructor |
| 19 */ | 22 */ |
| 20 remoting.Host = function() { | 23 remoting.Host = function() { |
| 21 /** @type {string} */ | 24 /** @type {string} */ |
| 22 this.hostName = ''; | 25 this.hostName = ''; |
| 23 /** @type {string} */ | 26 /** @type {string} */ |
| 24 this.hostId = ''; | 27 this.hostId = ''; |
| 25 /** @type {string} */ | 28 /** @type {string} */ |
| 26 this.status = ''; | 29 this.status = ''; |
| 27 /** @type {string} */ | 30 /** @type {string} */ |
| 28 this.jabberId = ''; | 31 this.jabberId = ''; |
| 29 /** @type {string} */ | 32 /** @type {string} */ |
| 30 this.publicKey = ''; | 33 this.publicKey = ''; |
| 31 /** @type {string} */ | 34 /** @type {string} */ |
| 32 this.hostVersion = ''; | 35 this.hostVersion = ''; |
| 33 /** @type {Array<string>} */ | 36 /** @type {Array<string>} */ |
| 34 this.tokenUrlPatterns = []; | 37 this.tokenUrlPatterns = []; |
| 35 /** @type {string} */ | 38 /** @type {string} */ |
| 36 this.updatedTime = ''; | 39 this.updatedTime = ''; |
| 37 /** @type {string} */ | 40 /** @type {string} */ |
| 38 this.hostOfflineReason = ''; | 41 this.hostOfflineReason = ''; |
| 42 /** @type {remoting.Host.Options} */ | |
|
Jamie
2015/02/18 00:33:10
Either make this private, or remove the getter. Si
| |
| 43 this.options_ = new remoting.Host.Options(this.hostId); | |
| 44 }; | |
| 45 | |
| 46 /** @return {remoting.Host.Options} */ | |
| 47 remoting.Host.prototype.options = function() { | |
| 48 return this.options_; | |
| 39 }; | 49 }; |
| 40 | 50 |
| 41 /** | 51 /** |
| 52 * @constructor | |
| 53 * @param {string} hostId | |
| 54 * @struct | |
| 55 */ | |
| 56 remoting.Host.Options = function(hostId) { | |
| 57 /** @private */ | |
| 58 this.hostId_ = hostId; | |
| 59 /** @private */ | |
| 60 this.isInitialized_ = false; | |
| 61 /** @type {boolean} */ | |
| 62 this.shrinkToFit = false; | |
| 63 /** @type {boolean} */ | |
| 64 this.resizeToClient = false; | |
| 65 /** @type {string} */ | |
| 66 this.remapKeys = ''; | |
| 67 /** @type {number} */ | |
| 68 this.desktopScale = 1; | |
| 69 }; | |
| 70 | |
| 71 remoting.Host.Options.prototype.save = function() { | |
| 72 base.debug.assert(this.isInitialized_); | |
| 73 remoting.HostSettings.save(this.hostId_, this); | |
| 74 }; | |
| 75 | |
| 76 | |
| 77 /** @return {Promise} A promise that resolves when the settings are loaded. */ | |
| 78 remoting.Host.Options.prototype.load = function() { | |
| 79 var that = this; | |
| 80 if (this.isInitialized_) { | |
| 81 return Promise.resolve(); | |
| 82 } | |
| 83 return base.Promise.as(remoting.HostSettings.load, [this.hostId_]).then( | |
| 84 /** | |
| 85 * @param {Object.<string|boolean|number>} options | |
| 86 */ | |
| 87 function(options) { | |
| 88 that.isInitialized_ = true; | |
| 89 that.resizeToClient = | |
| 90 getBooleanAttr(options, 'resizeToClient', false); | |
| 91 that.shrinkToFit = getBooleanAttr(options, 'shrinkToFit', false); | |
| 92 that.desktopScale = getNumberAttr(options, 'desktopScale', 1); | |
| 93 that.remapKeys = getStringAttr(options, 'remapKeys', ''); | |
| 94 }); | |
| 95 }; | |
| 96 | |
| 97 /** | |
| 42 * Determine whether a host needs to be manually updated. This is the case if | 98 * Determine whether a host needs to be manually updated. This is the case if |
| 43 * the host's major version number is more than 1 lower than that of the web- | 99 * the host's major version number is more than 1 lower than that of the web- |
| 44 * app (a difference of 1 is tolerated due to the different update mechanisms) | 100 * app (a difference of 1 is tolerated due to the different update mechanisms) |
| 45 * and if the host is on-line (off-line hosts are not expected to auto-update). | 101 * and if the host is on-line (off-line hosts are not expected to auto-update). |
| 46 * | 102 * |
| 47 * @param {remoting.Host} host The host information from the directory. | 103 * @param {remoting.Host} host The host information from the directory. |
| 48 * @param {string|number} webappVersion The version number of the web-app, in | 104 * @param {string|number} webappVersion The version number of the web-app, in |
| 49 * either dotted-decimal notation notation, or directly represented by the | 105 * either dotted-decimal notation notation, or directly represented by the |
| 50 * major version. | 106 * major version. |
| 51 * @return {boolean} True if the host is on-line but out-of-date. | 107 * @return {boolean} True if the host is on-line but out-of-date. |
| 52 */ | 108 */ |
| 53 remoting.Host.needsUpdate = function(host, webappVersion) { | 109 remoting.Host.needsUpdate = function(host, webappVersion) { |
| 54 if (host.status != 'ONLINE') { | 110 if (host.status != 'ONLINE') { |
| 55 return false; | 111 return false; |
| 56 } | 112 } |
| 57 var hostMajorVersion = parseInt(host.hostVersion, 10); | 113 var hostMajorVersion = parseInt(host.hostVersion, 10); |
| 58 if (isNaN(hostMajorVersion)) { | 114 if (isNaN(hostMajorVersion)) { |
| 59 // Host versions 26 and higher include the version number in heartbeats, | 115 // Host versions 26 and higher include the version number in heartbeats, |
| 60 // so if it's missing then the host is at most version 25. | 116 // so if it's missing then the host is at most version 25. |
| 61 hostMajorVersion = 25; | 117 hostMajorVersion = 25; |
| 62 } | 118 } |
| 63 return (parseInt(webappVersion, 10) - hostMajorVersion) > 1; | 119 return (parseInt(webappVersion, 10) - hostMajorVersion) > 1; |
| 64 }; | 120 }; |
| 121 | |
| 122 })(); | |
| OLD | NEW |