diff options
21 files changed, 406 insertions, 406 deletions
diff --git a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc index 4d9807f..db4a238 100644 --- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc +++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc @@ -105,11 +105,11 @@ ChromeSpeechRecognitionManagerDelegate:: } void ChromeSpeechRecognitionManagerDelegate::ShowRecognitionRequested( - int caller_id, + int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect) { - bubble_controller_->CreateBubble(caller_id, render_process_id, + bubble_controller_->CreateBubble(session_id, render_process_id, render_view_id, element_rect); } @@ -132,34 +132,34 @@ void ChromeSpeechRecognitionManagerDelegate::GetRequestInfo( *request_info = optional_request_info_->value(); } -void ChromeSpeechRecognitionManagerDelegate::ShowWarmUp(int caller_id) { - bubble_controller_->SetBubbleWarmUpMode(caller_id); +void ChromeSpeechRecognitionManagerDelegate::ShowWarmUp(int session_id) { + bubble_controller_->SetBubbleWarmUpMode(session_id); } -void ChromeSpeechRecognitionManagerDelegate::ShowRecognizing(int caller_id) { - bubble_controller_->SetBubbleRecognizingMode(caller_id); +void ChromeSpeechRecognitionManagerDelegate::ShowRecognizing(int session_id) { + bubble_controller_->SetBubbleRecognizingMode(session_id); } -void ChromeSpeechRecognitionManagerDelegate::ShowRecording(int caller_id) { - bubble_controller_->SetBubbleRecordingMode(caller_id); +void ChromeSpeechRecognitionManagerDelegate::ShowRecording(int session_id) { + bubble_controller_->SetBubbleRecordingMode(session_id); } void ChromeSpeechRecognitionManagerDelegate::ShowInputVolume( - int caller_id, float volume, float noise_volume) { - bubble_controller_->SetBubbleInputVolume(caller_id, volume, noise_volume); + int session_id, float volume, float noise_volume) { + bubble_controller_->SetBubbleInputVolume(session_id, volume, noise_volume); } -void ChromeSpeechRecognitionManagerDelegate::ShowMicError(int caller_id, - MicError error) { +void ChromeSpeechRecognitionManagerDelegate::ShowMicError(int session_id, + MicError error) { switch (error) { case MIC_ERROR_NO_DEVICE_AVAILABLE: bubble_controller_->SetBubbleMessage( - caller_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_NO_MIC)); + session_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_NO_MIC)); break; case MIC_ERROR_DEVICE_IN_USE: bubble_controller_->SetBubbleMessage( - caller_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_IN_USE)); + session_id, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_IN_USE)); break; default: @@ -168,7 +168,7 @@ void ChromeSpeechRecognitionManagerDelegate::ShowMicError(int caller_id, } void ChromeSpeechRecognitionManagerDelegate::ShowRecognizerError( - int caller_id, content::SpeechRecognitionErrorCode error) { + int session_id, content::SpeechRecognitionErrorCode error) { struct ErrorMessageMapEntry { content::SpeechRecognitionErrorCode error; int message_id; @@ -187,7 +187,7 @@ void ChromeSpeechRecognitionManagerDelegate::ShowRecognizerError( for (size_t i = 0; i < ARRAYSIZE_UNSAFE(error_message_map); ++i) { if (error_message_map[i].error == error) { bubble_controller_->SetBubbleMessage( - caller_id, + session_id, l10n_util::GetStringUTF16(error_message_map[i].message_id)); return; } @@ -196,27 +196,27 @@ void ChromeSpeechRecognitionManagerDelegate::ShowRecognizerError( NOTREACHED() << "unknown error " << error; } -void ChromeSpeechRecognitionManagerDelegate::DoClose(int caller_id) { - bubble_controller_->CloseBubble(caller_id); +void ChromeSpeechRecognitionManagerDelegate::DoClose(int session_id) { + bubble_controller_->CloseBubble(session_id); } void ChromeSpeechRecognitionManagerDelegate::InfoBubbleButtonClicked( - int caller_id, SpeechRecognitionBubble::Button button) { + int session_id, SpeechRecognitionBubble::Button button) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (button == SpeechRecognitionBubble::BUTTON_CANCEL) { SpeechRecognitionManager::GetInstance()->CancelRecognitionForRequest( - caller_id); + session_id); } else if (button == SpeechRecognitionBubble::BUTTON_TRY_AGAIN) { SpeechRecognitionManager::GetInstance()->StartRecognitionForRequest( - caller_id); + session_id); } } void ChromeSpeechRecognitionManagerDelegate::InfoBubbleFocusChanged( - int caller_id) { + int session_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - SpeechRecognitionManager::GetInstance()->FocusLostForRequest(caller_id); + SpeechRecognitionManager::GetInstance()->FocusLostForRequest(session_id); } } // namespace speech diff --git a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h index cf4e7db..d209852 100644 --- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h +++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h @@ -23,28 +23,28 @@ class ChromeSpeechRecognitionManagerDelegate // SpeechRecognitionBubbleControllerDelegate methods. virtual void InfoBubbleButtonClicked( - int caller_id, SpeechRecognitionBubble::Button button) OVERRIDE; - virtual void InfoBubbleFocusChanged(int caller_id) OVERRIDE; + int session_id, SpeechRecognitionBubble::Button button) OVERRIDE; + virtual void InfoBubbleFocusChanged(int session_id) OVERRIDE; protected: // SpeechRecognitionManagerDelegate methods. virtual void GetRequestInfo(bool* can_report_metrics, std::string* request_info) OVERRIDE; - virtual void ShowRecognitionRequested(int caller_id, + virtual void ShowRecognitionRequested(int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect) OVERRIDE; - virtual void ShowWarmUp(int caller_id) OVERRIDE; - virtual void ShowRecognizing(int caller_id) OVERRIDE; - virtual void ShowRecording(int caller_id) OVERRIDE; - virtual void ShowInputVolume(int caller_id, + virtual void ShowWarmUp(int session_id) OVERRIDE; + virtual void ShowRecognizing(int session_id) OVERRIDE; + virtual void ShowRecording(int session_id) OVERRIDE; + virtual void ShowInputVolume(int session_id, float volume, float noise_volume) OVERRIDE; - virtual void ShowMicError(int caller_id, + virtual void ShowMicError(int session_id, MicError error) OVERRIDE; virtual void ShowRecognizerError( - int caller_id, content::SpeechRecognitionErrorCode error) OVERRIDE; - virtual void DoClose(int caller_id) OVERRIDE; + int session_id, content::SpeechRecognitionErrorCode error) OVERRIDE; + virtual void DoClose(int session_id) OVERRIDE; private: class OptionalRequestInfo; diff --git a/chrome/browser/speech/speech_input_extension_apitest.cc b/chrome/browser/speech/speech_input_extension_apitest.cc index 422e639..7dab696 100644 --- a/chrome/browser/speech/speech_input_extension_apitest.cc +++ b/chrome/browser/speech/speech_input_extension_apitest.cc @@ -77,7 +77,7 @@ class SpeechInputExtensionApiTest : public ExtensionApiTest, virtual void StartRecording( content::SpeechRecognitionEventListener* listener, net::URLRequestContextGetter* context_getter, - int caller_id, + int session_id, const std::string& language, const std::string& grammar, bool filter_profanities) OVERRIDE; @@ -107,7 +107,7 @@ class SpeechInputExtensionApiTest : public ExtensionApiTest, }; private: - void ProvideResults(int caller_id); + void ProvideResults(int session_id); bool recording_devices_available_; bool recognizer_is_valid_; @@ -131,7 +131,7 @@ SpeechInputExtensionApiTest::~SpeechInputExtensionApiTest() { void SpeechInputExtensionApiTest::StartRecording( content::SpeechRecognitionEventListener* listener, net::URLRequestContextGetter* context_getter, - int caller_id, + int session_id, const std::string& language, const std::string& grammar, bool filter_profanities) { @@ -143,7 +143,7 @@ void SpeechInputExtensionApiTest::StartRecording( FROM_HERE, base::Bind(&SpeechInputExtensionManager::OnAudioStart, GetManager(), - caller_id), + session_id), base::TimeDelta()); // Notify sound start in the input device. @@ -151,7 +151,7 @@ void SpeechInputExtensionApiTest::StartRecording( FROM_HERE, base::Bind(&SpeechInputExtensionManager::OnSoundStart, GetManager(), - caller_id), + session_id), base::TimeDelta()); if (result_delay_ms_ != kDontDispatchCall) { @@ -160,7 +160,7 @@ void SpeechInputExtensionApiTest::StartRecording( FROM_HERE, base::Bind(&SpeechInputExtensionApiTest::ProvideResults, this, - caller_id), + session_id), base::TimeDelta::FromMilliseconds(result_delay_ms_)); } } @@ -170,17 +170,17 @@ void SpeechInputExtensionApiTest::StopRecording(bool recognition_failed) { recognizer_is_valid_ = false; } -void SpeechInputExtensionApiTest::ProvideResults(int caller_id) { +void SpeechInputExtensionApiTest::ProvideResults(int session_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (next_error_ != content::SPEECH_RECOGNITION_ERROR_NONE) { - GetManager()->OnRecognitionError(caller_id, next_error_); + GetManager()->OnRecognitionError(session_id, next_error_); return; } - GetManager()->OnSoundEnd(caller_id); - GetManager()->OnAudioEnd(caller_id); - GetManager()->OnRecognitionResult(caller_id, next_result_); + GetManager()->OnSoundEnd(session_id); + GetManager()->OnAudioEnd(session_id); + GetManager()->OnRecognitionResult(session_id, next_result_); } // Every test should leave the manager in the idle state when finished. diff --git a/chrome/browser/speech/speech_input_extension_manager.cc b/chrome/browser/speech/speech_input_extension_manager.cc index 95f539d..b69c7a9 100644 --- a/chrome/browser/speech/speech_input_extension_manager.cc +++ b/chrome/browser/speech/speech_input_extension_manager.cc @@ -55,9 +55,11 @@ const char kOnResultEvent[] = "experimental.speechInput.onResult"; const char kOnSoundStartEvent[] = "experimental.speechInput.onSoundStart"; const char kOnSoundEndEvent[] = "experimental.speechInput.onSoundEnd"; -// Caller id provided to the speech recognizer. Since only one extension can +// Session id provided to the speech recognizer. Since only one extension can // be recording on the same time a constant value is enough as id. -static const int kSpeechCallerId = 1; +// TODO(primiano) this will not be valid anymore once speech input extension +// will use the SpeechRecognitionManager and not the SpeechRecognizer directly. +static const int kSpeechInputSessionId = 1; // Wrap an SpeechInputExtensionManager using scoped_refptr to avoid // assertion failures on destruction because of not using release(). @@ -239,10 +241,10 @@ void SpeechInputExtensionManager::ResetToIdleState() { } void SpeechInputExtensionManager::OnRecognitionResult( - int caller_id, + int session_id, const content::SpeechRecognitionResult& result) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK_EQ(caller_id, kSpeechCallerId); + DCHECK_EQ(session_id, kSpeechInputSessionId); // Stopping will start the disassociation with the extension. // Make a copy to report the results to the proper one. @@ -284,26 +286,26 @@ void SpeechInputExtensionManager::SetRecognitionResultOnUIThread( DispatchEventToExtension(extension_id, kOnResultEvent, json_args); } -void SpeechInputExtensionManager::OnRecognitionStart(int caller_id) { - DCHECK_EQ(caller_id, kSpeechCallerId); +void SpeechInputExtensionManager::OnRecognitionStart(int session_id) { + DCHECK_EQ(session_id, kSpeechInputSessionId); } -void SpeechInputExtensionManager::OnAudioStart(int caller_id) { +void SpeechInputExtensionManager::OnAudioStart(int session_id) { VLOG(1) << "OnAudioStart"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK_EQ(caller_id, kSpeechCallerId); + DCHECK_EQ(session_id, kSpeechInputSessionId); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(&SpeechInputExtensionManager::DidStartReceivingAudioOnUIThread, this)); } -void SpeechInputExtensionManager::OnAudioEnd(int caller_id) { - DCHECK_EQ(caller_id, kSpeechCallerId); +void SpeechInputExtensionManager::OnAudioEnd(int session_id) { + DCHECK_EQ(session_id, kSpeechInputSessionId); } -void SpeechInputExtensionManager::OnRecognitionEnd(int caller_id) { - DCHECK_EQ(caller_id, kSpeechCallerId); +void SpeechInputExtensionManager::OnRecognitionEnd(int session_id) { + DCHECK_EQ(session_id, kSpeechInputSessionId); } void SpeechInputExtensionManager::DidStartReceivingAudioOnUIThread() { @@ -341,9 +343,9 @@ void SpeechInputExtensionManager::DidStartReceivingAudioOnUIThread() { } void SpeechInputExtensionManager::OnRecognitionError( - int caller_id, const content::SpeechRecognitionError& error) { + int session_id, const content::SpeechRecognitionError& error) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK_EQ(caller_id, kSpeechCallerId); + DCHECK_EQ(session_id, kSpeechInputSessionId); VLOG(1) << "OnRecognitionError: " << error.code; base::AutoLock auto_lock(state_lock_); @@ -401,13 +403,13 @@ void SpeechInputExtensionManager::OnRecognitionError( } void SpeechInputExtensionManager::OnEnvironmentEstimationComplete( - int caller_id) { - DCHECK_EQ(caller_id, kSpeechCallerId); + int session_id) { + DCHECK_EQ(session_id, kSpeechInputSessionId); } -void SpeechInputExtensionManager::OnSoundStart(int caller_id) { +void SpeechInputExtensionManager::OnSoundStart(int session_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK_EQ(caller_id, kSpeechCallerId); + DCHECK_EQ(session_id, kSpeechInputSessionId); VLOG(1) << "OnSoundStart"; std::string json_args; @@ -417,9 +419,9 @@ void SpeechInputExtensionManager::OnSoundStart(int caller_id) { json_args)); } -void SpeechInputExtensionManager::OnSoundEnd(int caller_id) { +void SpeechInputExtensionManager::OnSoundEnd(int session_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK_EQ(caller_id, kSpeechCallerId); + DCHECK_EQ(session_id, kSpeechInputSessionId); VLOG(1) << "OnSoundEnd"; std::string json_args; @@ -565,7 +567,7 @@ void SpeechInputExtensionManager::StartOnIOThread( } GetSpeechInputExtensionInterface()->StartRecording( - this, context_getter, kSpeechCallerId, language, grammar, + this, context_getter, kSpeechInputSessionId, language, grammar, filter_profanities); } @@ -609,14 +611,14 @@ void SpeechInputExtensionManager::IsRecordingOnUIThread( void SpeechInputExtensionManager::StartRecording( content::SpeechRecognitionEventListener* listener, net::URLRequestContextGetter* context_getter, - int caller_id, + int session_id, const std::string& language, const std::string& grammar, bool filter_profanities) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(!recognizer_); recognizer_ = content::SpeechRecognizer::Create( - listener, caller_id, language, grammar, context_getter, + listener, session_id, language, grammar, context_getter, filter_profanities, "", ""); recognizer_->StartRecognition(); } @@ -713,10 +715,10 @@ void SpeechInputExtensionManager::StopSucceededOnUIThread() { content::Details<std::string>(&extension_id)); } -void SpeechInputExtensionManager::OnAudioLevelsChange(int caller_id, - float volume, - float noise_volume) { - DCHECK_EQ(caller_id, kSpeechCallerId); +void SpeechInputExtensionManager::OnAudioLevelsChange(int session_id, + float volume, + float noise_volume) { + DCHECK_EQ(session_id, kSpeechInputSessionId); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(&SpeechInputExtensionManager::SetInputVolumeOnUIThread, diff --git a/chrome/browser/speech/speech_input_extension_manager.h b/chrome/browser/speech/speech_input_extension_manager.h index 52dfe7e..45db138 100644 --- a/chrome/browser/speech/speech_input_extension_manager.h +++ b/chrome/browser/speech/speech_input_extension_manager.h @@ -40,7 +40,7 @@ class SpeechInputExtensionInterface { virtual void StartRecording( content::SpeechRecognitionEventListener* listener, net::URLRequestContextGetter* context_getter, - int caller_id, + int session_id, const std::string& language, const std::string& grammar, bool filter_profanities) = 0; @@ -117,19 +117,19 @@ class SpeechInputExtensionManager const content::NotificationDetails& details) OVERRIDE; // Methods from SpeechRecognitionEventListener. - virtual void OnRecognitionStart(int caller_id) OVERRIDE; - virtual void OnAudioStart(int caller_id) OVERRIDE; - virtual void OnEnvironmentEstimationComplete(int caller_id) OVERRIDE; - virtual void OnSoundStart(int caller_id) OVERRIDE; - virtual void OnSoundEnd(int caller_id) OVERRIDE; - virtual void OnAudioEnd(int caller_id) OVERRIDE; + 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 OnRecognitionResult( - int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; + int session_id, const content::SpeechRecognitionResult& result) OVERRIDE; virtual void OnRecognitionError( - int caller_id, const content::SpeechRecognitionError& error) OVERRIDE; - virtual void OnAudioLevelsChange(int caller_id, float volume, + int session_id, const content::SpeechRecognitionError& error) OVERRIDE; + virtual void OnAudioLevelsChange(int session_id, float volume, float noise_volume) OVERRIDE; - virtual void OnRecognitionEnd(int caller_id) OVERRIDE; + virtual void OnRecognitionEnd(int session_id) OVERRIDE; // Methods for API testing. void SetSpeechInputExtensionInterface( @@ -144,7 +144,7 @@ class SpeechInputExtensionManager virtual void StartRecording( content::SpeechRecognitionEventListener* listener, net::URLRequestContextGetter* context_getter, - int caller_id, + int session_id, const std::string& language, const std::string& grammar, bool filter_profanities) OVERRIDE; diff --git a/chrome/browser/speech/speech_recognition_bubble_controller.cc b/chrome/browser/speech/speech_recognition_bubble_controller.cc index f2b3f0b..fc66279 100644 --- a/chrome/browser/speech/speech_recognition_bubble_controller.cc +++ b/chrome/browser/speech/speech_recognition_bubble_controller.cc @@ -21,7 +21,7 @@ namespace speech { SpeechRecognitionBubbleController::SpeechRecognitionBubbleController( Delegate* delegate) : delegate_(delegate), - current_bubble_caller_id_(0), + current_bubble_session_id_(0), registrar_(new content::NotificationRegistrar) { } @@ -30,7 +30,7 @@ SpeechRecognitionBubbleController::~SpeechRecognitionBubbleController() { } void SpeechRecognitionBubbleController::CreateBubble( - int caller_id, + int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect) { @@ -38,14 +38,15 @@ void SpeechRecognitionBubbleController::CreateBubble( BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&SpeechRecognitionBubbleController::CreateBubble, this, - caller_id, render_process_id, render_view_id, element_rect)); + session_id, render_process_id, render_view_id, + element_rect)); return; } DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, render_view_id); - DCHECK_EQ(0u, bubbles_.count(caller_id)); + DCHECK_EQ(0u, bubbles_.count(session_id)); SpeechRecognitionBubble* bubble = SpeechRecognitionBubble::Create( web_contents, this, element_rect); if (!bubble) { @@ -55,58 +56,58 @@ void SpeechRecognitionBubbleController::CreateBubble( BrowserThread::IO, FROM_HERE, base::Bind( &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked, - this, caller_id, SpeechRecognitionBubble::BUTTON_CANCEL)); + this, session_id, SpeechRecognitionBubble::BUTTON_CANCEL)); return; } - bubbles_[caller_id] = bubble; + bubbles_[session_id] = bubble; - UpdateTabContentsSubscription(caller_id, BUBBLE_ADDED); + UpdateTabContentsSubscription(session_id, BUBBLE_ADDED); } -void SpeechRecognitionBubbleController::CloseBubble(int caller_id) { - ProcessRequestInUiThread(caller_id, REQUEST_CLOSE, string16(), 0, 0); +void SpeechRecognitionBubbleController::CloseBubble(int session_id) { + ProcessRequestInUiThread(session_id, REQUEST_CLOSE, string16(), 0, 0); } -void SpeechRecognitionBubbleController::SetBubbleWarmUpMode(int caller_id) { - ProcessRequestInUiThread(caller_id, REQUEST_SET_WARM_UP_MODE, +void SpeechRecognitionBubbleController::SetBubbleWarmUpMode(int session_id) { + ProcessRequestInUiThread(session_id, REQUEST_SET_WARM_UP_MODE, string16(), 0, 0); } -void SpeechRecognitionBubbleController::SetBubbleRecordingMode(int caller_id) { - ProcessRequestInUiThread(caller_id, REQUEST_SET_RECORDING_MODE, +void SpeechRecognitionBubbleController::SetBubbleRecordingMode(int session_id) { + ProcessRequestInUiThread(session_id, REQUEST_SET_RECORDING_MODE, string16(), 0, 0); } void SpeechRecognitionBubbleController::SetBubbleRecognizingMode( - int caller_id) { - ProcessRequestInUiThread(caller_id, REQUEST_SET_RECOGNIZING_MODE, + int session_id) { + ProcessRequestInUiThread(session_id, REQUEST_SET_RECOGNIZING_MODE, string16(), 0, 0); } void SpeechRecognitionBubbleController::SetBubbleInputVolume( - int caller_id, float volume, float noise_volume) { - ProcessRequestInUiThread(caller_id, REQUEST_SET_INPUT_VOLUME, string16(), + int session_id, float volume, float noise_volume) { + ProcessRequestInUiThread(session_id, REQUEST_SET_INPUT_VOLUME, string16(), volume, noise_volume); } -void SpeechRecognitionBubbleController::SetBubbleMessage(int caller_id, +void SpeechRecognitionBubbleController::SetBubbleMessage(int session_id, const string16& text) { - ProcessRequestInUiThread(caller_id, REQUEST_SET_MESSAGE, text, 0, 0); + ProcessRequestInUiThread(session_id, REQUEST_SET_MESSAGE, text, 0, 0); } void SpeechRecognitionBubbleController::UpdateTabContentsSubscription( - int caller_id, ManageSubscriptionAction action) { + int session_id, ManageSubscriptionAction action) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // If there are any other bubbles existing for the same WebContents, we would // have subscribed to tab close notifications on their behalf and we need to // stay registered. So we don't change the subscription in such cases. - WebContents* web_contents = bubbles_[caller_id]->GetWebContents(); - for (BubbleCallerIdMap::iterator iter = bubbles_.begin(); + WebContents* web_contents = bubbles_[session_id]->GetWebContents(); + for (BubbleSessionIdMap::iterator iter = bubbles_.begin(); iter != bubbles_.end(); ++iter) { if (iter->second->GetWebContents() == web_contents && - iter->first != caller_id) { + iter->first != session_id) { // At least one other bubble exists for the same WebContents. So don't // make any change to the subscription. return; @@ -129,7 +130,7 @@ void SpeechRecognitionBubbleController::Observe( if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { // Cancel all bubbles and active recognition sessions for this tab. WebContents* web_contents = content::Source<WebContents>(source).ptr(); - BubbleCallerIdMap::iterator iter = bubbles_.begin(); + BubbleSessionIdMap::iterator iter = bubbles_.begin(); while (iter != bubbles_.end()) { if (iter->second->GetWebContents() == web_contents) { BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, @@ -150,29 +151,29 @@ void SpeechRecognitionBubbleController::Observe( } void SpeechRecognitionBubbleController::ProcessRequestInUiThread( - int caller_id, RequestType type, const string16& text, float volume, + int session_id, RequestType type, const string16& text, float volume, float noise_volume) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( &SpeechRecognitionBubbleController::ProcessRequestInUiThread, this, - caller_id, type, text, volume, noise_volume)); + session_id, type, text, volume, noise_volume)); return; } DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // The bubble may have been closed before we got a chance to process this // request. So check before proceeding. - if (!bubbles_.count(caller_id)) + if (!bubbles_.count(session_id)) return; bool change_active_bubble = (type == REQUEST_SET_WARM_UP_MODE || type == REQUEST_SET_MESSAGE); if (change_active_bubble) { - if (current_bubble_caller_id_ && current_bubble_caller_id_ != caller_id) - bubbles_[current_bubble_caller_id_]->Hide(); - current_bubble_caller_id_ = caller_id; + if (current_bubble_session_id_ && current_bubble_session_id_ != session_id) + bubbles_[current_bubble_session_id_]->Hide(); + current_bubble_session_id_ = session_id; } - SpeechRecognitionBubble* bubble = bubbles_[caller_id]; + SpeechRecognitionBubble* bubble = bubbles_[session_id]; switch (type) { case REQUEST_SET_WARM_UP_MODE: bubble->SetWarmUpMode(); @@ -190,11 +191,11 @@ void SpeechRecognitionBubbleController::ProcessRequestInUiThread( bubble->SetInputVolume(volume, noise_volume); break; case REQUEST_CLOSE: - if (current_bubble_caller_id_ == caller_id) - current_bubble_caller_id_ = 0; - UpdateTabContentsSubscription(caller_id, BUBBLE_REMOVED); + if (current_bubble_session_id_ == session_id) + current_bubble_session_id_ = 0; + UpdateTabContentsSubscription(session_id, BUBBLE_REMOVED); delete bubble; - bubbles_.erase(caller_id); + bubbles_.erase(session_id); break; default: NOTREACHED(); @@ -208,37 +209,37 @@ void SpeechRecognitionBubbleController::ProcessRequestInUiThread( void SpeechRecognitionBubbleController::InfoBubbleButtonClicked( SpeechRecognitionBubble::Button button) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(current_bubble_caller_id_); + DCHECK(current_bubble_session_id_); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind( &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked, - this, current_bubble_caller_id_, button)); + this, current_bubble_session_id_, button)); } void SpeechRecognitionBubbleController::InfoBubbleFocusChanged() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(current_bubble_caller_id_); + DCHECK(current_bubble_session_id_); - int old_bubble_caller_id = current_bubble_caller_id_; - current_bubble_caller_id_ = 0; + int old_bubble_session_id = current_bubble_session_id_; + current_bubble_session_id_ = 0; BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind( &SpeechRecognitionBubbleController::InvokeDelegateFocusChanged, - this, old_bubble_caller_id)); + this, old_bubble_session_id)); } void SpeechRecognitionBubbleController::InvokeDelegateButtonClicked( - int caller_id, SpeechRecognitionBubble::Button button) { - delegate_->InfoBubbleButtonClicked(caller_id, button); + int session_id, SpeechRecognitionBubble::Button button) { + delegate_->InfoBubbleButtonClicked(session_id, button); } void SpeechRecognitionBubbleController::InvokeDelegateFocusChanged( - int caller_id) { - delegate_->InfoBubbleFocusChanged(caller_id); + int session_id) { + delegate_->InfoBubbleFocusChanged(session_id); } } // namespace speech diff --git a/chrome/browser/speech/speech_recognition_bubble_controller.h b/chrome/browser/speech/speech_recognition_bubble_controller.h index 58ed656..744cb64 100644 --- a/chrome/browser/speech/speech_recognition_bubble_controller.h +++ b/chrome/browser/speech/speech_recognition_bubble_controller.h @@ -38,11 +38,11 @@ class SpeechRecognitionBubbleController public: // Invoked when the user clicks on a button in the speech recognition UI. virtual void InfoBubbleButtonClicked( - int caller_id, SpeechRecognitionBubble::Button button) = 0; + int session_id, SpeechRecognitionBubble::Button button) = 0; // Invoked when the user clicks outside the speech recognition info bubble // causing it to close and input focus to change. - virtual void InfoBubbleFocusChanged(int caller_id) = 0; + virtual void InfoBubbleFocusChanged(int session_id) = 0; protected: virtual ~Delegate() {} @@ -53,31 +53,31 @@ class SpeechRecognitionBubbleController // Creates a new speech recognition UI bubble. One of the SetXxxx methods // below need to be called to specify what to display. - void CreateBubble(int caller_id, + void CreateBubble(int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect); // Indicates to the user that audio hardware is warming up. This also makes // the bubble visible if not already visible. - void SetBubbleWarmUpMode(int caller_id); + void SetBubbleWarmUpMode(int session_id); // Indicates to the user that audio recording is in progress. This also makes // the bubble visible if not already visible. - void SetBubbleRecordingMode(int caller_id); + void SetBubbleRecordingMode(int session_id); // Indicates to the user that recognition is in progress. If the bubble is // hidden, |Show| must be called to make it appear on screen. - void SetBubbleRecognizingMode(int caller_id); + void SetBubbleRecognizingMode(int session_id); // Displays the given string with the 'Try again' and 'Cancel' buttons. If the // bubble is hidden, |Show| must be called to make it appear on screen. - void SetBubbleMessage(int caller_id, const string16& text); + void SetBubbleMessage(int session_id, const string16& text); // Updates the current captured audio volume displayed on screen. - void SetBubbleInputVolume(int caller_id, float volume, float noise_volume); + void SetBubbleInputVolume(int session_id, float volume, float noise_volume); - void CloseBubble(int caller_id); + void CloseBubble(int session_id); // SpeechRecognitionBubble::Delegate methods. virtual void InfoBubbleButtonClicked( @@ -105,10 +105,10 @@ class SpeechRecognitionBubbleController BUBBLE_REMOVED }; - void InvokeDelegateButtonClicked(int caller_id, + void InvokeDelegateButtonClicked(int session_id, SpeechRecognitionBubble::Button button); - void InvokeDelegateFocusChanged(int caller_id); - void ProcessRequestInUiThread(int caller_id, + void InvokeDelegateFocusChanged(int session_id); + void ProcessRequestInUiThread(int session_id, RequestType type, const string16& text, float volume, @@ -119,7 +119,7 @@ class SpeechRecognitionBubbleController // the WebContents if this was the first bubble for the tab. Similarly if the // bubble was being removed, this method unregisters from WebContents if this // was the last bubble associated with that tab. - void UpdateTabContentsSubscription(int caller_id, + void UpdateTabContentsSubscription(int session_id, ManageSubscriptionAction action); // Only accessed in the IO thread. @@ -127,14 +127,14 @@ class SpeechRecognitionBubbleController // *** The following are accessed only in the UI thread. - // The caller id for currently visible bubble (since only one bubble is + // The session id for currently visible bubble (since only one bubble is // visible at any time). - int current_bubble_caller_id_; + int current_bubble_session_id_; - // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by - // this object and get destroyed by |CloseBubble|. - typedef std::map<int, SpeechRecognitionBubble*> BubbleCallerIdMap; - BubbleCallerIdMap bubbles_; + // Map of session-ids to bubble objects. The bubbles are weak pointers owned + // by this object and get destroyed by |CloseBubble|. + typedef std::map<int, SpeechRecognitionBubble*> BubbleSessionIdMap; + BubbleSessionIdMap bubbles_; scoped_ptr<content::NotificationRegistrar> registrar_; }; diff --git a/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc b/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc index bf1ad88..d4aa4ef 100644 --- a/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc +++ b/chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc @@ -95,7 +95,7 @@ class SpeechRecognitionBubbleControllerTest } // SpeechRecognitionBubbleControllerDelegate methods. - virtual void InfoBubbleButtonClicked(int caller_id, + virtual void InfoBubbleButtonClicked(int session_id, SpeechRecognitionBubble::Button button) { VLOG(1) << "Received InfoBubbleButtonClicked for button " << button; EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -107,7 +107,7 @@ class SpeechRecognitionBubbleControllerTest message_loop()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); } - virtual void InfoBubbleFocusChanged(int caller_id) { + virtual void InfoBubbleFocusChanged(int session_id) { VLOG(1) << "Received InfoBubbleFocusChanged"; EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); focus_changed_ = true; @@ -131,9 +131,9 @@ class SpeechRecognitionBubbleControllerTest static void ActivateBubble() { if (MockSpeechRecognitionBubble::type() == MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED) { - test_fixture_->controller_->SetBubbleWarmUpMode(kBubbleCallerId); + test_fixture_->controller_->SetBubbleWarmUpMode(kBubbleSessionId); } else { - test_fixture_->controller_->SetBubbleMessage(kBubbleCallerId, + test_fixture_->controller_->SetBubbleMessage(kBubbleSessionId, ASCIIToUTF16("Test")); } } @@ -149,7 +149,7 @@ class SpeechRecognitionBubbleControllerTest MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&ActivateBubble)); - // The |tab_contents| parameter would be NULL since the dummy caller id + // The |tab_contents| parameter would be NULL since the dummy session id // passed to CreateBubble would not have matched any active tab. So get a // real WebContents pointer from the test fixture and pass that, because // the bubble controller registers for tab close notifications which need @@ -171,14 +171,14 @@ class SpeechRecognitionBubbleControllerTest bool focus_changed_; scoped_refptr<SpeechRecognitionBubbleController> controller_; - static const int kBubbleCallerId; + static const int kBubbleSessionId; static SpeechRecognitionBubbleControllerTest* test_fixture_; }; SpeechRecognitionBubbleControllerTest* SpeechRecognitionBubbleControllerTest::test_fixture_ = NULL; -const int SpeechRecognitionBubbleControllerTest::kBubbleCallerId = 1; +const int SpeechRecognitionBubbleControllerTest::kBubbleSessionId = 1; MockSpeechRecognitionBubble::BubbleType MockSpeechRecognitionBubble::type_ = MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED; @@ -189,12 +189,12 @@ TEST_F(SpeechRecognitionBubbleControllerTest, TestFocusChanged) { MockSpeechRecognitionBubble::set_type( MockSpeechRecognitionBubble::BUBBLE_TEST_FOCUS_CHANGED); - controller_->CreateBubble(kBubbleCallerId, 1, 1, gfx::Rect(1, 1)); + controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); MessageLoop::current()->Run(); EXPECT_TRUE(focus_changed_); EXPECT_FALSE(cancel_clicked_); EXPECT_FALSE(try_again_clicked_); - controller_->CloseBubble(kBubbleCallerId); + controller_->CloseBubble(kBubbleSessionId); } // Test that the speech bubble UI gets created in the UI thread and that the @@ -203,12 +203,12 @@ TEST_F(SpeechRecognitionBubbleControllerTest, TestRecognitionCancelled) { MockSpeechRecognitionBubble::set_type( MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_CANCEL); - controller_->CreateBubble(kBubbleCallerId, 1, 1, gfx::Rect(1, 1)); + controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); MessageLoop::current()->Run(); EXPECT_TRUE(cancel_clicked_); EXPECT_FALSE(try_again_clicked_); EXPECT_FALSE(focus_changed_); - controller_->CloseBubble(kBubbleCallerId); + controller_->CloseBubble(kBubbleSessionId); } // Test that the speech bubble UI gets created in the UI thread and that the @@ -217,12 +217,12 @@ TEST_F(SpeechRecognitionBubbleControllerTest, TestTryAgainClicked) { MockSpeechRecognitionBubble::set_type( MockSpeechRecognitionBubble::BUBBLE_TEST_CLICK_TRY_AGAIN); - controller_->CreateBubble(kBubbleCallerId, 1, 1, gfx::Rect(1, 1)); + controller_->CreateBubble(kBubbleSessionId, 1, 1, gfx::Rect(1, 1)); MessageLoop::current()->Run(); EXPECT_FALSE(cancel_clicked_); EXPECT_TRUE(try_again_clicked_); EXPECT_FALSE(focus_changed_); - controller_->CloseBubble(kBubbleCallerId); + controller_->CloseBubble(kBubbleSessionId); } } // namespace speech diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 5cef5da..2f26a73 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -500,8 +500,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { #if defined(ENABLE_INPUT_SPEECH) channel_->AddFilter(new speech::InputTagSpeechDispatcherHost( GetID(), browser_context->GetRequestContext(), - browser_context->GetSpeechRecognitionPreferences(), - content::BrowserMainLoop::GetAudioManager())); + 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 6ec3be0..29eebb64 100644 --- a/content/browser/speech/input_tag_speech_dispatcher_host.cc +++ b/content/browser/speech/input_tag_speech_dispatcher_host.cc @@ -14,12 +14,16 @@ using content::BrowserThread; namespace speech { -//----------------------------- Callers ----------------------------- +//----------------------------- Sessions ----------------------------- + +// TODO(primiano) Remove session handling from here in the next CL. The manager +// shall be the only one in charge of keeping all the context information for +// all recognition sessions. // 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 InputTagSpeechDispatcherHost::Callers { +class InputTagSpeechDispatcherHost::Sessions { public: // Creates a new ID for a given tuple. int CreateId(int render_process_id, int render_view_id, int request_id); @@ -36,32 +40,32 @@ class InputTagSpeechDispatcherHost::Callers { int request_id(int id); private: - struct CallerInfo { + struct SessionInfo { int render_process_id; int render_view_id; int request_id; }; - friend struct base::DefaultLazyInstanceTraits<Callers>; + friend struct base::DefaultLazyInstanceTraits<Sessions>; - Callers(); + Sessions(); - std::map<int, CallerInfo> callers_; + std::map<int, SessionInfo> sessions_; int next_id_; }; -static base::LazyInstance<InputTagSpeechDispatcherHost::Callers> - g_callers = LAZY_INSTANCE_INITIALIZER; +static base::LazyInstance<InputTagSpeechDispatcherHost::Sessions> + g_sessions = LAZY_INSTANCE_INITIALIZER; -InputTagSpeechDispatcherHost::Callers::Callers() +InputTagSpeechDispatcherHost::Sessions::Sessions() : next_id_(1) { } -int InputTagSpeechDispatcherHost::Callers::GetId(int render_process_id, +int InputTagSpeechDispatcherHost::Sessions::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; + for (std::map<int, SessionInfo>::iterator it = sessions_.begin(); + it != sessions_.end(); it++) { + const SessionInfo& item = it->second; if (item.render_process_id == render_process_id && item.render_view_id == render_view_id && item.request_id == request_id) { @@ -76,33 +80,33 @@ int InputTagSpeechDispatcherHost::Callers::GetId(int render_process_id, return 0; } -int InputTagSpeechDispatcherHost::Callers::CreateId(int render_process_id, +int InputTagSpeechDispatcherHost::Sessions::CreateId(int render_process_id, int render_view_id, int request_id) { - CallerInfo info; + SessionInfo info; info.render_process_id = render_process_id; info.render_view_id = render_view_id; info.request_id = request_id; - callers_[next_id_] = info; + sessions_[next_id_] = info; return next_id_++; } -void InputTagSpeechDispatcherHost::Callers::RemoveId(int id) { - callers_.erase(id); +void InputTagSpeechDispatcherHost::Sessions::RemoveId(int id) { + sessions_.erase(id); } -int InputTagSpeechDispatcherHost::Callers::render_process_id( +int InputTagSpeechDispatcherHost::Sessions::render_process_id( int id) { - return callers_[id].render_process_id; + return sessions_[id].render_process_id; } -int InputTagSpeechDispatcherHost::Callers::render_view_id( +int InputTagSpeechDispatcherHost::Sessions::render_view_id( int id) { - return callers_[id].render_view_id; + return sessions_[id].render_view_id; } -int InputTagSpeechDispatcherHost::Callers::request_id(int id) { - return callers_[id].request_id; +int InputTagSpeechDispatcherHost::Sessions::request_id(int id) { + return sessions_[id].request_id; } //----------------------- InputTagSpeechDispatcherHost ---------------------- @@ -117,13 +121,11 @@ void InputTagSpeechDispatcherHost::set_manager( InputTagSpeechDispatcherHost::InputTagSpeechDispatcherHost( int render_process_id, net::URLRequestContextGetter* context_getter, - content::SpeechRecognitionPreferences* recognition_preferences, - media::AudioManager* audio_manager) + content::SpeechRecognitionPreferences* recognition_preferences) : render_process_id_(render_process_id), may_have_pending_requests_(false), context_getter_(context_getter), - recognition_preferences_(recognition_preferences), - audio_manager_(audio_manager) { + 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. @@ -171,9 +173,9 @@ bool InputTagSpeechDispatcherHost::OnMessageReceived( void InputTagSpeechDispatcherHost::OnStartRecognition( const InputTagSpeechHostMsg_StartRecognition_Params ¶ms) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int caller_id = g_callers.Get().CreateId( + int session_id = g_sessions.Get().CreateId( render_process_id_, params.render_view_id, params.request_id); - manager()->StartRecognition(this, caller_id, + manager()->StartRecognition(this, session_id, render_process_id_, params.render_view_id, params.element_rect, params.language, params.grammar, @@ -184,55 +186,55 @@ void InputTagSpeechDispatcherHost::OnStartRecognition( void InputTagSpeechDispatcherHost::OnCancelRecognition(int render_view_id, int request_id) { - int caller_id = g_callers.Get().GetId( + int session_id = g_sessions.Get().GetId( render_process_id_, render_view_id, request_id); - if (caller_id) { - manager()->CancelRecognition(caller_id); + if (session_id) { + manager()->CancelRecognition(session_id); // Request sequence ended so remove mapping. - g_callers.Get().RemoveId(caller_id); + g_sessions.Get().RemoveId(session_id); } } void InputTagSpeechDispatcherHost::OnStopRecording(int render_view_id, int request_id) { - int caller_id = g_callers.Get().GetId( + int session_id = g_sessions.Get().GetId( render_process_id_, render_view_id, request_id); - if (caller_id) - manager()->StopRecording(caller_id); + if (session_id) + manager()->StopRecording(session_id); } void InputTagSpeechDispatcherHost::SetRecognitionResult( - int caller_id, const content::SpeechRecognitionResult& result) { + int session_id, const content::SpeechRecognitionResult& result) { VLOG(1) << "InputTagSpeechDispatcherHost::SetRecognitionResult enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - 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, + int session_render_view_id = g_sessions.Get().render_view_id(session_id); + int session_request_id = g_sessions.Get().request_id(session_id); + Send(new InputTagSpeechMsg_SetRecognitionResult(session_render_view_id, + session_request_id, result)); VLOG(1) << "InputTagSpeechDispatcherHost::SetRecognitionResult exit"; } -void InputTagSpeechDispatcherHost::DidCompleteRecording(int caller_id) { +void InputTagSpeechDispatcherHost::DidCompleteRecording(int session_id) { VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecording enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - 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)); + int session_render_view_id = g_sessions.Get().render_view_id(session_id); + int session_request_id = g_sessions.Get().request_id(session_id); + Send(new InputTagSpeechMsg_RecordingComplete(session_render_view_id, + session_request_id)); VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecording exit"; } -void InputTagSpeechDispatcherHost::DidCompleteRecognition(int caller_id) { +void InputTagSpeechDispatcherHost::DidCompleteRecognition(int session_id) { VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecognition enter"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - 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_RecognitionComplete(caller_render_view_id, - caller_request_id)); + int session_render_view_id = + g_sessions.Get().render_view_id(session_id); + int session_request_id = g_sessions.Get().request_id(session_id); + Send(new InputTagSpeechMsg_RecognitionComplete(session_render_view_id, + session_request_id)); // Request sequence ended, so remove mapping. - g_callers.Get().RemoveId(caller_id); + g_sessions.Get().RemoveId(session_id); VLOG(1) << "InputTagSpeechDispatcherHost::DidCompleteRecognition exit"; } diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.h b/content/browser/speech/input_tag_speech_dispatcher_host.h index c988faf..95bd252 100644 --- a/content/browser/speech/input_tag_speech_dispatcher_host.h +++ b/content/browser/speech/input_tag_speech_dispatcher_host.h @@ -31,19 +31,18 @@ class SpeechRecognitionManagerImpl; class CONTENT_EXPORT InputTagSpeechDispatcherHost : public content::BrowserMessageFilter { public: - class Callers; + class Sessions; InputTagSpeechDispatcherHost( int render_process_id, net::URLRequestContextGetter* context_getter, - content::SpeechRecognitionPreferences* recognition_preferences, - media::AudioManager* audio_manager); + content::SpeechRecognitionPreferences* recognition_preferences); // Methods called by SpeechRecognitionManagerImpl. - void SetRecognitionResult(int caller_id, + void SetRecognitionResult(int session_id, const content::SpeechRecognitionResult& result); - void DidCompleteRecording(int caller_id); - void DidCompleteRecognition(int caller_id); + void DidCompleteRecording(int session_id); + void DidCompleteRecognition(int session_id); // content::BrowserMessageFilter implementation. virtual bool OnMessageReceived(const IPC::Message& message, @@ -69,7 +68,6 @@ class CONTENT_EXPORT InputTagSpeechDispatcherHost scoped_refptr<net::URLRequestContextGetter> context_getter_; scoped_refptr<content::SpeechRecognitionPreferences> recognition_preferences_; - media::AudioManager* audio_manager_; static SpeechRecognitionManagerImpl* manager_; diff --git a/content/browser/speech/speech_recognition_browsertest.cc b/content/browser/speech/speech_recognition_browsertest.cc index 70dcc6f..ea8f95e 100644 --- a/content/browser/speech/speech_recognition_browsertest.cc +++ b/content/browser/speech/speech_recognition_browsertest.cc @@ -35,7 +35,7 @@ const char kTestResult[] = "Pictures of the moon"; class FakeSpeechRecognitionManager : public SpeechRecognitionManagerImpl { public: FakeSpeechRecognitionManager() - : caller_id_(0), + : session_id_(0), delegate_(NULL), did_cancel_all_(false), should_send_fake_response_(true), @@ -65,7 +65,7 @@ class FakeSpeechRecognitionManager : public SpeechRecognitionManagerImpl { // SpeechRecognitionManager methods. virtual void StartRecognition( InputTagSpeechDispatcherHost* delegate, - int caller_id, + int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect, @@ -75,9 +75,9 @@ class FakeSpeechRecognitionManager : public SpeechRecognitionManagerImpl { net::URLRequestContextGetter* context_getter, content::SpeechRecognitionPreferences* recognition_prefs) OVERRIDE { VLOG(1) << "StartRecognition invoked."; - EXPECT_EQ(0, caller_id_); + EXPECT_EQ(0, session_id_); EXPECT_EQ(NULL, delegate_); - caller_id_ = caller_id; + session_id_ = session_id; delegate_ = delegate; grammar_ = grammar; if (should_send_fake_response_) { @@ -93,15 +93,15 @@ class FakeSpeechRecognitionManager : public SpeechRecognitionManagerImpl { } recognition_started_event_.Signal(); } - virtual void CancelRecognition(int caller_id) OVERRIDE { + virtual void CancelRecognition(int session_id) OVERRIDE { VLOG(1) << "CancelRecognition invoked."; - EXPECT_EQ(caller_id_, caller_id); - caller_id_ = 0; + EXPECT_EQ(session_id_, session_id); + session_id_ = 0; delegate_ = NULL; } - virtual void StopRecording(int caller_id) OVERRIDE { + virtual void StopRecording(int session_id) OVERRIDE { VLOG(1) << "StopRecording invoked."; - EXPECT_EQ(caller_id_, caller_id); + EXPECT_EQ(session_id_, session_id); // Nothing to do here since we aren't really recording. } virtual void CancelAllRequestsWithDelegate( @@ -116,21 +116,21 @@ class FakeSpeechRecognitionManager : public SpeechRecognitionManagerImpl { private: void SetFakeRecognitionResult() { - if (caller_id_) { // Do a check in case we were cancelled.. + if (session_id_) { // Do a check in case we were cancelled.. VLOG(1) << "Setting fake recognition result."; - delegate_->DidCompleteRecording(caller_id_); + delegate_->DidCompleteRecording(session_id_); content::SpeechRecognitionResult results; results.hypotheses.push_back(content::SpeechRecognitionHypothesis( ASCIIToUTF16(kTestResult), 1.0)); - delegate_->SetRecognitionResult(caller_id_, results); - delegate_->DidCompleteRecognition(caller_id_); - caller_id_ = 0; + delegate_->SetRecognitionResult(session_id_, results); + delegate_->DidCompleteRecognition(session_id_); + session_id_ = 0; delegate_ = NULL; VLOG(1) << "Finished setting fake recognition result."; } } - int caller_id_; + int session_id_; InputTagSpeechDispatcherHost* delegate_; std::string grammar_; bool did_cancel_all_; diff --git a/content/browser/speech/speech_recognition_manager_impl.cc b/content/browser/speech/speech_recognition_manager_impl.cc index ddd373a..ed567e1 100644 --- a/content/browser/speech/speech_recognition_manager_impl.cc +++ b/content/browser/speech/speech_recognition_manager_impl.cc @@ -33,7 +33,7 @@ namespace speech { struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { SpeechRecognitionParams( InputTagSpeechDispatcherHost* delegate, - int caller_id, + int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect, @@ -43,7 +43,7 @@ struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { net::URLRequestContextGetter* context_getter, content::SpeechRecognitionPreferences* recognition_prefs) : delegate(delegate), - caller_id(caller_id), + session_id(session_id), render_process_id(render_process_id), render_view_id(render_view_id), element_rect(element_rect), @@ -55,7 +55,7 @@ struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { } InputTagSpeechDispatcherHost* delegate; - int caller_id; + int session_id; int render_process_id; int render_view_id; gfx::Rect element_rect; @@ -72,7 +72,7 @@ SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() : can_report_metrics_(false), - recording_caller_id_(0) { + recording_session_id_(0) { delegate_.reset(content::GetContentClient()->browser()-> GetSpeechRecognitionManagerDelegate()); } @@ -94,13 +94,13 @@ string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); } -bool SpeechRecognitionManagerImpl::HasPendingRequest(int caller_id) const { - return requests_.find(caller_id) != requests_.end(); +bool SpeechRecognitionManagerImpl::HasPendingRequest(int session_id) const { + return requests_.find(session_id) != requests_.end(); } InputTagSpeechDispatcherHost* SpeechRecognitionManagerImpl::GetDelegate( - int caller_id) const { - return requests_.find(caller_id)->second.delegate; + int session_id) const { + return requests_.find(session_id)->second.delegate; } void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { @@ -122,7 +122,7 @@ void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { void SpeechRecognitionManagerImpl::StartRecognition( InputTagSpeechDispatcherHost* delegate, - int caller_id, + int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect, @@ -138,7 +138,7 @@ void SpeechRecognitionManagerImpl::StartRecognition( &SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition, base::Unretained(this), SpeechRecognitionParams( - delegate, caller_id, render_process_id, render_view_id, + delegate, session_id, render_process_id, render_view_id, element_rect, language, grammar, origin_url, context_getter, recognition_prefs))); } @@ -170,78 +170,78 @@ void SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition( void SpeechRecognitionManagerImpl::ProceedStartingRecognition( const SpeechRecognitionParams& params) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(!HasPendingRequest(params.caller_id)); + DCHECK(!HasPendingRequest(params.session_id)); if (delegate_.get()) { delegate_->ShowRecognitionRequested( - params.caller_id, params.render_process_id, params.render_view_id, + params.session_id, params.render_process_id, params.render_view_id, params.element_rect); delegate_->GetRequestInfo(&can_report_metrics_, &request_info_); } - Request* request = &requests_[params.caller_id]; + Request* request = &requests_[params.session_id]; request->delegate = params.delegate; request->recognizer = content::SpeechRecognizer::Create( - this, params.caller_id, params.language, params.grammar, + this, params.session_id, params.language, params.grammar, params.context_getter, params.recognition_prefs->FilterProfanities(), request_info_, can_report_metrics_ ? params.origin_url : ""); request->is_active = false; - StartRecognitionForRequest(params.caller_id); + StartRecognitionForRequest(params.session_id); } -void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int caller_id) { - SpeechRecognizerMap::iterator request = requests_.find(caller_id); +void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int session_id) { + SpeechRecognizerMap::iterator request = requests_.find(session_id); if (request == requests_.end()) { NOTREACHED(); return; } - // We should not currently be recording for the caller. - CHECK(recording_caller_id_ != caller_id); + // We should not currently be recording for the session. + CHECK(recording_session_id_ != session_id); - // If we are currently recording audio for another caller, abort that cleanly. - if (recording_caller_id_) - CancelRecognitionAndInformDelegate(recording_caller_id_); - recording_caller_id_ = caller_id; - requests_[caller_id].is_active = true; - requests_[caller_id].recognizer->StartRecognition(); + // If we are currently recording audio for another session, abort it cleanly. + if (recording_session_id_) + CancelRecognitionAndInformDelegate(recording_session_id_); + recording_session_id_ = session_id; + requests_[session_id].is_active = true; + requests_[session_id].recognizer->StartRecognition(); if (delegate_.get()) - delegate_->ShowWarmUp(caller_id); + delegate_->ShowWarmUp(session_id); } -void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) { - // Ignore if the caller id was not in our active recognizers list because the +void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int session_id) { + // Ignore if the session 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. - if (!HasPendingRequest(caller_id)) + if (!HasPendingRequest(session_id)) return; - CancelRecognitionAndInformDelegate(caller_id); + CancelRecognitionAndInformDelegate(session_id); } -void SpeechRecognitionManagerImpl::FocusLostForRequest(int caller_id) { +void SpeechRecognitionManagerImpl::FocusLostForRequest(int session_id) { // See above comment. - if (!HasPendingRequest(caller_id)) + if (!HasPendingRequest(session_id)) return; // If this is an ongoing recording or if we were displaying an error message // to the user, abort it since user has switched focus. Otherwise // recognition has started and keep that going so user can start speaking to // another element while this gets the results in parallel. - if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) - CancelRecognitionAndInformDelegate(caller_id); + if (recording_session_id_ == session_id || !requests_[session_id].is_active) + CancelRecognitionAndInformDelegate(session_id); } -void SpeechRecognitionManagerImpl::CancelRecognition(int caller_id) { - DCHECK(HasPendingRequest(caller_id)); - if (requests_[caller_id].is_active) - requests_[caller_id].recognizer->AbortRecognition(); - requests_.erase(caller_id); - if (recording_caller_id_ == caller_id) - recording_caller_id_ = 0; +void SpeechRecognitionManagerImpl::CancelRecognition(int session_id) { + DCHECK(HasPendingRequest(session_id)); + if (requests_[session_id].is_active) + requests_[session_id].recognizer->AbortRecognition(); + requests_.erase(session_id); + if (recording_session_id_ == session_id) + recording_session_id_ = 0; if (delegate_.get()) - delegate_->DoClose(caller_id); + delegate_->DoClose(session_id); } void SpeechRecognitionManagerImpl::CancelAllRequestsWithDelegate( @@ -258,101 +258,101 @@ void SpeechRecognitionManagerImpl::CancelAllRequestsWithDelegate( } } -void SpeechRecognitionManagerImpl::StopRecording(int caller_id) { +void SpeechRecognitionManagerImpl::StopRecording(int session_id) { // No pending requests on extension popups. - if (!HasPendingRequest(caller_id)) + if (!HasPendingRequest(session_id)) return; - requests_[caller_id].recognizer->StopAudioCapture(); + requests_[session_id].recognizer->StopAudioCapture(); } // -------- SpeechRecognitionEventListener interface implementation. --------- void SpeechRecognitionManagerImpl::OnRecognitionResult( - int caller_id, const content::SpeechRecognitionResult& result) { - DCHECK(HasPendingRequest(caller_id)); - GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); + int session_id, const content::SpeechRecognitionResult& result) { + DCHECK(HasPendingRequest(session_id)); + GetDelegate(session_id)->SetRecognitionResult(session_id, result); } -void SpeechRecognitionManagerImpl::OnAudioEnd(int caller_id) { - if (recording_caller_id_ != caller_id) +void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) { + if (recording_session_id_ != session_id) return; - DCHECK_EQ(recording_caller_id_, caller_id); - DCHECK(HasPendingRequest(caller_id)); - if (!requests_[caller_id].is_active) + DCHECK_EQ(recording_session_id_, session_id); + DCHECK(HasPendingRequest(session_id)); + if (!requests_[session_id].is_active) return; - recording_caller_id_ = 0; - GetDelegate(caller_id)->DidCompleteRecording(caller_id); + recording_session_id_ = 0; + GetDelegate(session_id)->DidCompleteRecording(session_id); if (delegate_.get()) - delegate_->ShowRecognizing(caller_id); + delegate_->ShowRecognizing(session_id); } -void SpeechRecognitionManagerImpl::OnRecognitionEnd(int caller_id) { - if (!HasPendingRequest(caller_id) || !requests_[caller_id].is_active) +void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) { + if (!HasPendingRequest(session_id) || !requests_[session_id].is_active) return; - GetDelegate(caller_id)->DidCompleteRecognition(caller_id); - requests_.erase(caller_id); + GetDelegate(session_id)->DidCompleteRecognition(session_id); + requests_.erase(session_id); if (delegate_.get()) - delegate_->DoClose(caller_id); + delegate_->DoClose(session_id); } -void SpeechRecognitionManagerImpl::OnSoundStart(int caller_id) { +void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) { } -void SpeechRecognitionManagerImpl::OnSoundEnd(int caller_id) { +void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) { } void SpeechRecognitionManagerImpl::OnRecognitionError( - int caller_id, const content::SpeechRecognitionError& error) { - DCHECK(HasPendingRequest(caller_id)); - if (caller_id == recording_caller_id_) - recording_caller_id_ = 0; - requests_[caller_id].is_active = false; + int session_id, const content::SpeechRecognitionError& error) { + DCHECK(HasPendingRequest(session_id)); + if (session_id == recording_session_id_) + recording_session_id_ = 0; + requests_[session_id].is_active = false; if (delegate_.get()) { if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && error.details == content::SPEECH_AUDIO_ERROR_DETAILS_NO_MIC) { - delegate_->ShowMicError(caller_id, + delegate_->ShowMicError(session_id, SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); } else if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && error.details == content::SPEECH_AUDIO_ERROR_DETAILS_IN_USE) { - delegate_->ShowMicError( - caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); + delegate_->ShowMicError(session_id, + SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); } else { - delegate_->ShowRecognizerError(caller_id, error.code); + delegate_->ShowRecognizerError(session_id, error.code); } } } -void SpeechRecognitionManagerImpl::OnAudioStart(int caller_id) { - DCHECK(HasPendingRequest(caller_id)); - DCHECK_EQ(recording_caller_id_, caller_id); +void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) { + DCHECK(HasPendingRequest(session_id)); + DCHECK_EQ(recording_session_id_, session_id); if (delegate_.get()) - delegate_->ShowRecording(caller_id); + delegate_->ShowRecording(session_id); } -void SpeechRecognitionManagerImpl::OnRecognitionStart(int caller_id) { +void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { } void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete( - int caller_id) { - DCHECK(HasPendingRequest(caller_id)); - DCHECK_EQ(recording_caller_id_, caller_id); + int session_id) { + DCHECK(HasPendingRequest(session_id)); + DCHECK_EQ(recording_session_id_, session_id); } void SpeechRecognitionManagerImpl::OnAudioLevelsChange( - int caller_id, float volume, float noise_volume) { - DCHECK(HasPendingRequest(caller_id)); - DCHECK_EQ(recording_caller_id_, caller_id); + int session_id, float volume, float noise_volume) { + DCHECK(HasPendingRequest(session_id)); + DCHECK_EQ(recording_session_id_, session_id); if (delegate_.get()) - delegate_->ShowInputVolume(caller_id, volume, noise_volume); + delegate_->ShowInputVolume(session_id, volume, noise_volume); } void SpeechRecognitionManagerImpl::CancelRecognitionAndInformDelegate( - int caller_id) { - InputTagSpeechDispatcherHost* cur_delegate = GetDelegate(caller_id); - CancelRecognition(caller_id); - cur_delegate->DidCompleteRecording(caller_id); - cur_delegate->DidCompleteRecognition(caller_id); + int session_id) { + InputTagSpeechDispatcherHost* cur_delegate = GetDelegate(session_id); + CancelRecognition(session_id); + cur_delegate->DidCompleteRecording(session_id); + cur_delegate->DidCompleteRecognition(session_id); } SpeechRecognitionManagerImpl::Request::Request() diff --git a/content/browser/speech/speech_recognition_manager_impl.h b/content/browser/speech/speech_recognition_manager_impl.h index bb38cec..9a0c967 100644 --- a/content/browser/speech/speech_recognition_manager_impl.h +++ b/content/browser/speech/speech_recognition_manager_impl.h @@ -40,9 +40,9 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl static SpeechRecognitionManagerImpl* GetInstance(); // SpeechRecognitionManager implementation: - virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; - virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; - virtual void FocusLostForRequest(int caller_id) OVERRIDE; + virtual void StartRecognitionForRequest(int session_id) OVERRIDE; + virtual void CancelRecognitionForRequest(int session_id) OVERRIDE; + virtual void FocusLostForRequest(int session_id) OVERRIDE; virtual bool HasAudioInputDevices() OVERRIDE; virtual bool IsCapturingAudio() OVERRIDE; virtual string16 GetAudioInputDeviceModel() OVERRIDE; @@ -58,7 +58,7 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl // input (in page coordinates). virtual void StartRecognition( InputTagSpeechDispatcherHost* delegate, - int caller_id, + int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect, @@ -67,25 +67,25 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl const std::string& origin_url, net::URLRequestContextGetter* context_getter, content::SpeechRecognitionPreferences* speech_recognition_prefs); - virtual void CancelRecognition(int caller_id); + virtual void CancelRecognition(int session_id); virtual void CancelAllRequestsWithDelegate( InputTagSpeechDispatcherHost* delegate); - virtual void StopRecording(int caller_id); + virtual void StopRecording(int session_id); // SpeechRecognitionEventListener methods. - virtual void OnRecognitionStart(int caller_id) OVERRIDE; - virtual void OnAudioStart(int caller_id) OVERRIDE; - virtual void OnEnvironmentEstimationComplete(int caller_id) OVERRIDE; - virtual void OnSoundStart(int caller_id) OVERRIDE; - virtual void OnSoundEnd(int caller_id) OVERRIDE; - virtual void OnAudioEnd(int caller_id) OVERRIDE; - virtual void OnRecognitionEnd(int caller_id) OVERRIDE; + 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 caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; + int session_id, const content::SpeechRecognitionResult& result) OVERRIDE; virtual void OnRecognitionError( - int caller_id, const content::SpeechRecognitionError& error) OVERRIDE; + int session_id, const content::SpeechRecognitionError& error) OVERRIDE; virtual void OnAudioLevelsChange( - int caller_id, float volume, float noise_volume) OVERRIDE; + int session_id, float volume, float noise_volume) OVERRIDE; protected: // Private constructor to enforce singleton. @@ -93,7 +93,7 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl SpeechRecognitionManagerImpl(); virtual ~SpeechRecognitionManagerImpl(); - bool HasPendingRequest(int caller_id) const; + bool HasPendingRequest(int session_id) const; private: struct Request { @@ -107,19 +107,19 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl struct SpeechRecognitionParams; - InputTagSpeechDispatcherHost* GetDelegate(int caller_id) const; + InputTagSpeechDispatcherHost* GetDelegate(int session_id) const; void CheckRenderViewTypeAndStartRecognition( const SpeechRecognitionParams& params); void ProceedStartingRecognition(const SpeechRecognitionParams& params); - void CancelRecognitionAndInformDelegate(int caller_id); + void CancelRecognitionAndInformDelegate(int session_id); typedef std::map<int, Request> SpeechRecognizerMap; SpeechRecognizerMap requests_; std::string request_info_; bool can_report_metrics_; - int recording_caller_id_; + int recording_session_id_; scoped_ptr<content::SpeechRecognitionManagerDelegate> delegate_; }; diff --git a/content/browser/speech/speech_recognizer_impl.cc b/content/browser/speech/speech_recognizer_impl.cc index d9d9bab..d8b765f 100644 --- a/content/browser/speech/speech_recognizer_impl.cc +++ b/content/browser/speech/speech_recognizer_impl.cc @@ -63,9 +63,13 @@ bool DetectClipping(const speech::AudioChunk& chunk) { } // namespace +// TODO(primiano) Create(...) is transitional (until we fix speech input +// extensions) and should be removed soon. The manager should be the only one +// knowing the existence of SpeechRecognizer(Impl), thus the only one in charge +// of instantiating it. SpeechRecognizer* SpeechRecognizer::Create( SpeechRecognitionEventListener* listener, - int caller_id, + int session_id, const std::string& language, const std::string& grammar, net::URLRequestContextGetter* context_getter, @@ -89,7 +93,7 @@ SpeechRecognizer* SpeechRecognizer::Create( google_remote_engine->SetConfig(remote_engine_config); return new speech::SpeechRecognizerImpl(listener, - caller_id, + session_id, google_remote_engine); } @@ -106,13 +110,13 @@ COMPILE_ASSERT(SpeechRecognizerImpl::kNumBitsPerAudioSample % 8 == 0, SpeechRecognizerImpl::SpeechRecognizerImpl( SpeechRecognitionEventListener* listener, - int caller_id, + int session_id, SpeechRecognitionEngine* engine) : listener_(listener), testing_audio_manager_(NULL), recognition_engine_(engine), endpointer_(kAudioSampleRate), - caller_id_(caller_id), + session_id_(session_id), is_dispatching_event_(false), state_(STATE_IDLE) { DCHECK(listener_ != NULL); @@ -406,7 +410,7 @@ SpeechRecognizerImpl::StartRecording(const FSMEventArgs&) { DVLOG(1) << "SpeechRecognizerImpl starting audio capture."; num_samples_recorded_ = 0; audio_level_ = 0; - listener_->OnRecognitionStart(caller_id_); + listener_->OnRecognitionStart(session_id_); if (!audio_manager->HasAudioInputDevices()) { return AbortWithError(SpeechRecognitionError( @@ -447,7 +451,7 @@ SpeechRecognizerImpl::StartRecognitionEngine(const FSMEventArgs& event_args) { // started and the delegate notified about the event. DCHECK(recognition_engine_.get() != NULL); recognition_engine_->StartRecognition(); - listener_->OnAudioStart(caller_id_); + listener_->OnAudioStart(session_id_); // This is a little hack, since TakeAudioChunk() is already called by // ProcessAudioPipeline(). It is the best tradeoff, unless we allow dropping @@ -461,7 +465,7 @@ SpeechRecognizerImpl::WaitEnvironmentEstimationCompletion(const FSMEventArgs&) { DCHECK(endpointer_.IsEstimatingEnvironment()); if (GetElapsedTimeMs() >= kEndpointerEstimationTimeMs) { endpointer_.SetUserInputMode(); - listener_->OnEnvironmentEstimationComplete(caller_id_); + listener_->OnEnvironmentEstimationComplete(session_id_); return STATE_WAITING_FOR_SPEECH; } else { return STATE_ESTIMATING_ENVIRONMENT; @@ -471,7 +475,7 @@ SpeechRecognizerImpl::WaitEnvironmentEstimationCompletion(const FSMEventArgs&) { SpeechRecognizerImpl::FSMState SpeechRecognizerImpl::DetectUserSpeechOrTimeout(const FSMEventArgs&) { if (endpointer_.DidStartReceivingSpeech()) { - listener_->OnSoundStart(caller_id_); + listener_->OnSoundStart(session_id_); return STATE_RECOGNIZING; } else if (GetElapsedTimeMs() >= kNoSpeechTimeoutMs) { return AbortWithError( @@ -497,9 +501,9 @@ SpeechRecognizerImpl::StopCaptureAndWaitForResult(const FSMEventArgs&) { recognition_engine_->AudioChunksEnded(); if (state_ > STATE_WAITING_FOR_SPEECH) - listener_->OnSoundEnd(caller_id_); + listener_->OnSoundEnd(session_id_); - listener_->OnAudioEnd(caller_id_); + listener_->OnAudioEnd(session_id_); return STATE_WAITING_FINAL_RESULT; } @@ -538,15 +542,15 @@ SpeechRecognizerImpl::FSMState SpeechRecognizerImpl::AbortWithError( } if (state_ > STATE_WAITING_FOR_SPEECH && state_ < STATE_WAITING_FINAL_RESULT) - listener_->OnSoundEnd(caller_id_); + listener_->OnSoundEnd(session_id_); if (state_ > STATE_STARTING && state_ < STATE_WAITING_FINAL_RESULT) - listener_->OnAudioEnd(caller_id_); + listener_->OnAudioEnd(session_id_); if (error != NULL) - listener_->OnRecognitionError(caller_id_, *error); + listener_->OnRecognitionError(session_id_, *error); - listener_->OnRecognitionEnd(caller_id_); + listener_->OnRecognitionEnd(session_id_); return STATE_IDLE; } @@ -563,8 +567,8 @@ SpeechRecognizerImpl::ProcessFinalResult(const FSMEventArgs& event_args) { const SpeechRecognitionResult& result = event_args.engine_result; DVLOG(1) << "Got valid result"; recognition_engine_->EndRecognition(); - listener_->OnRecognitionResult(caller_id_, result); - listener_->OnRecognitionEnd(caller_id_); + listener_->OnRecognitionResult(session_id_, result); + listener_->OnRecognitionEnd(session_id_); return STATE_IDLE; } @@ -615,7 +619,7 @@ void SpeechRecognizerImpl::UpdateSignalAndNoiseLevels(const float& rms, kAudioMeterRangeMaxUnclipped); listener_->OnAudioLevelsChange( - caller_id_, clip_detected ? 1.0f : audio_level_, noise_level); + session_id_, clip_detected ? 1.0f : audio_level_, noise_level); } const SpeechRecognitionEngine& diff --git a/content/browser/speech/speech_recognizer_impl.h b/content/browser/speech/speech_recognizer_impl.h index a2cce74..5b37d61 100644 --- a/content/browser/speech/speech_recognizer_impl.h +++ b/content/browser/speech/speech_recognizer_impl.h @@ -18,11 +18,9 @@ namespace content { class SpeechRecognitionEventListener; -struct SpeechRecognitionResult; } namespace media { -class AudioInputController; class AudioManager; } @@ -32,7 +30,7 @@ namespace speech { // /content/public/browser/speech_recognizer.h interface since this class should // not be visible outside (currently we need it for speech input extension API). -// Handles speech recognition for a session (identified by |caller_id|), taking +// Handles speech recognition for a session (identified by |session_id|), taking // care of audio capture, silence detection/endpointer and interaction with the // SpeechRecognitionEngine. class CONTENT_EXPORT SpeechRecognizerImpl @@ -48,7 +46,7 @@ class CONTENT_EXPORT SpeechRecognizerImpl SpeechRecognizerImpl( content::SpeechRecognitionEventListener* listener, - int caller_id, + int session_id, SpeechRecognitionEngine* engine); virtual ~SpeechRecognizerImpl(); @@ -152,7 +150,7 @@ class CONTENT_EXPORT SpeechRecognizerImpl scoped_ptr<SpeechRecognitionEngine> recognition_engine_; Endpointer endpointer_; scoped_refptr<media::AudioInputController> audio_controller_; - int caller_id_; + int session_id_; int num_samples_recorded_; float audio_level_; bool is_dispatching_event_; diff --git a/content/browser/speech/speech_recognizer_impl_unittest.cc b/content/browser/speech/speech_recognizer_impl_unittest.cc index 5dbe6cc..d9658f9 100644 --- a/content/browser/speech/speech_recognizer_impl_unittest.cc +++ b/content/browser/speech/speech_recognizer_impl_unittest.cc @@ -147,52 +147,52 @@ class SpeechRecognizerImplTest : public content::SpeechRecognitionEventListener, } // Overridden from content::SpeechRecognitionEventListener: - virtual void OnAudioStart(int caller_id) OVERRIDE { + virtual void OnAudioStart(int session_id) OVERRIDE { audio_started_ = true; CheckEventsConsistency(); } - virtual void OnAudioEnd(int caller_id) OVERRIDE { + virtual void OnAudioEnd(int session_id) OVERRIDE { audio_ended_ = true; CheckEventsConsistency(); } virtual void OnRecognitionResult( - int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE { + int session_id, const content::SpeechRecognitionResult& result) OVERRIDE { result_received_ = true; } virtual void OnRecognitionError( - int caller_id, const content::SpeechRecognitionError& error) OVERRIDE { + int session_id, const content::SpeechRecognitionError& error) OVERRIDE { EXPECT_TRUE(recognition_started_); EXPECT_FALSE(recognition_ended_); error_ = error.code; } - virtual void OnAudioLevelsChange(int caller_id, float volume, + virtual void OnAudioLevelsChange(int session_id, float volume, float noise_volume) OVERRIDE { volume_ = volume; noise_volume_ = noise_volume; } - virtual void OnRecognitionEnd(int caller_id) OVERRIDE { + virtual void OnRecognitionEnd(int session_id) OVERRIDE { recognition_ended_ = true; CheckEventsConsistency(); } - virtual void OnRecognitionStart(int caller_id) OVERRIDE { + virtual void OnRecognitionStart(int session_id) OVERRIDE { recognition_started_ = true; CheckEventsConsistency(); } - virtual void OnEnvironmentEstimationComplete(int caller_id) OVERRIDE {} + virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE {} - virtual void OnSoundStart(int caller_id) OVERRIDE { + virtual void OnSoundStart(int session_id) OVERRIDE { sound_started_ = true; CheckEventsConsistency(); } - virtual void OnSoundEnd(int caller_id) OVERRIDE { + virtual void OnSoundEnd(int session_id) OVERRIDE { sound_ended_ = true; CheckEventsConsistency(); } diff --git a/content/public/browser/speech_recognition_event_listener.h b/content/public/browser/speech_recognition_event_listener.h index 7ce6995..10d64b3 100644 --- a/content/public/browser/speech_recognition_event_listener.h +++ b/content/public/browser/speech_recognition_event_listener.h @@ -19,46 +19,46 @@ class CONTENT_EXPORT SpeechRecognitionEventListener { public: // Invoked when the StartRequest is received and the recognition process is // started. - virtual void OnRecognitionStart(int caller_id_id) = 0; + virtual void OnRecognitionStart(int session_id) = 0; // Invoked when the first audio capture is initiated. - virtual void OnAudioStart(int caller_id) = 0; + virtual void OnAudioStart(int session_id) = 0; // At the start of recognition, a short amount of audio is recorded to // estimate the environment/background noise and this callback is issued // after that is complete. Typically the delegate brings up any speech // recognition UI once this callback is received. - virtual void OnEnvironmentEstimationComplete(int caller_id) = 0; + virtual void OnEnvironmentEstimationComplete(int session_id) = 0; // Informs that the end pointer has started detecting sound (possibly speech). - virtual void OnSoundStart(int caller_id) = 0; + virtual void OnSoundStart(int session_id) = 0; // Informs that the end pointer has stopped detecting sound (a long silence). - virtual void OnSoundEnd(int caller_id) = 0; + virtual void OnSoundEnd(int session_id) = 0; // Invoked when audio capture stops, either due to the end pointer detecting // silence, an internal error, or an explicit stop was issued. - virtual void OnAudioEnd(int caller_id) = 0; + virtual void OnAudioEnd(int session_id) = 0; // Invoked when a result is retrieved. - virtual void OnRecognitionResult(int caller_id, + virtual void OnRecognitionResult(int session_id, const SpeechRecognitionResult& result) = 0; // Invoked if there was an error while capturing or recognizing audio. // The recognition has already been cancelled when this call is made and // no more events will be raised. - virtual void OnRecognitionError(int caller_id, + virtual void OnRecognitionError(int session_id, const SpeechRecognitionError& error) = 0; // Informs of a change in the captured audio level, useful if displaying // a microphone volume indicator while recording. // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range. - virtual void OnAudioLevelsChange(int caller_id, float volume, - float noise_volume) = 0; + virtual void OnAudioLevelsChange(int session_id, + float volume, float noise_volume) = 0; // This is guaranteed to be the last event raised in the recognition // process and the |SpeechRecognizer| object can be freed if necessary. - virtual void OnRecognitionEnd(int caller_id) = 0; + virtual void OnRecognitionEnd(int session_id) = 0; protected: virtual ~SpeechRecognitionEventListener() { } diff --git a/content/public/browser/speech_recognition_manager.h b/content/public/browser/speech_recognition_manager.h index 89651c1..9c94999 100644 --- a/content/public/browser/speech_recognition_manager.h +++ b/content/public/browser/speech_recognition_manager.h @@ -20,14 +20,14 @@ class SpeechRecognitionManager { CONTENT_EXPORT static SpeechRecognitionManager* GetInstance(); // Starts/restarts recognition for an existing request. - virtual void StartRecognitionForRequest(int caller_id) = 0; + virtual void StartRecognitionForRequest(int session_id) = 0; // Cancels recognition for an existing request. - virtual void CancelRecognitionForRequest(int caller_id) = 0; + virtual void CancelRecognitionForRequest(int session_id) = 0; // Called when the user clicks outside the speech input UI causing it to close // and possibly have speech input go to another element. - virtual void FocusLostForRequest(int caller_id) = 0; + virtual void FocusLostForRequest(int session_id) = 0; // Returns true if the OS reports existence of audio recording devices. virtual bool HasAudioInputDevices() = 0; diff --git a/content/public/browser/speech_recognition_manager_delegate.h b/content/public/browser/speech_recognition_manager_delegate.h index dc52947..7156bc2 100644 --- a/content/public/browser/speech_recognition_manager_delegate.h +++ b/content/public/browser/speech_recognition_manager_delegate.h @@ -38,34 +38,34 @@ class SpeechRecognitionManagerDelegate { // the view port for the given caller. The embedder should call the // StartRecognition or CancelRecognition methods on SpeechInutManager in // response. - virtual void ShowRecognitionRequested(int caller_id, + virtual void ShowRecognitionRequested(int session_id, int render_process_id, int render_view_id, const gfx::Rect& element_rect) = 0; // Called when recognition is starting up. - virtual void ShowWarmUp(int caller_id) = 0; + virtual void ShowWarmUp(int session_id) = 0; // Called when recognition has started. - virtual void ShowRecognizing(int caller_id) = 0; + virtual void ShowRecognizing(int session_id) = 0; // Called when recording has started. - virtual void ShowRecording(int caller_id) = 0; + virtual void ShowRecording(int session_id) = 0; // Continuously updated with the current input volume. - virtual void ShowInputVolume(int caller_id, + virtual void ShowInputVolume(int session_id, float volume, float noise_volume) = 0; // Called when no microphone has been found. - virtual void ShowMicError(int caller_id, MicError error) = 0; + virtual void ShowMicError(int session_id, MicError error) = 0; // Called when there has been a error with the recognition. - virtual void ShowRecognizerError(int caller_id, + virtual void ShowRecognizerError(int session_id, SpeechRecognitionErrorCode error) = 0; // Called when recognition has ended or has been canceled. - virtual void DoClose(int caller_id) = 0; + virtual void DoClose(int session_id) = 0; }; } // namespace content diff --git a/content/public/browser/speech_recognizer.h b/content/public/browser/speech_recognizer.h index 4e64e10..330048e 100644 --- a/content/public/browser/speech_recognizer.h +++ b/content/public/browser/speech_recognizer.h @@ -25,13 +25,9 @@ class SpeechRecognitionEventListener; class SpeechRecognizer : public base::RefCountedThreadSafe<SpeechRecognizer> { public: - // TODO(primiano) Create(...) is transitional (until we fix speech input - // extensions) and should be removed soon. The manager should be the only one - // knowing the existence of SpeechRecognizer, thus the only one in charge of - // instantiating it. CONTENT_EXPORT static SpeechRecognizer* Create( SpeechRecognitionEventListener* event_listener, - int caller_id, + int session_id, const std::string& language, const std::string& grammar, net::URLRequestContextGetter* context_getter, |
