| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 * | 107 * |
| 108 * @param {function():void} onDone Completion callback. | 108 * @param {function():void} onDone Completion callback. |
| 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 = 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} */ cached; | 119 that.hosts_ = /** @type {Array} */ 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 }; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 * | 191 * |
| 192 * @param {function(boolean):void} onDone The callback passed to |refresh|. | 192 * @param {function(boolean):void} onDone The callback passed to |refresh|. |
| 193 * @param {XMLHttpRequest} xhr The XHR object for the host list request. | 193 * @param {XMLHttpRequest} xhr The XHR object for the host list request. |
| 194 * @return {void} Nothing. | 194 * @return {void} Nothing. |
| 195 * @private | 195 * @private |
| 196 */ | 196 */ |
| 197 remoting.HostList.prototype.parseHostListResponse_ = function(onDone, xhr) { | 197 remoting.HostList.prototype.parseHostListResponse_ = function(onDone, xhr) { |
| 198 this.lastError_ = ''; | 198 this.lastError_ = ''; |
| 199 try { | 199 try { |
| 200 if (xhr.status == 200) { | 200 if (xhr.status == 200) { |
| 201 var response = | 201 var response = /** @type {{data: {items: Array}}} */ |
| 202 /** @type {{data: {items: Array}}} */ jsonParseSafe(xhr.responseText); | 202 (base.jsonParseSafe(xhr.responseText)); |
| 203 if (response && response.data) { | 203 if (response && response.data) { |
| 204 if (response.data.items) { | 204 if (response.data.items) { |
| 205 this.hosts_ = response.data.items; | 205 this.hosts_ = response.data.items; |
| 206 /** | 206 /** |
| 207 * @param {remoting.Host} a | 207 * @param {remoting.Host} a |
| 208 * @param {remoting.Host} b | 208 * @param {remoting.Host} b |
| 209 */ | 209 */ |
| 210 var cmp = function(a, b) { | 210 var cmp = function(a, b) { |
| 211 if (a.status < b.status) { | 211 if (a.status < b.status) { |
| 212 return 1; | 212 return 1; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 }; | 490 }; |
| 491 | 491 |
| 492 /** | 492 /** |
| 493 * Called when the user clicks the button next to the error message. The action | 493 * Called when the user clicks the button next to the error message. The action |
| 494 * depends on the error. | 494 * depends on the error. |
| 495 * | 495 * |
| 496 * @private | 496 * @private |
| 497 */ | 497 */ |
| 498 remoting.HostList.prototype.onErrorClick_ = function() { | 498 remoting.HostList.prototype.onErrorClick_ = function() { |
| 499 if (this.lastError_ == remoting.Error.AUTHENTICATION_FAILED) { | 499 if (this.lastError_ == remoting.Error.AUTHENTICATION_FAILED) { |
| 500 remoting.oauth2.doAuthRedirect(); | 500 remoting.oauth2.doAuthRedirect(function() { |
| 501 window.location.reload(); |
| 502 }); |
| 501 } else { | 503 } else { |
| 502 this.refresh(remoting.updateLocalHostState); | 504 this.refresh(remoting.updateLocalHostState); |
| 503 } | 505 } |
| 504 }; | 506 }; |
| 505 | 507 |
| 506 /** | 508 /** |
| 507 * Save the host list to local storage. | 509 * Save the host list to local storage. |
| 508 */ | 510 */ |
| 509 remoting.HostList.prototype.save_ = function() { | 511 remoting.HostList.prototype.save_ = function() { |
| 510 var items = {}; | 512 var items = {}; |
| 511 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); | 513 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); |
| 512 chrome.storage.local.set(items); | 514 chrome.storage.local.set(items); |
| 513 }; | 515 }; |
| 514 | 516 |
| 515 /** | 517 /** |
| 516 * Key name under which Me2Me hosts are cached. | 518 * Key name under which Me2Me hosts are cached. |
| 517 */ | 519 */ |
| 518 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 520 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
| 519 | 521 |
| 520 /** @type {remoting.HostList} */ | 522 /** @type {remoting.HostList} */ |
| 521 remoting.hostList = null; | 523 remoting.hostList = null; |
| OLD | NEW |