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

Side by Side Diff: chrome/browser/resources/hotword_audio_verification/flow.js

Issue 528113003: Hotword Audio Verification App: Adds to hotwordPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-one
Patch Set: Rebase Created 6 years, 2 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() { 5 (function() {
6 6
7 // Correspond to steps in the hotword opt-in flow. 7 // Correspond to steps in the hotword opt-in flow.
8 /** @const */ var HOTWORD_AUDIO_HISTORY = 'hotword-audio-history-container'; 8 /** @const */ var HOTWORD_AUDIO_HISTORY = 'hotword-audio-history-container';
9 /** @const */ var HOTWORD_ONLY_START = 'hotword-only-container'; 9 /** @const */ var HOTWORD_ONLY_START = 'hotword-only-container';
10 /** @const */ var AUDIO_HISTORY_START = 'audio-history-container'; 10 /** @const */ var AUDIO_HISTORY_START = 'audio-history-container';
11 /** @const */ var SPEECH_TRAINING = 'speech-training-container'; 11 /** @const */ var SPEECH_TRAINING = 'speech-training-container';
12 /** @const */ var FINISHED = 'finished-container'; 12 /** @const */ var FINISHED = 'finished-container';
13 13
14 /** @const */ var FLOWS = { 14 /**
15 HOTWORD_AND_AUDIO_HISTORY: [ 15 * These flows correspond to the three LaunchModes as defined in
16 HOTWORD_AUDIO_HISTORY, SPEECH_TRAINING, FINISHED], 16 * chrome/browser/search/hotword_service.h and should be kept in sync
17 HOTWORD_ONLY: [HOTWORD_ONLY_START, SPEECH_TRAINING, FINISHED], 17 * with them.
18 AUDIO_HISTORY_ONLY: [AUDIO_HISTORY_START] 18 * @const
19 }; 19 */
20 var FLOWS = [
21 [AUDIO_HISTORY_START],
22 [HOTWORD_ONLY_START, SPEECH_TRAINING, FINISHED],
23 [HOTWORD_AUDIO_HISTORY, SPEECH_TRAINING, FINISHED]
24 ];
20 25
21 /** 26 /**
22 * Class to control the page flow of the always-on hotword and 27 * Class to control the page flow of the always-on hotword and
23 * Audio History opt-in process. 28 * Audio History opt-in process.
24 * @constructor 29 * @constructor
25 */ 30 */
26 function Flow() { 31 function Flow() {
27 this.currentStepIndex_ = -1; 32 this.currentStepIndex_ = -1;
28 this.currentFlow_ = []; 33 this.currentFlow_ = [];
29 } 34 }
30 35
31 /** 36 /**
32 * Gets the appropriate flow and displays its first page.
33 */
34 Flow.prototype.startFlow = function() {
35 this.currentFlow_ = getFlowForSetting_.apply(this);
36 this.advanceStep();
37 };
38
39 /**
40 * Advances the current step. 37 * Advances the current step.
41 */ 38 */
42 Flow.prototype.advanceStep = function() { 39 Flow.prototype.advanceStep = function() {
43 this.currentStepIndex_++; 40 this.currentStepIndex_++;
44 if (this.currentStepIndex_ < this.currentFlow_.length) 41 if (this.currentStepIndex_ < this.currentFlow_.length)
45 showStep_.apply(this); 42 this.showStep_.apply(this);
43 };
44
45 /**
46 * Gets the appropriate flow and displays its first page.
47 */
48 Flow.prototype.startFlow = function() {
49 if (chrome.hotwordPrivate && chrome.hotwordPrivate.getLaunchState)
50 chrome.hotwordPrivate.getLaunchState(this.startFlowForMode_.bind(this));
46 }; 51 };
47 52
48 // ---- private methods: 53 // ---- private methods:
49 54
50 /** 55 /**
51 * Gets the appropriate flow for the current configuration of settings. 56 * Gets and starts the appropriate flow for the launch mode.
52 * @private 57 * @private
53 */ 58 */
54 getFlowForSetting_ = function() { 59 Flow.prototype.startFlowForMode_ = function(state) {
55 // TODO(kcarattini): This should eventually return the correct flow for 60 assert(state.launchMode >= 0 && state.launchMode < FLOWS.length,
56 // the current settings state. 61 'Invalid Launch Mode.');
57 return FLOWS.HOTWORD_AND_AUDIO_HISTORY; 62 this.currentFlow_ = FLOWS[state.launchMode];
63 this.advanceStep();
58 }; 64 };
59 65
60 /** 66 /**
61 * Displays the current step. If the current step is not the first step, 67 * Displays the current step. If the current step is not the first step,
62 * also hides the previous step. 68 * also hides the previous step.
63 * @private 69 * @private
64 */ 70 */
65 showStep_ = function() { 71 Flow.prototype.showStep_ = function() {
66 var currentStep = this.currentFlow_[this.currentStepIndex_]; 72 var currentStep = this.currentFlow_[this.currentStepIndex_];
67 var previousStep = null; 73 var previousStep = null;
68 if (this.currentStepIndex_ > 0) 74 if (this.currentStepIndex_ > 0)
69 previousStep = this.currentFlow_[this.currentStepIndex_ - 1]; 75 previousStep = this.currentFlow_[this.currentStepIndex_ - 1];
70 76
71 if (previousStep) 77 if (previousStep)
72 document.getElementById(previousStep).hidden = true; 78 document.getElementById(previousStep).hidden = true;
73 79
74 document.getElementById(currentStep).hidden = false; 80 document.getElementById(currentStep).hidden = false;
75 }; 81 };
76 82
77 window.Flow = Flow; 83 window.Flow = Flow;
78 })(); 84 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698