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

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

Issue 2651373002: Removing SpeechRecognitionManager::HasAudioInputDevices() and ShowAudioInputSettings() (Closed)
Patch Set: fix for tests Created 3 years, 11 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/browser/browser_main_loop.h" 14 #include "content/browser/browser_main_loop.h"
15 #include "content/browser/renderer_host/media/media_stream_manager.h" 15 #include "content/browser/renderer_host/media/media_stream_manager.h"
16 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 16 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
17 #include "content/browser/speech/speech_recognition_engine.h" 17 #include "content/browser/speech/speech_recognition_engine.h"
18 #include "content/browser/speech/speech_recognizer_impl.h" 18 #include "content/browser/speech/speech_recognizer_impl.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/content_browser_client.h" 20 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/resource_context.h" 21 #include "content/public/browser/resource_context.h"
22 #include "content/public/browser/speech_recognition_event_listener.h" 22 #include "content/public/browser/speech_recognition_event_listener.h"
23 #include "content/public/browser/speech_recognition_manager_delegate.h" 23 #include "content/public/browser/speech_recognition_manager_delegate.h"
24 #include "content/public/browser/speech_recognition_session_config.h" 24 #include "content/public/browser/speech_recognition_session_config.h"
25 #include "content/public/browser/speech_recognition_session_context.h" 25 #include "content/public/browser/speech_recognition_session_context.h"
26 #include "content/public/common/speech_recognition_error.h" 26 #include "content/public/common/speech_recognition_error.h"
27 #include "content/public/common/speech_recognition_result.h" 27 #include "content/public/common/speech_recognition_result.h"
28 #include "media/audio/audio_device_description.h" 28 #include "media/audio/audio_device_description.h"
29 #include "media/audio/audio_manager.h"
30 #include "url/gurl.h" 29 #include "url/gurl.h"
31 #include "url/origin.h" 30 #include "url/origin.h"
32 31
33 #if defined(OS_ANDROID) 32 #if defined(OS_ANDROID)
34 #include "content/browser/speech/speech_recognizer_impl_android.h" 33 #include "content/browser/speech/speech_recognizer_impl_android.h"
35 #endif 34 #endif
36 35
37 using base::Callback; 36 using base::Callback;
38 37
39 namespace content { 38 namespace content {
40 39
41 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_; 40 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_;
42 41
43 namespace { 42 namespace {
44 43
45 SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl; 44 SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl;
46 45
47 void ShowAudioInputSettingsOnFileThread(media::AudioManager* audio_manager) {
48 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
49 audio_manager->ShowAudioInputSettings();
50 }
51
52 } // namespace 46 } // namespace
53 47
54 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { 48 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() {
55 if (manager_for_tests_) 49 if (manager_for_tests_)
56 return manager_for_tests_; 50 return manager_for_tests_;
57 return SpeechRecognitionManagerImpl::GetInstance(); 51 return SpeechRecognitionManagerImpl::GetInstance();
58 } 52 }
59 53
60 void SpeechRecognitionManager::SetManagerForTesting( 54 void SpeechRecognitionManager::SetManagerForTesting(
61 SpeechRecognitionManager* manager) { 55 SpeechRecognitionManager* manager) {
62 manager_for_tests_ = manager; 56 manager_for_tests_ = manager;
63 } 57 }
64 58
65 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { 59 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() {
66 return g_speech_recognition_manager_impl; 60 return g_speech_recognition_manager_impl;
67 } 61 }
68 62
69 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl( 63 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl(
70 media::AudioManager* audio_manager, 64 MediaStreamManager* media_stream_manager)
71 MediaStreamManager* media_stream_manager) 65 : media_stream_manager_(media_stream_manager),
72 : audio_manager_(audio_manager),
73 media_stream_manager_(media_stream_manager),
74 primary_session_id_(kSessionIDInvalid), 66 primary_session_id_(kSessionIDInvalid),
75 last_session_id_(kSessionIDInvalid), 67 last_session_id_(kSessionIDInvalid),
76 is_dispatching_event_(false), 68 is_dispatching_event_(false),
77 delegate_(GetContentClient()->browser()-> 69 delegate_(GetContentClient()
78 CreateSpeechRecognitionManagerDelegate()), 70 ->browser()
71 ->CreateSpeechRecognitionManagerDelegate()),
79 weak_factory_(this) { 72 weak_factory_(this) {
80 DCHECK(!g_speech_recognition_manager_impl); 73 DCHECK(!g_speech_recognition_manager_impl);
81 g_speech_recognition_manager_impl = this; 74 g_speech_recognition_manager_impl = this;
82 } 75 }
83 76
84 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { 77 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() {
85 DCHECK(g_speech_recognition_manager_impl); 78 DCHECK(g_speech_recognition_manager_impl);
86 g_speech_recognition_manager_impl = NULL; 79 g_speech_recognition_manager_impl = NULL;
87 80
88 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end(); 81 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end();
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 SpeechRecognitionEventListener* 635 SpeechRecognitionEventListener*
643 SpeechRecognitionManagerImpl::GetDelegateListener() const { 636 SpeechRecognitionManagerImpl::GetDelegateListener() const {
644 return delegate_.get() ? delegate_->GetEventListener() : NULL; 637 return delegate_.get() ? delegate_->GetEventListener() : NULL;
645 } 638 }
646 639
647 const SpeechRecognitionSessionConfig& 640 const SpeechRecognitionSessionConfig&
648 SpeechRecognitionManagerImpl::GetSessionConfig(int session_id) const { 641 SpeechRecognitionManagerImpl::GetSessionConfig(int session_id) const {
649 return GetSession(session_id)->config; 642 return GetSession(session_id)->config;
650 } 643 }
651 644
652 bool SpeechRecognitionManagerImpl::HasAudioInputDevices() {
653 return audio_manager_->HasAudioInputDevices();
654 }
655
656 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() {
657 // Since AudioManager::ShowAudioInputSettings can potentially launch external
658 // processes, do that in the FILE thread to not block the calling threads.
659 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
660 base::Bind(&ShowAudioInputSettingsOnFileThread,
661 audio_manager_));
662 }
663
664 SpeechRecognitionManagerImpl::Session::Session() 645 SpeechRecognitionManagerImpl::Session::Session()
665 : id(kSessionIDInvalid), 646 : id(kSessionIDInvalid),
666 abort_requested(false), 647 abort_requested(false),
667 listener_is_active(true) { 648 listener_is_active(true) {
668 } 649 }
669 650
670 SpeechRecognitionManagerImpl::Session::~Session() { 651 SpeechRecognitionManagerImpl::Session::~Session() {
671 } 652 }
672 653
673 } // namespace content 654 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognition_manager_impl.h ('k') | content/public/browser/speech_recognition_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698