diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 20:34:19 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 20:34:19 +0000 |
commit | ee2a62078e0a3c44628a80337d6b548883071c5a (patch) | |
tree | 5a1e22d59b368d770164bf3b4b56598332535d43 /chrome/browser/speech/speech_recognizer.cc | |
parent | e2dffe003add45048a608aef0de27784efc72e34 (diff) | |
download | chromium_src-ee2a62078e0a3c44628a80337d6b548883071c5a.zip chromium_src-ee2a62078e0a3c44628a80337d6b548883071c5a.tar.gz chromium_src-ee2a62078e0a3c44628a80337d6b548883071c5a.tar.bz2 |
Fix a potential assert in SpeechRecognizer dtor.
When StopRecognition is invoked and no data was recorded, there is a possibility that the delegate
might release the recognizer within the DidCompleteRecognition callback. So we now perform cleanup
tasks such as freeing the encoder_ object before invoking the delegate. Without this change there
would be an assert in the SpeechRecognizer dtor about encoder_ remaining valid.
BUG=none
TEST=Manual, double-click on the speech button quickly a few times and verify no assert pops up in the dtor.
Review URL: http://codereview.chromium.org/6381004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71994 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/speech/speech_recognizer.cc')
-rw-r--r-- | chrome/browser/speech/speech_recognizer.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/chrome/browser/speech/speech_recognizer.cc b/chrome/browser/speech/speech_recognizer.cc index 38bbeca..113600b 100644 --- a/chrome/browser/speech/speech_recognizer.cc +++ b/chrome/browser/speech/speech_recognizer.cc @@ -129,8 +129,12 @@ void SpeechRecognizer::StopRecording() { // Since the http request takes a single string as POST data, allocate // one and copy over bytes from the audio buffers to the string. // And If we haven't got any audio yet end the recognition sequence here. + string mime_type = encoder_->mime_type(); string data; - if (!encoder_->GetEncodedData(&data)) { + encoder_->GetEncodedData(&data); + encoder_.reset(); + + if (data.empty()) { // Guard against the delegate freeing us until we finish our job. scoped_refptr<SpeechRecognizer> me(this); delegate_->DidCompleteRecognition(caller_id_); @@ -139,9 +143,8 @@ void SpeechRecognizer::StopRecording() { request_.reset(new SpeechRecognitionRequest( Profile::GetDefaultRequestContext(), this)); request_->Send(language_, grammar_, hardware_info_, origin_url_, - encoder_->mime_type(), data); + mime_type, data); } - encoder_.reset(); } void SpeechRecognizer::ReleaseAudioBuffers() { |