OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/speech/speech_input_manager_impl.h" | 5 #include "content/browser/speech/speech_recognition_manager_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/browser_main_loop.h" | 8 #include "content/browser/browser_main_loop.h" |
9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
10 #include "content/browser/speech/speech_input_dispatcher_host.h" | 10 #include "content/browser/speech/input_tag_speech_dispatcher_host.h" |
11 #include "content/browser/speech/speech_recognizer_impl.h" | 11 #include "content/browser/speech/speech_recognizer_impl.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
14 #include "content/public/browser/render_view_host_delegate.h" | 14 #include "content/public/browser/render_view_host_delegate.h" |
15 #include "content/public/browser/resource_context.h" | 15 #include "content/public/browser/resource_context.h" |
16 #include "content/public/browser/speech_input_manager_delegate.h" | 16 #include "content/public/browser/speech_recognition_manager_delegate.h" |
17 #include "content/public/browser/speech_input_preferences.h" | 17 #include "content/public/browser/speech_recognition_preferences.h" |
18 #include "content/public/common/view_type.h" | 18 #include "content/public/common/view_type.h" |
19 | 19 |
20 using content::BrowserMainLoop; | 20 using content::BrowserMainLoop; |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 using content::SpeechInputManagerDelegate; | 22 using content::SpeechRecognitionManager; |
| 23 using content::SpeechRecognitionManagerDelegate; |
23 | 24 |
24 content::SpeechInputManager* content::SpeechInputManager::GetInstance() { | 25 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { |
25 return speech_input::SpeechInputManagerImpl::GetInstance(); | 26 return speech::SpeechRecognitionManagerImpl::GetInstance(); |
26 } | 27 } |
27 | 28 |
28 namespace speech_input { | 29 namespace speech { |
29 | 30 |
30 struct SpeechInputManagerImpl::SpeechInputParams { | 31 struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { |
31 SpeechInputParams(SpeechInputDispatcherHost* delegate, | 32 SpeechRecognitionParams(InputTagSpeechDispatcherHost* delegate, |
32 int caller_id, | 33 int caller_id, |
33 int render_process_id, | 34 int render_process_id, |
34 int render_view_id, | 35 int render_view_id, |
35 const gfx::Rect& element_rect, | 36 const gfx::Rect& element_rect, |
36 const std::string& language, | 37 const std::string& language, |
37 const std::string& grammar, | 38 const std::string& grammar, |
38 const std::string& origin_url, | 39 const std::string& origin_url, |
39 net::URLRequestContextGetter* context_getter, | 40 net::URLRequestContextGetter* context_getter, |
40 content::SpeechInputPreferences* speech_input_prefs) | 41 content::SpeechRecognitionPreferences* recognition_prefs) |
41 : delegate(delegate), | 42 : delegate(delegate), |
42 caller_id(caller_id), | 43 caller_id(caller_id), |
43 render_process_id(render_process_id), | 44 render_process_id(render_process_id), |
44 render_view_id(render_view_id), | 45 render_view_id(render_view_id), |
45 element_rect(element_rect), | 46 element_rect(element_rect), |
46 language(language), | 47 language(language), |
47 grammar(grammar), | 48 grammar(grammar), |
48 origin_url(origin_url), | 49 origin_url(origin_url), |
49 context_getter(context_getter), | 50 context_getter(context_getter), |
50 speech_input_prefs(speech_input_prefs) { | 51 recognition_prefs(recognition_prefs) { |
51 } | 52 } |
52 | 53 |
53 SpeechInputDispatcherHost* delegate; | 54 InputTagSpeechDispatcherHost* delegate; |
54 int caller_id; | 55 int caller_id; |
55 int render_process_id; | 56 int render_process_id; |
56 int render_view_id; | 57 int render_view_id; |
57 gfx::Rect element_rect; | 58 gfx::Rect element_rect; |
58 std::string language; | 59 std::string language; |
59 std::string grammar; | 60 std::string grammar; |
60 std::string origin_url; | 61 std::string origin_url; |
61 net::URLRequestContextGetter* context_getter; | 62 net::URLRequestContextGetter* context_getter; |
62 content::SpeechInputPreferences* speech_input_prefs; | 63 content::SpeechRecognitionPreferences* recognition_prefs; |
63 }; | 64 }; |
64 | 65 |
65 SpeechInputManagerImpl* SpeechInputManagerImpl::GetInstance() { | 66 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { |
66 return Singleton<SpeechInputManagerImpl>::get(); | 67 return Singleton<SpeechRecognitionManagerImpl>::get(); |
67 } | 68 } |
68 | 69 |
69 SpeechInputManagerImpl::SpeechInputManagerImpl() | 70 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() |
70 : can_report_metrics_(false), | 71 : can_report_metrics_(false), |
71 recording_caller_id_(0) { | 72 recording_caller_id_(0) { |
72 delegate_ = | 73 delegate_ = content::GetContentClient()->browser()-> |
73 content::GetContentClient()->browser()->GetSpeechInputManagerDelegate(); | 74 GetSpeechRecognitionManagerDelegate(); |
74 } | 75 } |
75 | 76 |
76 SpeechInputManagerImpl::~SpeechInputManagerImpl() { | 77 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { |
77 while (requests_.begin() != requests_.end()) | 78 while (requests_.begin() != requests_.end()) |
78 CancelRecognition(requests_.begin()->first); | 79 CancelRecognition(requests_.begin()->first); |
79 } | 80 } |
80 | 81 |
81 bool SpeechInputManagerImpl::HasAudioInputDevices() { | 82 bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { |
82 return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); | 83 return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); |
83 } | 84 } |
84 | 85 |
85 bool SpeechInputManagerImpl::IsRecordingInProcess() { | 86 bool SpeechRecognitionManagerImpl::IsCapturingAudio() { |
86 return BrowserMainLoop::GetAudioManager()->IsRecordingInProcess(); | 87 return BrowserMainLoop::GetAudioManager()->IsRecordingInProcess(); |
87 } | 88 } |
88 | 89 |
89 string16 SpeechInputManagerImpl::GetAudioInputDeviceModel() { | 90 string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { |
90 return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); | 91 return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); |
91 } | 92 } |
92 | 93 |
93 bool SpeechInputManagerImpl::HasPendingRequest(int caller_id) const { | 94 bool SpeechRecognitionManagerImpl::HasPendingRequest(int caller_id) const { |
94 return requests_.find(caller_id) != requests_.end(); | 95 return requests_.find(caller_id) != requests_.end(); |
95 } | 96 } |
96 | 97 |
97 SpeechInputDispatcherHost* SpeechInputManagerImpl::GetDelegate( | 98 InputTagSpeechDispatcherHost* SpeechRecognitionManagerImpl::GetDelegate( |
98 int caller_id) const { | 99 int caller_id) const { |
99 return requests_.find(caller_id)->second.delegate; | 100 return requests_.find(caller_id)->second.delegate; |
100 } | 101 } |
101 | 102 |
102 void SpeechInputManagerImpl::ShowAudioInputSettings() { | 103 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { |
103 // Since AudioManager::ShowAudioInputSettings can potentially launch external | 104 // Since AudioManager::ShowAudioInputSettings can potentially launch external |
104 // processes, do that in the FILE thread to not block the calling threads. | 105 // processes, do that in the FILE thread to not block the calling threads. |
105 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 106 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
106 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
107 BrowserThread::FILE, FROM_HERE, | 108 BrowserThread::FILE, FROM_HERE, |
108 base::Bind(&SpeechInputManagerImpl::ShowAudioInputSettings, | 109 base::Bind(&SpeechRecognitionManagerImpl::ShowAudioInputSettings, |
109 base::Unretained(this))); | 110 base::Unretained(this))); |
110 return; | 111 return; |
111 } | 112 } |
112 | 113 |
113 AudioManager* audio_manager = BrowserMainLoop::GetAudioManager(); | 114 AudioManager* audio_manager = BrowserMainLoop::GetAudioManager(); |
114 DCHECK(audio_manager->CanShowAudioInputSettings()); | 115 DCHECK(audio_manager->CanShowAudioInputSettings()); |
115 if (audio_manager->CanShowAudioInputSettings()) | 116 if (audio_manager->CanShowAudioInputSettings()) |
116 audio_manager->ShowAudioInputSettings(); | 117 audio_manager->ShowAudioInputSettings(); |
117 } | 118 } |
118 | 119 |
119 void SpeechInputManagerImpl::StartRecognition( | 120 void SpeechRecognitionManagerImpl::StartRecognition( |
120 SpeechInputDispatcherHost* delegate, | 121 InputTagSpeechDispatcherHost* delegate, |
121 int caller_id, | 122 int caller_id, |
122 int render_process_id, | 123 int render_process_id, |
123 int render_view_id, | 124 int render_view_id, |
124 const gfx::Rect& element_rect, | 125 const gfx::Rect& element_rect, |
125 const std::string& language, | 126 const std::string& language, |
126 const std::string& grammar, | 127 const std::string& grammar, |
127 const std::string& origin_url, | 128 const std::string& origin_url, |
128 net::URLRequestContextGetter* context_getter, | 129 net::URLRequestContextGetter* context_getter, |
129 content::SpeechInputPreferences* speech_input_prefs) { | 130 content::SpeechRecognitionPreferences* recognition_prefs) { |
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
131 BrowserThread::PostTask( | 132 BrowserThread::PostTask( |
132 BrowserThread::UI, FROM_HERE, | 133 BrowserThread::UI, FROM_HERE, |
133 base::Bind( | 134 base::Bind( |
134 &SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition, | 135 &SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition, |
135 base::Unretained(this), | 136 base::Unretained(this), |
136 SpeechInputParams( | 137 SpeechRecognitionParams( |
137 delegate, caller_id, render_process_id, render_view_id, | 138 delegate, caller_id, render_process_id, render_view_id, |
138 element_rect, language, grammar, origin_url, context_getter, | 139 element_rect, language, grammar, origin_url, context_getter, |
139 speech_input_prefs))); | 140 recognition_prefs))); |
140 } | 141 } |
141 | 142 |
142 void SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition( | 143 void SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition( |
143 const SpeechInputParams& params) { | 144 const SpeechRecognitionParams& params) { |
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
145 | 146 |
146 RenderViewHostImpl* render_view_host = RenderViewHostImpl::FromID( | 147 RenderViewHostImpl* render_view_host = RenderViewHostImpl::FromID( |
147 params.render_process_id, params.render_view_id); | 148 params.render_process_id, params.render_view_id); |
148 if (!render_view_host || !render_view_host->GetDelegate()) | 149 if (!render_view_host || !render_view_host->GetDelegate()) |
149 return; | 150 return; |
150 | 151 |
151 // For host delegates other than TabContents we can't reliably show a popup, | 152 // For host delegates other than TabContents we can't reliably show a popup, |
152 // including the speech input bubble. In these cases for privacy reasons we | 153 // including the speech input bubble. In these cases for privacy reasons we |
153 // don't want to start recording if the user can't be properly notified. | 154 // don't want to start recording if the user can't be properly notified. |
154 // An example of this is trying to show the speech input bubble within an | 155 // An example of this is trying to show the speech input bubble within an |
155 // extension popup: http://crbug.com/92083. In these situations the speech | 156 // extension popup: http://crbug.com/92083. In these situations the speech |
156 // input extension API should be used instead. | 157 // input extension API should be used instead. |
157 if (render_view_host->GetDelegate()->GetRenderViewType() == | 158 if (render_view_host->GetDelegate()->GetRenderViewType() == |
158 content::VIEW_TYPE_TAB_CONTENTS) { | 159 content::VIEW_TYPE_TAB_CONTENTS) { |
159 BrowserThread::PostTask( | 160 BrowserThread::PostTask( |
160 BrowserThread::IO, FROM_HERE, | 161 BrowserThread::IO, FROM_HERE, |
161 base::Bind(&SpeechInputManagerImpl::ProceedStartingRecognition, | 162 base::Bind(&SpeechRecognitionManagerImpl::ProceedStartingRecognition, |
162 base::Unretained(this), params)); | 163 base::Unretained(this), params)); |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
166 void SpeechInputManagerImpl::ProceedStartingRecognition( | 167 void SpeechRecognitionManagerImpl::ProceedStartingRecognition( |
167 const SpeechInputParams& params) { | 168 const SpeechRecognitionParams& params) { |
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
169 DCHECK(!HasPendingRequest(params.caller_id)); | 170 DCHECK(!HasPendingRequest(params.caller_id)); |
170 | 171 |
171 if (delegate_) { | 172 if (delegate_) { |
172 delegate_->ShowRecognitionRequested( | 173 delegate_->ShowRecognitionRequested( |
173 params.caller_id, params.render_process_id, params.render_view_id, | 174 params.caller_id, params.render_process_id, params.render_view_id, |
174 params.element_rect); | 175 params.element_rect); |
175 delegate_->GetRequestInfo(&can_report_metrics_, &request_info_); | 176 delegate_->GetRequestInfo(&can_report_metrics_, &request_info_); |
176 } | 177 } |
177 | 178 |
178 SpeechInputRequest* request = &requests_[params.caller_id]; | 179 Request* request = &requests_[params.caller_id]; |
179 request->delegate = params.delegate; | 180 request->delegate = params.delegate; |
180 request->recognizer = new SpeechRecognizerImpl( | 181 request->recognizer = new SpeechRecognizerImpl( |
181 this, params.caller_id, params.language, params.grammar, | 182 this, params.caller_id, params.language, params.grammar, |
182 params.context_getter, params.speech_input_prefs->FilterProfanities(), | 183 params.context_getter, params.recognition_prefs->FilterProfanities(), |
183 request_info_, can_report_metrics_ ? params.origin_url : ""); | 184 request_info_, can_report_metrics_ ? params.origin_url : ""); |
184 request->is_active = false; | 185 request->is_active = false; |
185 | 186 |
186 StartRecognitionForRequest(params.caller_id); | 187 StartRecognitionForRequest(params.caller_id); |
187 } | 188 } |
188 | 189 |
189 void SpeechInputManagerImpl::StartRecognitionForRequest(int caller_id) { | 190 void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int caller_id) { |
190 SpeechRecognizerMap::iterator request = requests_.find(caller_id); | 191 SpeechRecognizerMap::iterator request = requests_.find(caller_id); |
191 if (request == requests_.end()) { | 192 if (request == requests_.end()) { |
192 NOTREACHED(); | 193 NOTREACHED(); |
193 return; | 194 return; |
194 } | 195 } |
195 | 196 |
196 // We should not currently be recording for the caller. | 197 // We should not currently be recording for the caller. |
197 CHECK(recording_caller_id_ != caller_id); | 198 CHECK(recording_caller_id_ != caller_id); |
198 | 199 |
199 // If we are currently recording audio for another caller, abort that cleanly. | 200 // If we are currently recording audio for another caller, abort that cleanly. |
200 if (recording_caller_id_) | 201 if (recording_caller_id_) |
201 CancelRecognitionAndInformDelegate(recording_caller_id_); | 202 CancelRecognitionAndInformDelegate(recording_caller_id_); |
202 | 203 |
203 if (!HasAudioInputDevices()) { | 204 if (!HasAudioInputDevices()) { |
204 if (delegate_) { | 205 if (delegate_) { |
205 delegate_->ShowMicError( | 206 delegate_->ShowMicError(caller_id, |
206 caller_id, SpeechInputManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); | 207 SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); |
207 } | 208 } |
208 } else if (IsRecordingInProcess()) { | 209 } else if (IsCapturingAudio()) { |
209 if (delegate_) { | 210 if (delegate_) { |
210 delegate_->ShowMicError( | 211 delegate_->ShowMicError( |
211 caller_id, SpeechInputManagerDelegate::MIC_ERROR_DEVICE_IN_USE); | 212 caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); |
212 } | 213 } |
213 } else { | 214 } else { |
214 recording_caller_id_ = caller_id; | 215 recording_caller_id_ = caller_id; |
215 requests_[caller_id].is_active = true; | 216 requests_[caller_id].is_active = true; |
216 requests_[caller_id].recognizer->StartRecording(); | 217 requests_[caller_id].recognizer->StartRecording(); |
217 if (delegate_) | 218 if (delegate_) |
218 delegate_->ShowWarmUp(caller_id); | 219 delegate_->ShowWarmUp(caller_id); |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 void SpeechInputManagerImpl::CancelRecognitionForRequest(int caller_id) { | 223 void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) { |
223 // Ignore if the caller id was not in our active recognizers list because the | 224 // Ignore if the caller id was not in our active recognizers list because the |
224 // user might have clicked more than once, or recognition could have been | 225 // user might have clicked more than once, or recognition could have been |
225 // ended due to other reasons before the user click was processed. | 226 // ended due to other reasons before the user click was processed. |
226 if (!HasPendingRequest(caller_id)) | 227 if (!HasPendingRequest(caller_id)) |
227 return; | 228 return; |
228 | 229 |
229 CancelRecognitionAndInformDelegate(caller_id); | 230 CancelRecognitionAndInformDelegate(caller_id); |
230 } | 231 } |
231 | 232 |
232 void SpeechInputManagerImpl::FocusLostForRequest(int caller_id) { | 233 void SpeechRecognitionManagerImpl::FocusLostForRequest(int caller_id) { |
233 // See above comment. | 234 // See above comment. |
234 if (!HasPendingRequest(caller_id)) | 235 if (!HasPendingRequest(caller_id)) |
235 return; | 236 return; |
236 | 237 |
237 // If this is an ongoing recording or if we were displaying an error message | 238 // If this is an ongoing recording or if we were displaying an error message |
238 // to the user, abort it since user has switched focus. Otherwise | 239 // to the user, abort it since user has switched focus. Otherwise |
239 // recognition has started and keep that going so user can start speaking to | 240 // recognition has started and keep that going so user can start speaking to |
240 // another element while this gets the results in parallel. | 241 // another element while this gets the results in parallel. |
241 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) | 242 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) |
242 CancelRecognitionAndInformDelegate(caller_id); | 243 CancelRecognitionAndInformDelegate(caller_id); |
243 } | 244 } |
244 | 245 |
245 void SpeechInputManagerImpl::CancelRecognition(int caller_id) { | 246 void SpeechRecognitionManagerImpl::CancelRecognition(int caller_id) { |
246 DCHECK(HasPendingRequest(caller_id)); | 247 DCHECK(HasPendingRequest(caller_id)); |
247 if (requests_[caller_id].is_active) | 248 if (requests_[caller_id].is_active) |
248 requests_[caller_id].recognizer->CancelRecognition(); | 249 requests_[caller_id].recognizer->CancelRecognition(); |
249 requests_.erase(caller_id); | 250 requests_.erase(caller_id); |
250 if (recording_caller_id_ == caller_id) | 251 if (recording_caller_id_ == caller_id) |
251 recording_caller_id_ = 0; | 252 recording_caller_id_ = 0; |
252 if (delegate_) | 253 if (delegate_) |
253 delegate_->DoClose(caller_id); | 254 delegate_->DoClose(caller_id); |
254 } | 255 } |
255 | 256 |
256 void SpeechInputManagerImpl::CancelAllRequestsWithDelegate( | 257 void SpeechRecognitionManagerImpl::CancelAllRequestsWithDelegate( |
257 SpeechInputDispatcherHost* delegate) { | 258 InputTagSpeechDispatcherHost* delegate) { |
258 SpeechRecognizerMap::iterator it = requests_.begin(); | 259 SpeechRecognizerMap::iterator it = requests_.begin(); |
259 while (it != requests_.end()) { | 260 while (it != requests_.end()) { |
260 if (it->second.delegate == delegate) { | 261 if (it->second.delegate == delegate) { |
261 CancelRecognition(it->first); | 262 CancelRecognition(it->first); |
262 // This map will have very few elements so it is simpler to restart. | 263 // This map will have very few elements so it is simpler to restart. |
263 it = requests_.begin(); | 264 it = requests_.begin(); |
264 } else { | 265 } else { |
265 ++it; | 266 ++it; |
266 } | 267 } |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 void SpeechInputManagerImpl::StopRecording(int caller_id) { | 271 void SpeechRecognitionManagerImpl::StopRecording(int caller_id) { |
271 // No pending requests on extension popups. | 272 // No pending requests on extension popups. |
272 if (!HasPendingRequest(caller_id)) | 273 if (!HasPendingRequest(caller_id)) |
273 return; | 274 return; |
274 | 275 |
275 requests_[caller_id].recognizer->StopRecording(); | 276 requests_[caller_id].recognizer->StopRecording(); |
276 } | 277 } |
277 | 278 |
278 void SpeechInputManagerImpl::SetRecognitionResult( | 279 void SpeechRecognitionManagerImpl::SetRecognitionResult( |
279 int caller_id, const content::SpeechInputResult& result) { | 280 int caller_id, const content::SpeechRecognitionResult& result) { |
280 DCHECK(HasPendingRequest(caller_id)); | 281 DCHECK(HasPendingRequest(caller_id)); |
281 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); | 282 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); |
282 } | 283 } |
283 | 284 |
284 void SpeechInputManagerImpl::DidCompleteRecording(int caller_id) { | 285 void SpeechRecognitionManagerImpl::DidCompleteRecording(int caller_id) { |
285 DCHECK(recording_caller_id_ == caller_id); | 286 DCHECK(recording_caller_id_ == caller_id); |
286 DCHECK(HasPendingRequest(caller_id)); | 287 DCHECK(HasPendingRequest(caller_id)); |
287 recording_caller_id_ = 0; | 288 recording_caller_id_ = 0; |
288 GetDelegate(caller_id)->DidCompleteRecording(caller_id); | 289 GetDelegate(caller_id)->DidCompleteRecording(caller_id); |
289 if (delegate_) | 290 if (delegate_) |
290 delegate_->ShowRecognizing(caller_id); | 291 delegate_->ShowRecognizing(caller_id); |
291 } | 292 } |
292 | 293 |
293 void SpeechInputManagerImpl::DidCompleteRecognition(int caller_id) { | 294 void SpeechRecognitionManagerImpl::DidCompleteRecognition(int caller_id) { |
294 GetDelegate(caller_id)->DidCompleteRecognition(caller_id); | 295 GetDelegate(caller_id)->DidCompleteRecognition(caller_id); |
295 requests_.erase(caller_id); | 296 requests_.erase(caller_id); |
296 if (delegate_) | 297 if (delegate_) |
297 delegate_->DoClose(caller_id); | 298 delegate_->DoClose(caller_id); |
298 } | 299 } |
299 | 300 |
300 void SpeechInputManagerImpl::DidStartReceivingSpeech(int caller_id) { | 301 void SpeechRecognitionManagerImpl::DidStartReceivingSpeech(int caller_id) { |
301 } | 302 } |
302 | 303 |
303 void SpeechInputManagerImpl::DidStopReceivingSpeech(int caller_id) { | 304 void SpeechRecognitionManagerImpl::DidStopReceivingSpeech(int caller_id) { |
304 } | 305 } |
305 | 306 |
306 void SpeechInputManagerImpl::OnRecognizerError( | 307 void SpeechRecognitionManagerImpl::OnRecognizerError( |
307 int caller_id, content::SpeechInputError error) { | 308 int caller_id, content::SpeechRecognitionErrorCode error) { |
308 if (caller_id == recording_caller_id_) | 309 if (caller_id == recording_caller_id_) |
309 recording_caller_id_ = 0; | 310 recording_caller_id_ = 0; |
310 requests_[caller_id].is_active = false; | 311 requests_[caller_id].is_active = false; |
311 if (delegate_) | 312 if (delegate_) |
312 delegate_->ShowRecognizerError(caller_id, error); | 313 delegate_->ShowRecognizerError(caller_id, error); |
313 } | 314 } |
314 | 315 |
315 void SpeechInputManagerImpl::DidStartReceivingAudio(int caller_id) { | 316 void SpeechRecognitionManagerImpl::DidStartReceivingAudio(int caller_id) { |
316 DCHECK(HasPendingRequest(caller_id)); | 317 DCHECK(HasPendingRequest(caller_id)); |
317 DCHECK(recording_caller_id_ == caller_id); | 318 DCHECK(recording_caller_id_ == caller_id); |
318 if (delegate_) | 319 if (delegate_) |
319 delegate_->ShowRecording(caller_id); | 320 delegate_->ShowRecording(caller_id); |
320 } | 321 } |
321 | 322 |
322 void SpeechInputManagerImpl::DidCompleteEnvironmentEstimation(int caller_id) { | 323 void SpeechRecognitionManagerImpl::DidCompleteEnvironmentEstimation( |
| 324 int caller_id) { |
323 DCHECK(HasPendingRequest(caller_id)); | 325 DCHECK(HasPendingRequest(caller_id)); |
324 DCHECK(recording_caller_id_ == caller_id); | 326 DCHECK(recording_caller_id_ == caller_id); |
325 } | 327 } |
326 | 328 |
327 void SpeechInputManagerImpl::SetInputVolume(int caller_id, float volume, | 329 void SpeechRecognitionManagerImpl::SetInputVolume(int caller_id, float volume, |
328 float noise_volume) { | 330 float noise_volume) { |
329 DCHECK(HasPendingRequest(caller_id)); | 331 DCHECK(HasPendingRequest(caller_id)); |
330 DCHECK_EQ(recording_caller_id_, caller_id); | 332 DCHECK_EQ(recording_caller_id_, caller_id); |
331 if (delegate_) | 333 if (delegate_) |
332 delegate_->ShowInputVolume(caller_id, volume, noise_volume); | 334 delegate_->ShowInputVolume(caller_id, volume, noise_volume); |
333 } | 335 } |
334 | 336 |
335 void SpeechInputManagerImpl::CancelRecognitionAndInformDelegate( | 337 void SpeechRecognitionManagerImpl::CancelRecognitionAndInformDelegate( |
336 int caller_id) { | 338 int caller_id) { |
337 SpeechInputDispatcherHost* cur_delegate = GetDelegate(caller_id); | 339 InputTagSpeechDispatcherHost* cur_delegate = GetDelegate(caller_id); |
338 CancelRecognition(caller_id); | 340 CancelRecognition(caller_id); |
339 cur_delegate->DidCompleteRecording(caller_id); | 341 cur_delegate->DidCompleteRecording(caller_id); |
340 cur_delegate->DidCompleteRecognition(caller_id); | 342 cur_delegate->DidCompleteRecognition(caller_id); |
341 } | 343 } |
342 | 344 |
343 SpeechInputManagerImpl::SpeechInputRequest::SpeechInputRequest() | 345 SpeechRecognitionManagerImpl::Request::Request() |
344 : delegate(NULL), | 346 : delegate(NULL), |
345 is_active(false) { | 347 is_active(false) { |
346 } | 348 } |
347 | 349 |
348 SpeechInputManagerImpl::SpeechInputRequest::~SpeechInputRequest() { | 350 SpeechRecognitionManagerImpl::Request::~Request() { |
349 } | 351 } |
350 | 352 |
351 } // namespace speech_input | 353 } // namespace speech |
OLD | NEW |