OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_recognizer_impl.h" | 5 #include "content/browser/speech/speech_recognizer_impl.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/browser_main_loop.h" | 10 #include "content/browser/browser_main_loop.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 void SpeechRecognizerImpl::StopAudioCapture() { | 225 void SpeechRecognizerImpl::StopAudioCapture() { |
226 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 226 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
227 base::Bind(&SpeechRecognizerImpl::DispatchEvent, | 227 base::Bind(&SpeechRecognizerImpl::DispatchEvent, |
228 this, FSMEventArgs(EVENT_STOP_CAPTURE))); | 228 this, FSMEventArgs(EVENT_STOP_CAPTURE))); |
229 } | 229 } |
230 | 230 |
231 bool SpeechRecognizerImpl::IsActive() const { | 231 bool SpeechRecognizerImpl::IsActive() const { |
232 // Checking the FSM state from another thread (thus, while the FSM is | 232 // Checking the FSM state from another thread (thus, while the FSM is |
233 // potentially concurrently evolving) is meaningless. | 233 // potentially concurrently evolving) is meaningless. |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 234 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
235 return state_ != STATE_IDLE && state_ != STATE_ENDED; | 235 return state_ != STATE_IDLE && state_ != STATE_ENDED; |
236 } | 236 } |
237 | 237 |
238 bool SpeechRecognizerImpl::IsCapturingAudio() const { | 238 bool SpeechRecognizerImpl::IsCapturingAudio() const { |
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // See IsActive(). | 239 DCHECK_CURRENTLY_ON(BrowserThread::IO); // See IsActive(). |
240 const bool is_capturing_audio = state_ >= STATE_STARTING && | 240 const bool is_capturing_audio = state_ >= STATE_STARTING && |
241 state_ <= STATE_RECOGNIZING; | 241 state_ <= STATE_RECOGNIZING; |
242 DCHECK((is_capturing_audio && (audio_controller_.get() != NULL)) || | 242 DCHECK((is_capturing_audio && (audio_controller_.get() != NULL)) || |
243 (!is_capturing_audio && audio_controller_.get() == NULL)); | 243 (!is_capturing_audio && audio_controller_.get() == NULL)); |
244 return is_capturing_audio; | 244 return is_capturing_audio; |
245 } | 245 } |
246 | 246 |
247 const SpeechRecognitionEngine& | 247 const SpeechRecognitionEngine& |
248 SpeechRecognizerImpl::recognition_engine() const { | 248 SpeechRecognizerImpl::recognition_engine() const { |
249 return *(recognition_engine_.get()); | 249 return *(recognition_engine_.get()); |
250 } | 250 } |
251 | 251 |
252 SpeechRecognizerImpl::~SpeechRecognizerImpl() { | 252 SpeechRecognizerImpl::~SpeechRecognizerImpl() { |
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
254 endpointer_.EndSession(); | 254 endpointer_.EndSession(); |
255 if (audio_controller_.get()) { | 255 if (audio_controller_.get()) { |
256 audio_controller_->Close( | 256 audio_controller_->Close( |
257 base::Bind(&KeepAudioControllerRefcountedForDtor, audio_controller_)); | 257 base::Bind(&KeepAudioControllerRefcountedForDtor, audio_controller_)); |
258 audio_log_->OnClosed(0); | 258 audio_log_->OnClosed(0); |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 // Invoked in the audio thread. | 262 // Invoked in the audio thread. |
263 void SpeechRecognizerImpl::OnError(AudioInputController* controller, | 263 void SpeechRecognizerImpl::OnError(AudioInputController* controller, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // particular, it is not true anymore that this class can be freed after the | 305 // particular, it is not true anymore that this class can be freed after the |
306 // OnRecognitionEnd event, since the audio_controller_.Close() asynchronous | 306 // OnRecognitionEnd event, since the audio_controller_.Close() asynchronous |
307 // call can be still in progress after the end event. Currently, it does not | 307 // call can be still in progress after the end event. Currently, it does not |
308 // represent a problem for the browser itself, since refcounting protects us | 308 // represent a problem for the browser itself, since refcounting protects us |
309 // against such race conditions. However, we should fix this in the next CLs. | 309 // against such race conditions. However, we should fix this in the next CLs. |
310 // For instance, tests are currently working just because the | 310 // For instance, tests are currently working just because the |
311 // TestAudioInputController is not closing asynchronously as the real controller | 311 // TestAudioInputController is not closing asynchronously as the real controller |
312 // does, but they will become flaky if TestAudioInputController will be fixed. | 312 // does, but they will become flaky if TestAudioInputController will be fixed. |
313 | 313 |
314 void SpeechRecognizerImpl::DispatchEvent(const FSMEventArgs& event_args) { | 314 void SpeechRecognizerImpl::DispatchEvent(const FSMEventArgs& event_args) { |
315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 315 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
316 DCHECK_LE(event_args.event, EVENT_MAX_VALUE); | 316 DCHECK_LE(event_args.event, EVENT_MAX_VALUE); |
317 DCHECK_LE(state_, STATE_MAX_VALUE); | 317 DCHECK_LE(state_, STATE_MAX_VALUE); |
318 | 318 |
319 // Event dispatching must be sequential, otherwise it will break all the rules | 319 // Event dispatching must be sequential, otherwise it will break all the rules |
320 // and the assumptions of the finite state automata model. | 320 // and the assumptions of the finite state automata model. |
321 DCHECK(!is_dispatching_event_); | 321 DCHECK(!is_dispatching_event_); |
322 is_dispatching_event_ = true; | 322 is_dispatching_event_ = true; |
323 | 323 |
324 // Guard against the delegate freeing us until we finish processing the event. | 324 // Guard against the delegate freeing us until we finish processing the event. |
325 scoped_refptr<SpeechRecognizerImpl> me(this); | 325 scoped_refptr<SpeechRecognizerImpl> me(this); |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 809 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
810 : event(event_value), | 810 : event(event_value), |
811 audio_data(NULL), | 811 audio_data(NULL), |
812 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { | 812 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { |
813 } | 813 } |
814 | 814 |
815 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { | 815 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { |
816 } | 816 } |
817 | 817 |
818 } // namespace content | 818 } // namespace content |
OLD | NEW |