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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 /** @param {boolean} installed */ |
126 return this.isInstalled().then(function(installed){ | 126 return this.isInstalled().then(function(installed){ |
127 if (installed) { | 127 if (installed) { |
128 return Promise.resolve(true); | 128 return Promise.resolve(true); |
129 } | 129 } |
130 | 130 |
131 if (that.downloadAndWaitForInstallPromise_ !== null) { | 131 if (that.downloadAndWaitForInstallPromise_ === null) { |
132 that.downloadAndWaitForInstallPromise_ = new Promise( | 132 that.downloadAndWaitForInstallPromise_ = new Promise( |
133 /** @param {Function} resolve */ | 133 /** @param {Function} resolve */ |
134 function(resolve){ | 134 function(resolve){ |
135 that.download(); | 135 that.download(); |
136 that.checkInstallIntervalId_ = window.setInterval(function() { | 136 that.checkInstallIntervalId_ = window.setInterval(function() { |
137 /** @param {boolean} installed */ | 137 /** @param {boolean} installed */ |
138 that.isInstalled().then(function(installed) { | 138 that.isInstalled().then(function(installed) { |
139 if (installed) { | 139 if (installed) { |
140 that.cancel(); | 140 that.cancel(); |
141 resolve(); | 141 resolve(); |
(...skipping 11 matching lines...) Expand all Loading... |
153 * For example | 153 * For example |
154 * var promise = hostInstaller.downloadAndWaitForInstall(); | 154 * var promise = hostInstaller.downloadAndWaitForInstall(); |
155 * hostInstaller.cancel(); // This will prevent |promise| from fulfilling. | 155 * hostInstaller.cancel(); // This will prevent |promise| from fulfilling. |
156 */ | 156 */ |
157 remoting.HostInstaller.prototype.cancel = function() { | 157 remoting.HostInstaller.prototype.cancel = function() { |
158 if (this.checkInstallIntervalId_ !== null) { | 158 if (this.checkInstallIntervalId_ !== null) { |
159 window.clearInterval(this.checkInstallIntervalId_); | 159 window.clearInterval(this.checkInstallIntervalId_); |
160 this.checkInstallIntervalId_ = null; | 160 this.checkInstallIntervalId_ = null; |
161 } | 161 } |
162 this.downloadAndWaitForInstallPromise_ = null; | 162 this.downloadAndWaitForInstallPromise_ = null; |
163 }; | 163 }; |
OLD | NEW |