Index: content/browser/speech/speech_recognition_manager_impl.cc |
diff --git a/content/browser/speech/speech_recognition_manager_impl.cc b/content/browser/speech/speech_recognition_manager_impl.cc |
index 46e26137ee4944c34917cb889c13448de5b2cca8..6a9fa6349ec4cfff727bc807522efa2085056fc3 100644 |
--- a/content/browser/speech/speech_recognition_manager_impl.cc |
+++ b/content/browser/speech/speech_recognition_manager_impl.cc |
@@ -203,24 +203,11 @@ void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int caller_id) { |
// If we are currently recording audio for another caller, abort that cleanly. |
if (recording_caller_id_) |
CancelRecognitionAndInformDelegate(recording_caller_id_); |
- |
Primiano Tucci (use gerrit)
2012/03/15 09:14:36
These checks have been moved into the speech_recog
|
- if (!HasAudioInputDevices()) { |
- if (delegate_) { |
- delegate_->ShowMicError(caller_id, |
- SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); |
- } |
- } else if (IsCapturingAudio()) { |
- if (delegate_) { |
- delegate_->ShowMicError( |
- caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); |
- } |
- } else { |
- recording_caller_id_ = caller_id; |
- requests_[caller_id].is_active = true; |
- requests_[caller_id].recognizer->StartRecognition(); |
- if (delegate_) |
- delegate_->ShowWarmUp(caller_id); |
- } |
+ recording_caller_id_ = caller_id; |
+ requests_[caller_id].is_active = true; |
+ requests_[caller_id].recognizer->StartRecognition(); |
+ if (delegate_) |
+ delegate_->ShowWarmUp(caller_id); |
} |
void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) { |
@@ -284,12 +271,17 @@ void SpeechRecognitionManagerImpl::StopRecording(int caller_id) { |
void SpeechRecognitionManagerImpl::OnRecognitionResult( |
int caller_id, const content::SpeechRecognitionResult& result) { |
DCHECK(HasPendingRequest(caller_id)); |
+ DCHECK(result.error == content::SPEECH_RECOGNITION_ERROR_NONE); |
GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); |
} |
void SpeechRecognitionManagerImpl::OnAudioEnd(int caller_id) { |
+ if (recording_caller_id_ != caller_id) |
Primiano Tucci (use gerrit)
2012/03/15 09:14:36
Basically we need these checks because the new eve
hans
2012/03/16 11:12:56
maybe put a comment on the if statement about when
Primiano Tucci (use gerrit)
2012/03/16 15:03:42
Spoiler: this code is going to disappear in the ne
|
+ return; |
DCHECK_EQ(recording_caller_id_, caller_id); |
DCHECK(HasPendingRequest(caller_id)); |
+ if (!requests_[caller_id].is_active) |
+ return; |
recording_caller_id_ = 0; |
GetDelegate(caller_id)->DidCompleteRecording(caller_id); |
if (delegate_) |
@@ -297,6 +289,8 @@ void SpeechRecognitionManagerImpl::OnAudioEnd(int caller_id) { |
} |
void SpeechRecognitionManagerImpl::OnRecognitionEnd(int caller_id) { |
+ if (!HasPendingRequest(caller_id) || !requests_[caller_id].is_active) |
+ return; |
GetDelegate(caller_id)->DidCompleteRecognition(caller_id); |
requests_.erase(caller_id); |
if (delegate_) |
@@ -310,12 +304,24 @@ void SpeechRecognitionManagerImpl::OnSoundEnd(int caller_id) { |
} |
void SpeechRecognitionManagerImpl::OnRecognitionError( |
- int caller_id, const content::SpeechRecognitionErrorCode& error) { |
+ int caller_id, const content::SpeechRecognitionError& error) { |
+ DCHECK(HasPendingRequest(caller_id)); |
if (caller_id == recording_caller_id_) |
recording_caller_id_ = 0; |
requests_[caller_id].is_active = false; |
- if (delegate_) |
- delegate_->ShowRecognizerError(caller_id, error); |
+ if (delegate_) { |
+ if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && |
+ error.details == content::AUDIO_ERROR_NO_MIC) { |
+ delegate_->ShowMicError(caller_id, |
hans
2012/03/16 11:12:56
indentation looks wrong
Primiano Tucci (use gerrit)
2012/03/16 15:03:42
Done.
|
+ SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); |
+ } else if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && |
+ error.details == content::AUDIO_ERROR_MIC_IN_USE) { |
+ delegate_->ShowMicError( |
+ caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); |
+ } else { |
+ delegate_->ShowRecognizerError(caller_id, error.code); |
+ } |
+ } |
} |
void SpeechRecognitionManagerImpl::OnAudioStart(int caller_id) { |