Index: content/browser/speech/speech_input_manager.cc |
=================================================================== |
--- content/browser/speech/speech_input_manager.cc (revision 114012) |
+++ content/browser/speech/speech_input_manager.cc (working copy) |
@@ -7,6 +7,7 @@ |
#include "base/bind.h" |
#include "content/browser/renderer_host/render_view_host.h" |
#include "content/browser/renderer_host/render_view_host_delegate.h" |
+#include "content/browser/resource_context.h" |
#include "content/browser/speech/speech_input_preferences.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/common/view_type.h" |
@@ -26,7 +27,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 +38,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 +52,7 @@ |
std::string origin_url; |
net::URLRequestContextGetter* context_getter; |
SpeechInputPreferences* speech_input_prefs; |
+ scoped_refptr<AudioManager> audio_manager_; |
}; |
SpeechInputManager::SpeechInputManager() |
@@ -70,21 +74,36 @@ |
return requests_.find(caller_id)->second.delegate; |
} |
-void SpeechInputManager::ShowAudioInputSettings() { |
+// static |
+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(); |
} |
+// static |
+void SpeechInputManager::ShowAudioInputSettingsFromUI( |
+ const content::ResourceContext* resource_context) { |
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&SpeechInputManager::ShowAudioInputSettingsFromUI, |
+ base::Unretained(resource_context))); |
+ return; |
+ } |
+ ShowAudioInputSettings(resource_context->audio_manager()); |
+} |
+ |
void SpeechInputManager::StartRecognition( |
SpeechInputManagerDelegate* delegate, |
int caller_id, |
@@ -95,14 +114,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( |
@@ -137,13 +157,15 @@ |
ShowRecognitionRequested( |
params.caller_id, params.render_process_id, params.render_view_id, |
params.element_rect); |
- GetRequestInfo(&can_report_metrics_, &request_info_); |
+ GetRequestInfo(params.audio_manager_, &can_report_metrics_, |
+ &request_info_); |
SpeechInputRequest* request = &requests_[params.caller_id]; |
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_, |
+ params.speech_input_prefs->filter_profanities(), |
request_info_, can_report_metrics_ ? params.origin_url : ""); |
request->is_active = false; |
@@ -151,15 +173,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; |