OLD | NEW |
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 "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/renderer_host/media/media_stream_ui_proxy.h" | 10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 using base::Callback; | 30 using base::Callback; |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 | 33 |
34 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_; | 34 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl; | 38 SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl; |
39 | 39 |
40 void ShowAudioInputSettingsOnFileThread() { | 40 void ShowAudioInputSettingsOnFileThread(media::AudioManager* audio_manager) { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
42 BrowserMainLoop::GetAudioManager()->ShowAudioInputSettings(); | 42 audio_manager->ShowAudioInputSettings(); |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { | 47 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { |
48 if (manager_for_tests_) | 48 if (manager_for_tests_) |
49 return manager_for_tests_; | 49 return manager_for_tests_; |
50 return SpeechRecognitionManagerImpl::GetInstance(); | 50 return SpeechRecognitionManagerImpl::GetInstance(); |
51 } | 51 } |
52 | 52 |
53 void SpeechRecognitionManager::SetManagerForTests( | 53 void SpeechRecognitionManager::SetManagerForTests( |
54 SpeechRecognitionManager* manager) { | 54 SpeechRecognitionManager* manager) { |
55 manager_for_tests_ = manager; | 55 manager_for_tests_ = manager; |
56 } | 56 } |
57 | 57 |
58 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { | 58 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { |
59 return g_speech_recognition_manager_impl; | 59 return g_speech_recognition_manager_impl; |
60 } | 60 } |
61 | 61 |
62 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() | 62 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl( |
63 : primary_session_id_(kSessionIDInvalid), | 63 media::AudioManager* audio_manager, |
| 64 MediaStreamManager* media_stream_manager) |
| 65 : audio_manager_(audio_manager), |
| 66 media_stream_manager_(media_stream_manager), |
| 67 primary_session_id_(kSessionIDInvalid), |
64 last_session_id_(kSessionIDInvalid), | 68 last_session_id_(kSessionIDInvalid), |
65 is_dispatching_event_(false), | 69 is_dispatching_event_(false), |
66 delegate_(GetContentClient()->browser()-> | 70 delegate_(GetContentClient()->browser()-> |
67 GetSpeechRecognitionManagerDelegate()), | 71 GetSpeechRecognitionManagerDelegate()), |
68 weak_factory_(this) { | 72 weak_factory_(this) { |
69 DCHECK(!g_speech_recognition_manager_impl); | 73 DCHECK(!g_speech_recognition_manager_impl); |
70 g_speech_recognition_manager_impl = this; | 74 g_speech_recognition_manager_impl = this; |
71 } | 75 } |
72 | 76 |
73 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { | 77 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 bool ask_user, | 180 bool ask_user, |
177 bool is_allowed) { | 181 bool is_allowed) { |
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
179 if (!SessionExists(session_id)) | 183 if (!SessionExists(session_id)) |
180 return; | 184 return; |
181 | 185 |
182 if (ask_user) { | 186 if (ask_user) { |
183 SessionsTable::iterator iter = sessions_.find(session_id); | 187 SessionsTable::iterator iter = sessions_.find(session_id); |
184 DCHECK(iter != sessions_.end()); | 188 DCHECK(iter != sessions_.end()); |
185 SpeechRecognitionSessionContext& context = iter->second->context; | 189 SpeechRecognitionSessionContext& context = iter->second->context; |
186 context.label = | 190 context.label = media_stream_manager_->MakeMediaAccessRequest( |
187 BrowserMainLoop::GetMediaStreamManager()->MakeMediaAccessRequest( | 191 context.render_process_id, |
188 context.render_process_id, | 192 context.render_view_id, |
189 context.render_view_id, | 193 StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE), |
190 StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE), | 194 GURL(context.context_name), |
191 GURL(context.context_name), | 195 base::Bind( |
192 base::Bind( | 196 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, |
193 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, | 197 weak_factory_.GetWeakPtr(), session_id)); |
194 weak_factory_.GetWeakPtr(), session_id)); | |
195 return; | 198 return; |
196 } | 199 } |
197 | 200 |
198 if (is_allowed) { | 201 if (is_allowed) { |
199 base::MessageLoop::current()->PostTask( | 202 base::MessageLoop::current()->PostTask( |
200 FROM_HERE, | 203 FROM_HERE, |
201 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 204 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
202 weak_factory_.GetWeakPtr(), | 205 weak_factory_.GetWeakPtr(), |
203 session_id, | 206 session_id, |
204 EVENT_START)); | 207 EVENT_START)); |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 SpeechRecognitionManagerImpl::GetDelegateListener() const { | 638 SpeechRecognitionManagerImpl::GetDelegateListener() const { |
636 return delegate_.get() ? delegate_->GetEventListener() : NULL; | 639 return delegate_.get() ? delegate_->GetEventListener() : NULL; |
637 } | 640 } |
638 | 641 |
639 const SpeechRecognitionSessionConfig& | 642 const SpeechRecognitionSessionConfig& |
640 SpeechRecognitionManagerImpl::GetSessionConfig(int session_id) const { | 643 SpeechRecognitionManagerImpl::GetSessionConfig(int session_id) const { |
641 return GetSession(session_id)->config; | 644 return GetSession(session_id)->config; |
642 } | 645 } |
643 | 646 |
644 bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { | 647 bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { |
645 return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); | 648 return audio_manager_->HasAudioInputDevices(); |
646 } | 649 } |
647 | 650 |
648 string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { | 651 string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { |
649 return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); | 652 return audio_manager_->GetAudioInputDeviceModel(); |
650 } | 653 } |
651 | 654 |
652 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { | 655 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { |
653 // Since AudioManager::ShowAudioInputSettings can potentially launch external | 656 // Since AudioManager::ShowAudioInputSettings can potentially launch external |
654 // processes, do that in the FILE thread to not block the calling threads. | 657 // processes, do that in the FILE thread to not block the calling threads. |
655 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 658 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
656 base::Bind(&ShowAudioInputSettingsOnFileThread)); | 659 base::Bind(&ShowAudioInputSettingsOnFileThread, |
| 660 audio_manager_)); |
657 } | 661 } |
658 | 662 |
659 SpeechRecognitionManagerImpl::Session::Session() | 663 SpeechRecognitionManagerImpl::Session::Session() |
660 : id(kSessionIDInvalid), | 664 : id(kSessionIDInvalid), |
661 listener_is_active(true) { | 665 listener_is_active(true) { |
662 } | 666 } |
663 | 667 |
664 SpeechRecognitionManagerImpl::Session::~Session() { | 668 SpeechRecognitionManagerImpl::Session::~Session() { |
665 } | 669 } |
666 | 670 |
667 } // namespace content | 671 } // namespace content |
OLD | NEW |