Loosen up heuristics for detecting account creation forms.
[chromium-blink-merge.git] / remoting / webapp / suspend_monitor.js
blobec45444e0e779f695f9875326385d58f90f2d1ec
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.
5 /**
6 * @fileoverview
7 * Class to detect when the device is suspended, for example when a laptop's
8 * lid is closed.
9 */
12 'use strict';
14 /** @suppress {duplicate} */
15 var remoting = remoting || {};
17 /**
18 * @param {function():void} callback Callback function to invoke when a
19 * suspend+resume operation has been detected.
21 * @constructor
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;
32 this.start_();
35 /** @private */
36 remoting.SuspendMonitor.prototype.start_ = function() {
37 window.setTimeout(this.checkSuspend_.bind(this), this.timerIntervalMs_);
38 this.callbackExpectedTime_ = new Date().getTime() + this.timerIntervalMs_;
41 /** @private */
42 remoting.SuspendMonitor.prototype.checkSuspend_ = function() {
43 var lateByMs = new Date().getTime() - this.callbackExpectedTime_;
44 if (lateByMs > this.lateToleranceMs_) {
45 this.callback_();
47 this.start_();
50 /** @type {remoting.SuspendMonitor?} */
51 remoting.suspendMonitor = null;