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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 'hostId': hostId, | 60 'hostId': hostId, |
61 'hostName': hostName, | 61 'hostName': hostName, |
62 'publicKey': hostPublicKey | 62 'publicKey': hostPublicKey |
63 } | 63 } |
64 }; | 64 }; |
65 new remoting.Xhr({ | 65 new remoting.Xhr({ |
66 method: 'PUT', | 66 method: 'PUT', |
67 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, | 67 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, |
68 jsonContent: newHostDetails, | 68 jsonContent: newHostDetails, |
69 oauthToken: token | 69 oauthToken: token |
70 }).start().then(remoting.Xhr.defaultResponse(onDone, onError)); | 70 }).start().then(remoting.HostListApiImpl.defaultResponse_(onDone, onError)); |
71 }; | 71 }; |
72 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); | 72 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); |
Jamie
2015/03/24 19:44:11
Why have you reverted the useIdentity change as we
John Williams
2015/03/24 23:34:41
Accident.
| |
73 }; | 73 }; |
74 | 74 |
75 /** | 75 /** |
76 * Delete a host. | 76 * Delete a host. |
77 * | 77 * |
78 * @param {function():void} onDone | 78 * @param {function():void} onDone |
79 * @param {function(!remoting.Error):void} onError | 79 * @param {function(!remoting.Error):void} onError |
80 * @param {string} hostId | 80 * @param {string} hostId |
81 */ | 81 */ |
82 remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) { | 82 remoting.HostListApiImpl.prototype.remove = function(hostId, onDone, onError) { |
83 /** @param {string} token */ | 83 /** @param {string} token */ |
84 var onToken = function(token) { | 84 var onToken = function(token) { |
85 new remoting.Xhr({ | 85 new remoting.Xhr({ |
86 method: 'DELETE', | 86 method: 'DELETE', |
87 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, | 87 url: remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId, |
88 oauthToken: token | 88 oauthToken: token |
89 }).start().then(remoting.Xhr.defaultResponse( | 89 }).start().then(remoting.HostListApiImpl.defaultResponse_( |
90 onDone, onError, [remoting.Error.Tag.NOT_FOUND])); | 90 onDone, onError, [remoting.Error.Tag.NOT_FOUND])); |
91 }; | 91 }; |
92 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); | 92 remoting.identity.getToken().then(onToken, remoting.Error.handler(onError)); |
93 }; | 93 }; |
94 | 94 |
95 /** | 95 /** |
96 * Handle the results of the host list request. A success response will | 96 * Handle the results of the host list request. A success response will |
97 * include a JSON-encoded list of host descriptions, which is parsed and | 97 * include a JSON-encoded list of host descriptions, which is parsed and |
98 * passed to the callback. | 98 * passed to the callback. |
99 * | 99 * |
(...skipping 28 matching lines...) Expand all Loading... | |
128 base.getStringAttr(item, 'hostOfflineReason', ''); | 128 base.getStringAttr(item, 'hostOfflineReason', ''); |
129 return host; | 129 return host; |
130 }); | 130 }); |
131 onDone(hosts); | 131 onDone(hosts); |
132 } | 132 } |
133 } else { | 133 } else { |
134 onError(remoting.Error.fromHttpStatus(response.status)); | 134 onError(remoting.Error.fromHttpStatus(response.status)); |
135 } | 135 } |
136 }; | 136 }; |
137 | 137 |
138 /** | |
139 * Generic success/failure response proxy. | |
140 * | |
141 * @param {function():void} onDone | |
142 * @param {function(!remoting.Error):void} onError | |
143 * @param {Array<remoting.Error.Tag>=} opt_ignoreErrors | |
144 * @return {function(!remoting.Xhr.Response):void} | |
145 * @private | |
146 */ | |
147 remoting.HostListApiImpl.defaultResponse_ = function( | |
148 onDone, onError, opt_ignoreErrors) { | |
149 /** @param {!remoting.Xhr.Response} response */ | |
150 var result = function(response) { | |
151 var error = remoting.Error.fromHttpStatus(response.status); | |
152 if (error.isNone()) { | |
153 onDone(); | |
154 return; | |
155 } | |
156 | |
157 if (opt_ignoreErrors && error.hasTag.apply(error, opt_ignoreErrors)) { | |
158 onDone(); | |
159 return; | |
160 } | |
161 | |
162 onError(error); | |
163 }; | |
164 return result; | |
165 }; | |
166 | |
138 /** @type {remoting.HostListApi} */ | 167 /** @type {remoting.HostListApi} */ |
139 remoting.hostListApi = new remoting.HostListApiImpl(); | 168 remoting.hostListApi = new remoting.HostListApiImpl(); |
140 | 169 |
141 })(); | 170 })(); |
OLD | NEW |