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

Side by Side Diff: ui/app_list/speech_ui_model.cc

Issue 2422873002: Remove usage of FOR_EACH_OBSERVER macro in ui/app_list (Closed)
Patch Set: Created 4 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
« no previous file with comments | « ui/app_list/search_result.cc ('k') | ui/app_list/views/app_list_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "ui/app_list/speech_ui_model.h" 5 #include "ui/app_list/speech_ui_model.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 17 matching lines...) Expand all
28 28
29 SpeechUIModel::~SpeechUIModel() {} 29 SpeechUIModel::~SpeechUIModel() {}
30 30
31 void SpeechUIModel::SetSpeechResult(const base::string16& result, 31 void SpeechUIModel::SetSpeechResult(const base::string16& result,
32 bool is_final) { 32 bool is_final) {
33 if (result_ == result && is_final_ == is_final) 33 if (result_ == result && is_final_ == is_final)
34 return; 34 return;
35 35
36 result_ = result; 36 result_ = result;
37 is_final_ = is_final; 37 is_final_ = is_final;
38 FOR_EACH_OBSERVER(SpeechUIModelObserver, 38 for (auto& observer : observers_)
39 observers_, 39 observer.OnSpeechResult(result, is_final);
40 OnSpeechResult(result, is_final));
41 } 40 }
42 41
43 void SpeechUIModel::UpdateSoundLevel(int16_t level) { 42 void SpeechUIModel::UpdateSoundLevel(int16_t level) {
44 if (sound_level_ == level) 43 if (sound_level_ == level)
45 return; 44 return;
46 45
47 sound_level_ = level; 46 sound_level_ = level;
48 47
49 // Tweak the sound level limits adaptively. 48 // Tweak the sound level limits adaptively.
50 // - min is the minimum value during the speech recognition starts but speech 49 // - min is the minimum value during the speech recognition starts but speech
(...skipping 12 matching lines...) Expand all
63 62
64 int16_t range = maximum_sound_level_ - minimum_sound_level_; 63 int16_t range = maximum_sound_level_ - minimum_sound_level_;
65 uint8_t visible_level = 0; 64 uint8_t visible_level = 0;
66 if (range > 0) { 65 if (range > 0) {
67 int16_t visible_level_in_range = std::min( 66 int16_t visible_level_in_range = std::min(
68 std::max(minimum_sound_level_, sound_level_), maximum_sound_level_); 67 std::max(minimum_sound_level_, sound_level_), maximum_sound_level_);
69 visible_level = (visible_level_in_range - minimum_sound_level_) * 68 visible_level = (visible_level_in_range - minimum_sound_level_) *
70 std::numeric_limits<uint8_t>::max() / range; 69 std::numeric_limits<uint8_t>::max() / range;
71 } 70 }
72 71
73 FOR_EACH_OBSERVER(SpeechUIModelObserver, 72 for (auto& observer : observers_)
74 observers_, 73 observer.OnSpeechSoundLevelChanged(visible_level);
75 OnSpeechSoundLevelChanged(visible_level));
76 } 74 }
77 75
78 void SpeechUIModel::SetSpeechRecognitionState(SpeechRecognitionState new_state, 76 void SpeechUIModel::SetSpeechRecognitionState(SpeechRecognitionState new_state,
79 bool always_show_ui) { 77 bool always_show_ui) {
80 // Don't show the speech view on a change to a network error or if the state 78 // Don't show the speech view on a change to a network error or if the state
81 // has not changed, unless |always_show_ui| is true. 79 // has not changed, unless |always_show_ui| is true.
82 if (!always_show_ui && 80 if (!always_show_ui &&
83 (state_ == new_state || new_state == SPEECH_RECOGNITION_NETWORK_ERROR)) { 81 (state_ == new_state || new_state == SPEECH_RECOGNITION_NETWORK_ERROR)) {
84 state_ = new_state; 82 state_ = new_state;
85 return; 83 return;
86 } 84 }
87 85
88 state_ = new_state; 86 state_ = new_state;
89 87
90 // Revert the min/max sound level to the default. 88 // Revert the min/max sound level to the default.
91 if (state_ != SPEECH_RECOGNITION_RECOGNIZING && 89 if (state_ != SPEECH_RECOGNITION_RECOGNIZING &&
92 state_ != SPEECH_RECOGNITION_IN_SPEECH) { 90 state_ != SPEECH_RECOGNITION_IN_SPEECH) {
93 minimum_sound_level_ = kDefaultSoundLevel; 91 minimum_sound_level_ = kDefaultSoundLevel;
94 maximum_sound_level_ = kDefaultSoundLevel; 92 maximum_sound_level_ = kDefaultSoundLevel;
95 } 93 }
96 94
97 FOR_EACH_OBSERVER(SpeechUIModelObserver, 95 for (auto& observer : observers_)
98 observers_, 96 observer.OnSpeechRecognitionStateChanged(new_state);
99 OnSpeechRecognitionStateChanged(new_state));
100 } 97 }
101 98
102 void SpeechUIModel::AddObserver(SpeechUIModelObserver* observer) { 99 void SpeechUIModel::AddObserver(SpeechUIModelObserver* observer) {
103 observers_.AddObserver(observer); 100 observers_.AddObserver(observer);
104 } 101 }
105 102
106 void SpeechUIModel::RemoveObserver(SpeechUIModelObserver* observer) { 103 void SpeechUIModel::RemoveObserver(SpeechUIModelObserver* observer) {
107 observers_.RemoveObserver(observer); 104 observers_.RemoveObserver(observer);
108 } 105 }
109 106
110 } // namespace app_list 107 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/search_result.cc ('k') | ui/app_list/views/app_list_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698