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

Unified Diff: chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js

Issue 2777203006: Added auto-scan, made some small changes to how prefs are stored, refactored. (Closed)
Patch Set: Created 3 years, 9 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
Index: chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js
diff --git a/chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js b/chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js
new file mode 100644
index 0000000000000000000000000000000000000000..92b7e5eb3eec38153b585f12f7efd6260c5ab571
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js
@@ -0,0 +1,104 @@
+// Copyright 2017 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.
+
+/**
+ * Class to handle changes to auto-scan.
+ *
+ * @constructor
+ * @param {SwitchAccessInterface} switchAccess
+ */
+let AutoScanManager = function(switchAccess) {
+ /**
+ * SwitchAccess reference.
+ * @private {SwitchAccessInterface}
+ */
+ this.switchAccess_ = switchAccess;
+
+ /**
+ * Auto-scan interval ID.
+ *
+ * @private {number}
+ */
+ this.intervalID_ = 0;
+
+ /**
+ * Length of auto-scan interval in seconds.
+ *
+ * @private {number}
+ */
+ this.scanTime_ =
+ /** @type {number} */ (switchAccess.switchAccessPrefs
+ .getPref('autoScanTime'));
+
+ let enabled = switchAccess.switchAccessPrefs.getPref('enableAutoScan');
+ if (enabled)
+ this.start_();
+};
+
+AutoScanManager.prototype = {
+ /**
+ * Stop the window from moving to the next node at a fixed interval.
+ *
+ * @private
+ */
+ stop_: function() {
+ window.clearInterval(this.intervalID_);
+ this.intervalID_ = 0;
+ },
+
+ /**
+ * Set the window to move to the next node at an interval in seconds equal to
+ * this.scanTime_.
+ *
+ * @private
+ */
+ start_: function() {
+ this.intervalID_ = window.setInterval(
+ this.switchAccess_.moveToNext.bind(this.switchAccess_),
+ this.scanTime_ * 1000);
+ },
+
+ /**
+ * Return true if auto-scan is currently running. Otherwise return false.
+ *
+ * @return {boolean}
+ */
+ isRunning: function() {
+ return this.intervalID_ !== 0;
+ },
+
+ /**
+ * Restart auto-scan under the current settings.
+ */
+ restart: function() {
+ this.stop_();
+ this.start_();
+ },
+
+ /**
+ * Stop auto-scan if it is currently running. Then, if |enabled| is true,
+ * turn on auto-scan. Otherwise leave it off.
+ *
+ * @param {boolean} enabled
+ */
+ setEnabled: function(enabled) {
+ if (this.isRunning())
+ this.stop_();
+ if (enabled)
+ this.start_();
+ },
+
+ /**
+ * Update this.scanTime_ to |scanTime|. Then, if auto-scan is currently
+ * running, restart it.
+ *
+ * @param {number} scanTime
dmazzoni 2017/03/29 05:52:20 Document "in seconds" here
elichtenberg 2017/03/29 19:15:11 Done.
+ */
+ setScanTime: function(scanTime) {
+ this.scanTime_ = scanTime;
+ if (this.isRunning()) {
+ this.restart();
+ }
+ },
+};

Powered by Google App Engine
This is Rietveld 408576698