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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 virtual void StartRecognition(SpeechInputManagerDelegate* delegate, | 104 virtual void StartRecognition(SpeechInputManagerDelegate* delegate, |
105 int caller_id, | 105 int caller_id, |
106 int render_process_id, | 106 int render_process_id, |
107 int render_view_id, | 107 int render_view_id, |
108 const gfx::Rect& element_rect, | 108 const gfx::Rect& element_rect, |
109 const std::string& language, | 109 const std::string& language, |
110 const std::string& grammar, | 110 const std::string& grammar, |
111 const std::string& origin_url); | 111 const std::string& origin_url); |
112 virtual void CancelRecognition(int caller_id); | 112 virtual void CancelRecognition(int caller_id); |
113 virtual void StopRecording(int caller_id); | 113 virtual void StopRecording(int caller_id); |
| 114 virtual void CancelAllRequestsWithDelegate( |
| 115 SpeechInputManagerDelegate* delegate); |
114 | 116 |
115 // SpeechRecognizer::Delegate methods. | 117 // SpeechRecognizer::Delegate methods. |
116 virtual void SetRecognitionResult(int caller_id, | 118 virtual void SetRecognitionResult(int caller_id, |
117 bool error, | 119 bool error, |
118 const SpeechInputResultArray& result); | 120 const SpeechInputResultArray& result); |
119 virtual void DidCompleteRecording(int caller_id); | 121 virtual void DidCompleteRecording(int caller_id); |
120 virtual void DidCompleteRecognition(int caller_id); | 122 virtual void DidCompleteRecognition(int caller_id); |
121 virtual void OnRecognizerError(int caller_id, | 123 virtual void OnRecognizerError(int caller_id, |
122 SpeechRecognizer::ErrorCode error); | 124 SpeechRecognizer::ErrorCode error); |
123 virtual void DidCompleteEnvironmentEstimation(int caller_id); | 125 virtual void DidCompleteEnvironmentEstimation(int caller_id); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void SpeechInputManagerImpl::CancelRecognition(int caller_id) { | 260 void SpeechInputManagerImpl::CancelRecognition(int caller_id) { |
259 DCHECK(HasPendingRequest(caller_id)); | 261 DCHECK(HasPendingRequest(caller_id)); |
260 if (requests_[caller_id].is_active) | 262 if (requests_[caller_id].is_active) |
261 requests_[caller_id].recognizer->CancelRecognition(); | 263 requests_[caller_id].recognizer->CancelRecognition(); |
262 requests_.erase(caller_id); | 264 requests_.erase(caller_id); |
263 if (recording_caller_id_ == caller_id) | 265 if (recording_caller_id_ == caller_id) |
264 recording_caller_id_ = 0; | 266 recording_caller_id_ = 0; |
265 bubble_controller_->CloseBubble(caller_id); | 267 bubble_controller_->CloseBubble(caller_id); |
266 } | 268 } |
267 | 269 |
| 270 void SpeechInputManagerImpl::CancelAllRequestsWithDelegate( |
| 271 SpeechInputManagerDelegate* delegate) { |
| 272 SpeechRecognizerMap::iterator it = requests_.begin(); |
| 273 while (it != requests_.end()) { |
| 274 if (it->second.delegate == delegate) { |
| 275 CancelRecognition(it->first); |
| 276 // This map will have very few elements so it is simpler to restart. |
| 277 it = requests_.begin(); |
| 278 } else { |
| 279 ++it; |
| 280 } |
| 281 } |
| 282 } |
| 283 |
268 void SpeechInputManagerImpl::StopRecording(int caller_id) { | 284 void SpeechInputManagerImpl::StopRecording(int caller_id) { |
269 DCHECK(HasPendingRequest(caller_id)); | 285 DCHECK(HasPendingRequest(caller_id)); |
270 requests_[caller_id].recognizer->StopRecording(); | 286 requests_[caller_id].recognizer->StopRecording(); |
271 } | 287 } |
272 | 288 |
273 void SpeechInputManagerImpl::SetRecognitionResult( | 289 void SpeechInputManagerImpl::SetRecognitionResult( |
274 int caller_id, bool error, const SpeechInputResultArray& result) { | 290 int caller_id, bool error, const SpeechInputResultArray& result) { |
275 DCHECK(HasPendingRequest(caller_id)); | 291 DCHECK(HasPendingRequest(caller_id)); |
276 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); | 292 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); |
277 } | 293 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // to the user, abort it since user has switched focus. Otherwise | 381 // to the user, abort it since user has switched focus. Otherwise |
366 // recognition has started and keep that going so user can start speaking to | 382 // recognition has started and keep that going so user can start speaking to |
367 // another element while this gets the results in parallel. | 383 // another element while this gets the results in parallel. |
368 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { | 384 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { |
369 CancelRecognitionAndInformDelegate(caller_id); | 385 CancelRecognitionAndInformDelegate(caller_id); |
370 } | 386 } |
371 } | 387 } |
372 } | 388 } |
373 | 389 |
374 } // namespace speech_input | 390 } // namespace speech_input |
OLD | NEW |