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

Side by Side Diff: remoting/webapp/base/js/host.js

Issue 2621403004: Create proper object types when loading host cache. (Closed)
Patch Set: Created 3 years, 11 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 | « no previous file | remoting/webapp/base/js/host_options.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 this.tokenUrlPatterns = []; 46 this.tokenUrlPatterns = [];
47 /** @type {string} */ 47 /** @type {string} */
48 this.updatedTime = ''; 48 this.updatedTime = '';
49 /** @type {string} */ 49 /** @type {string} */
50 this.hostOfflineReason = ''; 50 this.hostOfflineReason = '';
51 /** @type {remoting.HostOptions} */ 51 /** @type {remoting.HostOptions} */
52 this.options = new remoting.HostOptions(hostId); 52 this.options = new remoting.HostOptions(hostId);
53 }; 53 };
54 54
55 /** 55 /**
56 * Create a typed Host instance from an untyped Object.
57 *
58 * @param {Object} object
59 * @return {remoting.Host}
60 */
61 remoting.Host.fromObject = function(object) {
62 try {
63 var result = new remoting.Host(base.assertString(object.hostId));
64 result.hostName = base.assertString(object.hostName);
65 result.status = base.assertString(object.status);
66 result.jabberId = base.assertString(object.jabberId);
67 result.publicKey = base.assertString(object.publicKey);
68 result.hostVersion = base.assertString(object.hostVersion);
69 result.hostOs = base.assertNumber(object.hostOs);
70 result.hostOsVersion = base.assertString(object.hostOsVersion);
71 result.tokenUrlPatterns = base.assertArray(object.tokenUrlPatterns);
72 result.updatedTime = base.assertString(object.updatedTime);
73 result.hostOfflineReason = base.assertString(object.hostOfflineReason);
74 result.options = remoting.HostOptions.fromObject(
75 base.assertObject(object.options), base.assertString(object.hostId));
76 return result;
77 } catch (e) {
78 console.error(e);
79 return null;
80 }
81 };
82
83 /**
56 * Determine whether a host needs to be manually updated. This is the case if 84 * Determine whether a host needs to be manually updated. This is the case if
57 * the host's major version number is more than 2 lower than that of the web- 85 * the host's major version number is more than 2 lower than that of the web-
58 * app (a difference of 2 is tolerated due to the different update mechanisms 86 * app (a difference of 2 is tolerated due to the different update mechanisms
59 * and to handle cases where we may skip releasing a version) and if the host is 87 * and to handle cases where we may skip releasing a version) and if the host is
60 * on-line (off-line hosts are not expected to auto-update). 88 * on-line (off-line hosts are not expected to auto-update).
61 * 89 *
62 * @param {remoting.Host} host The host information from the directory. 90 * @param {remoting.Host} host The host information from the directory.
63 * @param {string|number} webappVersion The version number of the web-app, in 91 * @param {string|number} webappVersion The version number of the web-app, in
64 * either dotted-decimal notation notation, or directly represented by the 92 * either dotted-decimal notation notation, or directly represented by the
65 * major version. 93 * major version.
66 * @return {boolean} True if the host is on-line but out-of-date. 94 * @return {boolean} True if the host is on-line but out-of-date.
67 */ 95 */
68 remoting.Host.needsUpdate = function(host, webappVersion) { 96 remoting.Host.needsUpdate = function(host, webappVersion) {
69 if (host.status != 'ONLINE') { 97 if (host.status != 'ONLINE') {
70 return false; 98 return false;
71 } 99 }
72 var hostMajorVersion = parseInt(host.hostVersion, 10); 100 var hostMajorVersion = parseInt(host.hostVersion, 10);
73 if (isNaN(hostMajorVersion)) { 101 if (isNaN(hostMajorVersion)) {
74 // Host versions 26 and higher include the version number in heartbeats, 102 // Host versions 26 and higher include the version number in heartbeats,
75 // so if it's missing then the host is at most version 25. 103 // so if it's missing then the host is at most version 25.
76 hostMajorVersion = 25; 104 hostMajorVersion = 25;
77 } 105 }
78 return (parseInt(webappVersion, 10) - hostMajorVersion) > 2; 106 return (parseInt(webappVersion, 10) - hostMajorVersion) > 2;
79 }; 107 };
80 108
81 })(); 109 })();
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/base/js/host_options.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698