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

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: Review comments Created 6 years, 3 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));
51 }
46 }; 52 };
47 53
48 // ---- private methods: 54 // ---- private methods:
49 55
50 /** 56 /**
51 * Gets the appropriate flow for the current configuration of settings. 57 * Gets and starts the appropriate flow for the launch mode.
52 * @private 58 * @private
53 */ 59 */
54 getFlowForSetting_ = function() { 60 Flow.prototype.startFlowForMode_ = function(state) {
55 // TODO(kcarattini): This should eventually return the correct flow for 61 if (state.launchMode >= 0 && state.launchMode < FLOWS.length) {
56 // the current settings state. 62 this.currentFlow_ = FLOWS[state.launchMode];
57 return FLOWS.HOTWORD_AND_AUDIO_HISTORY; 63 this.advanceStep();
64 }
58 }; 65 };
59 66
60 /** 67 /**
61 * Displays the current step. If the current step is not the first step, 68 * Displays the current step. If the current step is not the first step,
62 * also hides the previous step. 69 * also hides the previous step.
63 * @private 70 * @private
64 */ 71 */
65 showStep_ = function() { 72 Flow.prototype.showStep_ = function() {
66 var currentStep = this.currentFlow_[this.currentStepIndex_]; 73 var currentStep = this.currentFlow_[this.currentStepIndex_];
67 var previousStep = null; 74 var previousStep = null;
68 if (this.currentStepIndex_ > 0) 75 if (this.currentStepIndex_ > 0)
69 previousStep = this.currentFlow_[this.currentStepIndex_ - 1]; 76 previousStep = this.currentFlow_[this.currentStepIndex_ - 1];
70 77
71 if (previousStep) 78 if (previousStep)
72 document.getElementById(previousStep).hidden = true; 79 document.getElementById(previousStep).hidden = true;
73 80
74 document.getElementById(currentStep).hidden = false; 81 document.getElementById(currentStep).hidden = false;
75 }; 82 };
76 83
77 window.Flow = Flow; 84 window.Flow = Flow;
78 })(); 85 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698