Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: remoting/webapp/crd/js/host_controller.js

Issue 955283002: Converted remoting.Error from an enum to a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/webapp/crd/js/error.js ('k') | remoting/webapp/crd/js/host_daemon_facade.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'use strict'; 5 'use strict';
6 6
7 /** @suppress {duplicate} */ 7 /** @suppress {duplicate} */
8 var remoting = remoting || {}; 8 var remoting = remoting || {};
9 9
10 /** @constructor */ 10 /** @constructor */
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 /** 151 /**
152 * @param {string} hostName 152 * @param {string} hostName
153 * @param {string} publicKey 153 * @param {string} publicKey
154 * @param {remoting.HostController.AsyncResult} result 154 * @param {remoting.HostController.AsyncResult} result
155 */ 155 */
156 function onStarted(hostName, publicKey, result) { 156 function onStarted(hostName, publicKey, result) {
157 if (result == remoting.HostController.AsyncResult.OK) { 157 if (result == remoting.HostController.AsyncResult.OK) {
158 remoting.hostList.onLocalHostStarted(hostName, newHostId, publicKey); 158 remoting.hostList.onLocalHostStarted(hostName, newHostId, publicKey);
159 onDone(); 159 onDone();
160 } else if (result == remoting.HostController.AsyncResult.CANCELLED) { 160 } else if (result == remoting.HostController.AsyncResult.CANCELLED) {
161 onStartError(remoting.Error.CANCELLED); 161 onStartError(new remoting.Error(remoting.Error.Tag.CANCELLED));
162 } else { 162 } else {
163 onStartError(remoting.Error.UNEXPECTED); 163 onStartError(remoting.Error.unexpected());
164 } 164 }
165 } 165 }
166 166
167 /** 167 /**
168 * @param {string} hostName 168 * @param {string} hostName
169 * @param {string} publicKey 169 * @param {string} publicKey
170 * @param {string} privateKey 170 * @param {string} privateKey
171 * @param {?string} xmppLogin 171 * @param {?string} xmppLogin
172 * @param {?string} refreshToken 172 * @param {?string} refreshToken
173 * @param {?string} clientBaseJid 173 * @param {?string} clientBaseJid
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 that.hostDaemonFacade_.getPinHash( 255 that.hostDaemonFacade_.getPinHash(
256 newHostId, hostPin, startHostWithHash.bind( 256 newHostId, hostPin, startHostWithHash.bind(
257 null, hostName, publicKey, privateKey, 257 null, hostName, publicKey, privateKey,
258 email, remoting.oauth2.getRefreshToken(), email), 258 email, remoting.oauth2.getRefreshToken(), email),
259 onError); 259 onError);
260 }); 260 });
261 } 261 }
262 } else { 262 } else {
263 console.log('Failed to register the host. Status: ' + xhr.status + 263 console.log('Failed to register the host. Status: ' + xhr.status +
264 ' response: ' + xhr.responseText); 264 ' response: ' + xhr.responseText);
265 onError(remoting.Error.REGISTRATION_FAILED); 265 onError(new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED));
266 } 266 }
267 } 267 }
268 268
269 /** 269 /**
270 * @param {string} hostName 270 * @param {string} hostName
271 * @param {string} privateKey 271 * @param {string} privateKey
272 * @param {string} publicKey 272 * @param {string} publicKey
273 * @param {?string} hostClientId 273 * @param {?string} hostClientId
274 * @param {string} oauthToken 274 * @param {string} oauthToken
275 */ 275 */
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return; 367 return;
368 } 368 }
369 onDone(); 369 onDone();
370 } 370 }
371 371
372 /** @param {remoting.HostController.AsyncResult} result */ 372 /** @param {remoting.HostController.AsyncResult} result */
373 function onStopped(result) { 373 function onStopped(result) {
374 if (result == remoting.HostController.AsyncResult.OK) { 374 if (result == remoting.HostController.AsyncResult.OK) {
375 that.getLocalHostId(unregisterHost); 375 that.getLocalHostId(unregisterHost);
376 } else if (result == remoting.HostController.AsyncResult.CANCELLED) { 376 } else if (result == remoting.HostController.AsyncResult.CANCELLED) {
377 onError(remoting.Error.CANCELLED); 377 onError(new remoting.Error(remoting.Error.Tag.CANCELLED));
378 } else { 378 } else {
379 onError(remoting.Error.UNEXPECTED); 379 onError(remoting.Error.unexpected());
380 } 380 }
381 } 381 }
382 382
383 this.hostDaemonFacade_.stopDaemon(onStopped, onError); 383 this.hostDaemonFacade_.stopDaemon(onStopped, onError);
384 }; 384 };
385 385
386 /** 386 /**
387 * Check the host configuration is valid (non-null, and contains both host_id 387 * Check the host configuration is valid (non-null, and contains both host_id
388 * and xmpp_login keys). 388 * and xmpp_login keys).
389 * @param {Object} config The host configuration. 389 * @param {Object} config The host configuration.
(...skipping 14 matching lines...) Expand all
404 remoting.HostController.prototype.updatePin = function(newPin, onDone, 404 remoting.HostController.prototype.updatePin = function(newPin, onDone,
405 onError) { 405 onError) {
406 /** @type {remoting.HostController} */ 406 /** @type {remoting.HostController} */
407 var that = this; 407 var that = this;
408 408
409 /** @param {remoting.HostController.AsyncResult} result */ 409 /** @param {remoting.HostController.AsyncResult} result */
410 function onConfigUpdated(result) { 410 function onConfigUpdated(result) {
411 if (result == remoting.HostController.AsyncResult.OK) { 411 if (result == remoting.HostController.AsyncResult.OK) {
412 onDone(); 412 onDone();
413 } else if (result == remoting.HostController.AsyncResult.CANCELLED) { 413 } else if (result == remoting.HostController.AsyncResult.CANCELLED) {
414 onError(remoting.Error.CANCELLED); 414 onError(new remoting.Error(remoting.Error.Tag.CANCELLED));
415 } else { 415 } else {
416 onError(remoting.Error.UNEXPECTED); 416 onError(remoting.Error.unexpected());
417 } 417 }
418 } 418 }
419 419
420 /** @param {string} pinHash */ 420 /** @param {string} pinHash */
421 function updateDaemonConfigWithHash(pinHash) { 421 function updateDaemonConfigWithHash(pinHash) {
422 var newConfig = { 422 var newConfig = {
423 host_secret_hash: pinHash 423 host_secret_hash: pinHash
424 }; 424 };
425 that.hostDaemonFacade_.updateDaemonConfig(newConfig, onConfigUpdated, 425 that.hostDaemonFacade_.updateDaemonConfig(newConfig, onConfigUpdated,
426 onError); 426 onError);
427 } 427 }
428 428
429 /** @param {Object} config */ 429 /** @param {Object} config */
430 function onConfig(config) { 430 function onConfig(config) {
431 if (!isHostConfigValid_(config)) { 431 if (!isHostConfigValid_(config)) {
432 onError(remoting.Error.UNEXPECTED); 432 onError(remoting.Error.unexpected());
433 return; 433 return;
434 } 434 }
435 /** @type {string} */ 435 /** @type {string} */
436 var hostId = config['host_id']; 436 var hostId = config['host_id'];
437 that.hostDaemonFacade_.getPinHash( 437 that.hostDaemonFacade_.getPinHash(
438 hostId, newPin, updateDaemonConfigWithHash, onError); 438 hostId, newPin, updateDaemonConfigWithHash, onError);
439 } 439 }
440 440
441 // TODO(sergeyu): When crbug.com/121518 is fixed: replace this call 441 // TODO(sergeyu): When crbug.com/121518 is fixed: replace this call
442 // with an unprivileged version if that is necessary. 442 // with an unprivileged version if that is necessary.
443 this.hostDaemonFacade_.getDaemonConfig(onConfig, onError); 443 this.hostDaemonFacade_.getDaemonConfig(onConfig, onError);
444 }; 444 };
445 445
446 /** 446 /**
447 * Get the state of the local host. 447 * Get the state of the local host.
448 * 448 *
449 * @param {function(remoting.HostController.State):void} onDone Completion 449 * @param {function(remoting.HostController.State):void} onDone Completion
450 * callback. 450 * callback.
451 */ 451 */
452 remoting.HostController.prototype.getLocalHostState = function(onDone) { 452 remoting.HostController.prototype.getLocalHostState = function(onDone) {
453 /** @param {!remoting.Error} error */ 453 /** @param {!remoting.Error} error */
454 function onError(error) { 454 function onError(error) {
455 onDone((error.tag == remoting.Error.Tag.MISSING_PLUGIN) ? 455 onDone((error.hasTag(remoting.Error.Tag.MISSING_PLUGIN)) ?
456 remoting.HostController.State.NOT_INSTALLED : 456 remoting.HostController.State.NOT_INSTALLED :
457 remoting.HostController.State.UNKNOWN); 457 remoting.HostController.State.UNKNOWN);
458 } 458 }
459 this.hostDaemonFacade_.getDaemonState(onDone, onError); 459 this.hostDaemonFacade_.getDaemonState(onDone, onError);
460 }; 460 };
461 461
462 /** 462 /**
463 * Get the id of the local host, or null if it is not registered. 463 * Get the id of the local host, or null if it is not registered.
464 * 464 *
465 * @param {function(string?):void} onDone Completion callback. 465 * @param {function(string?):void} onDone Completion callback.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 signalStrategy.connect( 569 signalStrategy.connect(
570 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); 570 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token);
571 } 571 }
572 572
573 remoting.identity.getToken().then( 573 remoting.identity.getToken().then(
574 connectSignalingWithToken, remoting.Error.handler(onError)); 574 connectSignalingWithToken, remoting.Error.handler(onError));
575 }; 575 };
576 576
577 /** @type {remoting.HostController} */ 577 /** @type {remoting.HostController} */
578 remoting.hostController = null; 578 remoting.hostController = null;
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/error.js ('k') | remoting/webapp/crd/js/host_daemon_facade.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698