summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-26 08:47:45 +0000
committerjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-26 08:47:45 +0000
commit3bbc9c037fc47d572770db4bda5c78a8a9006893 (patch)
treeb8e20b7ebbfc4aa603d6e2ef60bc1580b7cf286f /remoting
parentfd720d86dddbaaff1f940d0796c914e5fe7f7200 (diff)
downloadchromium_src-3bbc9c037fc47d572770db4bda5c78a8a9006893.zip
chromium_src-3bbc9c037fc47d572770db4bda5c78a8a9006893.tar.gz
chromium_src-3bbc9c037fc47d572770db4bda5c78a8a9006893.tar.bz2
Refactor getLocalHostStateAndId to help with native messaging implementation.
Also, get rid of the cache of the local host id from HostController. It's only used to unregister the host, and IMO the code is cleaner if it's re-fetched as needed in this case. The overhead of doing so should be minimal. BUG=173509 Review URL: https://chromiumcodereview.appspot.com/12902047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190603 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/webapp/event_handlers.js6
-rw-r--r--remoting/webapp/host_controller.js86
-rw-r--r--remoting/webapp/host_setup_dialog.js74
-rw-r--r--remoting/webapp/remoting.js16
4 files changed, 117 insertions, 65 deletions
diff --git a/remoting/webapp/event_handlers.js b/remoting/webapp/event_handlers.js
index 90f33fe..ff132ef 100644
--- a/remoting/webapp/event_handlers.js
+++ b/remoting/webapp/event_handlers.js
@@ -87,12 +87,6 @@ function onLoad() {
fn: function() { remoting.setMode(remoting.AppMode.HOME); } },
{ event: 'click', id: 'host-config-error-dismiss',
fn: function() { remoting.setMode(remoting.AppMode.HOME); } },
- { event: 'click', id: 'host-config-install-continue',
- fn: function() { remoting.hostSetupDialog.onInstallDialogOk(); } },
- { event: 'click', id: 'host-config-install-dismiss',
- fn: function() { remoting.hostSetupDialog.hide(); } },
- { event: 'click', id: 'host-config-install-retry', fn: function() {
- remoting.hostSetupDialog.onInstallDialogRetry(); } },
{ event: 'click', id: 'token-refresh-error-ok',
fn: function() { remoting.setMode(remoting.AppMode.HOME); } },
{ event: 'click', id: 'token-refresh-error-sign-in', fn: doAuthRedirect }
diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js
index 5520dfa..c35d63c 100644
--- a/remoting/webapp/host_controller.js
+++ b/remoting/webapp/host_controller.js
@@ -20,8 +20,6 @@ remoting.HostController = function() {
container.appendChild(this.plugin_);
}
- /** @type {string?} */
- this.localHostId_ = null;
/** @param {string} version */
var printVersion = function(version) {
if (version == '') {
@@ -63,21 +61,6 @@ remoting.HostController.AsyncResult = {
};
/**
- * 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;
-}
-
-/**
* Checks whether or not the host plugin is valid.
*
* @return {boolean} True if the plugin is supported and loaded; false
@@ -130,10 +113,8 @@ remoting.HostController.prototype.start = function(hostPin, consent, callback) {
* @param {string} publicKey */
function onStarted(callback, result, hostName, publicKey) {
if (result == remoting.HostController.AsyncResult.OK) {
- that.localHostId_ = newHostId;
remoting.hostList.onLocalHostStarted(hostName, newHostId, publicKey);
} else {
- that.localHostId_ = null;
// Unregister the host if we failed to start it.
remoting.HostList.unregisterHostById(newHostId);
}
@@ -247,14 +228,30 @@ remoting.HostController.prototype.stop = function(callback) {
/** @type {remoting.HostController} */
var that = this;
- /** @param {remoting.HostController.AsyncResult} result */
- function onStopped(result) {
- if (result == remoting.HostController.AsyncResult.OK &&
- that.localHostId_) {
- remoting.HostList.unregisterHostById(that.localHostId_);
+ /**
+ * @param {remoting.HostController.AsyncResult} result The result of the
+ * stopDaemon call, to be passed to the callback.
+ * @param {string?} hostId The host id of the local host.
+ */
+ function unregisterHost(result, hostId) {
+ if (hostId) {
+ remoting.HostList.unregisterHostById(hostId);
}
callback(result);
};
+
+ /**
+ * @param {remoting.HostController.AsyncResult} result The result of the
+ * stopDaemon call, to be passed to the callback.
+ */
+ function onStopped(result) {
+ if (result != remoting.HostController.AsyncResult.OK) {
+ callback(result);
+ return;
+ }
+ that.getLocalHostId(unregisterHost.bind(null, result));
+ };
+
this.plugin_.stopDaemon(onStopped);
};
@@ -319,37 +316,44 @@ 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.
+ * Get the state of the local host.
+ *
+ * TODO(lambroslambrou): get this via the native messaging API.
*
- * @param {function(remoting.HostController.State, string?):void} onDone
+ * @param {function(remoting.HostController.State):void} onDone
* Completion callback.
*/
-remoting.HostController.prototype.getLocalHostStateAndId = function(onDone) {
+remoting.HostController.prototype.getLocalHostState = function(onDone) {
+ var state = this.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);
+};
+
+/**
+ * Get the id of the local host, or null if it is not registered.
+ *
+ * @param {function(string?):void} onDone Completion callback.
+ */
+remoting.HostController.prototype.getLocalHostId = function(onDone) {
/** @type {remoting.HostController} */
var that = this;
/** @param {string} configStr */
function onConfig(configStr) {
var config = parseHostConfig_(configStr);
+ var hostId = null;
if (config) {
- that.localHostId_ = config['host_id'];
- } else {
- that.localHostId_ = null;
+ hostId = config['host_id'];
}
-
- 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_);
+ onDone(hostId);
};
try {
this.plugin_.getDaemonConfig(onConfig);
} catch (err) {
- onDone(remoting.HostController.State.NOT_IMPLEMENTED, null);
+ onDone(null);
}
};
diff --git a/remoting/webapp/host_setup_dialog.js b/remoting/webapp/host_setup_dialog.js
index 15e34ca..c3b76e9 100644
--- a/remoting/webapp/host_setup_dialog.js
+++ b/remoting/webapp/host_setup_dialog.js
@@ -104,6 +104,19 @@ remoting.HostSetupDialog = function(hostController) {
this.pinConfirm_ = document.getElementById('daemon-pin-confirm');
this.pinErrorDiv_ = document.getElementById('daemon-pin-error-div');
this.pinErrorMessage_ = document.getElementById('daemon-pin-error-message');
+ this.continueInstallButton_ = document.getElementById(
+ 'host-config-install-continue');
+ this.cancelInstallButton_ = document.getElementById(
+ 'host-config-install-dismiss');
+ this.retryInstallButton_ = document.getElementById(
+ 'host-config-install-retry');
+
+ this.continueInstallButton_.addEventListener(
+ 'click', this.onInstallDialogOk.bind(this), false);
+ this.cancelInstallButton_.addEventListener(
+ 'click', this.hide.bind(this), false);
+ this.retryInstallButton_.addEventListener(
+ 'click', this.onInstallDialogRetry.bind(this), false);
/** @type {remoting.HostSetupFlow} */
this.flow_ = new remoting.HostSetupFlow([remoting.HostSetupFlow.State.NONE]);
@@ -155,18 +168,32 @@ remoting.HostSetupDialog = function(hostController) {
* @return {void} Nothing.
*/
remoting.HostSetupDialog.prototype.showForStart = function() {
- // Although we don't need an access token in order to start the host,
- // using callWithToken here ensures consistent error handling in the
- // case where the refresh token is invalid.
- remoting.identity.callWithToken(this.showForStartWithToken_.bind(this),
- remoting.showErrorMessage);
+ /** @type {remoting.HostSetupDialog} */
+ var that = this;
+
+ /**
+ * @param {remoting.HostController.State} state
+ */
+ var onState = function(state) {
+ // Although we don't need an access token in order to start the host,
+ // using callWithToken here ensures consistent error handling in the
+ // case where the refresh token is invalid.
+ remoting.identity.callWithToken(
+ that.showForStartWithToken_.bind(that, state),
+ remoting.showErrorMessage);
+ };
+
+ this.hostController_.getLocalHostState(onState);
};
/**
+ * @param {remoting.HostController.State} state The current state of the local
+ * host.
* @param {string} token The OAuth2 token.
* @private
*/
-remoting.HostSetupDialog.prototype.showForStartWithToken_ = function(token) {
+remoting.HostSetupDialog.prototype.showForStartWithToken_ =
+ function(state, token) {
/** @type {remoting.HostSetupDialog} */
var that = this;
@@ -191,8 +218,11 @@ remoting.HostSetupDialog.prototype.showForStartWithToken_ = function(token) {
remoting.HostSetupFlow.State.STARTING_HOST,
remoting.HostSetupFlow.State.HOST_STARTED];
- if (navigator.platform.indexOf('Mac') != -1 &&
- !this.hostController_.isInstalled()) {
+ var installed =
+ state != remoting.HostController.State.NOT_INSTALLED &&
+ state != remoting.HostController.State.INSTALLING;
+
+ if (navigator.platform.indexOf('Mac') != -1 && !installed) {
flow.unshift(remoting.HostSetupFlow.State.INSTALL_HOST);
}
@@ -457,12 +487,28 @@ remoting.HostSetupDialog.validPin_ = function(pin) {
* @return {void} Nothing.
*/
remoting.HostSetupDialog.prototype.onInstallDialogOk = function() {
- if (this.hostController_.isInstalled()) {
- this.flow_.switchToNextStep(remoting.HostController.AsyncResult.OK);
- this.updateState_();
- } else {
- remoting.setMode(remoting.AppMode.HOST_SETUP_INSTALL_PENDING);
- }
+ this.continueInstallButton_.disabled = true;
+ this.cancelInstallButton_.disabled = true;
+
+ /** @type {remoting.HostSetupDialog} */
+ var that = this;
+
+ /** @param {remoting.HostController.State} state */
+ var onHostState = function(state) {
+ that.continueInstallButton_.disabled = false;
+ that.cancelInstallButton_.disabled = false;
+ var installed =
+ state != remoting.HostController.State.NOT_INSTALLED &&
+ state != remoting.HostController.State.INSTALLING;
+ if (installed) {
+ that.flow_.switchToNextStep(remoting.HostController.AsyncResult.OK);
+ that.updateState_();
+ } else {
+ remoting.setMode(remoting.AppMode.HOST_SETUP_INSTALL_PENDING);
+ }
+ };
+
+ this.hostController_.getLocalHostState(onHostState);
};
/**
diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js
index 931d0f7..c487fa1 100644
--- a/remoting/webapp/remoting.js
+++ b/remoting/webapp/remoting.js
@@ -147,14 +147,22 @@ remoting.initHomeScreenUi = function() {
*/
remoting.updateLocalHostState = function() {
/**
+ * @param {string?} hostId Host id.
+ */
+ var onHostId = function(hostId) {
+ remoting.hostController.getLocalHostState(onHostState.bind(null, hostId));
+ };
+
+ /**
+ * @param {string?} hostId Host id.
* @param {remoting.HostController.State} state Host state.
- * @param {string?} localHostId
*/
- var onHostState = function(state, localHostId) {
- remoting.hostList.setLocalHostStateAndId(state, localHostId);
+ var onHostState = function(hostId, state) {
+ remoting.hostList.setLocalHostStateAndId(state, hostId);
remoting.hostList.display();
};
- remoting.hostController.getLocalHostStateAndId(onHostState);
+
+ remoting.hostController.getLocalHostId(onHostId);
};
/**