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 | |
garykac
2012/08/04 00:43:46
Shouldn't there be
'use strict';
var remotin
Jamie
2012/08/04 00:51:39
Done.
| |
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_(); | |
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_(); | |
42 } | |
43 this.start_(); | |
44 }; | |
45 | |
46 /** @type {remoting.SuspendMonitor?} */ | |
47 remoting.suspendMonitor = null; | |
OLD | NEW |