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 * Class representing the host-list portion of the home screen UI. | 7 * Class representing the host-list portion of the home screen UI. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 */ | 109 */ |
| 110 remoting.HostList.prototype.load = function(onDone) { | 110 remoting.HostList.prototype.load = function(onDone) { |
| 111 // Load the cache of the last host-list, if present. | 111 // Load the cache of the last host-list, if present. |
| 112 /** @type {remoting.HostList} */ | 112 /** @type {remoting.HostList} */ |
| 113 var that = this; | 113 var that = this; |
| 114 /** @param {Object.<string>} items */ | 114 /** @param {Object.<string>} items */ |
| 115 var storeHostList = function(items) { | 115 var storeHostList = function(items) { |
| 116 if (items[remoting.HostList.HOSTS_KEY]) { | 116 if (items[remoting.HostList.HOSTS_KEY]) { |
| 117 var cached = base.jsonParseSafe(items[remoting.HostList.HOSTS_KEY]); | 117 var cached = base.jsonParseSafe(items[remoting.HostList.HOSTS_KEY]); |
| 118 if (cached) { | 118 if (cached) { |
| 119 that.hosts_ = /** @type {Array.<remoting.Host>} */ cached; | 119 that.hosts_ = /** @type {Array.<remoting.Host>} */ (cached); |
| 120 } else { | 120 } else { |
| 121 console.error('Invalid value for ' + remoting.HostList.HOSTS_KEY); | 121 console.error('Invalid value for ' + remoting.HostList.HOSTS_KEY); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 onDone(); | 124 onDone(); |
| 125 }; | 125 }; |
| 126 chrome.storage.local.get(remoting.HostList.HOSTS_KEY, storeHostList); | 126 chrome.storage.local.get(remoting.HostList.HOSTS_KEY, storeHostList); |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 /** | 129 /** |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 * include a JSON-encoded list of host descriptions, which we display if we're | 181 * include a JSON-encoded list of host descriptions, which we display if we're |
| 182 * able to successfully parse it. | 182 * able to successfully parse it. |
| 183 * | 183 * |
| 184 * @param {function(boolean):void} onDone The callback passed to |refresh|. | 184 * @param {function(boolean):void} onDone The callback passed to |refresh|. |
| 185 * @param {Array.<remoting.Host>} hosts The list of hosts for the user. | 185 * @param {Array.<remoting.Host>} hosts The list of hosts for the user. |
| 186 * @return {void} Nothing. | 186 * @return {void} Nothing. |
| 187 * @private | 187 * @private |
| 188 */ | 188 */ |
| 189 remoting.HostList.prototype.onHostListResponse_ = function(onDone, hosts) { | 189 remoting.HostList.prototype.onHostListResponse_ = function(onDone, hosts) { |
| 190 this.lastError_ = ''; | 190 this.lastError_ = ''; |
| 191 this.hosts_ = hosts; | |
| 192 this.sortHosts_(); | |
| 193 this.save_(); | |
| 194 this.loadingIndicator_.classList.remove('loading'); | |
| 195 onDone(this.lastError_ == ''); | |
| 196 }; | |
| 197 | |
| 198 /** | |
| 199 * Sort the internal list of hosts. | |
| 200 * | |
| 201 * @suppress {reportUnknownTypes} | |
| 202 * @return {void} Nothing. | |
| 203 */ | |
| 204 remoting.HostList.prototype.sortHosts_ = function() { | |
|
garykac
2015/01/12 20:22:37
Moved into a separate function so that the @suppre
| |
| 191 /** | 205 /** |
| 192 * Sort hosts, first by ONLINE/OFFLINE status and then by host-name. | 206 * Sort hosts, first by ONLINE/OFFLINE status and then by host-name. |
| 193 * | 207 * |
| 194 * @param {remoting.Host} a | 208 * @param {remoting.Host} a |
| 195 * @param {remoting.Host} b | 209 * @param {remoting.Host} b |
| 210 * @return {number} | |
| 196 */ | 211 */ |
| 197 var cmp = function(a, b) { | 212 var cmp = function(a, b) { |
| 198 if (a.status < b.status) { | 213 if (a.status < b.status) { |
| 199 return 1; | 214 return 1; |
| 200 } else if (b.status < a.status) { | 215 } else if (b.status < a.status) { |
| 201 return -1; | 216 return -1; |
| 202 } else if (a.hostName.toLocaleLowerCase() < | 217 } else if (a.hostName.toLocaleLowerCase() < |
| 203 b.hostName.toLocaleLowerCase()) { | 218 b.hostName.toLocaleLowerCase()) { |
| 204 return -1; | 219 return -1; |
| 205 } else if (a.hostName.toLocaleLowerCase() > | 220 } else if (a.hostName.toLocaleLowerCase() > |
| 206 b.hostName.toLocaleLowerCase()) { | 221 b.hostName.toLocaleLowerCase()) { |
| 207 return 1; | 222 return 1; |
| 208 } | 223 } |
| 209 return 0; | 224 return 0; |
| 210 }; | 225 }; |
| 211 this.hosts_ = /** @type {Array.<remoting.Host>} */ hosts.sort(cmp); | 226 |
| 212 this.save_(); | 227 this.hosts_ = this.hosts_.sort(cmp); |
| 213 this.loadingIndicator_.classList.remove('loading'); | |
| 214 onDone(this.lastError_ == ''); | |
| 215 }; | 228 }; |
| 216 | 229 |
| 217 /** | 230 /** |
| 218 * Display the list of hosts or error condition. | 231 * Display the list of hosts or error condition. |
| 219 * | 232 * |
| 220 * @return {void} Nothing. | 233 * @return {void} Nothing. |
| 221 */ | 234 */ |
| 222 remoting.HostList.prototype.display = function() { | 235 remoting.HostList.prototype.display = function() { |
| 223 this.table_.innerText = ''; | 236 this.table_.innerText = ''; |
| 224 this.errorMsg_.innerText = ''; | 237 this.errorMsg_.innerText = ''; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 chrome.storage.local.set(items); | 464 chrome.storage.local.set(items); |
| 452 }; | 465 }; |
| 453 | 466 |
| 454 /** | 467 /** |
| 455 * Key name under which Me2Me hosts are cached. | 468 * Key name under which Me2Me hosts are cached. |
| 456 */ | 469 */ |
| 457 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 470 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
| 458 | 471 |
| 459 /** @type {remoting.HostList} */ | 472 /** @type {remoting.HostList} */ |
| 460 remoting.hostList = null; | 473 remoting.hostList = null; |
| OLD | NEW |