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

Side by Side Diff: remoting/webapp/crd/js/host_daemon_facade.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: Requested changes. 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
OLDNEW
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 * Class to communicate with the host daemon via Native Messaging. 7 * Class to communicate with the host daemon via Native Messaging.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 30 matching lines...) Expand all
41 this.afterInitializationTasks_ = []; 41 this.afterInitializationTasks_ = [];
42 42
43 /** 43 /**
44 * A promise that fulfills when the daemon finishes initializing. 44 * A promise that fulfills when the daemon finishes initializing.
45 * It will be set to null when the promise fulfills. 45 * It will be set to null when the promise fulfills.
46 * @type {Promise} 46 * @type {Promise}
47 * @private 47 * @private
48 */ 48 */
49 this.initializingPromise_ = null; 49 this.initializingPromise_ = null;
50 50
51 /** @type {remoting.Error} @private */ 51 /** @type {!remoting.Error} @private */
52 this.error_ = remoting.Error.NONE; 52 this.error_ = remoting.Error.NONE;
53 53
54 /** @private */ 54 /** @private */
55 this.onIncomingMessageCallback_ = this.onIncomingMessage_.bind(this); 55 this.onIncomingMessageCallback_ = this.onIncomingMessage_.bind(this);
56 56
57 /** @private */ 57 /** @private */
58 this.onDisconnectCallback_ = this.onDisconnect_.bind(this); 58 this.onDisconnectCallback_ = this.onDisconnect_.bind(this);
59 59
60 this.initialize_(); 60 this.initialize_();
61 }; 61 };
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 return new Promise(connect.bind(this)); 112 return new Promise(connect.bind(this));
113 }; 113 };
114 114
115 /** 115 /**
116 * Type used for entries of |pendingReplies_| list. 116 * Type used for entries of |pendingReplies_| list.
117 * 117 *
118 * @param {string} type Type of the originating request. 118 * @param {string} type Type of the originating request.
119 * @param {function(...):void} onDone Response callback. Parameters depend on 119 * @param {function(...):void} onDone Response callback. Parameters depend on
120 * the request type. 120 * the request type.
121 * @param {function(remoting.Error):void} onError Callback to call on error. 121 * @param {function(!remoting.Error):void} onError Callback to call on error.
122 * @constructor 122 * @constructor
123 */ 123 */
124 remoting.HostDaemonFacade.PendingReply = function(type, onDone, onError) { 124 remoting.HostDaemonFacade.PendingReply = function(type, onDone, onError) {
125 this.type = type; 125 this.type = type;
126 this.onDone = onDone; 126 this.onDone = onDone;
127 this.onError = onError; 127 this.onError = onError;
128 }; 128 };
129 129
130 /** 130 /**
131 * @param {remoting.HostController.Feature} feature The feature to test for. 131 * @param {remoting.HostController.Feature} feature The feature to test for.
132 * @param {function(boolean):void} onDone Callback to return result. 132 * @param {function(boolean):void} onDone Callback to return result.
133 * @return {boolean} True if the implementation supports the named feature. 133 * @return {boolean} True if the implementation supports the named feature.
134 */ 134 */
135 remoting.HostDaemonFacade.prototype.hasFeature = function(feature, onDone) { 135 remoting.HostDaemonFacade.prototype.hasFeature = function(feature, onDone) {
136 /** @type {remoting.HostDaemonFacade} */ 136 /** @type {remoting.HostDaemonFacade} */
137 var that = this; 137 var that = this;
138 this.initialize_().then(function() { 138 this.initialize_().then(function() {
139 onDone(that.supportedFeatures_.indexOf(feature) >= 0); 139 onDone(that.supportedFeatures_.indexOf(feature) >= 0);
140 }, function (){ 140 }, function (){
141 onDone(false); 141 onDone(false);
142 }); 142 });
143 }; 143 };
144 144
145 /** 145 /**
146 * Initializes that the Daemon if necessary and posts the supplied message. 146 * Initializes that the Daemon if necessary and posts the supplied message.
147 * 147 *
148 * @param {{type: string}} message The message to post. 148 * @param {{type: string}} message The message to post.
149 * @param {function(...):void} onDone The callback, if any, to be triggered 149 * @param {function(...):void} onDone The callback, if any, to be triggered
150 * on response. 150 * on response.
151 * @param {function(remoting.Error):void} onError Callback to call on error. 151 * @param {function(!remoting.Error):void} onError Callback to call on error.
152 * @private 152 * @private
153 */ 153 */
154 remoting.HostDaemonFacade.prototype.postMessage_ = 154 remoting.HostDaemonFacade.prototype.postMessage_ =
155 function(message, onDone, onError) { 155 function(message, onDone, onError) {
156 /** @type {remoting.HostDaemonFacade} */ 156 /** @type {remoting.HostDaemonFacade} */
157 var that = this; 157 var that = this;
158 this.initialize_().then(function() { 158 this.initialize_().then(function() {
159 that.postMessageInternal_(message, onDone, onError); 159 that.postMessageInternal_(message, onDone, onError);
160 }, function() { 160 }, function() {
161 onError(that.error_); 161 onError(that.error_);
162 }); 162 });
163 }; 163 };
164 164
165 /** 165 /**
166 * Attaches a new ID to the supplied message, and posts it to the Native 166 * Attaches a new ID to the supplied message, and posts it to the Native
167 * Messaging port, adding |onDone| to the list of pending replies. 167 * Messaging port, adding |onDone| to the list of pending replies.
168 * |message| should have its 'type' field set, and any other fields set 168 * |message| should have its 'type' field set, and any other fields set
169 * depending on the message type. 169 * depending on the message type.
170 * 170 *
171 * @param {{type: string}} message The message to post. 171 * @param {{type: string}} message The message to post.
172 * @param {function(...):void} onDone The callback, if any, to be triggered 172 * @param {function(...):void} onDone The callback, if any, to be triggered
173 * on response. 173 * on response.
174 * @param {function(remoting.Error):void} onError Callback to call on error. 174 * @param {function(!remoting.Error):void} onError Callback to call on error.
175 * @return {void} Nothing. 175 * @return {void} Nothing.
176 * @private 176 * @private
177 */ 177 */
178 remoting.HostDaemonFacade.prototype.postMessageInternal_ = 178 remoting.HostDaemonFacade.prototype.postMessageInternal_ =
179 function(message, onDone, onError) { 179 function(message, onDone, onError) {
180 var id = this.nextId_++; 180 var id = this.nextId_++;
181 message['id'] = id; 181 message['id'] = id;
182 this.pendingReplies_[id] = new remoting.HostDaemonFacade.PendingReply( 182 this.pendingReplies_[id] = new remoting.HostDaemonFacade.PendingReply(
183 message.type + 'Response', onDone, onError); 183 message.type + 'Response', onDone, onError);
184 this.port_.postMessage(message); 184 this.port_.postMessage(message);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 for (var id in pendingReplies) { 340 for (var id in pendingReplies) {
341 var num_id = parseInt(id, 10); 341 var num_id = parseInt(id, 10);
342 pendingReplies[num_id].onError(this.error_); 342 pendingReplies[num_id].onError(this.error_);
343 } 343 }
344 } 344 }
345 345
346 /** 346 /**
347 * Gets local hostname. 347 * Gets local hostname.
348 * 348 *
349 * @param {function(string):void} onDone Callback to return result. 349 * @param {function(string):void} onDone Callback to return result.
350 * @param {function(remoting.Error):void} onError Callback to call on error. 350 * @param {function(!remoting.Error):void} onError Callback to call on error.
351 * @return {void} Nothing. 351 * @return {void} Nothing.
352 */ 352 */
353 remoting.HostDaemonFacade.prototype.getHostName = 353 remoting.HostDaemonFacade.prototype.getHostName =
354 function(onDone, onError) { 354 function(onDone, onError) {
355 this.postMessage_({type: 'getHostName'}, onDone, onError); 355 this.postMessage_({type: 'getHostName'}, onDone, onError);
356 }; 356 };
357 357
358 /** 358 /**
359 * Calculates PIN hash value to be stored in the config, passing the resulting 359 * Calculates PIN hash value to be stored in the config, passing the resulting
360 * hash value base64-encoded to the callback. 360 * hash value base64-encoded to the callback.
361 * 361 *
362 * @param {string} hostId The host ID. 362 * @param {string} hostId The host ID.
363 * @param {string} pin The PIN. 363 * @param {string} pin The PIN.
364 * @param {function(string):void} onDone Callback to return result. 364 * @param {function(string):void} onDone Callback to return result.
365 * @param {function(remoting.Error):void} onError Callback to call on error. 365 * @param {function(!remoting.Error):void} onError Callback to call on error.
366 * @return {void} Nothing. 366 * @return {void} Nothing.
367 */ 367 */
368 remoting.HostDaemonFacade.prototype.getPinHash = 368 remoting.HostDaemonFacade.prototype.getPinHash =
369 function(hostId, pin, onDone, onError) { 369 function(hostId, pin, onDone, onError) {
370 this.postMessage_({ 370 this.postMessage_({
371 type: 'getPinHash', 371 type: 'getPinHash',
372 hostId: hostId, 372 hostId: hostId,
373 pin: pin 373 pin: pin
374 }, onDone, onError); 374 }, onDone, onError);
375 }; 375 };
376 376
377 /** 377 /**
378 * Generates new key pair to use for the host. The specified callback is called 378 * Generates new key pair to use for the host. The specified callback is called
379 * when the key is generated. The key is returned in format understood by the 379 * when the key is generated. The key is returned in format understood by the
380 * host (PublicKeyInfo structure encoded with ASN.1 DER, and then BASE64). 380 * host (PublicKeyInfo structure encoded with ASN.1 DER, and then BASE64).
381 * 381 *
382 * @param {function(string, string):void} onDone Callback to return result. 382 * @param {function(string, string):void} onDone Callback to return result.
383 * @param {function(remoting.Error):void} onError Callback to call on error. 383 * @param {function(!remoting.Error):void} onError Callback to call on error.
384 * @return {void} Nothing. 384 * @return {void} Nothing.
385 */ 385 */
386 remoting.HostDaemonFacade.prototype.generateKeyPair = 386 remoting.HostDaemonFacade.prototype.generateKeyPair =
387 function(onDone, onError) { 387 function(onDone, onError) {
388 this.postMessage_({type: 'generateKeyPair'}, onDone, onError); 388 this.postMessage_({type: 'generateKeyPair'}, onDone, onError);
389 }; 389 };
390 390
391 /** 391 /**
392 * Updates host config with the values specified in |config|. All 392 * Updates host config with the values specified in |config|. All
393 * fields that are not specified in |config| remain 393 * fields that are not specified in |config| remain
394 * unchanged. Following parameters cannot be changed using this 394 * unchanged. Following parameters cannot be changed using this
395 * function: host_id, xmpp_login. Error is returned if |config| 395 * function: host_id, xmpp_login. Error is returned if |config|
396 * includes these parameters. Changes take effect before the callback 396 * includes these parameters. Changes take effect before the callback
397 * is called. 397 * is called.
398 * 398 *
399 * @param {Object} config The new config parameters. 399 * @param {Object} config The new config parameters.
400 * @param {function(remoting.HostController.AsyncResult):void} onDone 400 * @param {function(remoting.HostController.AsyncResult):void} onDone
401 * Callback to be called when finished. 401 * Callback to be called when finished.
402 * @param {function(remoting.Error):void} onError Callback to call on error. 402 * @param {function(!remoting.Error):void} onError Callback to call on error.
403 * @return {void} Nothing. 403 * @return {void} Nothing.
404 */ 404 */
405 remoting.HostDaemonFacade.prototype.updateDaemonConfig = 405 remoting.HostDaemonFacade.prototype.updateDaemonConfig =
406 function(config, onDone, onError) { 406 function(config, onDone, onError) {
407 this.postMessage_({ 407 this.postMessage_({
408 type: 'updateDaemonConfig', 408 type: 'updateDaemonConfig',
409 config: config 409 config: config
410 }, onDone, onError); 410 }, onDone, onError);
411 }; 411 };
412 412
413 /** 413 /**
414 * Loads daemon config. The config is passed as a JSON formatted string to the 414 * Loads daemon config. The config is passed as a JSON formatted string to the
415 * callback. 415 * callback.
416 * 416 *
417 * @param {function(Object):void} onDone Callback to return result. 417 * @param {function(Object):void} onDone Callback to return result.
418 * @param {function(remoting.Error):void} onError Callback to call on error. 418 * @param {function(!remoting.Error):void} onError Callback to call on error.
419 * @return {void} Nothing. 419 * @return {void} Nothing.
420 */ 420 */
421 remoting.HostDaemonFacade.prototype.getDaemonConfig = 421 remoting.HostDaemonFacade.prototype.getDaemonConfig =
422 function(onDone, onError) { 422 function(onDone, onError) {
423 this.postMessage_({type: 'getDaemonConfig'}, onDone, onError); 423 this.postMessage_({type: 'getDaemonConfig'}, onDone, onError);
424 }; 424 };
425 425
426 /** 426 /**
427 * Retrieves daemon version. The version is passed to onDone as a dotted decimal 427 * Retrieves daemon version. The version is passed to onDone as a dotted decimal
428 * string of the form major.minor.build.patch. 428 * string of the form major.minor.build.patch.
429 * 429 *
430 * @param {function(string):void} onDone Callback to be called to return result. 430 * @param {function(string):void} onDone Callback to be called to return result.
431 * @param {function(remoting.Error):void} onError Callback to call on error. 431 * @param {function(!remoting.Error):void} onError Callback to call on error.
432 * @return {void} 432 * @return {void}
433 */ 433 */
434 remoting.HostDaemonFacade.prototype.getDaemonVersion = 434 remoting.HostDaemonFacade.prototype.getDaemonVersion =
435 function(onDone, onError) { 435 function(onDone, onError) {
436 /** @type {remoting.HostDaemonFacade} */ 436 /** @type {remoting.HostDaemonFacade} */
437 var that = this; 437 var that = this;
438 this.initialize_().then(function() { 438 this.initialize_().then(function() {
439 onDone(that.version_); 439 onDone(that.version_);
440 }, function() { 440 }, function() {
441 onError(that.error_); 441 onError(that.error_);
442 }); 442 });
443 }; 443 };
444 444
445 /** 445 /**
446 * Get the user's consent to crash reporting. The consent flags are passed to 446 * Get the user's consent to crash reporting. The consent flags are passed to
447 * the callback as booleans: supported, allowed, set-by-policy. 447 * the callback as booleans: supported, allowed, set-by-policy.
448 * 448 *
449 * @param {function(boolean, boolean, boolean):void} onDone Callback to return 449 * @param {function(boolean, boolean, boolean):void} onDone Callback to return
450 * result. 450 * result.
451 * @param {function(remoting.Error):void} onError Callback to call on error. 451 * @param {function(!remoting.Error):void} onError Callback to call on error.
452 * @return {void} Nothing. 452 * @return {void} Nothing.
453 */ 453 */
454 remoting.HostDaemonFacade.prototype.getUsageStatsConsent = 454 remoting.HostDaemonFacade.prototype.getUsageStatsConsent =
455 function(onDone, onError) { 455 function(onDone, onError) {
456 this.postMessage_({type: 'getUsageStatsConsent'}, onDone, onError); 456 this.postMessage_({type: 'getUsageStatsConsent'}, onDone, onError);
457 }; 457 };
458 458
459 /** 459 /**
460 * Starts the daemon process with the specified configuration. 460 * Starts the daemon process with the specified configuration.
461 * 461 *
462 * @param {Object} config Host configuration. 462 * @param {Object} config Host configuration.
463 * @param {boolean} consent Consent to report crash dumps. 463 * @param {boolean} consent Consent to report crash dumps.
464 * @param {function(remoting.HostController.AsyncResult):void} onDone 464 * @param {function(remoting.HostController.AsyncResult):void} onDone
465 * Callback to return result. 465 * Callback to return result.
466 * @param {function(remoting.Error):void} onError Callback to call on error. 466 * @param {function(!remoting.Error):void} onError Callback to call on error.
467 * @return {void} Nothing. 467 * @return {void} Nothing.
468 */ 468 */
469 remoting.HostDaemonFacade.prototype.startDaemon = 469 remoting.HostDaemonFacade.prototype.startDaemon =
470 function(config, consent, onDone, onError) { 470 function(config, consent, onDone, onError) {
471 this.postMessage_({ 471 this.postMessage_({
472 type: 'startDaemon', 472 type: 'startDaemon',
473 config: config, 473 config: config,
474 consent: consent 474 consent: consent
475 }, onDone, onError); 475 }, onDone, onError);
476 }; 476 };
477 477
478 /** 478 /**
479 * Stops the daemon process. 479 * Stops the daemon process.
480 * 480 *
481 * @param {function(remoting.HostController.AsyncResult):void} onDone 481 * @param {function(remoting.HostController.AsyncResult):void} onDone
482 * Callback to return result. 482 * Callback to return result.
483 * @param {function(remoting.Error):void} onError Callback to call on error. 483 * @param {function(!remoting.Error):void} onError Callback to call on error.
484 * @return {void} Nothing. 484 * @return {void} Nothing.
485 */ 485 */
486 remoting.HostDaemonFacade.prototype.stopDaemon = 486 remoting.HostDaemonFacade.prototype.stopDaemon =
487 function(onDone, onError) { 487 function(onDone, onError) {
488 this.postMessage_({type: 'stopDaemon'}, onDone, onError); 488 this.postMessage_({type: 'stopDaemon'}, onDone, onError);
489 }; 489 };
490 490
491 /** 491 /**
492 * Gets the installed/running state of the Host process. 492 * Gets the installed/running state of the Host process.
493 * 493 *
494 * @param {function(remoting.HostController.State):void} onDone Callback to 494 * @param {function(remoting.HostController.State):void} onDone Callback to
495 * return result. 495 * return result.
496 * @param {function(remoting.Error):void} onError Callback to call on error. 496 * @param {function(!remoting.Error):void} onError Callback to call on error.
497 * @return {void} Nothing. 497 * @return {void} Nothing.
498 */ 498 */
499 remoting.HostDaemonFacade.prototype.getDaemonState = 499 remoting.HostDaemonFacade.prototype.getDaemonState =
500 function(onDone, onError) { 500 function(onDone, onError) {
501 this.postMessage_({type: 'getDaemonState'}, onDone, onError); 501 this.postMessage_({type: 'getDaemonState'}, onDone, onError);
502 } 502 }
503 503
504 /** 504 /**
505 * Retrieves the list of paired clients. 505 * Retrieves the list of paired clients.
506 * 506 *
507 * @param {function(Array<remoting.PairedClient>):void} onDone Callback to 507 * @param {function(Array<remoting.PairedClient>):void} onDone Callback to
508 * return result. 508 * return result.
509 * @param {function(remoting.Error):void} onError Callback to call on error. 509 * @param {function(!remoting.Error):void} onError Callback to call on error.
510 */ 510 */
511 remoting.HostDaemonFacade.prototype.getPairedClients = 511 remoting.HostDaemonFacade.prototype.getPairedClients =
512 function(onDone, onError) { 512 function(onDone, onError) {
513 this.postMessage_({type: 'getPairedClients'}, onDone, onError); 513 this.postMessage_({type: 'getPairedClients'}, onDone, onError);
514 } 514 }
515 515
516 /** 516 /**
517 * Clears all paired clients from the registry. 517 * Clears all paired clients from the registry.
518 * 518 *
519 * @param {function(boolean):void} onDone Callback to be called when finished. 519 * @param {function(boolean):void} onDone Callback to be called when finished.
520 * @param {function(remoting.Error):void} onError Callback to call on error. 520 * @param {function(!remoting.Error):void} onError Callback to call on error.
521 */ 521 */
522 remoting.HostDaemonFacade.prototype.clearPairedClients = 522 remoting.HostDaemonFacade.prototype.clearPairedClients =
523 function(onDone, onError) { 523 function(onDone, onError) {
524 this.postMessage_({type: 'clearPairedClients'}, onDone, onError); 524 this.postMessage_({type: 'clearPairedClients'}, onDone, onError);
525 } 525 }
526 526
527 /** 527 /**
528 * Deletes a paired client referenced by client id. 528 * Deletes a paired client referenced by client id.
529 * 529 *
530 * @param {string} client Client to delete. 530 * @param {string} client Client to delete.
531 * @param {function(boolean):void} onDone Callback to be called when finished. 531 * @param {function(boolean):void} onDone Callback to be called when finished.
532 * @param {function(remoting.Error):void} onError Callback to call on error. 532 * @param {function(!remoting.Error):void} onError Callback to call on error.
533 */ 533 */
534 remoting.HostDaemonFacade.prototype.deletePairedClient = 534 remoting.HostDaemonFacade.prototype.deletePairedClient =
535 function(client, onDone, onError) { 535 function(client, onDone, onError) {
536 this.postMessage_({ 536 this.postMessage_({
537 type: 'deletePairedClient', 537 type: 'deletePairedClient',
538 clientId: client 538 clientId: client
539 }, onDone, onError); 539 }, onDone, onError);
540 } 540 }
541 541
542 /** 542 /**
543 * Gets the API keys to obtain/use service account credentials. 543 * Gets the API keys to obtain/use service account credentials.
544 * 544 *
545 * @param {function(string):void} onDone Callback to return result. 545 * @param {function(string):void} onDone Callback to return result.
546 * @param {function(remoting.Error):void} onError Callback to call on error. 546 * @param {function(!remoting.Error):void} onError Callback to call on error.
547 * @return {void} Nothing. 547 * @return {void} Nothing.
548 */ 548 */
549 remoting.HostDaemonFacade.prototype.getHostClientId = 549 remoting.HostDaemonFacade.prototype.getHostClientId =
550 function(onDone, onError) { 550 function(onDone, onError) {
551 this.postMessage_({type: 'getHostClientId'}, onDone, onError); 551 this.postMessage_({type: 'getHostClientId'}, onDone, onError);
552 }; 552 };
553 553
554 /** 554 /**
555 * 555 *
556 * @param {string} authorizationCode OAuth authorization code. 556 * @param {string} authorizationCode OAuth authorization code.
557 * @param {function(string, string):void} onDone Callback to return result. 557 * @param {function(string, string):void} onDone Callback to return result.
558 * @param {function(remoting.Error):void} onError Callback to call on error. 558 * @param {function(!remoting.Error):void} onError Callback to call on error.
559 * @return {void} Nothing. 559 * @return {void} Nothing.
560 */ 560 */
561 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode = 561 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode =
562 function(authorizationCode, onDone, onError) { 562 function(authorizationCode, onDone, onError) {
563 this.postMessage_({ 563 this.postMessage_({
564 type: 'getCredentialsFromAuthCode', 564 type: 'getCredentialsFromAuthCode',
565 authorizationCode: authorizationCode 565 authorizationCode: authorizationCode
566 }, onDone, onError); 566 }, onDone, onError);
567 }; 567 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698