OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * REST API for host-list management. | 7 * REST API for host-list management. |
8 */ | 8 */ |
9 | 9 |
10 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 * @param {XMLHttpRequest} xhr | 105 * @param {XMLHttpRequest} xhr |
106 * @private | 106 * @private |
107 */ | 107 */ |
108 remoting.HostListApiImpl.prototype.parseHostListResponse_ = | 108 remoting.HostListApiImpl.prototype.parseHostListResponse_ = |
109 function(onDone, onError, xhr) { | 109 function(onDone, onError, xhr) { |
110 if (xhr.status == 200) { | 110 if (xhr.status == 200) { |
111 var response = /** @type {{data: {items: Array}}} */ | 111 var response = /** @type {{data: {items: Array}}} */ |
112 (base.jsonParseSafe(xhr.responseText)); | 112 (base.jsonParseSafe(xhr.responseText)); |
113 if (!response || !response.data) { | 113 if (!response || !response.data) { |
114 console.error('Invalid "hosts" response from server.'); | 114 console.error('Invalid "hosts" response from server.'); |
115 onError(remoting.Error.UNEXPECTED); | 115 onError(remoting.Error.unexpected()); |
116 } else { | 116 } else { |
117 var items = response.data.items || []; | 117 var items = response.data.items || []; |
118 var hosts = items.map( | 118 var hosts = items.map( |
119 function(/** Object */ item) { | 119 function(/** Object */ item) { |
120 var host = new remoting.Host(); | 120 var host = new remoting.Host(); |
121 host.hostName = getStringAttr(item, 'hostName', ''); | 121 host.hostName = getStringAttr(item, 'hostName', ''); |
122 host.hostId = getStringAttr(item, 'hostId', ''); | 122 host.hostId = getStringAttr(item, 'hostId', ''); |
123 host.status = getStringAttr(item, 'status', ''); | 123 host.status = getStringAttr(item, 'status', ''); |
124 host.jabberId = getStringAttr(item, 'jabberId', ''); | 124 host.jabberId = getStringAttr(item, 'jabberId', ''); |
125 host.publicKey = getStringAttr(item, 'publicKey', ''); | 125 host.publicKey = getStringAttr(item, 'publicKey', ''); |
126 host.hostVersion = getStringAttr(item, 'hostVersion', ''); | 126 host.hostVersion = getStringAttr(item, 'hostVersion', ''); |
127 host.tokenUrlPatterns = getArrayAttr(item, 'tokenUrlPatterns', []); | 127 host.tokenUrlPatterns = getArrayAttr(item, 'tokenUrlPatterns', []); |
128 host.updatedTime = getStringAttr(item, 'updatedTime', ''); | 128 host.updatedTime = getStringAttr(item, 'updatedTime', ''); |
129 host.hostOfflineReason = getStringAttr(item, 'hostOfflineReason', ''); | 129 host.hostOfflineReason = getStringAttr(item, 'hostOfflineReason', ''); |
130 return host; | 130 return host; |
131 }); | 131 }); |
132 onDone(hosts); | 132 onDone(hosts); |
133 } | 133 } |
134 } else { | 134 } else { |
135 onError(remoting.Error.fromHttpStatus(xhr.status)); | 135 onError(remoting.Error.fromHttpStatus(xhr.status)); |
136 } | 136 } |
137 }; | 137 }; |
138 | 138 |
139 /** @type {remoting.HostListApi} */ | 139 /** @type {remoting.HostListApi} */ |
140 remoting.hostListApi = new remoting.HostListApiImpl(); | 140 remoting.hostListApi = new remoting.HostListApiImpl(); |
141 | 141 |
142 })(); | 142 })(); |
143 | 143 |
OLD | NEW |