summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
authorhans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 10:10:34 +0000
committerhans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 10:10:34 +0000
commit64d09224049a393ad66c565299001beab3616c1e (patch)
treed7bb1d841856eaf297087711c6269e2f998057c3 /content/browser
parentc4205b9ed7bd1096500828e2893036c0f38a51df (diff)
downloadchromium_src-64d09224049a393ad66c565299001beab3616c1e.zip
chromium_src-64d09224049a393ad66c565299001beab3616c1e.tar.gz
chromium_src-64d09224049a393ad66c565299001beab3616c1e.tar.bz2
Introduced SpeechRecognitionDispatcher(Host) classes, handling dispatch of IPC messages for continuous speech recognition. (Speech CL2.1)
BUG=116954 TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=138801 Review URL: https://chromiumcodereview.appspot.com/10273006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc9
-rw-r--r--content/browser/speech/input_tag_speech_dispatcher_host.cc75
-rw-r--r--content/browser/speech/input_tag_speech_dispatcher_host.h4
-rw-r--r--content/browser/speech/speech_recognition_browsertest.cc12
-rw-r--r--content/browser/speech/speech_recognition_dispatcher_host.cc181
-rw-r--r--content/browser/speech/speech_recognition_dispatcher_host.h82
-rw-r--r--content/browser/speech/speech_recognition_manager_impl.cc16
-rw-r--r--content/browser/speech/speech_recognition_manager_impl.h7
8 files changed, 303 insertions, 83 deletions
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 27ba199..dd6dfdb 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -79,6 +79,8 @@
#include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
#include "content/browser/renderer_host/text_input_client_message_filter.h"
#include "content/browser/resolve_proxy_msg_helper.h"
+#include "content/browser/speech/input_tag_speech_dispatcher_host.h"
+#include "content/browser/speech/speech_recognition_dispatcher_host.h"
#include "content/browser/trace_message_filter.h"
#include "content/browser/worker_host/worker_message_filter.h"
#include "content/common/child_process_host_impl.h"
@@ -115,10 +117,6 @@
#include "content/common/font_cache_dispatcher_win.h"
#endif
-#if defined(ENABLE_INPUT_SPEECH)
-#include "content/browser/speech/input_tag_speech_dispatcher_host.h"
-#endif
-
#include "third_party/skia/include/core/SkBitmap.h"
using content::BrowserContext;
@@ -504,6 +502,9 @@ void RenderProcessHostImpl::CreateMessageFilters() {
channel_->AddFilter(new speech::InputTagSpeechDispatcherHost(
GetID(), browser_context->GetRequestContext(),
browser_context->GetSpeechRecognitionPreferences()));
+ channel_->AddFilter(new speech::SpeechRecognitionDispatcherHost(
+ GetID(), browser_context->GetRequestContext(),
+ browser_context->GetSpeechRecognitionPreferences()));
#endif
channel_->AddFilter(new FileAPIMessageFilter(
GetID(),
diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.cc b/content/browser/speech/input_tag_speech_dispatcher_host.cc
index 0fa54be..ef6f793 100644
--- a/content/browser/speech/input_tag_speech_dispatcher_host.cc
+++ b/content/browser/speech/input_tag_speech_dispatcher_host.cc
@@ -6,29 +6,16 @@
#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"
-using content::BrowserThread;
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,37 +29,25 @@ 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(
const IPC::Message& message, bool* message_was_ok) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(InputTagSpeechDispatcherHost, message,
*message_was_ok)
@@ -84,19 +59,16 @@ 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 &params) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ const InputTagSpeechHostMsg_StartRecognition_Params& params) {
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,32 +84,24 @@ 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);
}
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);
}
@@ -146,37 +110,34 @@ void InputTagSpeechDispatcherHost::OnStopRecording(int render_view_id,
void InputTagSpeechDispatcherHost::OnRecognitionResult(
int session_id, const content::SpeechRecognitionResult& result) {
VLOG(1) << "InputTagSpeechDispatcherHost::OnRecognitionResult enter";
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
const SpeechRecognitionSessionContext& context =
manager()->GetSessionContext(session_id);
Send(new InputTagSpeechMsg_SetRecognitionResult(
context.render_view_id,
- context.render_request_id,
+ context.request_id,
result));
VLOG(1) << "InputTagSpeechDispatcherHost::OnRecognitionResult exit";
}
void InputTagSpeechDispatcherHost::OnAudioEnd(int session_id) {
VLOG(1) << "InputTagSpeechDispatcherHost::OnAudioEnd enter";
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
const SpeechRecognitionSessionContext& context =
manager()->GetSessionContext(session_id);
Send(new InputTagSpeechMsg_RecordingComplete(context.render_view_id,
- context.render_request_id));
+ context.request_id));
VLOG(1) << "InputTagSpeechDispatcherHost::OnAudioEnd exit";
}
void InputTagSpeechDispatcherHost::OnRecognitionEnd(int session_id) {
VLOG(1) << "InputTagSpeechDispatcherHost::OnRecognitionEnd enter";
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
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";
}
diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.h b/content/browser/speech/input_tag_speech_dispatcher_host.h
index c7c96edb..703174cc 100644
--- a/content/browser/speech/input_tag_speech_dispatcher_host.h
+++ b/content/browser/speech/input_tag_speech_dispatcher_host.h
@@ -62,7 +62,7 @@ class CONTENT_EXPORT InputTagSpeechDispatcherHost
virtual ~InputTagSpeechDispatcherHost();
void OnStartRecognition(
- const InputTagSpeechHostMsg_StartRecognition_Params &params);
+ const InputTagSpeechHostMsg_StartRecognition_Params& params);
void OnCancelRecognition(int render_view_id, int request_id);
void OnStopRecording(int render_view_id, int request_id);
@@ -71,8 +71,6 @@ class CONTENT_EXPORT InputTagSpeechDispatcherHost
content::SpeechRecognitionManager* manager();
int render_process_id_;
- bool may_have_pending_requests_; // Set if we received any speech IPC request
-
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
scoped_refptr<content::SpeechRecognitionPreferences> recognition_preferences_;
diff --git a/content/browser/speech/speech_recognition_browsertest.cc b/content/browser/speech/speech_recognition_browsertest.cc
index a939fb6..f812ebf 100644
--- a/content/browser/speech/speech_recognition_browsertest.cc
+++ b/content/browser/speech/speech_recognition_browsertest.cc
@@ -130,12 +130,12 @@ class FakeSpeechRecognitionManager : public content::SpeechRecognitionManager {
virtual string16 GetAudioInputDeviceModel() OVERRIDE { return string16(); }
virtual void ShowAudioInputSettings() OVERRIDE {}
- virtual int LookupSessionByContext(
- base::Callback<bool(
- const content::SpeechRecognitionSessionContext&)> matcher)
- const OVERRIDE {
- bool matched = matcher.Run(session_ctx_);
- return matched ? session_id_ : 0;
+ virtual int GetSession(int render_process_id,
+ int render_view_id,
+ int request_id) const OVERRIDE {
+ return session_ctx_.render_process_id == render_process_id &&
+ session_ctx_.render_view_id == render_view_id &&
+ session_ctx_.request_id == request_id;
}
virtual const SpeechRecognitionSessionConfig& GetSessionConfig(
diff --git a/content/browser/speech/speech_recognition_dispatcher_host.cc b/content/browser/speech/speech_recognition_dispatcher_host.cc
new file mode 100644
index 0000000..55d032e
--- /dev/null
+++ b/content/browser/speech/speech_recognition_dispatcher_host.cc
@@ -0,0 +1,181 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/speech/speech_recognition_dispatcher_host.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/lazy_instance.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"
+#include "content/public/common/content_switches.h"
+
+using content::SpeechRecognitionManager;
+using content::SpeechRecognitionSessionConfig;
+using content::SpeechRecognitionSessionContext;
+
+namespace speech {
+SpeechRecognitionManager* SpeechRecognitionDispatcherHost::manager_for_tests_;
+
+void SpeechRecognitionDispatcherHost::SetManagerForTests(
+ SpeechRecognitionManager* manager) {
+ manager_for_tests_ = manager;
+}
+
+SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost(
+ int render_process_id,
+ net::URLRequestContextGetter* context_getter,
+ content::SpeechRecognitionPreferences* recognition_preferences)
+ : render_process_id_(render_process_id),
+ context_getter_(context_getter),
+ recognition_preferences_(recognition_preferences) {
+ // 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.
+}
+
+SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() {
+ if (SpeechRecognitionManager* sr_manager = manager())
+ sr_manager->AbortAllSessionsForListener(this);
+}
+
+SpeechRecognitionManager* SpeechRecognitionDispatcherHost::manager() {
+ if (manager_for_tests_)
+ return manager_for_tests_;
+
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(switches::kEnableScriptedSpeech))
+ return SpeechRecognitionManager::GetInstance();
+
+ return NULL;
+}
+
+bool SpeechRecognitionDispatcherHost::OnMessageReceived(
+ const IPC::Message& message, bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(SpeechRecognitionDispatcherHost, message,
+ *message_was_ok)
+ IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StartRequest,
+ OnStartRequest)
+ IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_AbortRequest,
+ OnAbortRequest)
+ IPC_MESSAGE_HANDLER(SpeechRecognitionHostMsg_StopCaptureRequest,
+ OnStopCaptureRequest)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void SpeechRecognitionDispatcherHost::OnStartRequest(
+ const SpeechRecognitionHostMsg_StartRequest_Params& params) {
+
+ SpeechRecognitionSessionContext context;
+ context.render_process_id = render_process_id_;
+ context.render_view_id = params.render_view_id;
+ context.request_id = params.request_id;
+
+ SpeechRecognitionSessionConfig config;
+ config.is_one_shot = params.is_one_shot;
+ config.language = params.language;
+ config.grammars = params.grammars;
+ config.origin_url = params.origin_url;
+ config.initial_context = context;
+ config.url_request_context_getter = context_getter_.get();
+ config.filter_profanities = recognition_preferences_->FilterProfanities();
+ config.event_listener = this;
+
+ int session_id = manager()->CreateSession(config);
+ DCHECK_NE(session_id, content::SpeechRecognitionManager::kSessionIDInvalid);
+ manager()->StartSession(session_id);
+}
+
+void SpeechRecognitionDispatcherHost::OnAbortRequest(int render_view_id,
+ int request_id) {
+ int session_id = manager()->GetSession(render_process_id_,
+ render_view_id,
+ request_id);
+ if (session_id != content::SpeechRecognitionManager::kSessionIDInvalid)
+ manager()->AbortSession(session_id);
+}
+
+void SpeechRecognitionDispatcherHost::OnStopCaptureRequest(
+ int render_view_id, int request_id) {
+ int session_id = manager()->GetSession(render_process_id_,
+ render_view_id,
+ request_id);
+ if (session_id != content::SpeechRecognitionManager::kSessionIDInvalid)
+ manager()->StopAudioCaptureForSession(session_id);
+}
+
+// -------- SpeechRecognitionEventListener interface implementation -----------
+
+void SpeechRecognitionDispatcherHost::OnRecognitionStart(int session_id) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_Started(context.render_view_id,
+ context.request_id));
+}
+
+void SpeechRecognitionDispatcherHost::OnAudioStart(int session_id) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_AudioStarted(context.render_view_id,
+ context.request_id));
+}
+
+void SpeechRecognitionDispatcherHost::OnSoundStart(int session_id) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_SoundStarted(context.render_view_id,
+ context.request_id));
+}
+
+void SpeechRecognitionDispatcherHost::OnSoundEnd(int session_id) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_SoundEnded(context.render_view_id,
+ context.request_id));
+}
+
+void SpeechRecognitionDispatcherHost::OnAudioEnd(int session_id) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_AudioEnded(context.render_view_id,
+ context.request_id));
+}
+
+void SpeechRecognitionDispatcherHost::OnRecognitionEnd(int session_id) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_Ended(context.render_view_id,
+ context.request_id));
+}
+
+void SpeechRecognitionDispatcherHost::OnRecognitionResult(
+ int session_id, const content::SpeechRecognitionResult& result) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_ResultRetrieved(context.render_view_id,
+ context.request_id,
+ result));
+}
+
+void SpeechRecognitionDispatcherHost::OnRecognitionError(
+ int session_id, const content::SpeechRecognitionError& error) {
+ const SpeechRecognitionSessionContext& context =
+ manager()->GetSessionContext(session_id);
+ Send(new SpeechRecognitionMsg_ErrorOccurred(context.render_view_id,
+ context.request_id,
+ error));
+}
+
+// The events below are currently not used by speech JS APIs implementation.
+void SpeechRecognitionDispatcherHost::OnAudioLevelsChange(
+ int session_id, float volume, float noise_volume) {}
+void SpeechRecognitionDispatcherHost::OnEnvironmentEstimationComplete(
+ int session_id) {}
+
+} // namespace speech
diff --git a/content/browser/speech/speech_recognition_dispatcher_host.h b/content/browser/speech/speech_recognition_dispatcher_host.h
new file mode 100644
index 0000000..3ebd8e4
--- /dev/null
+++ b/content/browser/speech/speech_recognition_dispatcher_host.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_
+#define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_
+#pragma once
+
+#include "base/memory/scoped_ptr.h"
+#include "content/common/content_export.h"
+#include "content/public/browser/browser_message_filter.h"
+#include "content/public/browser/speech_recognition_event_listener.h"
+#include "net/url_request/url_request_context_getter.h"
+
+struct SpeechRecognitionHostMsg_StartRequest_Params;
+
+namespace content {
+class SpeechRecognitionManager;
+class SpeechRecognitionPreferences;
+struct SpeechRecognitionResult;
+}
+
+namespace speech {
+
+// SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by
+// RenderMessageFilter. Basically it acts as a proxy, relaying the events coming
+// from the SpeechRecognitionManager to IPC messages (and vice versa).
+// It's the complement of SpeechRecognitionDispatcher (owned by RenderView).
+class CONTENT_EXPORT SpeechRecognitionDispatcherHost
+ : public content::BrowserMessageFilter,
+ public content::SpeechRecognitionEventListener {
+ public:
+ SpeechRecognitionDispatcherHost(
+ int render_process_id,
+ net::URLRequestContextGetter* context_getter,
+ content::SpeechRecognitionPreferences* recognition_preferences);
+
+ // SpeechRecognitionEventListener methods.
+ virtual void OnRecognitionStart(int session_id) OVERRIDE;
+ virtual void OnAudioStart(int session_id) OVERRIDE;
+ virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE;
+ virtual void OnSoundStart(int session_id) OVERRIDE;
+ virtual void OnSoundEnd(int session_id) OVERRIDE;
+ virtual void OnAudioEnd(int session_id) OVERRIDE;
+ virtual void OnRecognitionEnd(int session_id) OVERRIDE;
+ virtual void OnRecognitionResult(
+ int session_id, const content::SpeechRecognitionResult& result) OVERRIDE;
+ virtual void OnRecognitionError(
+ int session_id, const content::SpeechRecognitionError& error) OVERRIDE;
+ virtual void OnAudioLevelsChange(
+ int session_id, float volume, float noise_volume) OVERRIDE;
+
+ // content::BrowserMessageFilter implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) OVERRIDE;
+
+ // Singleton manager setter useful for tests.
+ static void SetManagerForTests(content::SpeechRecognitionManager* manager);
+
+ private:
+ virtual ~SpeechRecognitionDispatcherHost();
+
+ void OnStartRequest(
+ const SpeechRecognitionHostMsg_StartRequest_Params& params);
+ void OnAbortRequest(int render_view_id, int request_id);
+ void OnStopCaptureRequest(int render_view_id, int request_id);
+
+ // Returns the speech recognition manager to forward requests to.
+ content::SpeechRecognitionManager* manager();
+
+ int render_process_id_;
+ scoped_refptr<net::URLRequestContextGetter> context_getter_;
+ scoped_refptr<content::SpeechRecognitionPreferences> recognition_preferences_;
+
+ static content::SpeechRecognitionManager* manager_for_tests_;
+
+ DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost);
+};
+
+} // namespace speech
+
+#endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_
diff --git a/content/browser/speech/speech_recognition_manager_impl.cc b/content/browser/speech/speech_recognition_manager_impl.cc
index e1c3298..6bad70f 100644
--- a/content/browser/speech/speech_recognition_manager_impl.cc
+++ b/content/browser/speech/speech_recognition_manager_impl.cc
@@ -282,20 +282,18 @@ void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) {
this->AsWeakPtr(), session_id, EVENT_RECOGNITION_ENDED));
}
-// TODO(primiano) After CL2: if we see that both InputTagDispatcherHost and
-// SpeechRecognitionDispatcherHost do the same lookup operations, implement the
-// lookup method directly here.
-int SpeechRecognitionManagerImpl::LookupSessionByContext(
- Callback<bool(const SpeechRecognitionSessionContext&)> matcher) const {
+int SpeechRecognitionManagerImpl::GetSession(
+ int render_process_id, int render_view_id, int request_id) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
SessionsTable::const_iterator iter;
- // Note: the callback (matcher) must NEVER perform non-const calls on us.
for(iter = sessions_.begin(); iter != sessions_.end(); ++iter) {
const int session_id = iter->first;
- const Session& session = iter->second;
- bool matches = matcher.Run(session.context);
- if (matches)
+ const SpeechRecognitionSessionContext& context = iter->second.context;
+ if (context.render_process_id == render_process_id &&
+ context.render_view_id == render_view_id &&
+ context.request_id == request_id) {
return session_id;
+ }
}
return kSessionIDInvalid;
}
diff --git a/content/browser/speech/speech_recognition_manager_impl.h b/content/browser/speech/speech_recognition_manager_impl.h
index b27c031..5d43dfc 100644
--- a/content/browser/speech/speech_recognition_manager_impl.h
+++ b/content/browser/speech/speech_recognition_manager_impl.h
@@ -69,10 +69,9 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl :
int session_id) const OVERRIDE;
virtual content::SpeechRecognitionSessionContext GetSessionContext(
int session_id) const OVERRIDE;
- virtual int LookupSessionByContext(
- base::Callback<bool(
- const content::SpeechRecognitionSessionContext&)> matcher)
- const OVERRIDE;
+ virtual int GetSession(int render_process_id,
+ int render_view_id,
+ int request_id) const OVERRIDE;
virtual bool HasAudioInputDevices() OVERRIDE;
virtual bool IsCapturingAudio() OVERRIDE;
virtual string16 GetAudioInputDeviceModel() OVERRIDE;