Index: content/browser/speech/speech_input_manager.cc |
=================================================================== |
--- content/browser/speech/speech_input_manager.cc (revision 113173) |
+++ content/browser/speech/speech_input_manager.cc (working copy) |
@@ -26,7 +26,8 @@ |
const std::string& grammar, |
const std::string& origin_url, |
net::URLRequestContextGetter* context_getter, |
- SpeechInputPreferences* speech_input_prefs) |
+ SpeechInputPreferences* speech_input_prefs, |
+ AudioManager* audio_manager) |
: delegate(delegate), |
caller_id(caller_id), |
render_process_id(render_process_id), |
@@ -36,7 +37,8 @@ |
grammar(grammar), |
origin_url(origin_url), |
context_getter(context_getter), |
- speech_input_prefs(speech_input_prefs) { |
+ speech_input_prefs(speech_input_prefs), |
+ audio_manager_(audio_manager) { |
} |
Delegate* delegate; |
@@ -49,6 +51,7 @@ |
std::string origin_url; |
net::URLRequestContextGetter* context_getter; |
SpeechInputPreferences* speech_input_prefs; |
+ scoped_refptr<AudioManager> audio_manager_; |
}; |
SpeechInputManager::SpeechInputManager() |
@@ -70,19 +73,20 @@ |
return requests_.find(caller_id)->second.delegate; |
} |
-void SpeechInputManager::ShowAudioInputSettings() { |
+void SpeechInputManager::ShowAudioInputSettings(AudioManager* audio_manager) { |
// Since AudioManager::ShowAudioInputSettings can potentially launch external |
// processes, do that in the FILE thread to not block the calling threads. |
if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
BrowserThread::PostTask( |
BrowserThread::FILE, FROM_HERE, |
- base::Bind(&SpeechInputManager::ShowAudioInputSettings)); |
+ base::Bind(&SpeechInputManager::ShowAudioInputSettings, |
+ base::Unretained(audio_manager))); |
return; |
} |
- DCHECK(AudioManager::GetAudioManager()->CanShowAudioInputSettings()); |
- if (AudioManager::GetAudioManager()->CanShowAudioInputSettings()) |
- AudioManager::GetAudioManager()->ShowAudioInputSettings(); |
+ DCHECK(audio_manager->CanShowAudioInputSettings()); |
+ if (audio_manager->CanShowAudioInputSettings()) |
+ audio_manager->ShowAudioInputSettings(); |
} |
void SpeechInputManager::StartRecognition( |
@@ -95,14 +99,15 @@ |
const std::string& grammar, |
const std::string& origin_url, |
net::URLRequestContextGetter* context_getter, |
- SpeechInputPreferences* speech_input_prefs) { |
+ SpeechInputPreferences* speech_input_prefs, |
+ AudioManager* audio_manager) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
BrowserThread::PostTask( |
BrowserThread::UI, FROM_HERE, |
base::Bind(&SpeechInputManager::CheckRenderViewTypeAndStartRecognition, |
base::Unretained(this), SpeechInputParams(delegate, caller_id, |
render_process_id, render_view_id, element_rect, language, grammar, |
- origin_url, context_getter, speech_input_prefs))); |
+ origin_url, context_getter, speech_input_prefs, audio_manager))); |
} |
void SpeechInputManager::CheckRenderViewTypeAndStartRecognition( |
@@ -143,7 +148,8 @@ |
request->delegate = params.delegate; |
request->recognizer = new SpeechRecognizer( |
this, params.caller_id, params.language, params.grammar, |
- params.context_getter, params.speech_input_prefs->filter_profanities(), |
+ params.context_getter, params.audio_manager_.get(), |
+ params.speech_input_prefs->filter_profanities(), |
request_info_, can_report_metrics_ ? params.origin_url : ""); |
request->is_active = false; |
@@ -151,15 +157,20 @@ |
} |
void SpeechInputManager::StartRecognitionForRequest(int caller_id) { |
- DCHECK(HasPendingRequest(caller_id)); |
+ SpeechRecognizerMap::iterator request = requests_.find(caller_id); |
+ if (request == requests_.end()) { |
+ NOTREACHED(); |
+ return; |
+ } |
// If we are currently recording audio for another caller, abort that cleanly. |
if (recording_caller_id_) |
CancelRecognitionAndInformDelegate(recording_caller_id_); |
- if (!AudioManager::GetAudioManager()->HasAudioInputDevices()) { |
+ AudioManager* audio_man = request->second.recognizer->audio_manager(); |
+ if (!audio_man->HasAudioInputDevices()) { |
ShowMicError(caller_id, kNoDeviceAvailable); |
- } else if (AudioManager::GetAudioManager()->IsRecordingInProcess()) { |
+ } else if (audio_man->IsRecordingInProcess()) { |
ShowMicError(caller_id, kDeviceInUse); |
} else { |
recording_caller_id_ = caller_id; |