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

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: Fixed comment. 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
« no previous file with comments | « 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..5bf9400d52945fe8564c4ca726f2f8f1d5c14c2a
--- /dev/null
+++ b/remoting/webapp/suspend_monitor.js
@@ -0,0 +1,47 @@
+// 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. If the device is suspended,
+ * for example, a laptop's lid is closed, any subsequent errors detected by
+ * the active ClientSession should not be logged, as they arise from explicit
+ * user action.
+ */
+
garykac 2012/08/04 00:43:46 Shouldn't there be 'use strict'; var remotin
Jamie 2012/08/04 00:51:39 Done.
+/**
+ * @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;
« no previous file with comments | « remoting/webapp/remoting.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698