| 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 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { | 43 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { |
| 44 return SpeechRecognitionManagerImpl::GetInstance(); | 44 return SpeechRecognitionManagerImpl::GetInstance(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 #if !defined(OS_IOS) | 47 #if !defined(OS_IOS) |
| 48 class SpeechRecognitionManagerImpl::PermissionRequest | 48 class SpeechRecognitionManagerImpl::PermissionRequest |
| 49 : public media_stream::MediaStreamRequester { | 49 : public MediaStreamRequester { |
| 50 public: | 50 public: |
| 51 PermissionRequest(int session_id, | 51 PermissionRequest(int session_id, |
| 52 const base::Callback<void(bool is_allowed)>& callback) | 52 const base::Callback<void(bool is_allowed)>& callback) |
| 53 : session_id_(session_id), | 53 : session_id_(session_id), |
| 54 callback_(callback), | 54 callback_(callback), |
| 55 started_(false) { | 55 started_(false) { |
| 56 } | 56 } |
| 57 | 57 |
| 58 virtual ~PermissionRequest() { | 58 virtual ~PermissionRequest() { |
| 59 if (started_) | 59 if (started_) |
| 60 Abort(); | 60 Abort(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void Start(int render_process_id, int render_view_id, const GURL& origin) { | 63 void Start(int render_process_id, int render_view_id, const GURL& origin) { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 65 started_ = true; | 65 started_ = true; |
| 66 BrowserMainLoop::GetMediaStreamManager()->GenerateStream( | 66 BrowserMainLoop::GetMediaStreamManager()->GenerateStream( |
| 67 this, | 67 this, |
| 68 render_process_id, | 68 render_process_id, |
| 69 render_view_id, | 69 render_view_id, |
| 70 media_stream::StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, | 70 StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_DEVICE_VIDEO_CAPTURE), |
| 71 MEDIA_DEVICE_VIDEO_CAPTURE), | |
| 72 origin, | 71 origin, |
| 73 &label_); | 72 &label_); |
| 74 } | 73 } |
| 75 | 74 |
| 76 void Abort() { | 75 void Abort() { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 78 started_ = false; | 77 started_ = false; |
| 79 BrowserMainLoop::GetMediaStreamManager()->CancelRequest(label_); | 78 BrowserMainLoop::GetMediaStreamManager()->CancelRequest(label_); |
| 80 } | 79 } |
| 81 | 80 |
| 82 int Session() const { return session_id_; } | 81 int Session() const { return session_id_; } |
| 83 | 82 |
| 84 // MediaStreamRequester methods. | 83 // MediaStreamRequester methods. |
| 85 virtual void StreamGenerated( | 84 virtual void StreamGenerated( |
| 86 const std::string& label, | 85 const std::string& label, |
| 87 const media_stream::StreamDeviceInfoArray& audio_devices, | 86 const StreamDeviceInfoArray& audio_devices, |
| 88 const media_stream::StreamDeviceInfoArray& video_devices) OVERRIDE { | 87 const StreamDeviceInfoArray& video_devices) OVERRIDE { |
| 89 // TODO(hans): One day it would be nice to actually use the generated stream | 88 // TODO(hans): One day it would be nice to actually use the generated stream |
| 90 // but right now we only use it to request permission, and then we dump it. | 89 // but right now we only use it to request permission, and then we dump it. |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 92 started_ = false; | 91 started_ = false; |
| 93 BrowserThread::PostTask( | 92 BrowserThread::PostTask( |
| 94 BrowserThread::IO, | 93 BrowserThread::IO, |
| 95 FROM_HERE, | 94 FROM_HERE, |
| 96 base::Bind(&media_stream::MediaStreamManager::StopGeneratedStream, | 95 base::Bind(&MediaStreamManager::StopGeneratedStream, |
| 97 base::Unretained(BrowserMainLoop::GetMediaStreamManager()), | 96 base::Unretained(BrowserMainLoop::GetMediaStreamManager()), |
| 98 label)); | 97 label)); |
| 99 callback_.Run(true); | 98 callback_.Run(true); |
| 100 } | 99 } |
| 101 | 100 |
| 102 virtual void StreamGenerationFailed(const std::string& label) OVERRIDE { | 101 virtual void StreamGenerationFailed(const std::string& label) OVERRIDE { |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 104 started_ = false; | 103 started_ = false; |
| 105 callback_.Run(false); | 104 callback_.Run(false); |
| 106 } | 105 } |
| 107 | 106 |
| 108 // The callbacks below are ignored. | 107 // The callbacks below are ignored. |
| 109 virtual void DevicesEnumerated( | 108 virtual void DevicesEnumerated( |
| 110 const std::string& label, | 109 const std::string& label, |
| 111 const media_stream::StreamDeviceInfoArray& devices) OVERRIDE {} | 110 const StreamDeviceInfoArray& devices) OVERRIDE {} |
| 112 virtual void DeviceOpened( | 111 virtual void DeviceOpened( |
| 113 const std::string& label, | 112 const std::string& label, |
| 114 const media_stream::StreamDeviceInfo& device_info) OVERRIDE {} | 113 const StreamDeviceInfo& device_info) OVERRIDE {} |
| 115 | 114 |
| 116 private: | 115 private: |
| 117 int session_id_; | 116 int session_id_; |
| 118 base::Callback<void(bool is_allowed)> callback_; | 117 base::Callback<void(bool is_allowed)> callback_; |
| 119 std::string label_; | 118 std::string label_; |
| 120 bool started_; | 119 bool started_; |
| 121 }; | 120 }; |
| 122 #endif // !defined(OS_IOS) | 121 #endif // !defined(OS_IOS) |
| 123 | 122 |
| 124 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { | 123 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 672 |
| 674 SpeechRecognitionManagerImpl::Session::Session() | 673 SpeechRecognitionManagerImpl::Session::Session() |
| 675 : id(kSessionIDInvalid), | 674 : id(kSessionIDInvalid), |
| 676 listener_is_active(true) { | 675 listener_is_active(true) { |
| 677 } | 676 } |
| 678 | 677 |
| 679 SpeechRecognitionManagerImpl::Session::~Session() { | 678 SpeechRecognitionManagerImpl::Session::~Session() { |
| 680 } | 679 } |
| 681 | 680 |
| 682 } // namespace content | 681 } // namespace content |
| OLD | NEW |