diff options
author | primiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 11:01:02 +0000 |
---|---|---|
committer | primiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 11:01:02 +0000 |
commit | c52b28964090204b87634b396823c3709855079c (patch) | |
tree | 1e8e20c58dd735baa7f8312dc115fff224e4e5cd /content/browser/speech | |
parent | 9104f7e80f0bd0c2353254ec5c354199d965f44d (diff) | |
download | chromium_src-c52b28964090204b87634b396823c3709855079c.zip chromium_src-c52b28964090204b87634b396823c3709855079c.tar.gz chromium_src-c52b28964090204b87634b396823c3709855079c.tar.bz2 |
Renamed speech recognition code in preparation for introducing a new speech implementation.
- The general-purpose speech recognition classes (that will be needed also by future code) have been renamed to SpeechRecognition*;
- The IPC Messages and dispatcher(host) classes that are only related to the current input tag (x-webkit-speech) support have been renamed to InputTagSpeech*;
- The namespace has been renamed from speech_input to speech;
BUG=116954
TEST=
Review URL: https://chromiumcodereview.appspot.com/9568002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech')
21 files changed, 400 insertions, 394 deletions
diff --git a/content/browser/speech/audio_encoder.cc b/content/browser/speech/audio_encoder.cc index 683ec0e..83e0475 100644 --- a/content/browser/speech/audio_encoder.cc +++ b/content/browser/speech/audio_encoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -21,7 +21,7 @@ namespace { const char* const kContentTypeFLAC = "audio/x-flac; rate="; const int kFLACCompressionLevel = 0; // 0 for speed -class FLACEncoder : public speech_input::AudioEncoder { +class FLACEncoder : public speech::AudioEncoder { public: FLACEncoder(int sampling_rate, int bits_per_sample); virtual ~FLACEncoder(); @@ -107,7 +107,7 @@ const int kMaxSpeexFrameLength = 110; // (44kbps rate sampled at 32kHz). // make sure it is within the byte range. COMPILE_ASSERT(kMaxSpeexFrameLength <= 0xFF, invalidLength); -class SpeexEncoder : public speech_input::AudioEncoder { +class SpeexEncoder : public speech::AudioEncoder { public: explicit SpeexEncoder(int sampling_rate); virtual ~SpeexEncoder(); @@ -163,7 +163,7 @@ void SpeexEncoder::Encode(const short* samples, int num_samples) { } // namespace -namespace speech_input { +namespace speech { AudioEncoder* AudioEncoder::Create(Codec codec, int sampling_rate, @@ -205,4 +205,4 @@ void AudioEncoder::AppendToBuffer(std::string* item) { audio_buffers_.push_back(item); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/audio_encoder.h b/content/browser/speech/audio_encoder.h index 7b0a246..92bc645 100644 --- a/content/browser/speech/audio_encoder.h +++ b/content/browser/speech/audio_encoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -10,7 +10,7 @@ #include "base/basictypes.h" -namespace speech_input { +namespace speech { // Provides a simple interface to encode raw audio using the various speech // codecs. @@ -54,6 +54,6 @@ class AudioEncoder { DISALLOW_COPY_AND_ASSIGN(AudioEncoder); }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_ diff --git a/content/browser/speech/endpointer/endpointer.cc b/content/browser/speech/endpointer/endpointer.cc index 69c79a6..fe3e0bf 100644 --- a/content/browser/speech/endpointer/endpointer.cc +++ b/content/browser/speech/endpointer/endpointer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -12,7 +12,7 @@ namespace { static const int kFrameRate = 50; // 1 frame = 20ms of audio. } -namespace speech_input { +namespace speech { Endpointer::Endpointer(int sample_rate) : speech_input_possibly_complete_silence_length_us_(-1), diff --git a/content/browser/speech/endpointer/endpointer.h b/content/browser/speech/endpointer/endpointer.h index 2d74839..9ba2018 100644 --- a/content/browser/speech/endpointer/endpointer.h +++ b/content/browser/speech/endpointer/endpointer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -11,7 +11,7 @@ class EpStatus; -namespace speech_input { +namespace speech { // A simple interface to the underlying energy-endpointer implementation, this // class lets callers provide audio as being recorded and let them poll to find @@ -147,6 +147,6 @@ class CONTENT_EXPORT Endpointer { int32 frame_size_; }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_ENDPOINTER_ENDPOINTER_H_ diff --git a/content/browser/speech/endpointer/endpointer_unittest.cc b/content/browser/speech/endpointer/endpointer_unittest.cc index b71c01a..240e5dc 100644 --- a/content/browser/speech/endpointer/endpointer_unittest.cc +++ b/content/browser/speech/endpointer/endpointer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -15,7 +15,7 @@ const int kFrameSize = kSampleRate / kFrameRate; // 160 samples. COMPILE_ASSERT(kFrameSize == 160, invalid_frame_size); } -namespace speech_input { +namespace speech { class FrameProcessor { public: @@ -142,4 +142,4 @@ TEST(EndpointerTest, TestEmbeddedEndpointerEvents) { endpointer.EndSession(); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/endpointer/energy_endpointer.cc b/content/browser/speech/endpointer/energy_endpointer.cc index 39cf617..b88d7a3 100644 --- a/content/browser/speech/endpointer/energy_endpointer.cc +++ b/content/browser/speech/endpointer/energy_endpointer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. // @@ -41,7 +41,7 @@ float GetDecibel(float value) { } // namespace -namespace speech_input { +namespace speech { // Stores threshold-crossing histories for making decisions about the speech // state. diff --git a/content/browser/speech/endpointer/energy_endpointer.h b/content/browser/speech/endpointer/energy_endpointer.h index b440c4d..9db927a 100644 --- a/content/browser/speech/endpointer/energy_endpointer.h +++ b/content/browser/speech/endpointer/energy_endpointer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -44,7 +44,7 @@ #include "content/browser/speech/endpointer/energy_endpointer_params.h" #include "content/common/content_export.h" -namespace speech_input { +namespace speech { // Endpointer status codes enum EpStatus { @@ -150,6 +150,6 @@ class CONTENT_EXPORT EnergyEndpointer { DISALLOW_COPY_AND_ASSIGN(EnergyEndpointer); }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_ENDPOINTER_ENERGY_ENDPOINTER_H_ diff --git a/content/browser/speech/endpointer/energy_endpointer_params.cc b/content/browser/speech/endpointer/energy_endpointer_params.cc index e110b24..89852f1 100644 --- a/content/browser/speech/endpointer/energy_endpointer_params.cc +++ b/content/browser/speech/endpointer/energy_endpointer_params.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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/endpointer/energy_endpointer_params.h" -namespace speech_input { +namespace speech { EnergyEndpointerParams::EnergyEndpointerParams() { SetDefaults(); @@ -50,4 +50,4 @@ void EnergyEndpointerParams::operator=(const EnergyEndpointerParams& source) { contamination_rejection_period_ = source.contamination_rejection_period(); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/endpointer/energy_endpointer_params.h b/content/browser/speech/endpointer/energy_endpointer_params.h index 5a3ea42..9641d9d 100644 --- a/content/browser/speech/endpointer/energy_endpointer_params.h +++ b/content/browser/speech/endpointer/energy_endpointer_params.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "content/common/content_export.h" -namespace speech_input { +namespace speech { // Input parameters for the EnergyEndpointer class. class CONTENT_EXPORT EnergyEndpointerParams { @@ -133,6 +133,6 @@ class CONTENT_EXPORT EnergyEndpointerParams { float contamination_rejection_period_; }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_ENDPOINTER_ENERGY_ENDPOINTER_PARAMS_H_ diff --git a/content/browser/speech/speech_input_dispatcher_host.cc b/content/browser/speech/input_tag_speech_dispatcher_host.cc index 3883969..7c10270 100644 --- a/content/browser/speech/speech_input_dispatcher_host.cc +++ b/content/browser/speech/input_tag_speech_dispatcher_host.cc @@ -2,24 +2,24 @@ // 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_input_dispatcher_host.h" +#include "content/browser/speech/input_tag_speech_dispatcher_host.h" #include "base/lazy_instance.h" -#include "content/browser/speech/speech_input_manager_impl.h" +#include "content/browser/speech/speech_recognition_manager_impl.h" #include "content/browser/speech/speech_recognizer_impl.h" -#include "content/common/speech_input_messages.h" -#include "content/public/browser/speech_input_preferences.h" +#include "content/common/speech_recognition_messages.h" +#include "content/public/browser/speech_recognition_preferences.h" using content::BrowserThread; -namespace speech_input { +namespace speech { -//----------------------------- SpeechInputCallers ----------------------------- +//----------------------------- Callers ----------------------------- // A singleton class to map the tuple // (render-process-id, render-view-id, requestid) to a single ID which is passed // through rest of the speech code. -class SpeechInputDispatcherHost::SpeechInputCallers { +class InputTagSpeechDispatcherHost::Callers { public: // Creates a new ID for a given tuple. int CreateId(int render_process_id, int render_view_id, int request_id); @@ -41,24 +41,24 @@ class SpeechInputDispatcherHost::SpeechInputCallers { int render_view_id; int request_id; }; - friend struct base::DefaultLazyInstanceTraits<SpeechInputCallers>; + friend struct base::DefaultLazyInstanceTraits<Callers>; - SpeechInputCallers(); + Callers(); std::map<int, CallerInfo> callers_; int next_id_; }; -static base::LazyInstance<SpeechInputDispatcherHost::SpeechInputCallers> - g_speech_input_callers = LAZY_INSTANCE_INITIALIZER; +static base::LazyInstance<InputTagSpeechDispatcherHost::Callers> + g_callers = LAZY_INSTANCE_INITIALIZER; -SpeechInputDispatcherHost::SpeechInputCallers::SpeechInputCallers() +InputTagSpeechDispatcherHost::Callers::Callers() : next_id_(1) { } -int SpeechInputDispatcherHost::SpeechInputCallers::GetId(int render_process_id, - int render_view_id, - int request_id) { +int InputTagSpeechDispatcherHost::Callers::GetId(int render_process_id, + int render_view_id, + int request_id) { for (std::map<int, CallerInfo>::iterator it = callers_.begin(); it != callers_.end(); it++) { const CallerInfo& item = it->second; @@ -76,10 +76,9 @@ int SpeechInputDispatcherHost::SpeechInputCallers::GetId(int render_process_id, return 0; } -int SpeechInputDispatcherHost::SpeechInputCallers::CreateId( - int render_process_id, - int render_view_id, - int request_id) { +int InputTagSpeechDispatcherHost::Callers::CreateId(int render_process_id, + int render_view_id, + int request_id) { CallerInfo info; info.render_process_id = render_process_id; info.render_view_id = render_view_id; @@ -88,46 +87,49 @@ int SpeechInputDispatcherHost::SpeechInputCallers::CreateId( return next_id_++; } -void SpeechInputDispatcherHost::SpeechInputCallers::RemoveId(int id) { +void InputTagSpeechDispatcherHost::Callers::RemoveId(int id) { callers_.erase(id); } -int SpeechInputDispatcherHost::SpeechInputCallers::render_process_id(int id) { +int InputTagSpeechDispatcherHost::Callers::render_process_id( + int id) { return callers_[id].render_process_id; } -int SpeechInputDispatcherHost::SpeechInputCallers::render_view_id(int id) { +int InputTagSpeechDispatcherHost::Callers::render_view_id( + int id) { return callers_[id].render_view_id; } -int SpeechInputDispatcherHost::SpeechInputCallers::request_id(int id) { +int InputTagSpeechDispatcherHost::Callers::request_id(int id) { return callers_[id].request_id; } -//-------------------------- SpeechInputDispatcherHost ------------------------- +//----------------------- InputTagSpeechDispatcherHost ---------------------- -SpeechInputManagerImpl* SpeechInputDispatcherHost::manager_; +SpeechRecognitionManagerImpl* InputTagSpeechDispatcherHost::manager_; -void SpeechInputDispatcherHost::set_manager(SpeechInputManagerImpl* manager) { +void InputTagSpeechDispatcherHost::set_manager( + SpeechRecognitionManagerImpl* manager) { manager_ = manager; } -SpeechInputDispatcherHost::SpeechInputDispatcherHost( +InputTagSpeechDispatcherHost::InputTagSpeechDispatcherHost( int render_process_id, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_preferences, + content::SpeechRecognitionPreferences* recognition_preferences, AudioManager* audio_manager) : render_process_id_(render_process_id), may_have_pending_requests_(false), context_getter_(context_getter), - speech_input_preferences_(speech_input_preferences), + recognition_preferences_(recognition_preferences), audio_manager_(audio_manager) { // 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. } -SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { +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 @@ -137,27 +139,27 @@ SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { manager()->CancelAllRequestsWithDelegate(this); } -SpeechInputManagerImpl* SpeechInputDispatcherHost::manager() { +SpeechRecognitionManagerImpl* InputTagSpeechDispatcherHost::manager() { if (manager_) return manager_; #if defined(ENABLE_INPUT_SPEECH) - return SpeechInputManagerImpl::GetInstance(); + return SpeechRecognitionManagerImpl::GetInstance(); #else return NULL; #endif } -bool SpeechInputDispatcherHost::OnMessageReceived( +bool InputTagSpeechDispatcherHost::OnMessageReceived( const IPC::Message& message, bool* message_was_ok) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message, + IPC_BEGIN_MESSAGE_MAP_EX(InputTagSpeechDispatcherHost, message, *message_was_ok) - IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StartRecognition, + IPC_MESSAGE_HANDLER(InputTagSpeechHostMsg_StartRecognition, OnStartRecognition) - IPC_MESSAGE_HANDLER(SpeechInputHostMsg_CancelRecognition, + IPC_MESSAGE_HANDLER(InputTagSpeechHostMsg_CancelRecognition, OnCancelRecognition) - IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording, + IPC_MESSAGE_HANDLER(InputTagSpeechHostMsg_StopRecording, OnStopRecording) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -166,10 +168,10 @@ bool SpeechInputDispatcherHost::OnMessageReceived( return handled; } -void SpeechInputDispatcherHost::OnStartRecognition( - const SpeechInputHostMsg_StartRecognition_Params ¶ms) { +void InputTagSpeechDispatcherHost::OnStartRecognition( + const InputTagSpeechHostMsg_StartRecognition_Params ¶ms) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_id = g_speech_input_callers.Get().CreateId( + int caller_id = g_callers.Get().CreateId( render_process_id_, params.render_view_id, params.request_id); manager()->StartRecognition(this, caller_id, render_process_id_, @@ -177,63 +179,61 @@ void SpeechInputDispatcherHost::OnStartRecognition( params.language, params.grammar, params.origin_url, context_getter_.get(), - speech_input_preferences_.get()); + recognition_preferences_.get()); } -void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, - int request_id) { - int caller_id = g_speech_input_callers.Get().GetId( +void InputTagSpeechDispatcherHost::OnCancelRecognition(int render_view_id, + int request_id) { + int caller_id = g_callers.Get().GetId( render_process_id_, render_view_id, request_id); if (caller_id) { manager()->CancelRecognition(caller_id); // Request sequence ended so remove mapping. - g_speech_input_callers.Get().RemoveId(caller_id); + g_callers.Get().RemoveId(caller_id); } } -void SpeechInputDispatcherHost::OnStopRecording(int render_view_id, - int request_id) { - int caller_id = g_speech_input_callers.Get().GetId( +void InputTagSpeechDispatcherHost::OnStopRecording(int render_view_id, + int request_id) { + int caller_id = g_callers.Get().GetId( render_process_id_, render_view_id, request_id); if (caller_id) manager()->StopRecording(caller_id); } -void SpeechInputDispatcherHost::SetRecognitionResult( - int caller_id, const content::SpeechInputResult& result) { - VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult enter"; +void InputTagSpeechDispatcherHost::SetRecognitionResult( + int caller_id, const content::SpeechRecognitionResult& result) { + VLOG(1) << "InputTagSpeechDispatcherHost::SetRecognitionResult enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_render_view_id = - g_speech_input_callers.Get().render_view_id(caller_id); - int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); - Send(new SpeechInputMsg_SetRecognitionResult(caller_render_view_id, - caller_request_id, - result)); - VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult exit"; + int caller_render_view_id = g_callers.Get().render_view_id(caller_id); + int caller_request_id = g_callers.Get().request_id(caller_id); + Send(new InputTagSpeechMsg_SetRecognitionResult(caller_render_view_id, + caller_request_id, + result)); + VLOG(1) << "InputTagSpeechDispatcherHost::SetRecognitionResult exit"; } -void SpeechInputDispatcherHost::DidCompleteRecording(int caller_id) { - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording enter"; +void InputTagSpeechDispatcherHost::DidCompleteRecording(int caller_id) { + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecording enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_render_view_id = - g_speech_input_callers.Get().render_view_id(caller_id); - int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); - Send(new SpeechInputMsg_RecordingComplete(caller_render_view_id, - caller_request_id)); - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording exit"; + int caller_render_view_id = g_callers.Get().render_view_id(caller_id); + int caller_request_id = g_callers.Get().request_id(caller_id); + Send(new InputTagSpeechMsg_RecordingComplete(caller_render_view_id, + caller_request_id)); + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecording exit"; } -void SpeechInputDispatcherHost::DidCompleteRecognition(int caller_id) { - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition enter"; +void InputTagSpeechDispatcherHost::DidCompleteRecognition(int caller_id) { + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecognition enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); int caller_render_view_id = - g_speech_input_callers.Get().render_view_id(caller_id); - int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); - Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, - caller_request_id)); + g_callers.Get().render_view_id(caller_id); + int caller_request_id = g_callers.Get().request_id(caller_id); + Send(new InputTagSpeechMsg_RecognitionComplete(caller_render_view_id, + caller_request_id)); // Request sequence ended, so remove mapping. - g_speech_input_callers.Get().RemoveId(caller_id); - VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; + g_callers.Get().RemoveId(caller_id); + VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecognition exit"; } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.h b/content/browser/speech/input_tag_speech_dispatcher_host.h new file mode 100644 index 0000000..61d68b0 --- /dev/null +++ b/content/browser/speech/input_tag_speech_dispatcher_host.h @@ -0,0 +1,78 @@ +// 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_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ +#define CONTENT_BROWSER_SPEECH_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/content_export.h" +#include "content/public/browser/browser_message_filter.h" +#include "net/url_request/url_request_context_getter.h" + +class AudioManager; +struct InputTagSpeechHostMsg_StartRecognition_Params; + +namespace content { +class SpeechRecognitionPreferences; +struct SpeechRecognitionResult; +} + +namespace speech { + +class SpeechRecognitionManagerImpl; + +// InputTagSpeechDispatcherHost is a delegate for Speech API messages used by +// RenderMessageFilter. +// It's the complement of InputTagSpeechDispatcher (owned by RenderView). +class CONTENT_EXPORT InputTagSpeechDispatcherHost + : public content::BrowserMessageFilter { + public: + class Callers; + + InputTagSpeechDispatcherHost( + int render_process_id, + net::URLRequestContextGetter* context_getter, + content::SpeechRecognitionPreferences* recognition_preferences, + AudioManager* audio_manager); + + // Methods called by SpeechRecognitionManagerImpl. + void SetRecognitionResult(int caller_id, + const content::SpeechRecognitionResult& result); + void DidCompleteRecording(int caller_id); + void DidCompleteRecognition(int caller_id); + + // content::BrowserMessageFilter implementation. + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) OVERRIDE; + + // Singleton manager setter useful for tests. + static void set_manager(SpeechRecognitionManagerImpl* manager); + + private: + virtual ~InputTagSpeechDispatcherHost(); + + void OnStartRecognition( + const InputTagSpeechHostMsg_StartRecognition_Params ¶ms); + void OnCancelRecognition(int render_view_id, int request_id); + void OnStopRecording(int render_view_id, int request_id); + + // Returns the speech recognition manager to forward events to, creating one + // if needed. + SpeechRecognitionManagerImpl* manager(); + + int render_process_id_; + bool may_have_pending_requests_; // Set if we received any speech IPC request + + scoped_refptr<net::URLRequestContextGetter> context_getter_; + scoped_refptr<content::SpeechRecognitionPreferences> recognition_preferences_; + AudioManager* audio_manager_; + + static SpeechRecognitionManagerImpl* manager_; + + DISALLOW_COPY_AND_ASSIGN(InputTagSpeechDispatcherHost); +}; + +} // namespace speech + +#endif // CONTENT_BROWSER_SPEECH_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ diff --git a/content/browser/speech/speech_input_dispatcher_host.h b/content/browser/speech/speech_input_dispatcher_host.h deleted file mode 100644 index 5e38f37..0000000 --- a/content/browser/speech/speech_input_dispatcher_host.h +++ /dev/null @@ -1,78 +0,0 @@ -// 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_INPUT_DISPATCHER_HOST_H_ -#define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ - -#include "base/memory/scoped_ptr.h" -#include "content/common/content_export.h" -#include "content/public/browser/browser_message_filter.h" -#include "net/url_request/url_request_context_getter.h" - -class AudioManager; -struct SpeechInputHostMsg_StartRecognition_Params; - -namespace content { -class SpeechInputPreferences; -struct SpeechInputResult; -} - -namespace speech_input { - -class SpeechInputManagerImpl; - -// SpeechInputDispatcherHost is a delegate for Speech API messages used by -// RenderMessageFilter. -// It's the complement of SpeechInputDispatcher (owned by RenderView). -class CONTENT_EXPORT SpeechInputDispatcherHost - : public content::BrowserMessageFilter { - public: - class SpeechInputCallers; - - SpeechInputDispatcherHost( - int render_process_id, - net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_preferences, - AudioManager* audio_manager); - - // Methods called by SpeechInputManagerImpl. - void SetRecognitionResult(int caller_id, - const content::SpeechInputResult& result); - void DidCompleteRecording(int caller_id); - void DidCompleteRecognition(int caller_id); - - // content::BrowserMessageFilter implementation. - virtual bool OnMessageReceived(const IPC::Message& message, - bool* message_was_ok) OVERRIDE; - - // Singleton manager setter useful for tests. - static void set_manager(SpeechInputManagerImpl* manager); - - private: - virtual ~SpeechInputDispatcherHost(); - - void OnStartRecognition( - const SpeechInputHostMsg_StartRecognition_Params ¶ms); - void OnCancelRecognition(int render_view_id, int request_id); - void OnStopRecording(int render_view_id, int request_id); - - // Returns the speech input manager to forward events to, creating one if - // needed. - SpeechInputManagerImpl* manager(); - - int render_process_id_; - bool may_have_pending_requests_; // Set if we received any speech IPC request - - scoped_refptr<net::URLRequestContextGetter> context_getter_; - scoped_refptr<content::SpeechInputPreferences> speech_input_preferences_; - AudioManager* audio_manager_; - - static SpeechInputManagerImpl* manager_; - - DISALLOW_COPY_AND_ASSIGN(SpeechInputDispatcherHost); -}; - -} // namespace speech_input - -#endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_DISPATCHER_HOST_H_ diff --git a/content/browser/speech/speech_input_browsertest.cc b/content/browser/speech/speech_recognition_browsertest.cc index 6083ca0..0b56226 100644 --- a/content/browser/speech/speech_input_browsertest.cc +++ b/content/browser/speech/speech_recognition_browsertest.cc @@ -12,28 +12,28 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/speech/speech_input_dispatcher_host.h" -#include "content/browser/speech/speech_input_manager_impl.h" +#include "content/browser/speech/input_tag_speech_dispatcher_host.h" +#include "content/browser/speech/speech_recognition_manager_impl.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/public/browser/notification_types.h" #include "content/public/common/content_switches.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" using content::NavigationController; using content::WebContents; -namespace speech_input { -class FakeSpeechInputManager; +namespace speech { +class FakeSpeechRecognitionManager; } -namespace speech_input { +namespace speech { const char kTestResult[] = "Pictures of the moon"; -class FakeSpeechInputManager : public SpeechInputManagerImpl { +class FakeSpeechRecognitionManager : public SpeechRecognitionManagerImpl { public: - FakeSpeechInputManager() + FakeSpeechRecognitionManager() : caller_id_(0), delegate_(NULL), did_cancel_all_(false), @@ -61,9 +61,9 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { return recognition_started_event_; } - // SpeechInputManager methods. + // SpeechRecognitionManager methods. virtual void StartRecognition( - SpeechInputDispatcherHost* delegate, + InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -72,7 +72,7 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs) OVERRIDE { + content::SpeechRecognitionPreferences* recognition_prefs) OVERRIDE { VLOG(1) << "StartRecognition invoked."; EXPECT_EQ(0, caller_id_); EXPECT_EQ(NULL, delegate_); @@ -82,7 +82,7 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { if (should_send_fake_response_) { // Give the fake result in a short while. MessageLoop::current()->PostTask(FROM_HERE, base::Bind( - &FakeSpeechInputManager::SetFakeRecognitionResult, + &FakeSpeechRecognitionManager::SetFakeRecognitionResult, // This class does not need to be refcounted (typically done by // PostTask) since it will outlive the test and gets released only // when the test shuts down. Disabling refcounting here saves a bit @@ -104,7 +104,7 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { // Nothing to do here since we aren't really recording. } virtual void CancelAllRequestsWithDelegate( - SpeechInputDispatcherHost* delegate) OVERRIDE { + InputTagSpeechDispatcherHost* delegate) OVERRIDE { VLOG(1) << "CancelAllRequestsWithDelegate invoked."; // delegate_ is set to NULL if a fake result was received (see below), so // check that delegate_ matches the incoming parameter only when there is @@ -118,8 +118,8 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { if (caller_id_) { // Do a check in case we were cancelled.. VLOG(1) << "Setting fake recognition result."; delegate_->DidCompleteRecording(caller_id_); - content::SpeechInputResult results; - results.hypotheses.push_back(content::SpeechInputHypothesis( + content::SpeechRecognitionResult results; + results.hypotheses.push_back(content::SpeechRecognitionHypothesis( ASCIIToUTF16(kTestResult), 1.0)); delegate_->SetRecognitionResult(caller_id_, results); delegate_->DidCompleteRecognition(caller_id_); @@ -130,14 +130,14 @@ class FakeSpeechInputManager : public SpeechInputManagerImpl { } int caller_id_; - SpeechInputDispatcherHost* delegate_; + InputTagSpeechDispatcherHost* delegate_; std::string grammar_; bool did_cancel_all_; bool should_send_fake_response_; base::WaitableEvent recognition_started_event_; }; -class SpeechInputBrowserTest : public InProcessBrowserTest { +class SpeechRecognitionBrowserTest : public InProcessBrowserTest { public: // InProcessBrowserTest methods virtual void SetUpCommandLine(CommandLine* command_line) { @@ -150,7 +150,7 @@ class SpeechInputBrowserTest : public InProcessBrowserTest { } protected: - void LoadAndStartSpeechInputTest(const FilePath::CharType* filename) { + void LoadAndStartSpeechRecognitionTest(const FilePath::CharType* filename) { // The test page calculates the speech button's coordinate in the page on // load & sets that coordinate in the URL fragment. We send mouse down & up // events at that coordinate to trigger speech recognition. @@ -171,46 +171,47 @@ class SpeechInputBrowserTest : public InProcessBrowserTest { web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); mouse_event.type = WebKit::WebInputEvent::MouseUp; web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); - fake_speech_input_manager_.recognition_started_event().Wait(); + fake_speech_recognition_manager_.recognition_started_event().Wait(); // We should wait for a navigation event, raised by the test page JS code // upon the onwebkitspeechchange event, in all cases except when the // speech response is inhibited. - if (fake_speech_input_manager_.should_send_fake_response()) + if (fake_speech_recognition_manager_.should_send_fake_response()) observer.Wait(); } - void RunSpeechInputTest(const FilePath::CharType* filename) { + void RunSpeechRecognitionTest(const FilePath::CharType* filename) { // The fake speech input manager would receive the speech input // request and return the test string as recognition result. The test page // then sets the URL fragment as 'pass' if it received the expected string. - LoadAndStartSpeechInputTest(filename); + LoadAndStartSpeechRecognitionTest(filename); EXPECT_EQ("pass", browser()->GetSelectedWebContents()->GetURL().ref()); } // InProcessBrowserTest methods. virtual void SetUpInProcessBrowserTestFixture() { - fake_speech_input_manager_.set_should_send_fake_response(true); - speech_input_manager_ = &fake_speech_input_manager_; + fake_speech_recognition_manager_.set_should_send_fake_response(true); + speech_recognition_manager_ = &fake_speech_recognition_manager_; // Inject the fake manager factory so that the test result is returned to // the web page. - SpeechInputDispatcherHost::set_manager(speech_input_manager_); + InputTagSpeechDispatcherHost::set_manager(speech_recognition_manager_); } virtual void TearDownInProcessBrowserTestFixture() { - speech_input_manager_ = NULL; + speech_recognition_manager_ = NULL; } - FakeSpeechInputManager fake_speech_input_manager_; + FakeSpeechRecognitionManager fake_speech_recognition_manager_; // This is used by the static |fakeManager|, and it is a pointer rather than a // direct instance per the style guide. - static SpeechInputManagerImpl* speech_input_manager_; + static SpeechRecognitionManagerImpl* speech_recognition_manager_; }; -SpeechInputManagerImpl* SpeechInputBrowserTest::speech_input_manager_ = NULL; +SpeechRecognitionManagerImpl* + SpeechRecognitionBrowserTest::speech_recognition_manager_ = NULL; // TODO(satish): Once this flakiness has been fixed, add a second test here to // check for sending many clicks in succession to the speech button and verify @@ -220,33 +221,34 @@ SpeechInputManagerImpl* SpeechInputBrowserTest::speech_input_manager_ = NULL; // TODO(satish): Similar to above, once this flakiness has been fixed add // another test here to check that when speech recognition is in progress and // a renderer crashes, we get a call to -// SpeechInputManager::CancelAllRequestsWithDelegate. -IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, TestBasicRecognition) { - RunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); - EXPECT_TRUE(fake_speech_input_manager_.grammar().empty()); +// SpeechRecognitionManager::CancelAllRequestsWithDelegate. +IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestBasicRecognition) { + RunSpeechRecognitionTest(FILE_PATH_LITERAL("basic_recognition.html")); + EXPECT_TRUE(fake_speech_recognition_manager_.grammar().empty()); } -IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, GrammarAttribute) { - RunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html")); +IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, GrammarAttribute) { + RunSpeechRecognitionTest(FILE_PATH_LITERAL("grammar_attribute.html")); EXPECT_EQ("http://example.com/grammar.xml", - fake_speech_input_manager_.grammar()); + fake_speech_recognition_manager_.grammar()); } -IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, TestCancelAll) { +IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestCancelAll) { // The test checks that the cancel-all callback gets issued when a session // is pending, so don't send a fake response. // We are not expecting a navigation event being raised from the JS of the // test page JavaScript in this case. - fake_speech_input_manager_.set_should_send_fake_response(false); + fake_speech_recognition_manager_.set_should_send_fake_response(false); - LoadAndStartSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html")); + LoadAndStartSpeechRecognitionTest( + FILE_PATH_LITERAL("basic_recognition.html")); - // Make the renderer crash. This should trigger SpeechInputDispatcherHost to - // cancel all pending sessions. + // Make the renderer crash. This should trigger + // InputTagSpeechDispatcherHost to cancel all pending sessions. GURL test_url("about:crash"); ui_test_utils::NavigateToURL(browser(), test_url); - EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all()); + EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all()); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_input_manager_impl.cc b/content/browser/speech/speech_recognition_manager_impl.cc index 6df0b3d..9ced53f 100644 --- a/content/browser/speech/speech_input_manager_impl.cc +++ b/content/browser/speech/speech_recognition_manager_impl.cc @@ -2,33 +2,34 @@ // 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_input_manager_impl.h" +#include "content/browser/speech/speech_recognition_manager_impl.h" #include "base/bind.h" #include "content/browser/browser_main_loop.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/speech/speech_input_dispatcher_host.h" +#include "content/browser/speech/input_tag_speech_dispatcher_host.h" #include "content/browser/speech/speech_recognizer_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/render_view_host_delegate.h" #include "content/public/browser/resource_context.h" -#include "content/public/browser/speech_input_manager_delegate.h" -#include "content/public/browser/speech_input_preferences.h" +#include "content/public/browser/speech_recognition_manager_delegate.h" +#include "content/public/browser/speech_recognition_preferences.h" #include "content/public/common/view_type.h" using content::BrowserMainLoop; using content::BrowserThread; -using content::SpeechInputManagerDelegate; +using content::SpeechRecognitionManager; +using content::SpeechRecognitionManagerDelegate; -content::SpeechInputManager* content::SpeechInputManager::GetInstance() { - return speech_input::SpeechInputManagerImpl::GetInstance(); +SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { + return speech::SpeechRecognitionManagerImpl::GetInstance(); } -namespace speech_input { +namespace speech { -struct SpeechInputManagerImpl::SpeechInputParams { - SpeechInputParams(SpeechInputDispatcherHost* delegate, +struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { + SpeechRecognitionParams(InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -37,7 +38,7 @@ struct SpeechInputManagerImpl::SpeechInputParams { const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs) + content::SpeechRecognitionPreferences* recognition_prefs) : delegate(delegate), caller_id(caller_id), render_process_id(render_process_id), @@ -47,10 +48,10 @@ struct SpeechInputManagerImpl::SpeechInputParams { grammar(grammar), origin_url(origin_url), context_getter(context_getter), - speech_input_prefs(speech_input_prefs) { + recognition_prefs(recognition_prefs) { } - SpeechInputDispatcherHost* delegate; + InputTagSpeechDispatcherHost* delegate; int caller_id; int render_process_id; int render_view_id; @@ -59,53 +60,53 @@ struct SpeechInputManagerImpl::SpeechInputParams { std::string grammar; std::string origin_url; net::URLRequestContextGetter* context_getter; - content::SpeechInputPreferences* speech_input_prefs; + content::SpeechRecognitionPreferences* recognition_prefs; }; -SpeechInputManagerImpl* SpeechInputManagerImpl::GetInstance() { - return Singleton<SpeechInputManagerImpl>::get(); +SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { + return Singleton<SpeechRecognitionManagerImpl>::get(); } -SpeechInputManagerImpl::SpeechInputManagerImpl() +SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() : can_report_metrics_(false), recording_caller_id_(0) { - delegate_ = - content::GetContentClient()->browser()->GetSpeechInputManagerDelegate(); + delegate_ = content::GetContentClient()->browser()-> + GetSpeechRecognitionManagerDelegate(); } -SpeechInputManagerImpl::~SpeechInputManagerImpl() { +SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { while (requests_.begin() != requests_.end()) CancelRecognition(requests_.begin()->first); } -bool SpeechInputManagerImpl::HasAudioInputDevices() { +bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); } -bool SpeechInputManagerImpl::IsRecordingInProcess() { +bool SpeechRecognitionManagerImpl::IsCapturingAudio() { return BrowserMainLoop::GetAudioManager()->IsRecordingInProcess(); } -string16 SpeechInputManagerImpl::GetAudioInputDeviceModel() { +string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); } -bool SpeechInputManagerImpl::HasPendingRequest(int caller_id) const { +bool SpeechRecognitionManagerImpl::HasPendingRequest(int caller_id) const { return requests_.find(caller_id) != requests_.end(); } -SpeechInputDispatcherHost* SpeechInputManagerImpl::GetDelegate( +InputTagSpeechDispatcherHost* SpeechRecognitionManagerImpl::GetDelegate( int caller_id) const { return requests_.find(caller_id)->second.delegate; } -void SpeechInputManagerImpl::ShowAudioInputSettings() { +void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { // 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(&SpeechInputManagerImpl::ShowAudioInputSettings, + base::Bind(&SpeechRecognitionManagerImpl::ShowAudioInputSettings, base::Unretained(this))); return; } @@ -116,8 +117,8 @@ void SpeechInputManagerImpl::ShowAudioInputSettings() { audio_manager->ShowAudioInputSettings(); } -void SpeechInputManagerImpl::StartRecognition( - SpeechInputDispatcherHost* delegate, +void SpeechRecognitionManagerImpl::StartRecognition( + InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -126,21 +127,21 @@ void SpeechInputManagerImpl::StartRecognition( const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs) { + content::SpeechRecognitionPreferences* recognition_prefs) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind( - &SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition, + &SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition, base::Unretained(this), - SpeechInputParams( + SpeechRecognitionParams( delegate, caller_id, render_process_id, render_view_id, element_rect, language, grammar, origin_url, context_getter, - speech_input_prefs))); + recognition_prefs))); } -void SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition( - const SpeechInputParams& params) { +void SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition( + const SpeechRecognitionParams& params) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); RenderViewHostImpl* render_view_host = RenderViewHostImpl::FromID( @@ -158,13 +159,13 @@ void SpeechInputManagerImpl::CheckRenderViewTypeAndStartRecognition( content::VIEW_TYPE_TAB_CONTENTS) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - base::Bind(&SpeechInputManagerImpl::ProceedStartingRecognition, + base::Bind(&SpeechRecognitionManagerImpl::ProceedStartingRecognition, base::Unretained(this), params)); } } -void SpeechInputManagerImpl::ProceedStartingRecognition( - const SpeechInputParams& params) { +void SpeechRecognitionManagerImpl::ProceedStartingRecognition( + const SpeechRecognitionParams& params) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(!HasPendingRequest(params.caller_id)); @@ -175,18 +176,18 @@ void SpeechInputManagerImpl::ProceedStartingRecognition( delegate_->GetRequestInfo(&can_report_metrics_, &request_info_); } - SpeechInputRequest* request = &requests_[params.caller_id]; + Request* request = &requests_[params.caller_id]; request->delegate = params.delegate; request->recognizer = new SpeechRecognizerImpl( this, params.caller_id, params.language, params.grammar, - params.context_getter, params.speech_input_prefs->FilterProfanities(), + params.context_getter, params.recognition_prefs->FilterProfanities(), request_info_, can_report_metrics_ ? params.origin_url : ""); request->is_active = false; StartRecognitionForRequest(params.caller_id); } -void SpeechInputManagerImpl::StartRecognitionForRequest(int caller_id) { +void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int caller_id) { SpeechRecognizerMap::iterator request = requests_.find(caller_id); if (request == requests_.end()) { NOTREACHED(); @@ -202,13 +203,13 @@ void SpeechInputManagerImpl::StartRecognitionForRequest(int caller_id) { if (!HasAudioInputDevices()) { if (delegate_) { - delegate_->ShowMicError( - caller_id, SpeechInputManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); + delegate_->ShowMicError(caller_id, + SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); } - } else if (IsRecordingInProcess()) { + } else if (IsCapturingAudio()) { if (delegate_) { delegate_->ShowMicError( - caller_id, SpeechInputManagerDelegate::MIC_ERROR_DEVICE_IN_USE); + caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); } } else { recording_caller_id_ = caller_id; @@ -219,7 +220,7 @@ void SpeechInputManagerImpl::StartRecognitionForRequest(int caller_id) { } } -void SpeechInputManagerImpl::CancelRecognitionForRequest(int caller_id) { +void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) { // Ignore if the caller id was not in our active recognizers list because the // user might have clicked more than once, or recognition could have been // ended due to other reasons before the user click was processed. @@ -229,7 +230,7 @@ void SpeechInputManagerImpl::CancelRecognitionForRequest(int caller_id) { CancelRecognitionAndInformDelegate(caller_id); } -void SpeechInputManagerImpl::FocusLostForRequest(int caller_id) { +void SpeechRecognitionManagerImpl::FocusLostForRequest(int caller_id) { // See above comment. if (!HasPendingRequest(caller_id)) return; @@ -242,7 +243,7 @@ void SpeechInputManagerImpl::FocusLostForRequest(int caller_id) { CancelRecognitionAndInformDelegate(caller_id); } -void SpeechInputManagerImpl::CancelRecognition(int caller_id) { +void SpeechRecognitionManagerImpl::CancelRecognition(int caller_id) { DCHECK(HasPendingRequest(caller_id)); if (requests_[caller_id].is_active) requests_[caller_id].recognizer->CancelRecognition(); @@ -253,8 +254,8 @@ void SpeechInputManagerImpl::CancelRecognition(int caller_id) { delegate_->DoClose(caller_id); } -void SpeechInputManagerImpl::CancelAllRequestsWithDelegate( - SpeechInputDispatcherHost* delegate) { +void SpeechRecognitionManagerImpl::CancelAllRequestsWithDelegate( + InputTagSpeechDispatcherHost* delegate) { SpeechRecognizerMap::iterator it = requests_.begin(); while (it != requests_.end()) { if (it->second.delegate == delegate) { @@ -267,7 +268,7 @@ void SpeechInputManagerImpl::CancelAllRequestsWithDelegate( } } -void SpeechInputManagerImpl::StopRecording(int caller_id) { +void SpeechRecognitionManagerImpl::StopRecording(int caller_id) { // No pending requests on extension popups. if (!HasPendingRequest(caller_id)) return; @@ -275,13 +276,13 @@ void SpeechInputManagerImpl::StopRecording(int caller_id) { requests_[caller_id].recognizer->StopRecording(); } -void SpeechInputManagerImpl::SetRecognitionResult( - int caller_id, const content::SpeechInputResult& result) { +void SpeechRecognitionManagerImpl::SetRecognitionResult( + int caller_id, const content::SpeechRecognitionResult& result) { DCHECK(HasPendingRequest(caller_id)); GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); } -void SpeechInputManagerImpl::DidCompleteRecording(int caller_id) { +void SpeechRecognitionManagerImpl::DidCompleteRecording(int caller_id) { DCHECK(recording_caller_id_ == caller_id); DCHECK(HasPendingRequest(caller_id)); recording_caller_id_ = 0; @@ -290,21 +291,21 @@ void SpeechInputManagerImpl::DidCompleteRecording(int caller_id) { delegate_->ShowRecognizing(caller_id); } -void SpeechInputManagerImpl::DidCompleteRecognition(int caller_id) { +void SpeechRecognitionManagerImpl::DidCompleteRecognition(int caller_id) { GetDelegate(caller_id)->DidCompleteRecognition(caller_id); requests_.erase(caller_id); if (delegate_) delegate_->DoClose(caller_id); } -void SpeechInputManagerImpl::DidStartReceivingSpeech(int caller_id) { +void SpeechRecognitionManagerImpl::DidStartReceivingSpeech(int caller_id) { } -void SpeechInputManagerImpl::DidStopReceivingSpeech(int caller_id) { +void SpeechRecognitionManagerImpl::DidStopReceivingSpeech(int caller_id) { } -void SpeechInputManagerImpl::OnRecognizerError( - int caller_id, content::SpeechInputError error) { +void SpeechRecognitionManagerImpl::OnRecognizerError( + int caller_id, content::SpeechRecognitionErrorCode error) { if (caller_id == recording_caller_id_) recording_caller_id_ = 0; requests_[caller_id].is_active = false; @@ -312,40 +313,41 @@ void SpeechInputManagerImpl::OnRecognizerError( delegate_->ShowRecognizerError(caller_id, error); } -void SpeechInputManagerImpl::DidStartReceivingAudio(int caller_id) { +void SpeechRecognitionManagerImpl::DidStartReceivingAudio(int caller_id) { DCHECK(HasPendingRequest(caller_id)); DCHECK(recording_caller_id_ == caller_id); if (delegate_) delegate_->ShowRecording(caller_id); } -void SpeechInputManagerImpl::DidCompleteEnvironmentEstimation(int caller_id) { +void SpeechRecognitionManagerImpl::DidCompleteEnvironmentEstimation( + int caller_id) { DCHECK(HasPendingRequest(caller_id)); DCHECK(recording_caller_id_ == caller_id); } -void SpeechInputManagerImpl::SetInputVolume(int caller_id, float volume, - float noise_volume) { +void SpeechRecognitionManagerImpl::SetInputVolume(int caller_id, float volume, + float noise_volume) { DCHECK(HasPendingRequest(caller_id)); DCHECK_EQ(recording_caller_id_, caller_id); if (delegate_) delegate_->ShowInputVolume(caller_id, volume, noise_volume); } -void SpeechInputManagerImpl::CancelRecognitionAndInformDelegate( +void SpeechRecognitionManagerImpl::CancelRecognitionAndInformDelegate( int caller_id) { - SpeechInputDispatcherHost* cur_delegate = GetDelegate(caller_id); + InputTagSpeechDispatcherHost* cur_delegate = GetDelegate(caller_id); CancelRecognition(caller_id); cur_delegate->DidCompleteRecording(caller_id); cur_delegate->DidCompleteRecognition(caller_id); } -SpeechInputManagerImpl::SpeechInputRequest::SpeechInputRequest() +SpeechRecognitionManagerImpl::Request::Request() : delegate(NULL), is_active(false) { } -SpeechInputManagerImpl::SpeechInputRequest::~SpeechInputRequest() { +SpeechRecognitionManagerImpl::Request::~Request() { } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_input_manager_impl.h b/content/browser/speech/speech_recognition_manager_impl.h index 6675fb8..8b91029 100644 --- a/content/browser/speech/speech_input_manager_impl.h +++ b/content/browser/speech/speech_recognition_manager_impl.h @@ -2,8 +2,8 @@ // 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_INPUT_MANAGER_H_ -#define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ +#ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ +#define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ #include <map> #include <string> @@ -12,7 +12,7 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/memory/singleton.h" -#include "content/public/browser/speech_input_manager.h" +#include "content/public/browser/speech_recognition_manager.h" #include "content/public/browser/speech_recognizer_delegate.h" #include "ui/gfx/rect.h" @@ -20,32 +20,32 @@ class AudioManager; namespace content { class ResourceContext; -class SpeechInputManagerDelegate; -class SpeechInputPreferences; -struct SpeechInputResult; +class SpeechRecognitionManagerDelegate; +class SpeechRecognitionPreferences; +struct SpeechRecognitionResult; } namespace net { class URLRequestContextGetter; } -namespace speech_input { +namespace speech { -class SpeechInputDispatcherHost; +class InputTagSpeechDispatcherHost; class SpeechRecognizerImpl; -class CONTENT_EXPORT SpeechInputManagerImpl - : NON_EXPORTED_BASE(public content::SpeechInputManager), +class CONTENT_EXPORT SpeechRecognitionManagerImpl + : NON_EXPORTED_BASE(public content::SpeechRecognitionManager), NON_EXPORTED_BASE(public content::SpeechRecognizerDelegate) { public: - static SpeechInputManagerImpl* GetInstance(); + static SpeechRecognitionManagerImpl* GetInstance(); - // SpeechInputManager implementation: + // SpeechRecognitionManager implementation: virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; virtual void FocusLostForRequest(int caller_id) OVERRIDE; virtual bool HasAudioInputDevices() OVERRIDE; - virtual bool IsRecordingInProcess() OVERRIDE; + virtual bool IsCapturingAudio() OVERRIDE; virtual string16 GetAudioInputDeviceModel() OVERRIDE; virtual void ShowAudioInputSettings() OVERRIDE; @@ -58,7 +58,7 @@ class CONTENT_EXPORT SpeechInputManagerImpl // |element_rect| is the display bounds of the html element requesting speech // input (in page coordinates). virtual void StartRecognition( - SpeechInputDispatcherHost* delegate, + InputTagSpeechDispatcherHost* delegate, int caller_id, int render_process_id, int render_view_id, @@ -67,63 +67,63 @@ class CONTENT_EXPORT SpeechInputManagerImpl const std::string& grammar, const std::string& origin_url, net::URLRequestContextGetter* context_getter, - content::SpeechInputPreferences* speech_input_prefs); + content::SpeechRecognitionPreferences* speech_recognition_prefs); virtual void CancelRecognition(int caller_id); virtual void CancelAllRequestsWithDelegate( - SpeechInputDispatcherHost* delegate); + InputTagSpeechDispatcherHost* delegate); virtual void StopRecording(int caller_id); // Overridden from content::SpeechRecognizerDelegate: virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; virtual void SetRecognitionResult( - int caller_id, - const content::SpeechInputResult& result) OVERRIDE; + int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; virtual void DidCompleteRecording(int caller_id) OVERRIDE; virtual void DidCompleteRecognition(int caller_id) OVERRIDE; virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; - virtual void OnRecognizerError(int caller_id, - content::SpeechInputError error) OVERRIDE; + virtual void OnRecognizerError( + int caller_id, content::SpeechRecognitionErrorCode error) OVERRIDE; virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; virtual void SetInputVolume(int caller_id, float volume, float noise_volume) OVERRIDE; protected: // Private constructor to enforce singleton. - friend struct DefaultSingletonTraits<SpeechInputManagerImpl>; - SpeechInputManagerImpl(); - virtual ~SpeechInputManagerImpl(); + friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; + SpeechRecognitionManagerImpl(); + virtual ~SpeechRecognitionManagerImpl(); bool HasPendingRequest(int caller_id) const; private: - struct SpeechInputRequest { - SpeechInputRequest(); - ~SpeechInputRequest(); + struct Request { + Request(); + ~Request(); - SpeechInputDispatcherHost* delegate; + InputTagSpeechDispatcherHost* delegate; scoped_refptr<SpeechRecognizerImpl> recognizer; bool is_active; // Set to true when recording or recognition is going on. }; - struct SpeechInputParams; + struct SpeechRecognitionParams; - SpeechInputDispatcherHost* GetDelegate(int caller_id) const; + InputTagSpeechDispatcherHost* GetDelegate(int caller_id) const; - void CheckRenderViewTypeAndStartRecognition(const SpeechInputParams& params); - void ProceedStartingRecognition(const SpeechInputParams& params); + void CheckRenderViewTypeAndStartRecognition( + const SpeechRecognitionParams& params); + void ProceedStartingRecognition(const SpeechRecognitionParams& params); void CancelRecognitionAndInformDelegate(int caller_id); - typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; + typedef std::map<int, Request> SpeechRecognizerMap; SpeechRecognizerMap requests_; std::string request_info_; bool can_report_metrics_; int recording_caller_id_; - content::SpeechInputManagerDelegate* delegate_; + content::SpeechRecognitionManagerDelegate* delegate_; }; -} // namespace speech_input +} // namespace speech -#endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ +#endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ diff --git a/content/browser/speech/speech_recognition_request.cc b/content/browser/speech/speech_recognition_request.cc index 8176128..89dde84 100644 --- a/content/browser/speech/speech_recognition_request.cc +++ b/content/browser/speech/speech_recognition_request.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -11,7 +11,7 @@ #include "base/string_util.h" #include "base/values.h" #include "content/common/net/url_fetcher_impl.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "net/base/escape.h" #include "net/base/load_flags.h" #include "net/url_request/url_request_context.h" @@ -32,7 +32,7 @@ const char* const kConfidenceString = "confidence"; const int kMaxResults = 6; bool ParseServerResponse(const std::string& response_body, - content::SpeechInputResult* result) { + content::SpeechRecognitionResult* result) { if (response_body.empty()) { LOG(WARNING) << "ParseServerResponse: Response was empty."; return false; @@ -66,9 +66,9 @@ bool ParseServerResponse(const std::string& response_body, // Process the status. switch (status) { - case content::SPEECH_INPUT_ERROR_NONE: - case content::SPEECH_INPUT_ERROR_NO_SPEECH: - case content::SPEECH_INPUT_ERROR_NO_MATCH: + case content::SPEECH_RECOGNITION_ERROR_NONE: + case content::SPEECH_RECOGNITION_ERROR_NO_SPEECH: + case content::SPEECH_RECOGNITION_ERROR_NO_MATCH: break; default: @@ -77,7 +77,7 @@ bool ParseServerResponse(const std::string& response_body, return false; } - result->error = static_cast<content::SpeechInputError>(status); + result->error = static_cast<content::SpeechRecognitionErrorCode>(status); // Get the hypotheses. Value* hypotheses_value = NULL; @@ -121,7 +121,7 @@ bool ParseServerResponse(const std::string& response_body, double confidence = 0.0; hypothesis_value->GetDouble(kConfidenceString, &confidence); - result->hypotheses.push_back(content::SpeechInputHypothesis( + result->hypotheses.push_back(content::SpeechRecognitionHypothesis( utterance, confidence)); } @@ -135,7 +135,7 @@ bool ParseServerResponse(const std::string& response_body, } // namespace -namespace speech_input { +namespace speech { int SpeechRecognitionRequest::url_fetcher_id_for_tests = 0; @@ -211,12 +211,12 @@ void SpeechRecognitionRequest::OnURLFetchComplete( const content::URLFetcher* source) { DCHECK_EQ(url_fetcher_.get(), source); - content::SpeechInputResult result; + content::SpeechRecognitionResult result; std::string data; if (!source->GetStatus().is_success() || source->GetResponseCode() != 200 || !source->GetResponseAsString(&data) || !ParseServerResponse(data, &result)) { - result.error = content::SPEECH_INPUT_ERROR_NETWORK; + result.error = content::SPEECH_RECOGNITION_ERROR_NETWORK; } DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; @@ -224,4 +224,4 @@ void SpeechRecognitionRequest::OnURLFetchComplete( delegate_->SetRecognitionResult(result); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_recognition_request.h b/content/browser/speech/speech_recognition_request.h index 65a9733..b6ce077 100644 --- a/content/browser/speech/speech_recognition_request.h +++ b/content/browser/speech/speech_recognition_request.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -18,14 +18,14 @@ class URLFetcher; namespace content { -struct SpeechInputResult; +struct SpeechRecognitionResult; } namespace net { class URLRequestContextGetter; } -namespace speech_input { +namespace speech { // Provides a simple interface for sending recorded speech data to the server // and get back recognition results. @@ -38,7 +38,7 @@ class SpeechRecognitionRequest : public content::URLFetcherDelegate { class CONTENT_EXPORT Delegate { public: virtual void SetRecognitionResult( - const content::SpeechInputResult& result) = 0; + const content::SpeechRecognitionResult& result) = 0; protected: virtual ~Delegate() {} @@ -83,6 +83,6 @@ class SpeechRecognitionRequest : public content::URLFetcherDelegate { // the workaround was not needed for my machine). typedef SpeechRecognitionRequest::Delegate SpeechRecognitionRequestDelegate; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_REQUEST_H_ diff --git a/content/browser/speech/speech_recognition_request_unittest.cc b/content/browser/speech/speech_recognition_request_unittest.cc index 9221085..37b82f8 100644 --- a/content/browser/speech/speech_recognition_request_unittest.cc +++ b/content/browser/speech/speech_recognition_request_unittest.cc @@ -1,17 +1,17 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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 "base/message_loop.h" #include "base/utf_string_conversions.h" #include "content/browser/speech/speech_recognition_request.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" -namespace speech_input { +namespace speech { class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate, public testing::Test { @@ -24,14 +24,14 @@ class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate, // SpeechRecognitionRequestDelegate methods. virtual void SetRecognitionResult( - const content::SpeechInputResult& result) OVERRIDE { + const content::SpeechRecognitionResult& result) OVERRIDE { result_ = result; } protected: MessageLoop message_loop_; TestURLFetcherFactory url_fetcher_factory_; - content::SpeechInputResult result_; + content::SpeechRecognitionResult result_; }; void SpeechRecognitionRequestTest::CreateAndTestRequest( @@ -60,7 +60,7 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" "[{\"utterance\":\"123456\",\"confidence\":0.9}]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NONE); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); EXPECT_EQ(1U, result_.hypotheses.size()); EXPECT_EQ(ASCIIToUTF16("123456"), result_.hypotheses[0].utterance); EXPECT_EQ(0.9, result_.hypotheses[0].confidence); @@ -70,7 +70,7 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { "{\"status\":0,\"hypotheses\":[" "{\"utterance\":\"hello\",\"confidence\":0.9}," "{\"utterance\":\"123456\",\"confidence\":0.5}]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NONE); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); EXPECT_EQ(2u, result_.hypotheses.size()); EXPECT_EQ(ASCIIToUTF16("hello"), result_.hypotheses[0].utterance); EXPECT_EQ(0.9, result_.hypotheses[0].confidence); @@ -79,29 +79,29 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { // Zero results. CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":[]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NONE); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); EXPECT_EQ(0U, result_.hypotheses.size()); // Http failure case. CreateAndTestRequest(false, ""); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); // Invalid status case. CreateAndTestRequest(true, "{\"status\":\"invalid\",\"hypotheses\":[]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); // Server-side error case. CreateAndTestRequest(true, "{\"status\":1,\"hypotheses\":[]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); // Malformed JSON case. CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" "[{\"unknownkey\":\"hello\"}]}"); - EXPECT_EQ(result_.error, content::SPEECH_INPUT_ERROR_NETWORK); + EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); EXPECT_EQ(0U, result_.hypotheses.size()); } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_recognizer_impl.cc b/content/browser/speech/speech_recognizer_impl.cc index 9d4ed1c..bbcfbd2 100644 --- a/content/browser/speech/speech_recognizer_impl.cc +++ b/content/browser/speech/speech_recognizer_impl.cc @@ -9,7 +9,7 @@ #include "content/browser/browser_main_loop.h" #include "content/public/browser/speech_recognizer_delegate.h" #include "content/public/browser/browser_thread.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "net/url_request/url_request_context_getter.h" using content::BrowserMainLoop; @@ -61,12 +61,12 @@ SpeechRecognizer* SpeechRecognizer::Create( bool filter_profanities, const std::string& hardware_info, const std::string& origin_url) { - return new speech_input::SpeechRecognizerImpl( + return new speech::SpeechRecognizerImpl( delegate, caller_id, language, grammar, context_getter, filter_profanities, hardware_info, origin_url); } -namespace speech_input { +namespace speech { const int SpeechRecognizerImpl::kAudioSampleRate = 16000; const int SpeechRecognizerImpl::kAudioPacketIntervalMs = 100; @@ -208,7 +208,7 @@ void SpeechRecognizerImpl::HandleOnError(int error_code) { if (!audio_controller_.get()) return; - InformErrorAndCancelRecognition(content::SPEECH_INPUT_ERROR_AUDIO); + InformErrorAndCancelRecognition(content::SPEECH_RECOGNITION_ERROR_AUDIO); } void SpeechRecognizerImpl::OnData(AudioInputController* controller, @@ -272,7 +272,8 @@ void SpeechRecognizerImpl::HandleOnData(string* data) { bool speech_was_heard_after_packet = endpointer_.DidStartReceivingSpeech(); if (!speech_was_heard_after_packet && num_samples_recorded_ >= kNoSpeechTimeoutSec * kAudioSampleRate) { - InformErrorAndCancelRecognition(content::SPEECH_INPUT_ERROR_NO_SPEECH); + InformErrorAndCancelRecognition( + content::SPEECH_RECOGNITION_ERROR_NO_SPEECH); return; } @@ -303,8 +304,8 @@ void SpeechRecognizerImpl::HandleOnData(string* data) { } void SpeechRecognizerImpl::SetRecognitionResult( - const content::SpeechInputResult& result) { - if (result.error != content::SPEECH_INPUT_ERROR_NONE) { + const content::SpeechRecognitionResult& result) { + if (result.error != content::SPEECH_RECOGNITION_ERROR_NONE) { InformErrorAndCancelRecognition(result.error); return; } @@ -316,8 +317,8 @@ void SpeechRecognizerImpl::SetRecognitionResult( } void SpeechRecognizerImpl::InformErrorAndCancelRecognition( - content::SpeechInputError error) { - DCHECK_NE(error, content::SPEECH_INPUT_ERROR_NONE); + content::SpeechRecognitionErrorCode error) { + DCHECK_NE(error, content::SPEECH_RECOGNITION_ERROR_NONE); CancelRecognition(); // Guard against the delegate freeing us until we finish our job. @@ -343,4 +344,4 @@ void SpeechRecognizerImpl::SetAudioManagerForTesting( audio_manager_ = audio_manager; } -} // namespace speech_input +} // namespace speech diff --git a/content/browser/speech/speech_recognizer_impl.h b/content/browser/speech/speech_recognizer_impl.h index 0273ccb..25e0c0c 100644 --- a/content/browser/speech/speech_recognizer_impl.h +++ b/content/browser/speech/speech_recognizer_impl.h @@ -14,12 +14,12 @@ #include "content/browser/speech/endpointer/endpointer.h" #include "content/browser/speech/speech_recognition_request.h" #include "content/public/browser/speech_recognizer.h" -#include "content/public/common/speech_input_result.h" +#include "content/public/common/speech_recognition_result.h" #include "media/audio/audio_input_controller.h" class AudioManager; -namespace speech_input { +namespace speech { // Records audio, sends recorded audio to server and translates server response // to recognition result. @@ -47,8 +47,8 @@ class CONTENT_EXPORT SpeechRecognizerImpl void StopRecording(); // AudioInputController::EventHandler methods. - virtual void OnCreated(media::AudioInputController* controller) OVERRIDE { } - virtual void OnRecording(media::AudioInputController* controller) OVERRIDE { } + virtual void OnCreated(media::AudioInputController* controller) OVERRIDE {} + virtual void OnRecording(media::AudioInputController* controller) OVERRIDE {} virtual void OnError(media::AudioInputController* controller, int error_code) OVERRIDE; virtual void OnData(media::AudioInputController* controller, @@ -57,7 +57,7 @@ class CONTENT_EXPORT SpeechRecognizerImpl // SpeechRecognitionRequest::Delegate methods. virtual void SetRecognitionResult( - const content::SpeechInputResult& result) OVERRIDE; + const content::SpeechRecognitionResult& result) OVERRIDE; static const int kAudioSampleRate; static const int kAudioPacketIntervalMs; // Duration of each audio packet. @@ -69,7 +69,8 @@ class CONTENT_EXPORT SpeechRecognizerImpl private: friend class SpeechRecognizerTest; - void InformErrorAndCancelRecognition(content::SpeechInputError error); + void InformErrorAndCancelRecognition( + content::SpeechRecognitionErrorCode error); void SendRecordedAudioToServer(); void HandleOnError(int error_code); // Handles OnError in the IO thread. @@ -103,6 +104,6 @@ class CONTENT_EXPORT SpeechRecognizerImpl DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); }; -} // namespace speech_input +} // namespace speech #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ diff --git a/content/browser/speech/speech_recognizer_impl_unittest.cc b/content/browser/speech/speech_recognizer_impl_unittest.cc index 7388914..cfd2c33 100644 --- a/content/browser/speech/speech_recognizer_impl_unittest.cc +++ b/content/browser/speech/speech_recognizer_impl_unittest.cc @@ -20,7 +20,7 @@ using media::AudioInputController; using media::TestAudioInputController; using media::TestAudioInputControllerFactory; -namespace speech_input { +namespace speech { class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, public testing::Test { @@ -32,7 +32,7 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, recognition_complete_(false), result_received_(false), audio_received_(false), - error_(content::SPEECH_INPUT_ERROR_NONE), + error_(content::SPEECH_RECOGNITION_ERROR_NONE), volume_(-1.0f) { recognizer_ = new SpeechRecognizerImpl( this, 1, std::string(), std::string(), NULL, false, std::string(), @@ -49,7 +49,7 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, // Overridden from content::SpeechRecognizerDelegate: virtual void SetRecognitionResult( int caller_id, - const content::SpeechInputResult& result) OVERRIDE { + const content::SpeechRecognitionResult& result) OVERRIDE { result_received_ = true; } @@ -74,8 +74,8 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE { } - virtual void OnRecognizerError(int caller_id, - content::SpeechInputError error) OVERRIDE { + virtual void OnRecognizerError( + int caller_id, content::SpeechRecognitionErrorCode error) OVERRIDE { error_ = error; } @@ -119,7 +119,7 @@ class SpeechRecognizerTest : public content::SpeechRecognizerDelegate, bool recognition_complete_; bool result_received_; bool audio_received_; - content::SpeechInputError error_; + content::SpeechRecognitionErrorCode error_; TestURLFetcherFactory url_fetcher_factory_; TestAudioInputControllerFactory audio_input_controller_factory_; std::vector<uint8> audio_packet_; @@ -135,7 +135,7 @@ TEST_F(SpeechRecognizerTest, StopNoData) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); EXPECT_FALSE(audio_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, CancelNoData) { @@ -147,7 +147,7 @@ TEST_F(SpeechRecognizerTest, CancelNoData) { EXPECT_TRUE(recognition_complete_); EXPECT_FALSE(result_received_); EXPECT_FALSE(audio_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, StopWithData) { @@ -177,7 +177,7 @@ TEST_F(SpeechRecognizerTest, StopWithData) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); // Issue the network callback to complete the process. TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); @@ -194,7 +194,7 @@ TEST_F(SpeechRecognizerTest, StopWithData) { EXPECT_TRUE(recognition_complete_); EXPECT_TRUE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, CancelWithData) { @@ -213,7 +213,7 @@ TEST_F(SpeechRecognizerTest, CancelWithData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); } TEST_F(SpeechRecognizerTest, ConnectionError) { @@ -234,7 +234,7 @@ TEST_F(SpeechRecognizerTest, ConnectionError) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); // Issue the network callback to complete the process. fetcher->set_url(fetcher->GetOriginalURL()); @@ -248,7 +248,7 @@ TEST_F(SpeechRecognizerTest, ConnectionError) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NETWORK, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NETWORK, error_); } TEST_F(SpeechRecognizerTest, ServerError) { @@ -269,7 +269,7 @@ TEST_F(SpeechRecognizerTest, ServerError) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); // Issue the network callback to complete the process. fetcher->set_url(fetcher->GetOriginalURL()); @@ -282,7 +282,7 @@ TEST_F(SpeechRecognizerTest, ServerError) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NETWORK, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NETWORK, error_); } TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { @@ -297,7 +297,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_AUDIO, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_AUDIO, error_); } TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { @@ -316,7 +316,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_AUDIO, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_AUDIO, error_); } TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { @@ -341,7 +341,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NO_SPEECH, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NO_SPEECH, error_); } TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { @@ -372,7 +372,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { } MessageLoop::current()->RunAllPending(); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); EXPECT_TRUE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); @@ -415,10 +415,10 @@ TEST_F(SpeechRecognizerTest, SetInputVolumeCallback) { EXPECT_FLOAT_EQ(0.89926866f, volume_); EXPECT_FLOAT_EQ(0.75071919f, noise_volume_); - EXPECT_EQ(content::SPEECH_INPUT_ERROR_NONE, error_); + EXPECT_EQ(content::SPEECH_RECOGNITION_ERROR_NONE, error_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); recognizer_->CancelRecognition(); } -} // namespace speech_input +} // namespace speech |