| 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 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_requester.h" | 15 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 16 #include "content/public/browser/speech_recognition_event_listener.h" | 16 #include "content/public/browser/speech_recognition_event_listener.h" |
| 17 #include "content/public/browser/speech_recognition_manager.h" | 17 #include "content/public/browser/speech_recognition_manager.h" |
| 18 #include "content/public/browser/speech_recognition_session_config.h" | 18 #include "content/public/browser/speech_recognition_session_config.h" |
| 19 #include "content/public/browser/speech_recognition_session_context.h" | 19 #include "content/public/browser/speech_recognition_session_context.h" |
| 20 #include "content/public/common/speech_recognition_error.h" | 20 #include "content/public/common/speech_recognition_error.h" |
| 21 | 21 |
| 22 namespace media { |
| 23 class AudioManager; |
| 24 } |
| 25 |
| 22 namespace content { | 26 namespace content { |
| 23 class BrowserMainLoop; | 27 class BrowserMainLoop; |
| 28 class MediaStreamManager; |
| 24 class MediaStreamUIProxy; | 29 class MediaStreamUIProxy; |
| 25 class SpeechRecognitionManagerDelegate; | 30 class SpeechRecognitionManagerDelegate; |
| 26 class SpeechRecognizer; | 31 class SpeechRecognizer; |
| 27 | 32 |
| 28 // This is the manager for speech recognition. It is a single instance in | 33 // This is the manager for speech recognition. It is a single instance in |
| 29 // the browser process and can serve several requests. Each recognition request | 34 // the browser process and can serve several requests. Each recognition request |
| 30 // corresponds to a session, initiated via |CreateSession|. | 35 // corresponds to a session, initiated via |CreateSession|. |
| 31 // | 36 // |
| 32 // In any moment, the manager has a single session known as the primary session, | 37 // In any moment, the manager has a single session known as the primary session, |
| 33 // |primary_session_id_|. | 38 // |primary_session_id_|. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 virtual void OnRecognitionError( | 91 virtual void OnRecognitionError( |
| 87 int session_id, const SpeechRecognitionError& error) OVERRIDE; | 92 int session_id, const SpeechRecognitionError& error) OVERRIDE; |
| 88 virtual void OnAudioLevelsChange(int session_id, float volume, | 93 virtual void OnAudioLevelsChange(int session_id, float volume, |
| 89 float noise_volume) OVERRIDE; | 94 float noise_volume) OVERRIDE; |
| 90 | 95 |
| 91 protected: | 96 protected: |
| 92 // BrowserMainLoop is the only one allowed to istantiate and free us. | 97 // BrowserMainLoop is the only one allowed to istantiate and free us. |
| 93 friend class BrowserMainLoop; | 98 friend class BrowserMainLoop; |
| 94 // Needed for dtor. | 99 // Needed for dtor. |
| 95 friend struct base::DefaultDeleter<SpeechRecognitionManagerImpl>; | 100 friend struct base::DefaultDeleter<SpeechRecognitionManagerImpl>; |
| 96 SpeechRecognitionManagerImpl(); | 101 SpeechRecognitionManagerImpl(media::AudioManager* audio_manager, |
| 102 MediaStreamManager* media_stream_manager); |
| 97 virtual ~SpeechRecognitionManagerImpl(); | 103 virtual ~SpeechRecognitionManagerImpl(); |
| 98 | 104 |
| 99 private: | 105 private: |
| 100 // Data types for the internal Finite State Machine (FSM). | 106 // Data types for the internal Finite State Machine (FSM). |
| 101 enum FSMState { | 107 enum FSMState { |
| 102 SESSION_STATE_IDLE = 0, | 108 SESSION_STATE_IDLE = 0, |
| 103 SESSION_STATE_CAPTURING_AUDIO, | 109 SESSION_STATE_CAPTURING_AUDIO, |
| 104 SESSION_STATE_WAITING_FOR_RESULT, | 110 SESSION_STATE_WAITING_FOR_RESULT, |
| 105 SESSION_STATE_MAX_VALUE = SESSION_STATE_WAITING_FOR_RESULT | 111 SESSION_STATE_MAX_VALUE = SESSION_STATE_WAITING_FOR_RESULT |
| 106 }; | 112 }; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 void ResetCapturingSessionId(const Session& session); | 164 void ResetCapturingSessionId(const Session& session); |
| 159 void SessionDelete(Session* session); | 165 void SessionDelete(Session* session); |
| 160 void NotFeasible(const Session& session, FSMEvent event); | 166 void NotFeasible(const Session& session, FSMEvent event); |
| 161 | 167 |
| 162 bool SessionExists(int session_id) const; | 168 bool SessionExists(int session_id) const; |
| 163 Session* GetSession(int session_id) const; | 169 Session* GetSession(int session_id) const; |
| 164 SpeechRecognitionEventListener* GetListener(int session_id) const; | 170 SpeechRecognitionEventListener* GetListener(int session_id) const; |
| 165 SpeechRecognitionEventListener* GetDelegateListener() const; | 171 SpeechRecognitionEventListener* GetDelegateListener() const; |
| 166 int GetNextSessionID(); | 172 int GetNextSessionID(); |
| 167 | 173 |
| 174 media::AudioManager* audio_manager_; |
| 175 MediaStreamManager* media_stream_manager_; |
| 168 typedef std::map<int, Session*> SessionsTable; | 176 typedef std::map<int, Session*> SessionsTable; |
| 169 SessionsTable sessions_; | 177 SessionsTable sessions_; |
| 170 int primary_session_id_; | 178 int primary_session_id_; |
| 171 int last_session_id_; | 179 int last_session_id_; |
| 172 bool is_dispatching_event_; | 180 bool is_dispatching_event_; |
| 173 scoped_ptr<SpeechRecognitionManagerDelegate> delegate_; | 181 scoped_ptr<SpeechRecognitionManagerDelegate> delegate_; |
| 174 | 182 |
| 175 // Used for posting asynchronous tasks (on the IO thread) without worrying | 183 // Used for posting asynchronous tasks (on the IO thread) without worrying |
| 176 // about this class being destroyed in the meanwhile (due to browser shutdown) | 184 // about this class being destroyed in the meanwhile (due to browser shutdown) |
| 177 // since tasks pending on a destroyed WeakPtr are automatically discarded. | 185 // since tasks pending on a destroyed WeakPtr are automatically discarded. |
| 178 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_; | 186 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_; |
| 179 }; | 187 }; |
| 180 | 188 |
| 181 } // namespace content | 189 } // namespace content |
| 182 | 190 |
| 183 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ | 191 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
| OLD | NEW |