Commit f0977fde authored by kelvinp@chromium.org's avatar kelvinp@chromium.org

Hangouts remote desktop part IV - Host installer

This CL implements the HostInstaller, a class that enables the caller to download the host binary and monitor the install progress of the host by pinging the host periodically via native messaging.

Review URL: https://codereview.chromium.org/466143003

Cr-Commit-Position: refs/heads/master@{#289555}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289555 0039d316-1c4b-4281-b951-d872f2087c98
parent 99eacd13
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
'webapp/host_screen.js', 'webapp/host_screen.js',
'webapp/host_setup_dialog.js', 'webapp/host_setup_dialog.js',
'webapp/host_install_dialog.js', 'webapp/host_install_dialog.js',
'webapp/host_installer.js',
'webapp/paired_client_manager.js', 'webapp/paired_client_manager.js',
], ],
# UI files for displaying (in the client) info about available hosts. # UI files for displaying (in the client) info about available hosts.
......
...@@ -28,22 +28,16 @@ remoting.HostInstallDialog = function() { ...@@ -28,22 +28,16 @@ remoting.HostInstallDialog = function() {
this.cancelInstallButton_.disabled = false; this.cancelInstallButton_.disabled = false;
/** @private*/ /** @private*/
this.onDoneHandler_ = function() {} this.onDoneHandler_ = function() {};
/** @param {remoting.Error} error @private */ /** @param {remoting.Error} error @private */
this.onErrorHandler_ = function(error) {} this.onErrorHandler_ = function(error) {};
};
/** @type {Object.<string,string>} */ /**
remoting.HostInstallDialog.hostDownloadUrls = { * @type {remoting.HostInstaller}
'Win32' : 'http://dl.google.com/dl/edgedl/chrome-remote-desktop/' + * @private
'chromeremotedesktophost.msi', */
'MacIntel' : 'https://dl.google.com/chrome-remote-desktop/' + this.hostInstaller_ = new remoting.HostInstaller();
'chromeremotedesktop.dmg',
'Linux x86_64' : 'https://dl.google.com/linux/direct/' +
'chrome-remote-desktop_current_amd64.deb',
'Linux i386' : 'https://dl.google.com/linux/direct/' +
'chrome-remote-desktop_current_i386.deb'
}; };
/** /**
...@@ -63,28 +57,26 @@ remoting.HostInstallDialog.prototype.show = function(onDone, onError) { ...@@ -63,28 +57,26 @@ remoting.HostInstallDialog.prototype.show = function(onDone, onError) {
'click', this.onCancelClickedHandler_, false); 'click', this.onCancelClickedHandler_, false);
remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT); remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT);
var hostPackageUrl =
remoting.HostInstallDialog.hostDownloadUrls[navigator.platform];
if (hostPackageUrl === undefined) {
this.onErrorHandler_(remoting.Error.CANCELLED);
return;
}
// Start downloading the package.
if (remoting.isAppsV2) {
// TODO(jamiewalch): Use chrome.downloads when it is available to
// apps v2 (http://crbug.com/174046)
window.open(hostPackageUrl);
} else {
window.location = hostPackageUrl;
}
/** @type {function():void} */ /** @type {function():void} */
this.onDoneHandler_ = onDone; this.onDoneHandler_ = onDone;
/** @type {function(remoting.Error):void} */ /** @type {function(remoting.Error):void} */
this.onErrorHandler_ = onError; this.onErrorHandler_ = onError;
}
/** @type {remoting.HostInstaller} */
var hostInstaller = new remoting.HostInstaller();
/** @type {remoting.HostInstallDialog} */
var that = this;
this.hostInstaller_.downloadAndWaitForInstall().then(function() {
that.continueInstallButton_.click();
that.hostInstaller_.cancel();
}, function(){
that.onErrorHandler_(remoting.Error.CANCELLED);
that.hostInstaller_.cancel();
});
};
/** /**
* In manual host installation, onDone handler must call this method if it * In manual host installation, onDone handler must call this method if it
...@@ -108,15 +100,16 @@ remoting.HostInstallDialog.prototype.onOkClicked_ = function() { ...@@ -108,15 +100,16 @@ remoting.HostInstallDialog.prototype.onOkClicked_ = function() {
this.cancelInstallButton_.disabled = true; this.cancelInstallButton_.disabled = true;
this.onDoneHandler_(); this.onDoneHandler_();
} };
remoting.HostInstallDialog.prototype.onCancelClicked_ = function() { remoting.HostInstallDialog.prototype.onCancelClicked_ = function() {
this.continueInstallButton_.removeEventListener( this.continueInstallButton_.removeEventListener(
'click', this.onOkClickedHandler_, false); 'click', this.onOkClickedHandler_, false);
this.cancelInstallButton_.removeEventListener( this.cancelInstallButton_.removeEventListener(
'click', this.onCancelClickedHandler_, false); 'click', this.onCancelClickedHandler_, false);
this.hostInstaller_.cancel();
this.onErrorHandler_(remoting.Error.CANCELLED); this.onErrorHandler_(remoting.Error.CANCELLED);
} };
remoting.HostInstallDialog.prototype.onRetryClicked_ = function() { remoting.HostInstallDialog.prototype.onRetryClicked_ = function() {
this.retryInstallButton_.removeEventListener( this.retryInstallButton_.removeEventListener(
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
*
* HostInstaller allows the caller to download the host binary and monitor the
* install progress of the host by pinging the host periodically via native
* messaging.
*
* To download the host and wait for install:
* var hostInstaller = new remoting.HostInstaller();
* hostInstaller.downloadAndWaitForInstall().then(function() {
* // Install has completed.
* }, function(){
* // Download has failed.
* })
*
* To stop listening to the install progress:
* hostInstaller.cancel();
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @constructor
*/
remoting.HostInstaller = function() {
/**
* @type {Promise}
* @private
*/
this.downloadAndWaitForInstallPromise_ = null;
/**
* @type {?number}
* @private
*/
this.checkInstallIntervalId_ = null;
};
/**
* @return {Promise} The promise will resolve to a boolean value indicating
* whether the host is installed or not.
*/
remoting.HostInstaller.prototype.isInstalled = function() {
// Always do a fresh check as we don't get notified when the host is
// uninstalled.
/** @param {function(*=):void} resolve */
return new Promise(function(resolve) {
// TODO(kelvinp): Use different native messaging ports for the Me2me host
// vs It2MeHost.
/** @type {chrome.runtime.Port} */
var port =
chrome.runtime.connectNative('com.google.chrome.remote_assistance');
function onMessage() {
port.onDisconnect.removeListener(onDisconnected);
port.onMessage.removeListener(onMessage);
port.disconnect();
resolve(true);
}
function onDisconnected() {
port.onDisconnect.removeListener(onDisconnected);
port.onMessage.removeListener(onMessage);
resolve(false);
}
port.onDisconnect.addListener(onDisconnected);
port.onMessage.addListener(onMessage);
port.postMessage({type: 'hello'});
});
};
/**
* @throws {Error} Throws if there is no matching host binary for the current
* platform.
* @private
*/
remoting.HostInstaller.prototype.download_ = function() {
/** @type {Object.<string,string>} */
var hostDownloadUrls = {
'Win32' : 'http://dl.google.com/dl/edgedl/chrome-remote-desktop/' +
'chromeremotedesktophost.msi',
'MacIntel' : 'https://dl.google.com/chrome-remote-desktop/' +
'chromeremotedesktop.dmg',
'Linux x86_64' : 'https://dl.google.com/linux/direct/' +
'chrome-remote-desktop_current_amd64.deb',
'Linux i386' : 'https://dl.google.com/linux/direct/' +
'chrome-remote-desktop_current_i386.deb'
};
var hostPackageUrl = hostDownloadUrls[navigator.platform];
if (hostPackageUrl === undefined) {
throw new Error(remoting.Error.CANCELLED);
}
// Start downloading the package.
if (remoting.isAppsV2) {
// TODO(jamiewalch): Use chrome.downloads when it is available to
// apps v2 (http://crbug.com/174046)
window.open(hostPackageUrl);
} else {
window.location = hostPackageUrl;
}
};
/** @return {Promise} */
remoting.HostInstaller.prototype.downloadAndWaitForInstall = function() {
/** @type {remoting.HostInstaller} */
var that = this;
/**
* @type {number}
* @const
*/
var CHECK_INSTALL_INTERVAL_IN_MILLISECONDS = 1000;
/** @param {boolean} installed */
return this.isInstalled().then(function(installed){
if (installed) {
return Promise.resolve(true);
}
if (that.downloadAndWaitForInstallPromise_ !== null) {
that.downloadAndWaitForInstallPromise_ = new Promise(
/** @param {Function} resolve */
function(resolve){
that.download_();
that.checkInstallIntervalId_ = window.setInterval(function() {
/** @param {boolean} installed */
that.isInstalled().then(function(installed) {
if (installed) {
that.cancel();
resolve();
}
});
}, CHECK_INSTALL_INTERVAL_IN_MILLISECONDS);
});
}
return that.downloadAndWaitForInstallPromise_;
});
};
/**
* Stops waiting for the host to be installed.
* For example
* var promise = hostInstaller.downloadAndWaitForInstall();
* hostInstaller.cancel(); // This will prevent |promise| from fulfilling.
*/
remoting.HostInstaller.prototype.cancel = function() {
if (this.checkInstallIntervalId_ !== null) {
window.clearInterval(this.checkInstallIntervalId_);
this.checkInstallIntervalId_ = null;
}
this.downloadAndWaitForInstallPromise_ = null;
};
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment