OLD | NEW |
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 * | 7 * |
8 * HostInstaller allows the caller to download the host binary and monitor the | 8 * HostInstaller allows the caller to download the host binary and monitor the |
9 * install progress of the host by pinging the host periodically via native | 9 * install progress of the host by pinging the host periodically via native |
10 * messaging. | 10 * messaging. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 /** @return {Promise} */ | 115 /** @return {Promise} */ |
116 remoting.HostInstaller.prototype.downloadAndWaitForInstall = function() { | 116 remoting.HostInstaller.prototype.downloadAndWaitForInstall = function() { |
117 /** @type {remoting.HostInstaller} */ | 117 /** @type {remoting.HostInstaller} */ |
118 var that = this; | 118 var that = this; |
119 /** | 119 /** |
120 * @type {number} | 120 * @type {number} |
121 * @const | 121 * @const |
122 */ | 122 */ |
123 var CHECK_INSTALL_INTERVAL_IN_MILLISECONDS = 1000; | 123 var CHECK_INSTALL_INTERVAL_IN_MILLISECONDS = 1000; |
124 | 124 |
125 /** @param {boolean} installed */ | 125 return this.isInstalled().then( |
126 return this.isInstalled().then(function(installed){ | 126 /** @param {boolean} installed */ |
127 if (installed) { | 127 function(installed){ |
128 return Promise.resolve(true); | 128 if (installed) { |
129 } | 129 return Promise.resolve(true); |
| 130 } |
130 | 131 |
131 if (that.downloadAndWaitForInstallPromise_ === null) { | 132 if (that.downloadAndWaitForInstallPromise_ === null) { |
132 that.downloadAndWaitForInstallPromise_ = new Promise( | 133 that.downloadAndWaitForInstallPromise_ = new Promise( |
133 /** @param {Function} resolve */ | 134 /** @param {Function} resolve */ |
134 function(resolve){ | 135 function(resolve){ |
135 that.download(); | 136 that.download(); |
136 that.checkInstallIntervalId_ = window.setInterval(function() { | 137 that.checkInstallIntervalId_ = window.setInterval(function() { |
137 /** @param {boolean} installed */ | 138 that.isInstalled().then( |
138 that.isInstalled().then(function(installed) { | 139 /** @param {boolean} installed */ |
139 if (installed) { | 140 function(installed) { |
140 that.cancel(); | 141 if (installed) { |
141 resolve(); | 142 that.cancel(); |
142 } | 143 resolve(); |
143 }); | 144 } |
144 }, CHECK_INSTALL_INTERVAL_IN_MILLISECONDS); | 145 }); |
| 146 }, CHECK_INSTALL_INTERVAL_IN_MILLISECONDS); |
| 147 }); |
| 148 } |
| 149 return that.downloadAndWaitForInstallPromise_; |
145 }); | 150 }); |
146 } | |
147 return that.downloadAndWaitForInstallPromise_; | |
148 }); | |
149 }; | 151 }; |
150 | 152 |
151 /** | 153 /** |
152 * Stops waiting for the host to be installed. | 154 * Stops waiting for the host to be installed. |
153 * For example | 155 * For example |
154 * var promise = hostInstaller.downloadAndWaitForInstall(); | 156 * var promise = hostInstaller.downloadAndWaitForInstall(); |
155 * hostInstaller.cancel(); // This will prevent |promise| from fulfilling. | 157 * hostInstaller.cancel(); // This will prevent |promise| from fulfilling. |
156 */ | 158 */ |
157 remoting.HostInstaller.prototype.cancel = function() { | 159 remoting.HostInstaller.prototype.cancel = function() { |
158 if (this.checkInstallIntervalId_ !== null) { | 160 if (this.checkInstallIntervalId_ !== null) { |
159 window.clearInterval(this.checkInstallIntervalId_); | 161 window.clearInterval(this.checkInstallIntervalId_); |
160 this.checkInstallIntervalId_ = null; | 162 this.checkInstallIntervalId_ = null; |
161 } | 163 } |
162 this.downloadAndWaitForInstallPromise_ = null; | 164 this.downloadAndWaitForInstallPromise_ = null; |
163 }; | 165 }; |
OLD | NEW |