Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: content/browser/speech/speech_recognition_manager_impl.cc

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_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 "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "content/browser/browser_main_loop.h" 8 #include "content/browser/browser_main_loop.h"
12 #include "content/browser/renderer_host/media/media_stream_manager.h" 9 #include "content/browser/renderer_host/media/media_stream_manager.h"
13 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
14 #include "content/browser/speech/google_one_shot_remote_engine.h" 11 #include "content/browser/speech/google_one_shot_remote_engine.h"
15 #include "content/browser/speech/google_streaming_remote_engine.h" 12 #include "content/browser/speech/google_streaming_remote_engine.h"
16 #include "content/browser/speech/speech_recognition_engine.h" 13 #include "content/browser/speech/speech_recognition_engine.h"
17 #include "content/browser/speech/speech_recognizer_impl.h" 14 #include "content/browser/speech/speech_recognizer_impl.h"
18 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
20 #include "content/public/browser/resource_context.h" 17 #include "content/public/browser/resource_context.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 context.request_id, 203 context.request_id,
207 StreamOptions(true, false), 204 StreamOptions(true, false),
208 GURL(context.context_name), 205 GURL(context.context_name),
209 base::Bind( 206 base::Bind(
210 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, 207 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback,
211 weak_factory_.GetWeakPtr(), session_id)); 208 weak_factory_.GetWeakPtr(), session_id));
212 return; 209 return;
213 } 210 }
214 211
215 if (is_allowed) { 212 if (is_allowed) {
216 base::ThreadTaskRunnerHandle::Get()->PostTask( 213 base::MessageLoop::current()->PostTask(
217 FROM_HERE, 214 FROM_HERE,
218 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 215 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
219 weak_factory_.GetWeakPtr(), session_id, EVENT_START)); 216 weak_factory_.GetWeakPtr(),
217 session_id,
218 EVENT_START));
220 } else { 219 } else {
221 OnRecognitionError(session_id, SpeechRecognitionError( 220 OnRecognitionError(session_id, SpeechRecognitionError(
222 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED)); 221 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED));
223 base::ThreadTaskRunnerHandle::Get()->PostTask( 222 base::MessageLoop::current()->PostTask(
224 FROM_HERE, 223 FROM_HERE,
225 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 224 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
226 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); 225 weak_factory_.GetWeakPtr(),
226 session_id,
227 EVENT_ABORT));
227 } 228 }
228 } 229 }
229 230
230 void SpeechRecognitionManagerImpl::MediaRequestPermissionCallback( 231 void SpeechRecognitionManagerImpl::MediaRequestPermissionCallback(
231 int session_id, 232 int session_id,
232 const MediaStreamDevices& devices, 233 const MediaStreamDevices& devices,
233 scoped_ptr<MediaStreamUIProxy> stream_ui) { 234 scoped_ptr<MediaStreamUIProxy> stream_ui) {
234 DCHECK_CURRENTLY_ON(BrowserThread::IO); 235 DCHECK_CURRENTLY_ON(BrowserThread::IO);
235 236
236 SessionsTable::iterator iter = sessions_.find(session_id); 237 SessionsTable::iterator iter = sessions_.find(session_id);
(...skipping 22 matching lines...) Expand all
259 return; 260 return;
260 261
261 SessionsTable::iterator iter = sessions_.find(session_id); 262 SessionsTable::iterator iter = sessions_.find(session_id);
262 iter->second->ui.reset(); 263 iter->second->ui.reset();
263 264
264 if (iter->second->abort_requested) 265 if (iter->second->abort_requested)
265 return; 266 return;
266 267
267 iter->second->abort_requested = true; 268 iter->second->abort_requested = true;
268 269
269 base::ThreadTaskRunnerHandle::Get()->PostTask( 270 base::MessageLoop::current()->PostTask(
270 FROM_HERE, 271 FROM_HERE,
271 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 272 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
272 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); 273 weak_factory_.GetWeakPtr(),
274 session_id,
275 EVENT_ABORT));
273 } 276 }
274 277
275 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { 278 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) {
276 DCHECK_CURRENTLY_ON(BrowserThread::IO); 279 DCHECK_CURRENTLY_ON(BrowserThread::IO);
277 if (!SessionExists(session_id)) 280 if (!SessionExists(session_id))
278 return; 281 return;
279 282
280 SessionsTable::iterator iter = sessions_.find(session_id); 283 SessionsTable::iterator iter = sessions_.find(session_id);
281 iter->second->ui.reset(); 284 iter->second->ui.reset();
282 285
283 base::ThreadTaskRunnerHandle::Get()->PostTask( 286 base::MessageLoop::current()->PostTask(
284 FROM_HERE, 287 FROM_HERE,
285 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 288 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
286 weak_factory_.GetWeakPtr(), session_id, EVENT_STOP_CAPTURE)); 289 weak_factory_.GetWeakPtr(),
290 session_id,
291 EVENT_STOP_CAPTURE));
287 } 292 }
288 293
289 // Here begins the SpeechRecognitionEventListener interface implementation, 294 // Here begins the SpeechRecognitionEventListener interface implementation,
290 // which will simply relay the events to the proper listener registered for the 295 // which will simply relay the events to the proper listener registered for the
291 // particular session and to the catch-all listener provided by the delegate 296 // particular session and to the catch-all listener provided by the delegate
292 // (if any). 297 // (if any).
293 298
294 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { 299 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) {
295 DCHECK_CURRENTLY_ON(BrowserThread::IO); 300 DCHECK_CURRENTLY_ON(BrowserThread::IO);
296 if (!SessionExists(session_id)) 301 if (!SessionExists(session_id))
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 365
361 void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) { 366 void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) {
362 DCHECK_CURRENTLY_ON(BrowserThread::IO); 367 DCHECK_CURRENTLY_ON(BrowserThread::IO);
363 if (!SessionExists(session_id)) 368 if (!SessionExists(session_id))
364 return; 369 return;
365 370
366 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 371 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
367 delegate_listener->OnAudioEnd(session_id); 372 delegate_listener->OnAudioEnd(session_id);
368 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 373 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
369 listener->OnAudioEnd(session_id); 374 listener->OnAudioEnd(session_id);
370 base::ThreadTaskRunnerHandle::Get()->PostTask( 375 base::MessageLoop::current()->PostTask(
371 FROM_HERE, 376 FROM_HERE,
372 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 377 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
373 weak_factory_.GetWeakPtr(), session_id, EVENT_AUDIO_ENDED)); 378 weak_factory_.GetWeakPtr(),
379 session_id,
380 EVENT_AUDIO_ENDED));
374 } 381 }
375 382
376 void SpeechRecognitionManagerImpl::OnRecognitionResults( 383 void SpeechRecognitionManagerImpl::OnRecognitionResults(
377 int session_id, const SpeechRecognitionResults& results) { 384 int session_id, const SpeechRecognitionResults& results) {
378 DCHECK_CURRENTLY_ON(BrowserThread::IO); 385 DCHECK_CURRENTLY_ON(BrowserThread::IO);
379 if (!SessionExists(session_id)) 386 if (!SessionExists(session_id))
380 return; 387 return;
381 388
382 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 389 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
383 delegate_listener->OnRecognitionResults(session_id, results); 390 delegate_listener->OnRecognitionResults(session_id, results);
(...skipping 27 matching lines...) Expand all
411 418
412 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) { 419 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) {
413 DCHECK_CURRENTLY_ON(BrowserThread::IO); 420 DCHECK_CURRENTLY_ON(BrowserThread::IO);
414 if (!SessionExists(session_id)) 421 if (!SessionExists(session_id))
415 return; 422 return;
416 423
417 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 424 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
418 delegate_listener->OnRecognitionEnd(session_id); 425 delegate_listener->OnRecognitionEnd(session_id);
419 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 426 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
420 listener->OnRecognitionEnd(session_id); 427 listener->OnRecognitionEnd(session_id);
421 base::ThreadTaskRunnerHandle::Get()->PostTask( 428 base::MessageLoop::current()->PostTask(
422 FROM_HERE, base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 429 FROM_HERE,
423 weak_factory_.GetWeakPtr(), session_id, 430 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
424 EVENT_RECOGNITION_ENDED)); 431 weak_factory_.GetWeakPtr(),
432 session_id,
433 EVENT_RECOGNITION_ENDED));
425 } 434 }
426 435
427 int SpeechRecognitionManagerImpl::GetSession( 436 int SpeechRecognitionManagerImpl::GetSession(
428 int render_process_id, int render_view_id, int request_id) const { 437 int render_process_id, int render_view_id, int request_id) const {
429 DCHECK_CURRENTLY_ON(BrowserThread::IO); 438 DCHECK_CURRENTLY_ON(BrowserThread::IO);
430 SessionsTable::const_iterator iter; 439 SessionsTable::const_iterator iter;
431 for (iter = sessions_.begin(); iter != sessions_.end(); ++iter) { 440 for (iter = sessions_.begin(); iter != sessions_.end(); ++iter) {
432 const int session_id = iter->first; 441 const int session_id = iter->first;
433 const SpeechRecognitionSessionContext& context = iter->second->context; 442 const SpeechRecognitionSessionContext& context = iter->second->context;
434 if (context.render_process_id == render_process_id && 443 if (context.render_process_id == render_process_id &&
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 SpeechRecognitionManagerImpl::Session::Session() 694 SpeechRecognitionManagerImpl::Session::Session()
686 : id(kSessionIDInvalid), 695 : id(kSessionIDInvalid),
687 abort_requested(false), 696 abort_requested(false),
688 listener_is_active(true) { 697 listener_is_active(true) {
689 } 698 }
690 699
691 SpeechRecognitionManagerImpl::Session::~Session() { 700 SpeechRecognitionManagerImpl::Session::~Session() {
692 } 701 }
693 702
694 } // namespace content 703 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognition_browsertest.cc ('k') | content/browser/speech/speech_recognizer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698