| 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 'use strict'; | 10 'use strict'; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 remoting.HostListApiImpl.prototype.get = function(onDone, onError) { | 28 remoting.HostListApiImpl.prototype.get = function(onDone, onError) { |
| 29 /** @type {function(XMLHttpRequest):void} */ | 29 /** @type {function(XMLHttpRequest):void} */ |
| 30 var parseHostListResponse = | 30 var parseHostListResponse = |
| 31 this.parseHostListResponse_.bind(this, onDone, onError) | 31 this.parseHostListResponse_.bind(this, onDone, onError) |
| 32 /** @param {string} token */ | 32 /** @param {string} token */ |
| 33 var onToken = function(token) { | 33 var onToken = function(token) { |
| 34 var headers = { 'Authorization': 'OAuth ' + token }; | 34 var headers = { 'Authorization': 'OAuth ' + token }; |
| 35 remoting.xhr.get(remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', | 35 remoting.xhr.get(remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', |
| 36 parseHostListResponse, '', headers); | 36 parseHostListResponse, '', headers); |
| 37 }; | 37 }; |
| 38 remoting.identity.callWithToken(onToken, onError); | 38 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Update the information for a host. | 42 * Update the information for a host. |
| 43 * | 43 * |
| 44 * @param {function():void} onDone | 44 * @param {function():void} onDone |
| 45 * @param {function(remoting.Error):void} onError | 45 * @param {function(remoting.Error):void} onError |
| 46 * @param {string} hostId | 46 * @param {string} hostId |
| 47 * @param {string} hostName | 47 * @param {string} hostName |
| 48 * @param {string} hostPublicKey | 48 * @param {string} hostPublicKey |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 'hostName': hostName, | 61 'hostName': hostName, |
| 62 'publicKey': hostPublicKey | 62 'publicKey': hostPublicKey |
| 63 } | 63 } |
| 64 }; | 64 }; |
| 65 remoting.xhr.put( | 65 remoting.xhr.put( |
| 66 remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, | 66 remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, |
| 67 remoting.xhr.defaultResponse(onDone, onError), | 67 remoting.xhr.defaultResponse(onDone, onError), |
| 68 JSON.stringify(newHostDetails), | 68 JSON.stringify(newHostDetails), |
| 69 headers); | 69 headers); |
| 70 }; | 70 }; |
| 71 remoting.identity.callWithToken(onToken, onError); | 71 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Delete a host. | 75 * Delete a host. |
| 76 * | 76 * |
| 77 * @param {function():void} onDone | 77 * @param {function():void} onDone |
| 78 * @param {function(remoting.Error):void} onError | 78 * @param {function(remoting.Error):void} onError |
| 79 * @param {string} hostId | 79 * @param {string} hostId |
| 80 */ | 80 */ |
| 81 remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) { | 81 remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) { |
| 82 /** @param {string} token */ | 82 /** @param {string} token */ |
| 83 var onToken = function(token) { | 83 var onToken = function(token) { |
| 84 var headers = { 'Authorization': 'OAuth ' + token }; | 84 var headers = { 'Authorization': 'OAuth ' + token }; |
| 85 remoting.xhr.remove( | 85 remoting.xhr.remove( |
| 86 remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, | 86 remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, |
| 87 remoting.xhr.defaultResponse(onDone, onError), | 87 remoting.xhr.defaultResponse(onDone, onError), |
| 88 '', headers); | 88 '', headers); |
| 89 }; | 89 }; |
| 90 remoting.identity.callWithToken(onToken, onError); | 90 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Handle the results of the host list request. A success response will | 94 * Handle the results of the host list request. A success response will |
| 95 * include a JSON-encoded list of host descriptions, which is parsed and | 95 * include a JSON-encoded list of host descriptions, which is parsed and |
| 96 * passed to the callback. | 96 * passed to the callback. |
| 97 * | 97 * |
| 98 * @param {function(Array.<remoting.Host>):void} onDone | 98 * @param {function(Array.<remoting.Host>):void} onDone |
| 99 * @param {function(remoting.Error):void} onError | 99 * @param {function(remoting.Error):void} onError |
| 100 * @param {XMLHttpRequest} xhr | 100 * @param {XMLHttpRequest} xhr |
| (...skipping 11 matching lines...) Expand all Loading... |
| 112 var hosts = response.data.items || []; | 112 var hosts = response.data.items || []; |
| 113 onDone(hosts); | 113 onDone(hosts); |
| 114 } | 114 } |
| 115 } else { | 115 } else { |
| 116 onError(remoting.Error.fromHttpStatus(xhr.status)); | 116 onError(remoting.Error.fromHttpStatus(xhr.status)); |
| 117 } | 117 } |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 /** @type {remoting.HostListApi} */ | 120 /** @type {remoting.HostListApi} */ |
| 121 remoting.hostListApi = new remoting.HostListApiImpl(); | 121 remoting.hostListApi = new remoting.HostListApiImpl(); |
| OLD | NEW |