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

Side by Side Diff: content/browser/speech/speech_recognition_manager_impl.cc

Issue 9663066: Refactoring of chrome speech recognition architecture (CL1.3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed according to (partial) Satish review. Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
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_recognition_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/input_tag_speech_dispatcher_host.h" 10 #include "content/browser/speech/input_tag_speech_dispatcher_host.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 NOTREACHED(); 196 NOTREACHED();
197 return; 197 return;
198 } 198 }
199 199
200 // We should not currently be recording for the caller. 200 // We should not currently be recording for the caller.
201 CHECK(recording_caller_id_ != caller_id); 201 CHECK(recording_caller_id_ != caller_id);
202 202
203 // If we are currently recording audio for another caller, abort that cleanly. 203 // If we are currently recording audio for another caller, abort that cleanly.
204 if (recording_caller_id_) 204 if (recording_caller_id_)
205 CancelRecognitionAndInformDelegate(recording_caller_id_); 205 CancelRecognitionAndInformDelegate(recording_caller_id_);
206 206 recording_caller_id_ = caller_id;
207 if (!HasAudioInputDevices()) { 207 requests_[caller_id].is_active = true;
208 if (delegate_) { 208 requests_[caller_id].recognizer->StartRecognition();
Satish 2012/03/21 13:29:48 I see the checks present here before have now move
Primiano Tucci (use gerrit) 2012/03/22 11:20:41 Yes. Errors are not propagated to the dispatcher.
209 delegate_->ShowMicError(caller_id, 209 if (delegate_)
210 SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); 210 delegate_->ShowWarmUp(caller_id);
211 }
212 } else if (IsCapturingAudio()) {
213 if (delegate_) {
214 delegate_->ShowMicError(
215 caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE);
216 }
217 } else {
218 recording_caller_id_ = caller_id;
219 requests_[caller_id].is_active = true;
220 requests_[caller_id].recognizer->StartRecognition();
221 if (delegate_)
222 delegate_->ShowWarmUp(caller_id);
223 }
224 } 211 }
225 212
226 void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) { 213 void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) {
227 // Ignore if the caller id was not in our active recognizers list because the 214 // Ignore if the caller id was not in our active recognizers list because the
228 // user might have clicked more than once, or recognition could have been 215 // user might have clicked more than once, or recognition could have been
229 // ended due to other reasons before the user click was processed. 216 // ended due to other reasons before the user click was processed.
230 if (!HasPendingRequest(caller_id)) 217 if (!HasPendingRequest(caller_id))
231 return; 218 return;
232 219
233 CancelRecognitionAndInformDelegate(caller_id); 220 CancelRecognitionAndInformDelegate(caller_id);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 return; 264 return;
278 265
279 requests_[caller_id].recognizer->StopAudioCapture(); 266 requests_[caller_id].recognizer->StopAudioCapture();
280 } 267 }
281 268
282 // -------- SpeechRecognitionEventListener interface implementation. --------- 269 // -------- SpeechRecognitionEventListener interface implementation. ---------
283 270
284 void SpeechRecognitionManagerImpl::OnRecognitionResult( 271 void SpeechRecognitionManagerImpl::OnRecognitionResult(
285 int caller_id, const content::SpeechRecognitionResult& result) { 272 int caller_id, const content::SpeechRecognitionResult& result) {
286 DCHECK(HasPendingRequest(caller_id)); 273 DCHECK(HasPendingRequest(caller_id));
274 DCHECK(result.error == content::SPEECH_RECOGNITION_ERROR_NONE);
287 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); 275 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result);
288 } 276 }
289 277
290 void SpeechRecognitionManagerImpl::OnAudioEnd(int caller_id) { 278 void SpeechRecognitionManagerImpl::OnAudioEnd(int caller_id) {
279 if (recording_caller_id_ != caller_id)
Satish 2012/03/21 13:29:48 this check shouldn't be here as we have a DCHECK f
Primiano Tucci (use gerrit) 2012/03/22 11:20:41 Basically this checks were introduced because the
280 return;
291 DCHECK_EQ(recording_caller_id_, caller_id); 281 DCHECK_EQ(recording_caller_id_, caller_id);
292 DCHECK(HasPendingRequest(caller_id)); 282 DCHECK(HasPendingRequest(caller_id));
283 if (!requests_[caller_id].is_active)
Satish 2012/03/21 13:29:48 any reason why this check was added? seems like an
Primiano Tucci (use gerrit) 2012/03/22 11:20:41 Same as above. We could receive an AudioEnd of a r
284 return;
293 recording_caller_id_ = 0; 285 recording_caller_id_ = 0;
294 GetDelegate(caller_id)->DidCompleteRecording(caller_id); 286 GetDelegate(caller_id)->DidCompleteRecording(caller_id);
295 if (delegate_) 287 if (delegate_)
296 delegate_->ShowRecognizing(caller_id); 288 delegate_->ShowRecognizing(caller_id);
297 } 289 }
298 290
299 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int caller_id) { 291 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int caller_id) {
292 if (!HasPendingRequest(caller_id) || !requests_[caller_id].is_active)
Satish 2012/03/21 13:29:48 ditto, could be a DCHECK if you really want to che
Primiano Tucci (use gerrit) 2012/03/22 11:20:41 Same as above.
293 return;
300 GetDelegate(caller_id)->DidCompleteRecognition(caller_id); 294 GetDelegate(caller_id)->DidCompleteRecognition(caller_id);
301 requests_.erase(caller_id); 295 requests_.erase(caller_id);
302 if (delegate_) 296 if (delegate_)
303 delegate_->DoClose(caller_id); 297 delegate_->DoClose(caller_id);
304 } 298 }
305 299
306 void SpeechRecognitionManagerImpl::OnSoundStart(int caller_id) { 300 void SpeechRecognitionManagerImpl::OnSoundStart(int caller_id) {
307 } 301 }
308 302
309 void SpeechRecognitionManagerImpl::OnSoundEnd(int caller_id) { 303 void SpeechRecognitionManagerImpl::OnSoundEnd(int caller_id) {
310 } 304 }
311 305
312 void SpeechRecognitionManagerImpl::OnRecognitionError( 306 void SpeechRecognitionManagerImpl::OnRecognitionError(
313 int caller_id, const content::SpeechRecognitionErrorCode& error) { 307 int caller_id, const content::SpeechRecognitionError& error) {
308 DCHECK(HasPendingRequest(caller_id));
314 if (caller_id == recording_caller_id_) 309 if (caller_id == recording_caller_id_)
315 recording_caller_id_ = 0; 310 recording_caller_id_ = 0;
316 requests_[caller_id].is_active = false; 311 requests_[caller_id].is_active = false;
317 if (delegate_) 312 if (delegate_) {
318 delegate_->ShowRecognizerError(caller_id, error); 313 if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO &&
314 error.details == content::AUDIO_ERROR_NO_MIC) {
315 delegate_->ShowMicError(caller_id,
316 SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE);
317 } else if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO &&
318 error.details == content::AUDIO_ERROR_MIC_IN_USE) {
319 delegate_->ShowMicError(
320 caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE);
321 } else {
322 delegate_->ShowRecognizerError(caller_id, error.code);
323 }
324 }
319 } 325 }
320 326
321 void SpeechRecognitionManagerImpl::OnAudioStart(int caller_id) { 327 void SpeechRecognitionManagerImpl::OnAudioStart(int caller_id) {
322 DCHECK(HasPendingRequest(caller_id)); 328 DCHECK(HasPendingRequest(caller_id));
323 DCHECK_EQ(recording_caller_id_, caller_id); 329 DCHECK_EQ(recording_caller_id_, caller_id);
324 if (delegate_) 330 if (delegate_)
325 delegate_->ShowRecording(caller_id); 331 delegate_->ShowRecording(caller_id);
326 } 332 }
327 333
328 void SpeechRecognitionManagerImpl::OnRecognitionStart(int caller_id) { 334 void SpeechRecognitionManagerImpl::OnRecognitionStart(int caller_id) {
(...skipping 23 matching lines...) Expand all
352 358
353 SpeechRecognitionManagerImpl::Request::Request() 359 SpeechRecognitionManagerImpl::Request::Request()
354 : delegate(NULL), 360 : delegate(NULL),
355 is_active(false) { 361 is_active(false) {
356 } 362 }
357 363
358 SpeechRecognitionManagerImpl::Request::~Request() { 364 SpeechRecognitionManagerImpl::Request::~Request() {
359 } 365 }
360 366
361 } // namespace speech 367 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698