Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/speech/speech_input_manager.h" | 5 #include "content/browser/speech/speech_input_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browser_thread.h" | |
| 17 #include "chrome/browser/platform_util.h" | 18 #include "chrome/browser/platform_util.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/speech/speech_input_bubble_controller.h" | 20 #include "chrome/browser/speech/speech_input_bubble_controller.h" |
| 20 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
| 24 #include "content/browser/speech/speech_recognizer.h" | 25 #include "content/browser/speech/speech_recognizer.h" |
| 25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 26 #include "media/audio/audio_manager.h" | 27 #include "media/audio/audio_manager.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 114 |
| 114 // SpeechRecognizer::Delegate methods. | 115 // SpeechRecognizer::Delegate methods. |
| 115 virtual void SetRecognitionResult(int caller_id, | 116 virtual void SetRecognitionResult(int caller_id, |
| 116 bool error, | 117 bool error, |
| 117 const SpeechInputResultArray& result); | 118 const SpeechInputResultArray& result); |
| 118 virtual void DidCompleteRecording(int caller_id); | 119 virtual void DidCompleteRecording(int caller_id); |
| 119 virtual void DidCompleteRecognition(int caller_id); | 120 virtual void DidCompleteRecognition(int caller_id); |
| 120 virtual void OnRecognizerError(int caller_id, | 121 virtual void OnRecognizerError(int caller_id, |
| 121 SpeechRecognizer::ErrorCode error); | 122 SpeechRecognizer::ErrorCode error); |
| 122 virtual void DidCompleteEnvironmentEstimation(int caller_id); | 123 virtual void DidCompleteEnvironmentEstimation(int caller_id); |
| 123 virtual void SetInputVolume(int caller_id, float volume); | 124 virtual void SetInputVolume(int caller_id, float volume, float noise_volume); |
| 124 | 125 |
| 125 // SpeechInputBubbleController::Delegate methods. | 126 // SpeechInputBubbleController::Delegate methods. |
| 126 virtual void InfoBubbleButtonClicked(int caller_id, | 127 virtual void InfoBubbleButtonClicked(int caller_id, |
| 127 SpeechInputBubble::Button button); | 128 SpeechInputBubble::Button button); |
| 128 virtual void InfoBubbleFocusChanged(int caller_id); | 129 virtual void InfoBubbleFocusChanged(int caller_id); |
| 129 | 130 |
| 130 private: | 131 private: |
| 131 struct SpeechInputRequest { | 132 struct SpeechInputRequest { |
| 132 SpeechInputManagerDelegate* delegate; | 133 SpeechInputManagerDelegate* delegate; |
| 133 scoped_refptr<SpeechRecognizer> recognizer; | 134 scoped_refptr<SpeechRecognizer> recognizer; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 // Official Chrome builds have speech input enabled by default only in the | 177 // Official Chrome builds have speech input enabled by default only in the |
| 177 // dev channel. | 178 // dev channel. |
| 178 std::string channel = platform_util::GetVersionStringModifier(); | 179 std::string channel = platform_util::GetVersionStringModifier(); |
| 179 enabled = (channel == "dev"); | 180 enabled = (channel == "dev"); |
| 180 #endif | 181 #endif |
| 181 } | 182 } |
| 182 | 183 |
| 183 return enabled; | 184 return enabled; |
| 184 } | 185 } |
| 185 | 186 |
| 187 void SpeechInputManager::ShowAudioInputSettings() { | |
| 188 // Since AudioManager::ShowAudioInputSettings can potentially launch external | |
| 189 // processes, do that in the PROCESS_LAUNCHER thread to not block the calling | |
|
jam
2011/03/01 19:49:11
how long can AudioManager::ShowAudioInputSettings
Satish
2011/03/01 20:31:21
ShowAudioInputSettings does a check to figure out
| |
| 190 // threads. | |
| 191 if (!BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)) { | |
| 192 BrowserThread::PostTask( | |
| 193 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | |
| 194 NewRunnableFunction(&SpeechInputManager::ShowAudioInputSettings)); | |
| 195 return; | |
| 196 } | |
| 197 | |
| 198 DCHECK(AudioManager::GetAudioManager()->CanShowAudioInputSettings()); | |
| 199 if (AudioManager::GetAudioManager()->CanShowAudioInputSettings()) | |
| 200 AudioManager::GetAudioManager()->ShowAudioInputSettings(); | |
| 201 } | |
| 202 | |
| 186 SpeechInputManagerImpl::SpeechInputManagerImpl() | 203 SpeechInputManagerImpl::SpeechInputManagerImpl() |
| 187 : recording_caller_id_(0), | 204 : recording_caller_id_(0), |
| 188 bubble_controller_(new SpeechInputBubbleController( | 205 bubble_controller_(new SpeechInputBubbleController( |
| 189 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { | 206 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { |
| 190 } | 207 } |
| 191 | 208 |
| 192 SpeechInputManagerImpl::~SpeechInputManagerImpl() { | 209 SpeechInputManagerImpl::~SpeechInputManagerImpl() { |
| 193 while (requests_.begin() != requests_.end()) | 210 while (requests_.begin() != requests_.end()) |
| 194 CancelRecognition(requests_.begin()->first); | 211 CancelRecognition(requests_.begin()->first); |
| 195 } | 212 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 | 350 |
| 334 void SpeechInputManagerImpl::DidCompleteEnvironmentEstimation(int caller_id) { | 351 void SpeechInputManagerImpl::DidCompleteEnvironmentEstimation(int caller_id) { |
| 335 DCHECK(HasPendingRequest(caller_id)); | 352 DCHECK(HasPendingRequest(caller_id)); |
| 336 DCHECK(recording_caller_id_ == caller_id); | 353 DCHECK(recording_caller_id_ == caller_id); |
| 337 | 354 |
| 338 // Speech recognizer has gathered enough background audio so we can ask the | 355 // Speech recognizer has gathered enough background audio so we can ask the |
| 339 // user to start speaking. | 356 // user to start speaking. |
| 340 bubble_controller_->SetBubbleRecordingMode(caller_id); | 357 bubble_controller_->SetBubbleRecordingMode(caller_id); |
| 341 } | 358 } |
| 342 | 359 |
| 343 void SpeechInputManagerImpl::SetInputVolume(int caller_id, float volume) { | 360 void SpeechInputManagerImpl::SetInputVolume(int caller_id, float volume, |
| 361 float noise_volume) { | |
| 344 DCHECK(HasPendingRequest(caller_id)); | 362 DCHECK(HasPendingRequest(caller_id)); |
| 345 DCHECK_EQ(recording_caller_id_, caller_id); | 363 DCHECK_EQ(recording_caller_id_, caller_id); |
| 346 | 364 |
| 347 bubble_controller_->SetBubbleInputVolume(caller_id, volume); | 365 bubble_controller_->SetBubbleInputVolume(caller_id, volume, noise_volume); |
| 348 } | 366 } |
| 349 | 367 |
| 350 void SpeechInputManagerImpl::CancelRecognitionAndInformDelegate(int caller_id) { | 368 void SpeechInputManagerImpl::CancelRecognitionAndInformDelegate(int caller_id) { |
| 351 SpeechInputManagerDelegate* cur_delegate = GetDelegate(caller_id); | 369 SpeechInputManagerDelegate* cur_delegate = GetDelegate(caller_id); |
| 352 CancelRecognition(caller_id); | 370 CancelRecognition(caller_id); |
| 353 cur_delegate->DidCompleteRecording(caller_id); | 371 cur_delegate->DidCompleteRecording(caller_id); |
| 354 cur_delegate->DidCompleteRecognition(caller_id); | 372 cur_delegate->DidCompleteRecognition(caller_id); |
| 355 } | 373 } |
| 356 | 374 |
| 357 void SpeechInputManagerImpl::InfoBubbleButtonClicked( | 375 void SpeechInputManagerImpl::InfoBubbleButtonClicked( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 380 // to the user, abort it since user has switched focus. Otherwise | 398 // to the user, abort it since user has switched focus. Otherwise |
| 381 // recognition has started and keep that going so user can start speaking to | 399 // recognition has started and keep that going so user can start speaking to |
| 382 // another element while this gets the results in parallel. | 400 // another element while this gets the results in parallel. |
| 383 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { | 401 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { |
| 384 CancelRecognitionAndInformDelegate(caller_id); | 402 CancelRecognitionAndInformDelegate(caller_id); |
| 385 } | 403 } |
| 386 } | 404 } |
| 387 } | 405 } |
| 388 | 406 |
| 389 } // namespace speech_input | 407 } // namespace speech_input |
| OLD | NEW |