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

Unified Diff: content/browser/speech/speech_input_manager.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/speech/speech_input_manager.h ('k') | content/browser/speech/speech_recognizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « content/browser/speech/speech_input_manager.h ('k') | content/browser/speech/speech_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698