Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * Class to detect when the device is suspended. If the device is suspended, | |
| 8 * for example, a laptop's lid is closed, any subsequent errors detected by | |
| 9 * the active ClientSession should not be logged, as they arise from explicit | |
| 10 * user action. | |
| 11 */ | |
| 12 | |
| 13 /** | |
| 14 * @param {function():void} callback Callback function to invoke when a | |
| 15 * suspend+resume operation has been detected. | |
| 16 * | |
| 17 * @constructor | |
| 18 */ | |
| 19 remoting.SuspendMonitor = function (callback) { | |
| 20 /** @type {function():void} @private */ | |
| 21 this.callback_ = callback; | |
| 22 /** @type {number} @private */ | |
| 23 this.timerIntervalMs_ = 60 * 1000; | |
| 24 /** @type {number} @private */ | |
| 25 this.lateToleranceMs_ = 60 * 1000; | |
| 26 /** @type {number} @private */ | |
| 27 this.callbackExpectedTime_ = 0; | |
| 28 this.start_(); | |
|
simonmorris
2012/08/03 21:48:49
It might be better to start the suspend monitor on
Jamie
2012/08/03 23:15:14
I don't think that will happen. If the callback is
| |
| 29 }; | |
| 30 | |
| 31 /** @private */ | |
| 32 remoting.SuspendMonitor.prototype.start_ = function() { | |
| 33 window.setTimeout(this.checkSuspend_.bind(this), this.timerIntervalMs_); | |
| 34 this.callbackExpectedTime_ = new Date().getTime() + this.timerIntervalMs_; | |
| 35 }; | |
| 36 | |
| 37 /** @private */ | |
| 38 remoting.SuspendMonitor.prototype.checkSuspend_ = function() { | |
| 39 var lateByMs = new Date().getTime() - this.callbackExpectedTime_; | |
| 40 if (lateByMs > this.lateToleranceMs_) { | |
| 41 this.callback_(); | |
|
simonmorris
2012/08/03 21:48:49
This will typically be called 30 seconds after the
Jamie
2012/08/03 23:15:14
That is only true for very short suspension period
| |
| 42 } | |
| 43 this.start_(); | |
| 44 }; | |
| 45 | |
| 46 /** @type {remoting.SuspendMonitor?} */ | |
| 47 remoting.suspendMonitor = null; | |
| OLD | NEW |