Index: content/browser/speech/input_tag_speech_dispatcher_host.cc |
diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.cc b/content/browser/speech/input_tag_speech_dispatcher_host.cc |
index 0fa54be0a6b808ac8e01fdf41bddc3263fcc9633..fdd3378fd3484b27c7ea7eb5799eab45c6408b11 100644 |
--- a/content/browser/speech/input_tag_speech_dispatcher_host.cc |
+++ b/content/browser/speech/input_tag_speech_dispatcher_host.cc |
@@ -6,9 +6,8 @@ |
#include "base/bind.h" |
#include "base/lazy_instance.h" |
-#include "content/browser/speech/speech_recognition_manager_impl.h" |
-#include "content/browser/speech/speech_recognizer_impl.h" |
#include "content/common/speech_recognition_messages.h" |
+#include "content/public/browser/speech_recognition_manager.h" |
#include "content/public/browser/speech_recognition_preferences.h" |
#include "content/public/browser/speech_recognition_session_config.h" |
#include "content/public/browser/speech_recognition_session_context.h" |
@@ -18,17 +17,6 @@ using content::SpeechRecognitionManager; |
using content::SpeechRecognitionSessionConfig; |
using content::SpeechRecognitionSessionContext; |
-namespace { |
-bool IsSameContext(int render_process_id, |
- int render_view_id, |
- int render_request_id, |
- const SpeechRecognitionSessionContext& context) { |
- return context.render_process_id == render_process_id && |
- context.render_view_id == render_view_id && |
- context.render_request_id == render_request_id; |
-} |
-} // namespace |
- |
namespace speech { |
SpeechRecognitionManager* InputTagSpeechDispatcherHost::manager_for_tests_; |
@@ -42,32 +30,21 @@ InputTagSpeechDispatcherHost::InputTagSpeechDispatcherHost( |
net::URLRequestContextGetter* url_request_context_getter, |
content::SpeechRecognitionPreferences* recognition_preferences) |
: render_process_id_(render_process_id), |
- may_have_pending_requests_(false), |
url_request_context_getter_(url_request_context_getter), |
recognition_preferences_(recognition_preferences) { |
- // This is initialized by Browser. Do not add any non-trivial |
- // initialization here, instead do it lazily when required (e.g. see the |
- // method |manager()|) or add an Init() method. |
+ // Do not add any non-trivial initialization here, instead do it lazily when |
+ // required (e.g. see the method |manager()|) or add an Init() method. |
} |
InputTagSpeechDispatcherHost::~InputTagSpeechDispatcherHost() { |
- // If the renderer crashed for some reason or if we didn't receive a proper |
- // Cancel/Stop call for an existing session, cancel such active sessions now. |
- // We first check if this dispatcher received any speech IPC requst so that |
- // we don't end up creating the speech input manager for web pages which don't |
- // use speech input. |
- if (may_have_pending_requests_) |
- manager()->AbortAllSessionsForListener(this); |
+ if (SpeechRecognitionManager* sr_manager = manager()) |
+ sr_manager->AbortAllSessionsForListener(this); |
} |
SpeechRecognitionManager* InputTagSpeechDispatcherHost::manager() { |
if (manager_for_tests_) |
return manager_for_tests_; |
-#if defined(ENABLE_INPUT_SPEECH) |
return SpeechRecognitionManager::GetInstance(); |
-#else |
- return NULL; |
-#endif |
} |
bool InputTagSpeechDispatcherHost::OnMessageReceived( |
@@ -84,19 +61,17 @@ bool InputTagSpeechDispatcherHost::OnMessageReceived( |
OnStopRecording) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
- if (handled) |
- may_have_pending_requests_ = true; |
return handled; |
} |
void InputTagSpeechDispatcherHost::OnStartRecognition( |
- const InputTagSpeechHostMsg_StartRecognition_Params ¶ms) { |
+ const InputTagSpeechHostMsg_StartRecognition_Params& params) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
SpeechRecognitionSessionContext context; |
context.render_process_id = render_process_id_; |
context.render_view_id = params.render_view_id; |
- context.render_request_id = params.request_id; |
+ context.request_id = params.request_id; |
context.element_rect = params.element_rect; |
SpeechRecognitionSessionConfig config; |
@@ -112,20 +87,16 @@ void InputTagSpeechDispatcherHost::OnStartRecognition( |
config.event_listener = this; |
int session_id = manager()->CreateSession(config); |
- if (session_id == SpeechRecognitionManager::kSessionIDInvalid) |
- return; |
- |
- manager()->StartSession(session_id); |
+ DCHECK_NE(session_id, content::SpeechRecognitionManager::kSessionIDInvalid); |
+ manager()->StartSession(session_id); |
} |
void InputTagSpeechDispatcherHost::OnCancelRecognition(int render_view_id, |
int request_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- int session_id = manager()->LookupSessionByContext( |
- base::Bind(&IsSameContext, |
- render_process_id_, |
- render_view_id, |
- request_id)); |
+ int session_id = manager()->GetSession(render_process_id_, |
+ render_view_id, |
+ request_id); |
if (session_id != SpeechRecognitionManager::kSessionIDInvalid) |
manager()->AbortSession(session_id); |
} |
@@ -133,11 +104,9 @@ void InputTagSpeechDispatcherHost::OnCancelRecognition(int render_view_id, |
void InputTagSpeechDispatcherHost::OnStopRecording(int render_view_id, |
int request_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- int session_id = manager()->LookupSessionByContext( |
- base::Bind(&IsSameContext, |
- render_process_id_, |
- render_view_id, |
- request_id)); |
+ int session_id = manager()->GetSession(render_process_id_, |
+ render_view_id, |
+ request_id); |
DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid); |
manager()->StopAudioCaptureForSession(session_id); |
} |
@@ -153,7 +122,7 @@ void InputTagSpeechDispatcherHost::OnRecognitionResult( |
Send(new InputTagSpeechMsg_SetRecognitionResult( |
context.render_view_id, |
- context.render_request_id, |
+ context.request_id, |
result)); |
VLOG(1) << "InputTagSpeechDispatcherHost::OnRecognitionResult exit"; |
} |
@@ -166,7 +135,7 @@ void InputTagSpeechDispatcherHost::OnAudioEnd(int session_id) { |
manager()->GetSessionContext(session_id); |
Send(new InputTagSpeechMsg_RecordingComplete(context.render_view_id, |
- context.render_request_id)); |
+ context.request_id)); |
VLOG(1) << "InputTagSpeechDispatcherHost::OnAudioEnd exit"; |
} |
@@ -176,7 +145,7 @@ void InputTagSpeechDispatcherHost::OnRecognitionEnd(int session_id) { |
const SpeechRecognitionSessionContext& context = |
manager()->GetSessionContext(session_id); |
Send(new InputTagSpeechMsg_RecognitionComplete(context.render_view_id, |
- context.render_request_id)); |
+ context.request_id)); |
VLOG(1) << "InputTagSpeechDispatcherHost::OnRecognitionEnd exit"; |
} |