summaryrefslogtreecommitdiffstats
path: root/chrome/browser/speech
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/speech')
-rw-r--r--chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc46
-rw-r--r--chrome/browser/speech/chrome_speech_recognition_manager_delegate.h20
-rw-r--r--chrome/browser/speech/speech_input_extension_apitest.cc22
-rw-r--r--chrome/browser/speech/speech_input_extension_manager.cc56
-rw-r--r--chrome/browser/speech/speech_input_extension_manager.h24
-rw-r--r--chrome/browser/speech/speech_recognition_bubble_controller.cc91
-rw-r--r--chrome/browser/speech/speech_recognition_bubble_controller.h38
-rw-r--r--chrome/browser/speech/speech_recognition_bubble_controller_unittest.cc26
8 files changed, 163 insertions, 160 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