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 var that = this; | 109 var that = this; |
| 110 /** @param {string} token The OAuth2 token. */ | 110 /** @param {string} token The OAuth2 token. */ |
| 111 var getHosts = function(token) { | 111 var getHosts = function(token) { |
| 112 var headers = { 'Authorization': 'OAuth ' + token }; | 112 var headers = { 'Authorization': 'OAuth ' + token }; |
| 113 remoting.xhr.get( | 113 remoting.xhr.get( |
| 114 'https://www.googleapis.com/chromoting/v1/@me/hosts', | 114 'https://www.googleapis.com/chromoting/v1/@me/hosts', |
| 115 parseHostListResponse, '', headers); | 115 parseHostListResponse, '', headers); |
| 116 }; | 116 }; |
| 117 /** @param {remoting.Error} error */ | 117 /** @param {remoting.Error} error */ |
| 118 var onError = function(error) { | 118 var onError = function(error) { |
| 119 that.hosts_ = []; | |
| 119 that.lastError_ = error; | 120 that.lastError_ = error; |
| 120 onDone(false); | 121 onDone(false); |
| 121 }; | 122 }; |
| 122 this.hosts_ = []; | |
| 123 this.lastError_ = ''; | |
|
Wez
2012/07/11 20:48:10
Are you relying on the fact that lastError_ will o
Jamie
2012/07/11 20:53:11
No, I think your next comment is correct, and I sh
| |
| 124 remoting.oauth2.callWithToken(getHosts, onError); | 123 remoting.oauth2.callWithToken(getHosts, onError); |
| 125 }; | 124 }; |
| 126 | 125 |
| 127 /** | 126 /** |
| 128 * Handle the results of the host list request. A success response will | 127 * Handle the results of the host list request. A success response will |
| 129 * include a JSON-encoded list of host descriptions, which we display if we're | 128 * include a JSON-encoded list of host descriptions, which we display if we're |
| 130 * able to successfully parse it. | 129 * able to successfully parse it. |
| 131 * | 130 * |
| 132 * @param {function(boolean):void} onDone The callback passed to |refresh|. | 131 * @param {function(boolean):void} onDone The callback passed to |refresh|. |
| 133 * @param {XMLHttpRequest} xhr The XHR object for the host list request. | 132 * @param {XMLHttpRequest} xhr The XHR object for the host list request. |
| 134 * @return {void} Nothing. | 133 * @return {void} Nothing. |
| 135 * @private | 134 * @private |
| 136 */ | 135 */ |
| 137 remoting.HostList.prototype.parseHostListResponse_ = function(onDone, xhr) { | 136 remoting.HostList.prototype.parseHostListResponse_ = function(onDone, xhr) { |
| 137 this.hosts_ = []; | |
|
Wez
2012/07/11 20:48:10
I think you need to clear lastError_ here to avoid
Jamie
2012/07/11 20:53:11
Done.
| |
| 138 try { | 138 try { |
| 139 if (xhr.status == 200) { | 139 if (xhr.status == 200) { |
| 140 var response = | 140 var response = |
| 141 /** @type {{data: {items: Array}}} */ jsonParseSafe(xhr.responseText); | 141 /** @type {{data: {items: Array}}} */ jsonParseSafe(xhr.responseText); |
| 142 if (response && response.data) { | 142 if (response && response.data) { |
| 143 if (response.data.items) { | 143 if (response.data.items) { |
| 144 this.hosts_ = response.data.items; | 144 this.hosts_ = response.data.items; |
| 145 /** | 145 /** |
| 146 * @param {remoting.Host} a | 146 * @param {remoting.Host} a |
| 147 * @param {remoting.Host} b | 147 * @param {remoting.Host} b |
| 148 */ | 148 */ |
| 149 var cmp = function(a, b) { | 149 var cmp = function(a, b) { |
| 150 if (a.status < b.status) { | 150 if (a.status < b.status) { |
| 151 return 1; | 151 return 1; |
| 152 } else if (b.status < a.status) { | 152 } else if (b.status < a.status) { |
| 153 return -1; | 153 return -1; |
| 154 } | 154 } |
| 155 return 0; | 155 return 0; |
| 156 }; | 156 }; |
| 157 this.hosts_ = /** @type {Array} */ this.hosts_.sort(cmp); | 157 this.hosts_ = /** @type {Array} */ this.hosts_.sort(cmp); |
| 158 } else { | |
| 159 this.hosts_ = []; | |
| 160 } | 158 } |
| 161 } else { | 159 } else { |
| 160 this.lastError_ = remoting.Error.UNEXPECTED; | |
| 162 console.error('Invalid "hosts" response from server.'); | 161 console.error('Invalid "hosts" response from server.'); |
| 163 } | 162 } |
| 164 } else { | 163 } else { |
| 165 // Some other error. | 164 // Some other error. |
| 166 console.error('Bad status on host list query: ', xhr); | 165 console.error('Bad status on host list query: ', xhr); |
| 167 if (xhr.status == 401) { | 166 if (xhr.status == 401) { |
| 168 this.lastError_ = remoting.Error.AUTHENTICATION_FAILED; | 167 this.lastError_ = remoting.Error.AUTHENTICATION_FAILED; |
| 169 } else if (xhr.status == 503) { | 168 } else if (xhr.status == 503) { |
| 170 this.lastError_ = remoting.Error.SERVICE_UNAVAILABLE; | 169 this.lastError_ = remoting.Error.SERVICE_UNAVAILABLE; |
| 171 } else { | 170 } else { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 } | 326 } |
| 328 } | 327 } |
| 329 | 328 |
| 330 /** | 329 /** |
| 331 * Key name under which Me2Me hosts are cached. | 330 * Key name under which Me2Me hosts are cached. |
| 332 */ | 331 */ |
| 333 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 332 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
| 334 | 333 |
| 335 /** @type {remoting.HostList} */ | 334 /** @type {remoting.HostList} */ |
| 336 remoting.hostList = null; | 335 remoting.hostList = null; |
| OLD | NEW |