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.
7 * Class to detect when the device is suspended, for example when a laptop's
14 /** @suppress {duplicate} */
15 var remoting
= remoting
|| {};
18 * @param {function():void} callback Callback function to invoke when a
19 * suspend+resume operation has been detected.
23 remoting
.SuspendMonitor = function (callback
) {
24 /** @type {function():void} @private */
25 this.callback_
= callback
;
26 /** @type {number} @private */
27 this.timerIntervalMs_
= 60 * 1000;
28 /** @type {number} @private */
29 this.lateToleranceMs_
= 60 * 1000;
30 /** @type {number} @private */
31 this.callbackExpectedTime_
= 0;
36 remoting
.SuspendMonitor
.prototype.start_ = function() {
37 window
.setTimeout(this.checkSuspend_
.bind(this), this.timerIntervalMs_
);
38 this.callbackExpectedTime_
= new Date().getTime() + this.timerIntervalMs_
;
42 remoting
.SuspendMonitor
.prototype.checkSuspend_ = function() {
43 var lateByMs
= new Date().getTime() - this.callbackExpectedTime_
;
44 if (lateByMs
> this.lateToleranceMs_
) {
50 /** @type {remoting.SuspendMonitor?} */
51 remoting
.suspendMonitor
= null;