Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Unified Diff: remoting/webapp/suspend_monitor.js

Issue 10825187: Suppress "errors" that aren't really errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added JSCompiler hints. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« remoting/webapp/remoting.js ('K') | « remoting/webapp/remoting.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/suspend_monitor.js
diff --git a/remoting/webapp/suspend_monitor.js b/remoting/webapp/suspend_monitor.js
new file mode 100644
index 0000000000000000000000000000000000000000..ec45444e0e779f695f9875326385d58f90f2d1ec
--- /dev/null
+++ b/remoting/webapp/suspend_monitor.js
@@ -0,0 +1,51 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * Class to detect when the device is suspended, for example when a laptop's
+ * lid is closed.
+ */
+
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/**
+ * @param {function():void} callback Callback function to invoke when a
+ * suspend+resume operation has been detected.
+ *
+ * @constructor
+ */
+remoting.SuspendMonitor = function (callback) {
+ /** @type {function():void} @private */
+ this.callback_ = callback;
+ /** @type {number} @private */
+ this.timerIntervalMs_ = 60 * 1000;
+ /** @type {number} @private */
+ this.lateToleranceMs_ = 60 * 1000;
+ /** @type {number} @private */
+ this.callbackExpectedTime_ = 0;
+ this.start_();
+};
+
+/** @private */
+remoting.SuspendMonitor.prototype.start_ = function() {
+ window.setTimeout(this.checkSuspend_.bind(this), this.timerIntervalMs_);
+ this.callbackExpectedTime_ = new Date().getTime() + this.timerIntervalMs_;
+};
+
+/** @private */
+remoting.SuspendMonitor.prototype.checkSuspend_ = function() {
+ var lateByMs = new Date().getTime() - this.callbackExpectedTime_;
+ if (lateByMs > this.lateToleranceMs_) {
+ this.callback_();
+ }
+ this.start_();
+};
+
+/** @type {remoting.SuspendMonitor?} */
+remoting.suspendMonitor = null;
« remoting/webapp/remoting.js ('K') | « remoting/webapp/remoting.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698