OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/speech/speech_input_manager.h" | 5 #include "chrome/browser/speech/speech_input_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // SpeechInputManager methods. | 95 // SpeechInputManager methods. |
96 virtual void StartRecognition(SpeechInputManagerDelegate* delegate, | 96 virtual void StartRecognition(SpeechInputManagerDelegate* delegate, |
97 int caller_id, | 97 int caller_id, |
98 int render_process_id, | 98 int render_process_id, |
99 int render_view_id, | 99 int render_view_id, |
100 const gfx::Rect& element_rect, | 100 const gfx::Rect& element_rect, |
101 const std::string& language, | 101 const std::string& language, |
102 const std::string& grammar); | 102 const std::string& grammar); |
103 virtual void CancelRecognition(int caller_id); | 103 virtual void CancelRecognition(int caller_id); |
104 virtual void StopRecording(int caller_id); | 104 virtual void StopRecording(int caller_id); |
| 105 virtual void CancelAllRequestsWithDelegate( |
| 106 SpeechInputManagerDelegate* delegate); |
105 | 107 |
106 // SpeechRecognizer::Delegate methods. | 108 // SpeechRecognizer::Delegate methods. |
107 virtual void SetRecognitionResult(int caller_id, | 109 virtual void SetRecognitionResult(int caller_id, |
108 bool error, | 110 bool error, |
109 const SpeechInputResultArray& result); | 111 const SpeechInputResultArray& result); |
110 virtual void DidCompleteRecording(int caller_id); | 112 virtual void DidCompleteRecording(int caller_id); |
111 virtual void DidCompleteRecognition(int caller_id); | 113 virtual void DidCompleteRecognition(int caller_id); |
112 virtual void OnRecognizerError(int caller_id, | 114 virtual void OnRecognizerError(int caller_id, |
113 SpeechRecognizer::ErrorCode error); | 115 SpeechRecognizer::ErrorCode error); |
114 virtual void DidCompleteEnvironmentEstimation(int caller_id); | 116 virtual void DidCompleteEnvironmentEstimation(int caller_id); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 void SpeechInputManagerImpl::CancelRecognition(int caller_id) { | 249 void SpeechInputManagerImpl::CancelRecognition(int caller_id) { |
248 DCHECK(HasPendingRequest(caller_id)); | 250 DCHECK(HasPendingRequest(caller_id)); |
249 if (requests_[caller_id].is_active) | 251 if (requests_[caller_id].is_active) |
250 requests_[caller_id].recognizer->CancelRecognition(); | 252 requests_[caller_id].recognizer->CancelRecognition(); |
251 requests_.erase(caller_id); | 253 requests_.erase(caller_id); |
252 if (recording_caller_id_ == caller_id) | 254 if (recording_caller_id_ == caller_id) |
253 recording_caller_id_ = 0; | 255 recording_caller_id_ = 0; |
254 bubble_controller_->CloseBubble(caller_id); | 256 bubble_controller_->CloseBubble(caller_id); |
255 } | 257 } |
256 | 258 |
| 259 void SpeechInputManagerImpl::CancelAllRequestsWithDelegate( |
| 260 SpeechInputManagerDelegate* delegate) { |
| 261 SpeechRecognizerMap::iterator it = requests_.begin(); |
| 262 while (it != requests_.end()) { |
| 263 if (it->second.delegate == delegate) { |
| 264 CancelRecognition(it->first); |
| 265 // This map will have very few elements so it is simpler to restart. |
| 266 it = requests_.begin(); |
| 267 } else { |
| 268 ++it; |
| 269 } |
| 270 } |
| 271 } |
| 272 |
257 void SpeechInputManagerImpl::StopRecording(int caller_id) { | 273 void SpeechInputManagerImpl::StopRecording(int caller_id) { |
258 DCHECK(HasPendingRequest(caller_id)); | 274 DCHECK(HasPendingRequest(caller_id)); |
259 requests_[caller_id].recognizer->StopRecording(); | 275 requests_[caller_id].recognizer->StopRecording(); |
260 } | 276 } |
261 | 277 |
262 void SpeechInputManagerImpl::SetRecognitionResult( | 278 void SpeechInputManagerImpl::SetRecognitionResult( |
263 int caller_id, bool error, const SpeechInputResultArray& result) { | 279 int caller_id, bool error, const SpeechInputResultArray& result) { |
264 DCHECK(HasPendingRequest(caller_id)); | 280 DCHECK(HasPendingRequest(caller_id)); |
265 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); | 281 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); |
266 } | 282 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // to the user, abort it since user has switched focus. Otherwise | 370 // to the user, abort it since user has switched focus. Otherwise |
355 // recognition has started and keep that going so user can start speaking to | 371 // recognition has started and keep that going so user can start speaking to |
356 // another element while this gets the results in parallel. | 372 // another element while this gets the results in parallel. |
357 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { | 373 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { |
358 CancelRecognitionAndInformDelegate(caller_id); | 374 CancelRecognitionAndInformDelegate(caller_id); |
359 } | 375 } |
360 } | 376 } |
361 } | 377 } |
362 | 378 |
363 } // namespace speech_input | 379 } // namespace speech_input |
OLD | NEW |