OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_recognition_manager_impl.h" | 5 #include "content/browser/speech/speech_recognition_manager_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/browser_main_loop.h" | 8 #include "content/browser/browser_main_loop.h" |
9 #include "content/browser/renderer_host/media/media_stream_manager.h" | 9 #include "content/browser/renderer_host/media/media_stream_manager.h" |
10 #include "content/browser/speech/google_one_shot_remote_engine.h" | 10 #include "content/browser/speech/google_one_shot_remote_engine.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 GURL(context.context_name), | 171 GURL(context.context_name), |
172 base::Bind( | 172 base::Bind( |
173 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, | 173 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, |
174 weak_factory_.GetWeakPtr())); | 174 weak_factory_.GetWeakPtr())); |
175 | 175 |
176 return; | 176 return; |
177 } | 177 } |
178 #endif // defined(OS_IOS) | 178 #endif // defined(OS_IOS) |
179 | 179 |
180 if (is_allowed) { | 180 if (is_allowed) { |
181 MessageLoop::current()->PostTask(FROM_HERE, | 181 base::MessageLoop::current()->PostTask( |
| 182 FROM_HERE, |
182 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 183 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
183 weak_factory_.GetWeakPtr(), session_id, EVENT_START)); | 184 weak_factory_.GetWeakPtr(), |
| 185 session_id, |
| 186 EVENT_START)); |
184 } else { | 187 } else { |
185 OnRecognitionError(session_id, SpeechRecognitionError( | 188 OnRecognitionError(session_id, SpeechRecognitionError( |
186 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED)); | 189 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED)); |
187 MessageLoop::current()->PostTask(FROM_HERE, | 190 base::MessageLoop::current()->PostTask( |
| 191 FROM_HERE, |
188 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 192 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
189 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); | 193 weak_factory_.GetWeakPtr(), |
| 194 session_id, |
| 195 EVENT_ABORT)); |
190 } | 196 } |
191 } | 197 } |
192 | 198 |
193 void SpeechRecognitionManagerImpl::MediaRequestPermissionCallback( | 199 void SpeechRecognitionManagerImpl::MediaRequestPermissionCallback( |
194 const std::string& label, const MediaStreamDevices& devices) { | 200 const std::string& label, const MediaStreamDevices& devices) { |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
196 for (SessionsTable::iterator iter = sessions_.begin(); | 202 for (SessionsTable::iterator iter = sessions_.begin(); |
197 iter != sessions_.end(); ++iter) { | 203 iter != sessions_.end(); ++iter) { |
198 if (iter->second.context.label == label) { | 204 if (iter->second.context.label == label) { |
199 bool is_allowed = false; | 205 bool is_allowed = false; |
(...skipping 18 matching lines...) Expand all Loading... |
218 if (!SessionExists(session_id)) | 224 if (!SessionExists(session_id)) |
219 return; | 225 return; |
220 | 226 |
221 #if !defined(OS_IOS) | 227 #if !defined(OS_IOS) |
222 const SpeechRecognitionSessionContext& context = | 228 const SpeechRecognitionSessionContext& context = |
223 GetSessionContext(session_id); | 229 GetSessionContext(session_id); |
224 if (!context.label.empty()) | 230 if (!context.label.empty()) |
225 BrowserMainLoop::GetMediaStreamManager()->CancelRequest(context.label); | 231 BrowserMainLoop::GetMediaStreamManager()->CancelRequest(context.label); |
226 #endif // !defined(OS_IOS) | 232 #endif // !defined(OS_IOS) |
227 | 233 |
228 MessageLoop::current()->PostTask(FROM_HERE, | 234 base::MessageLoop::current()->PostTask( |
| 235 FROM_HERE, |
229 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 236 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
230 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); | 237 weak_factory_.GetWeakPtr(), |
| 238 session_id, |
| 239 EVENT_ABORT)); |
231 } | 240 } |
232 | 241 |
233 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { | 242 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
235 if (!SessionExists(session_id)) | 244 if (!SessionExists(session_id)) |
236 return; | 245 return; |
237 | 246 |
238 #if !defined(OS_IOS) | 247 #if !defined(OS_IOS) |
239 const SpeechRecognitionSessionContext& context = | 248 const SpeechRecognitionSessionContext& context = |
240 GetSessionContext(session_id); | 249 GetSessionContext(session_id); |
241 if (!context.label.empty()) | 250 if (!context.label.empty()) |
242 BrowserMainLoop::GetMediaStreamManager()->CancelRequest(context.label); | 251 BrowserMainLoop::GetMediaStreamManager()->CancelRequest(context.label); |
243 #endif // !defined(OS_IOS) | 252 #endif // !defined(OS_IOS) |
244 | 253 |
245 MessageLoop::current()->PostTask(FROM_HERE, | 254 base::MessageLoop::current()->PostTask( |
| 255 FROM_HERE, |
246 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 256 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
247 weak_factory_.GetWeakPtr(), session_id, EVENT_STOP_CAPTURE)); | 257 weak_factory_.GetWeakPtr(), |
| 258 session_id, |
| 259 EVENT_STOP_CAPTURE)); |
248 } | 260 } |
249 | 261 |
250 // Here begins the SpeechRecognitionEventListener interface implementation, | 262 // Here begins the SpeechRecognitionEventListener interface implementation, |
251 // which will simply relay the events to the proper listener registered for the | 263 // which will simply relay the events to the proper listener registered for the |
252 // particular session (most likely InputTagSpeechDispatcherHost) and to the | 264 // particular session (most likely InputTagSpeechDispatcherHost) and to the |
253 // catch-all listener provided by the delegate (if any). | 265 // catch-all listener provided by the delegate (if any). |
254 | 266 |
255 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { | 267 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { |
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
257 if (!SessionExists(session_id)) | 269 if (!SessionExists(session_id)) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 336 |
325 void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) { | 337 void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) { |
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
327 if (!SessionExists(session_id)) | 339 if (!SessionExists(session_id)) |
328 return; | 340 return; |
329 | 341 |
330 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 342 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
331 delegate_listener->OnAudioEnd(session_id); | 343 delegate_listener->OnAudioEnd(session_id); |
332 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) | 344 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) |
333 listener->OnAudioEnd(session_id); | 345 listener->OnAudioEnd(session_id); |
334 MessageLoop::current()->PostTask(FROM_HERE, | 346 base::MessageLoop::current()->PostTask( |
| 347 FROM_HERE, |
335 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 348 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
336 weak_factory_.GetWeakPtr(), session_id, EVENT_AUDIO_ENDED)); | 349 weak_factory_.GetWeakPtr(), |
| 350 session_id, |
| 351 EVENT_AUDIO_ENDED)); |
337 } | 352 } |
338 | 353 |
339 void SpeechRecognitionManagerImpl::OnRecognitionResults( | 354 void SpeechRecognitionManagerImpl::OnRecognitionResults( |
340 int session_id, const SpeechRecognitionResults& results) { | 355 int session_id, const SpeechRecognitionResults& results) { |
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
342 if (!SessionExists(session_id)) | 357 if (!SessionExists(session_id)) |
343 return; | 358 return; |
344 | 359 |
345 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 360 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
346 delegate_listener->OnRecognitionResults(session_id, results); | 361 delegate_listener->OnRecognitionResults(session_id, results); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 // Notify the UI the devices has been closed. | 398 // Notify the UI the devices has been closed. |
384 BrowserMainLoop::GetMediaStreamManager()->NotifyUIDevicesClosed( | 399 BrowserMainLoop::GetMediaStreamManager()->NotifyUIDevicesClosed( |
385 context.label); | 400 context.label); |
386 } | 401 } |
387 #endif // !defined(OS_IOS) | 402 #endif // !defined(OS_IOS) |
388 | 403 |
389 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 404 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
390 delegate_listener->OnRecognitionEnd(session_id); | 405 delegate_listener->OnRecognitionEnd(session_id); |
391 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) | 406 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) |
392 listener->OnRecognitionEnd(session_id); | 407 listener->OnRecognitionEnd(session_id); |
393 MessageLoop::current()->PostTask(FROM_HERE, | 408 base::MessageLoop::current()->PostTask( |
| 409 FROM_HERE, |
394 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 410 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
395 weak_factory_.GetWeakPtr(), | 411 weak_factory_.GetWeakPtr(), |
396 session_id, | 412 session_id, |
397 EVENT_RECOGNITION_ENDED)); | 413 EVENT_RECOGNITION_ENDED)); |
398 } | 414 } |
399 | 415 |
400 int SpeechRecognitionManagerImpl::GetSession( | 416 int SpeechRecognitionManagerImpl::GetSession( |
401 int render_process_id, int render_view_id, int request_id) const { | 417 int render_process_id, int render_view_id, int request_id) const { |
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
403 SessionsTable::const_iterator iter; | 419 SessionsTable::const_iterator iter; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 657 |
642 SpeechRecognitionManagerImpl::Session::Session() | 658 SpeechRecognitionManagerImpl::Session::Session() |
643 : id(kSessionIDInvalid), | 659 : id(kSessionIDInvalid), |
644 listener_is_active(true) { | 660 listener_is_active(true) { |
645 } | 661 } |
646 | 662 |
647 SpeechRecognitionManagerImpl::Session::~Session() { | 663 SpeechRecognitionManagerImpl::Session::~Session() { |
648 } | 664 } |
649 | 665 |
650 } // namespace content | 666 } // namespace content |
OLD | NEW |