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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | remoting/webapp/base/js/host_options.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/base/js/host.js
diff --git a/remoting/webapp/base/js/host.js b/remoting/webapp/base/js/host.js
index 2b59edc0b241b7e4ced16c6cdeda71328128de65..2d9a7b140d9e87df70204d3dba8c87d2719ca90d 100644
--- a/remoting/webapp/base/js/host.js
+++ b/remoting/webapp/base/js/host.js
@@ -53,6 +53,34 @@ remoting.Host = function(hostId) {
};
/**
+ * Create a typed Host instance from an untyped Object.
+ *
+ * @param {Object} object
+ * @return {remoting.Host}
+ */
+remoting.Host.fromObject = function(object) {
+ try {
+ var result = new remoting.Host(base.assertString(object.hostId));
+ result.hostName = base.assertString(object.hostName);
+ result.status = base.assertString(object.status);
+ result.jabberId = base.assertString(object.jabberId);
+ result.publicKey = base.assertString(object.publicKey);
+ result.hostVersion = base.assertString(object.hostVersion);
+ result.hostOs = base.assertNumber(object.hostOs);
+ result.hostOsVersion = base.assertString(object.hostOsVersion);
+ result.tokenUrlPatterns = base.assertArray(object.tokenUrlPatterns);
+ result.updatedTime = base.assertString(object.updatedTime);
+ result.hostOfflineReason = base.assertString(object.hostOfflineReason);
+ result.options = remoting.HostOptions.fromObject(
+ base.assertObject(object.options), base.assertString(object.hostId));
+ return result;
+ } catch (e) {
+ console.error(e);
+ return null;
+ }
+};
+
+/**
* Determine whether a host needs to be manually updated. This is the case if
* the host's major version number is more than 2 lower than that of the web-
* app (a difference of 2 is tolerated due to the different update mechanisms
« 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