diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 00:37:21 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 00:37:21 +0000 |
commit | 2febe2d379df617daa59950de45105700d8a6518 (patch) | |
tree | 42096318a56e9c25752ed67cc0559338ebf636a0 /remoting | |
parent | ceefd7fdfd72ac1d845a053391601302af4d1f4d (diff) | |
download | chromium_src-2febe2d379df617daa59950de45105700d8a6518.zip chromium_src-2febe2d379df617daa59950de45105700d8a6518.tar.gz chromium_src-2febe2d379df617daa59950de45105700d8a6518.tar.bz2 |
Remove remoting.HostController.state()
In future, when we remove NPAPI we'll be getting host state asynchronously.
This change removes state() method from HostController class. Now the
getLocalHostStateAndId() should be used to get host state. There is still
isInstalled() used by the HostSetupDialog, but it the future it will need
to be removed as well.
Review URL: https://codereview.chromium.org/11418207
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170106 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/webapp/host_controller.js | 45 | ||||
-rw-r--r-- | remoting/webapp/host_list.js | 2 | ||||
-rw-r--r-- | remoting/webapp/host_setup_dialog.js | 6 | ||||
-rw-r--r-- | remoting/webapp/remoting.js | 33 |
4 files changed, 41 insertions, 45 deletions
diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js index 0dfabdb..53e332e 100644 --- a/remoting/webapp/host_controller.js +++ b/remoting/webapp/host_controller.js @@ -53,17 +53,21 @@ remoting.HostController.AsyncResult = { FAILED_DIRECTORY: 3 }; -/** @return {remoting.HostController.State} The current state of the daemon. */ -remoting.HostController.prototype.state = function() { - var result = this.plugin_.daemonState; - if (typeof(result) == 'undefined') { - // If the plug-in can't be instantiated, for example on ChromeOS, then - // return something sensible. - return remoting.HostController.State.NOT_IMPLEMENTED; - } else { - return result; - } -}; +/** + * Checks if the host is installed on the local computer. + * + * TODO(sergeyu): Make this method asynchronous or just remove it and use + * getLocalHostStateAndId() instead. + * + * @return {boolean} True if the host is installed. + */ +remoting.HostController.prototype.isInstalled = function() { + var state = this.plugin_.daemonState; + return typeof(state) != 'undefined' && + state != remoting.HostController.State.NOT_INSTALLED && + state != remoting.HostController.State.INSTALLING; +} + /** * @param {function(boolean, boolean, boolean):void} callback Callback to be @@ -269,9 +273,10 @@ remoting.HostController.prototype.updatePin = function(newPin, callback) { * Update the internal state so that the local host can be correctly filtered * out of the host list. * - * @param {function(string?):void} onDone Completion callback. + * @param {function(remoting.HostController.State, string?):void} onDone + * Completion callback. */ -remoting.HostController.prototype.getLocalHostId = function(onDone) { +remoting.HostController.prototype.getLocalHostStateAndId = function(onDone) { /** @type {remoting.HostController} */ var that = this; /** @param {string} configStr */ @@ -279,15 +284,23 @@ remoting.HostController.prototype.getLocalHostId = function(onDone) { var config = parseHostConfig_(configStr); if (config) { that.localHostId_ = config['host_id']; - onDone(that.localHostId_); } else { - onDone(null); + that.localHostId_ = null; } + + var state = that.plugin_.daemonState; + if (typeof(state) == 'undefined') { + // If the plug-in can't be instantiated, for example on ChromeOS, then + // return something sensible. + state = remoting.HostController.State.NOT_IMPLEMENTED; + } + + onDone(state, that.localHostId_); }; try { this.plugin_.getDaemonConfig(onConfig); } catch (err) { - onDone(null); + onDone(remoting.HostController.State.NOT_IMPLEMENTED, null); } }; diff --git a/remoting/webapp/host_list.js b/remoting/webapp/host_list.js index 89fdd71..9cc007c 100644 --- a/remoting/webapp/host_list.js +++ b/remoting/webapp/host_list.js @@ -429,7 +429,7 @@ remoting.HostList.prototype.onErrorClick_ = function() { } else { this.lastError_ = ''; this.display(); - this.refresh(remoting.extractThisHostAndDisplay); + this.refresh(remoting.updateLocalHostState); } } diff --git a/remoting/webapp/host_setup_dialog.js b/remoting/webapp/host_setup_dialog.js index ef7ee24..452e4ad 100644 --- a/remoting/webapp/host_setup_dialog.js +++ b/remoting/webapp/host_setup_dialog.js @@ -192,8 +192,7 @@ remoting.HostSetupDialog.prototype.showForStartWithToken_ = function(token) { remoting.HostSetupFlow.State.HOST_STARTED]; if (navigator.platform.indexOf('Mac') != -1 && - this.hostController_.state() == - remoting.HostController.State.NOT_INSTALLED) { + !this.hostController_.isInstalled()) { flow.unshift(remoting.HostSetupFlow.State.INSTALL_HOST); } @@ -458,8 +457,7 @@ remoting.HostSetupDialog.validPin_ = function(pin) { * @return {void} Nothing. */ remoting.HostSetupDialog.prototype.onInstallDialogOk = function() { - var state = this.hostController_.state(); - if (state == remoting.HostController.State.STOPPED) { + if (this.hostController_.isInstalled()) { this.flow_.switchToNextStep(remoting.HostController.AsyncResult.OK); this.updateState_(); } else { diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js index 11e20a8..3b58eeb 100644 --- a/remoting/webapp/remoting.js +++ b/remoting/webapp/remoting.js @@ -110,38 +110,23 @@ remoting.initDaemonUi = function () { remoting.hostSetupDialog = new remoting.HostSetupDialog(remoting.hostController); // Display the cached host list, then asynchronously update and re-display it. - remoting.extractThisHostAndDisplay(true); - remoting.hostList.refresh(remoting.extractThisHostAndDisplay); -}; - -/** - * Extract the remoting.Host object corresponding to this host (if any) and - * display the list. - * - * @param {boolean} success True if the host list refresh was successful. - * @return {void} Nothing. - */ -remoting.extractThisHostAndDisplay = function(success) { - if (success) { - remoting.updateLocalHostState(); - } else { - remoting.hostList.setLocalHostStateAndId( - remoting.hostController.state(), null); - remoting.hostList.display(); - } + remoting.updateLocalHostState(); + remoting.hostList.refresh(remoting.updateLocalHostState); }; /** * Fetches local host state and updates host list accordingly. */ remoting.updateLocalHostState = function() { - /** @param {string?} localHostId */ - var onHostId = function(localHostId) { - remoting.hostList.setLocalHostStateAndId( - remoting.hostController.state(), localHostId); + /** + * @param {remoting.HostController.State} state Host state. + * @param {string?} localHostId + */ + var onHostState = function(state, localHostId) { + remoting.hostList.setLocalHostStateAndId(state, localHostId); remoting.hostList.display(); }; - remoting.hostController.getLocalHostId(onHostId); + remoting.hostController.getLocalHostStateAndId(onHostState); } /** |