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 'use strict'; | 10 'use strict'; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 /** @private */ | 55 /** @private */ |
56 this.hostId_ = hostId; | 56 this.hostId_ = hostId; |
57 /** @type {boolean} */ | 57 /** @type {boolean} */ |
58 this.shrinkToFit = true; | 58 this.shrinkToFit = true; |
59 /** @type {boolean} */ | 59 /** @type {boolean} */ |
60 this.resizeToClient = true; | 60 this.resizeToClient = true; |
61 /** @type {string} */ | 61 /** @type {string} */ |
62 this.remapKeys = ''; | 62 this.remapKeys = ''; |
63 /** @type {number} */ | 63 /** @type {number} */ |
64 this.desktopScale = 1; | 64 this.desktopScale = 1; |
| 65 /** @type {remoting.PairingInfo} */ |
| 66 this.pairingInfo = {clientId: '', sharedSecret: ''}; |
65 }; | 67 }; |
66 | 68 |
67 remoting.Host.Options.prototype.save = function() { | 69 remoting.Host.Options.prototype.save = function() { |
68 // TODO(kelvinp): Migrate pairingInfo to use this class as well and get rid of | 70 // TODO(kelvinp): Migrate pairingInfo to use this class as well and get rid of |
69 // remoting.HostSettings. | 71 // remoting.HostSettings. |
70 remoting.HostSettings.save(this.hostId_, this); | 72 remoting.HostSettings.save(this.hostId_, this); |
71 }; | 73 }; |
72 | 74 |
73 | 75 |
74 /** @return {Promise} A promise that resolves when the settings are loaded. */ | 76 /** @return {Promise} A promise that resolves when the settings are loaded. */ |
75 remoting.Host.Options.prototype.load = function() { | 77 remoting.Host.Options.prototype.load = function() { |
76 var that = this; | 78 var that = this; |
77 return base.Promise.as(remoting.HostSettings.load, [this.hostId_]).then( | 79 return base.Promise.as(remoting.HostSettings.load, [this.hostId_]).then( |
78 /** | 80 /** |
79 * @param {Object.<string|boolean|number>} options | 81 * @param {Object.<string|boolean|number>} options |
80 */ | 82 */ |
81 function(options) { | 83 function(options) { |
82 // Must be defaulted to true so that app-remoting can resize the host | 84 // Must be defaulted to true so that app-remoting can resize the host |
83 // upon launching. | 85 // upon launching. |
84 // TODO(kelvinp): Uses a separate host options for app-remoting that | 86 // TODO(kelvinp): Uses a separate host options for app-remoting that |
85 // hardcodes resizeToClient to true. | 87 // hardcodes resizeToClient to true. |
86 that.resizeToClient = | 88 that.resizeToClient = |
87 getBooleanAttr(options, 'resizeToClient', true); | 89 getBooleanAttr(options, 'resizeToClient', true); |
88 that.shrinkToFit = getBooleanAttr(options, 'shrinkToFit', true); | 90 that.shrinkToFit = getBooleanAttr(options, 'shrinkToFit', true); |
89 that.desktopScale = getNumberAttr(options, 'desktopScale', 1); | 91 that.desktopScale = getNumberAttr(options, 'desktopScale', 1); |
90 that.remapKeys = getStringAttr(options, 'remapKeys', ''); | 92 that.remapKeys = getStringAttr(options, 'remapKeys', ''); |
| 93 that.pairingInfo = |
| 94 /** @type {remoting.PairingInfo} */ ( |
| 95 getObjectAttr(options, 'pairingInfo', that.pairingInfo)); |
91 }); | 96 }); |
92 }; | 97 }; |
93 | 98 |
94 /** | 99 /** |
95 * Determine whether a host needs to be manually updated. This is the case if | 100 * Determine whether a host needs to be manually updated. This is the case if |
96 * the host's major version number is more than 1 lower than that of the web- | 101 * the host's major version number is more than 1 lower than that of the web- |
97 * app (a difference of 1 is tolerated due to the different update mechanisms) | 102 * app (a difference of 1 is tolerated due to the different update mechanisms) |
98 * and if the host is on-line (off-line hosts are not expected to auto-update). | 103 * and if the host is on-line (off-line hosts are not expected to auto-update). |
99 * | 104 * |
100 * @param {remoting.Host} host The host information from the directory. | 105 * @param {remoting.Host} host The host information from the directory. |
101 * @param {string|number} webappVersion The version number of the web-app, in | 106 * @param {string|number} webappVersion The version number of the web-app, in |
102 * either dotted-decimal notation notation, or directly represented by the | 107 * either dotted-decimal notation notation, or directly represented by the |
103 * major version. | 108 * major version. |
104 * @return {boolean} True if the host is on-line but out-of-date. | 109 * @return {boolean} True if the host is on-line but out-of-date. |
105 */ | 110 */ |
106 remoting.Host.needsUpdate = function(host, webappVersion) { | 111 remoting.Host.needsUpdate = function(host, webappVersion) { |
107 if (host.status != 'ONLINE') { | 112 if (host.status != 'ONLINE') { |
108 return false; | 113 return false; |
109 } | 114 } |
110 var hostMajorVersion = parseInt(host.hostVersion, 10); | 115 var hostMajorVersion = parseInt(host.hostVersion, 10); |
111 if (isNaN(hostMajorVersion)) { | 116 if (isNaN(hostMajorVersion)) { |
112 // Host versions 26 and higher include the version number in heartbeats, | 117 // Host versions 26 and higher include the version number in heartbeats, |
113 // so if it's missing then the host is at most version 25. | 118 // so if it's missing then the host is at most version 25. |
114 hostMajorVersion = 25; | 119 hostMajorVersion = 25; |
115 } | 120 } |
116 return (parseInt(webappVersion, 10) - hostMajorVersion) > 1; | 121 return (parseInt(webappVersion, 10) - hostMajorVersion) > 1; |
117 }; | 122 }; |
118 | 123 |
119 })(); | 124 })(); |
OLD | NEW |