OLD | NEW |
---|---|
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 = { | |
15 HOTWORD_AND_AUDIO_HISTORY: [ | |
16 HOTWORD_AUDIO_HISTORY, SPEECH_TRAINING, FINISHED], | |
17 HOTWORD_ONLY: [HOTWORD_ONLY_START, SPEECH_TRAINING, FINISHED], | |
18 AUDIO_HISTORY_ONLY: [AUDIO_HISTORY_START] | |
19 }; | |
20 | |
21 /** | 14 /** |
22 * Class to control the page flow of the always-on hotword and | 15 * Class to control the page flow of the always-on hotword and |
23 * Audio History opt-in process. | 16 * Audio History opt-in process. |
24 * @constructor | 17 * @constructor |
25 */ | 18 */ |
26 function Flow() { | 19 function Flow() { |
27 this.currentStepIndex_ = -1; | 20 this.currentStepIndex_ = -1; |
28 this.currentFlow_ = []; | 21 this.currentFlow_ = []; |
29 } | 22 } |
30 | 23 |
31 /** | 24 /** |
32 * Gets the appropriate flow and displays its first page. | 25 * These flows correspond to the three LaunchModes as defined in |
26 * chrome/browser/search/hotword_service.h and should be kept in sync | |
27 * with them. | |
33 */ | 28 */ |
34 Flow.prototype.startFlow = function() { | 29 Flow.FLOWS_ = [ |
benwells
2014/09/09 20:57:30
Was there a reason to put this on Flow instead of
kcarattini
2014/09/10 08:14:28
No, it was done while I was debugging. Moved back
| |
35 this.currentFlow_ = getFlowForSetting_.apply(this); | 30 [AUDIO_HISTORY_START], |
36 this.advanceStep(); | 31 [HOTWORD_ONLY_START, SPEECH_TRAINING, FINISHED], |
37 }; | 32 [HOTWORD_AUDIO_HISTORY, SPEECH_TRAINING, FINISHED] |
33 ]; | |
38 | 34 |
39 /** | 35 /** |
40 * Advances the current step. | 36 * Advances the current step. |
41 */ | 37 */ |
42 Flow.prototype.advanceStep = function() { | 38 Flow.prototype.advanceStep = function() { |
43 this.currentStepIndex_++; | 39 this.currentStepIndex_++; |
44 if (this.currentStepIndex_ < this.currentFlow_.length) | 40 if (this.currentStepIndex_ < this.currentFlow_.length) |
45 showStep_.apply(this); | 41 this.showStep_.apply(this); |
42 }; | |
43 | |
44 /** | |
45 * Gets the appropriate flow and displays its first page. | |
46 */ | |
47 Flow.prototype.startFlow = function() { | |
48 chrome.hotwordAudioVerificationPrivate.getLaunchState( | |
49 this.getFlowForSetting_.bind(this)); | |
46 }; | 50 }; |
47 | 51 |
48 // ---- private methods: | 52 // ---- private methods: |
49 | 53 |
50 /** | 54 /** |
51 * Gets the appropriate flow for the current configuration of settings. | 55 * Gets the appropriate flow for the current configuration of settings. |
52 * @private | 56 * @private |
53 */ | 57 */ |
54 getFlowForSetting_ = function() { | 58 Flow.prototype.getFlowForSetting_ = function(state) { |
benwells
2014/09/09 20:57:30
I think this function should be called startFlowFo
kcarattini
2014/09/10 08:14:28
Done.
| |
55 // TODO(kcarattini): This should eventually return the correct flow for | 59 this.currentFlow_ = Flow.FLOWS_[state.launchMode]; |
56 // the current settings state. | 60 this.advanceStep(); |
57 return FLOWS.HOTWORD_AND_AUDIO_HISTORY; | |
58 }; | 61 }; |
59 | 62 |
60 /** | 63 /** |
61 * Displays the current step. If the current step is not the first step, | 64 * Displays the current step. If the current step is not the first step, |
62 * also hides the previous step. | 65 * also hides the previous step. |
63 * @private | 66 * @private |
64 */ | 67 */ |
65 showStep_ = function() { | 68 Flow.prototype.showStep_ = function() { |
66 var currentStep = this.currentFlow_[this.currentStepIndex_]; | 69 var currentStep = this.currentFlow_[this.currentStepIndex_]; |
67 var previousStep = null; | 70 var previousStep = null; |
68 if (this.currentStepIndex_ > 0) | 71 if (this.currentStepIndex_ > 0) |
69 previousStep = this.currentFlow_[this.currentStepIndex_ - 1]; | 72 previousStep = this.currentFlow_[this.currentStepIndex_ - 1]; |
70 | 73 |
71 if (previousStep) | 74 if (previousStep) |
72 document.getElementById(previousStep).hidden = true; | 75 document.getElementById(previousStep).hidden = true; |
73 | 76 |
74 document.getElementById(currentStep).hidden = false; | 77 document.getElementById(currentStep).hidden = false; |
75 }; | 78 }; |
76 | 79 |
77 window.Flow = Flow; | 80 window.Flow = Flow; |
78 })(); | 81 })(); |
OLD | NEW |