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

Unified Diff: chrome/browser/resources/hotword_audio_verification/flow.js

Issue 521483003: Hotword Audio Verification App: Adds hotwording assets and basic opt-in flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
Index: chrome/browser/resources/hotword_audio_verification/flow.js
diff --git a/chrome/browser/resources/hotword_audio_verification/flow.js b/chrome/browser/resources/hotword_audio_verification/flow.js
new file mode 100644
index 0000000000000000000000000000000000000000..ed86efb8c4c4f9aa04dcf4a74abcfb5e6f747085
--- /dev/null
+++ b/chrome/browser/resources/hotword_audio_verification/flow.js
@@ -0,0 +1,87 @@
+// Copyright 2014 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.
+
+(function(context) {
+
+ // Correspond to steps in the hotword opt-in flow.
+ /** @const */ var HOTWORD_AUDIO_HISTORY = 'hotword-audio-history-container';
+ /** @const */ var HOTWORD_ONLY_START = 'hotword-only-container';
+ /** @const */ var AUDIO_HISTORY_START = 'audio-history-container';
+ /** @const */ var SPEECH_TRAINING = 'speech-training-container';
+ /** @const */ var ALL_SET = 'all-set-container';
benwells 2014/09/01 01:28:48 Optional nit: when I first saw "ALL_SET" i thought
Matt Giuca 2014/09/01 05:35:43 Yeah, as a general comment, a lot of things in thi
kcarattini 2014/09/01 06:59:06 Acknowledged.
kcarattini 2014/09/01 06:59:06 Done.
+
+ /** @const */ var FLOWS = {
+ HOTWORD_AND_AUDIO_HISTORY: [
+ HOTWORD_AUDIO_HISTORY, SPEECH_TRAINING, ALL_SET],
+ HOTWORD_ONLY: [HOTWORD_ONLY_START, SPEECH_TRAINING, ALL_SET],
+ AUDIO_HISTORY_ONLY: [AUDIO_HISTORY_START]
+ };
+
+ /**
+ * Class to control the page flow of the always-on hotword and
+ * Audio History opt-in process.
+ * @constructor
+ */
+ function Flow() {
+ this.currentStepIndex_ = -1;
+ this.currentFlow_ = [];
+ }
+
+ /**
+ * Gets the appropriate flow and displays its first page.
+ */
+ Flow.prototype.startFlow = function() {
+ this.currentFlow_ = getFlowForSetting_.apply(this);
+ this.advanceStep();
+ };
+
+ /**
+ * Advances the current step.
+ * @return {boolean} true if we have not reached the end of the flow.
+ */
+ Flow.prototype.advanceStep = function() {
+ if (this.currentStepIndex_ >= 0) {
+ this.currentStepIndex_++;
+ if (this.currentStepIndex_ > this.currentFlow_.length) {
+ return false;
+ }
+ } else {
+ this.currentStepIndex_ = 0;
+ }
+
+ showStep_.apply(this);
+ return true;
+ };
+
+ // ---- private methods:
+
+ /**
+ * Gets the appropriate flow for the current configuration of settings.
+ * @private
+ */
+ getFlowForSetting_ = function() {
+ // TODO(kcarattini): This should eventually return the correct flow for
+ // the current settings state.
+ return FLOWS.HOTWORD_AND_AUDIO_HISTORY;
+ };
+
+ /**
+ * Displays the current step. If the current step is not the first step.
+ * also hides the previous step.
+ * @private
+ */
+ showStep_ = function() {
+ var currentStep = this.currentFlow_[this.currentStepIndex_];
+ var previousStep = null;
+ if (this.currentStepIndex_ > 0)
+ previousStep = this.currentFlow_[this.currentStepIndex_ - 1];
+
+ if (previousStep)
+ document.getElementById(previousStep).hidden = true;
+
+ document.getElementById(currentStep).hidden = false;
+ };
+
+ window.Flow = Flow;
+})(window);

Powered by Google App Engine
This is Rietveld 408576698