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

Side by Side 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: Responded to comments. Removed closure_support.js Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 * Class to handle changes to auto-scan.
7 *
8 * @constructor
9 * @param {SwitchAccessInterface} switchAccess
10 */
11 function AutoScanManager(switchAccess) {
12 /**
13 * SwitchAccess reference.
14 * @private {SwitchAccessInterface}
15 */
16 this.switchAccess_ = switchAccess;
17
18 /**
19 * Auto-scan interval ID.
20 *
21 * @private {number}
22 */
23 this.intervalID_ = 0;
24
25 /**
26 * Length of auto-scan interval in seconds.
27 *
28 * @private {number}
29 */
30 this.scanTime_ =
31 /** @type {number} */ (switchAccess.switchAccessPrefs
32 .getPref('autoScanTime'));
David Tseng 2017/03/29 21:57:20 Optional: you could get more type safety if you ad
elichtenberg 2017/03/30 21:46:56 Done.
33
34 let enabled = switchAccess.switchAccessPrefs.getPref('enableAutoScan');
35 if (enabled)
36 this.start_();
37 };
38
39 AutoScanManager.prototype = {
40 /**
41 * Stop the window from moving to the next node at a fixed interval.
42 *
43 * @private
44 */
45 stop_: function() {
46 window.clearInterval(this.intervalID_);
47 this.intervalID_ = 0;
David Tseng 2017/03/29 21:57:20 Would be clearer to make this undefined. setInterv
elichtenberg 2017/03/30 21:46:56 Done. I think the documentation said that the inte
48 },
49
50 /**
51 * Set the window to move to the next node at an interval in seconds equal to
52 * this.scanTime_.
53 *
54 * @private
55 */
56 start_: function() {
57 this.intervalID_ = window.setInterval(
58 this.switchAccess_.moveToNext.bind(this.switchAccess_),
59 this.scanTime_ * 1000);
David Tseng 2017/03/29 21:57:20 Any reason to not just store the scan time in ms?
elichtenberg 2017/03/30 21:46:56 Done. Didn't have a reason besides that the option
60 },
61
62 /**
63 * Return true if auto-scan is currently running. Otherwise return false.
64 *
65 * @return {boolean}
66 */
67 isRunning: function() {
68 return this.intervalID_ !== 0;
69 },
70
71 /**
72 * Restart auto-scan under the current settings.
73 */
74 restart: function() {
75 this.stop_();
76 this.start_();
77 },
78
79 /**
80 * Stop auto-scan if it is currently running. Then, if |enabled| is true,
81 * turn on auto-scan. Otherwise leave it off.
82 *
83 * @param {boolean} enabled
84 */
85 setEnabled: function(enabled) {
86 if (this.isRunning())
87 this.stop_();
88 if (enabled)
89 this.start_();
90 },
91
92 /**
93 * Update this.scanTime_ to |scanTime|. Then, if auto-scan is currently
94 * running, restart it.
95 *
96 * @param {number} scanTime Auto-scan interval time in seconds.
97 */
98 setScanTime: function(scanTime) {
99 this.scanTime_ = scanTime;
100 if (this.isRunning()) {
101 this.restart();
102 }
103 },
104 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698