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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
jam
2012/05/15 16:38:31
nit: not needed anymore
| |
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 content { | 22 namespace content { |
23 class BrowserMainLoop; | |
23 class SpeechRecognitionManagerDelegate; | 24 class SpeechRecognitionManagerDelegate; |
24 } | 25 } |
25 | 26 |
26 namespace speech { | 27 namespace speech { |
27 | 28 |
28 class SpeechRecognizerImpl; | 29 class SpeechRecognizerImpl; |
29 | 30 |
30 // This is the manager for speech recognition. It is a singleton instance in | 31 // This is the manager for speech recognition. It is a singleton instance in |
31 // the browser process and can serve several requests. Each recognition request | 32 // the browser process and can serve several requests. Each recognition request |
32 // corresponds to a session, initiated via |CreateSession|. | 33 // corresponds to a session, initiated via |CreateSession|. |
(...skipping 11 matching lines...) Expand all Loading... | |
44 // - Handles the instantiation of SpeechRecognitionEngine objects when | 45 // - Handles the instantiation of SpeechRecognitionEngine objects when |
45 // requested by SpeechRecognitionSessions. | 46 // requested by SpeechRecognitionSessions. |
46 // - Relays recognition results/status/error events of each session to the | 47 // - Relays recognition results/status/error events of each session to the |
47 // corresponding listener (demuxing on the base of their session_id). | 48 // corresponding listener (demuxing on the base of their session_id). |
48 // - Relays also recognition results/status/error events of every session to | 49 // - Relays also recognition results/status/error events of every session to |
49 // the catch-all snoop listener (optionally) provided by the delegate. | 50 // the catch-all snoop listener (optionally) provided by the delegate. |
50 class CONTENT_EXPORT SpeechRecognitionManagerImpl : | 51 class CONTENT_EXPORT SpeechRecognitionManagerImpl : |
51 public NON_EXPORTED_BASE(content::SpeechRecognitionManager), | 52 public NON_EXPORTED_BASE(content::SpeechRecognitionManager), |
52 public content::SpeechRecognitionEventListener { | 53 public content::SpeechRecognitionEventListener { |
53 public: | 54 public: |
55 // Returns the current SpeechRecognitionManagerImpl. Can be called only after | |
56 // the RecognitionMnager has been created (by BrowserMainLoop). | |
54 static SpeechRecognitionManagerImpl* GetInstance(); | 57 static SpeechRecognitionManagerImpl* GetInstance(); |
55 | 58 |
56 // SpeechRecognitionManager implementation. | 59 // SpeechRecognitionManager implementation. |
57 virtual int CreateSession( | 60 virtual int CreateSession( |
58 const content::SpeechRecognitionSessionConfig& config) OVERRIDE; | 61 const content::SpeechRecognitionSessionConfig& config) OVERRIDE; |
59 virtual void StartSession(int session_id) OVERRIDE; | 62 virtual void StartSession(int session_id) OVERRIDE; |
60 virtual void AbortSession(int session_id) OVERRIDE; | 63 virtual void AbortSession(int session_id) OVERRIDE; |
61 virtual void AbortAllSessionsForListener( | 64 virtual void AbortAllSessionsForListener( |
62 content::SpeechRecognitionEventListener* listener) OVERRIDE; | 65 content::SpeechRecognitionEventListener* listener) OVERRIDE; |
63 virtual void StopAudioCaptureForSession(int session_id) OVERRIDE; | 66 virtual void StopAudioCaptureForSession(int session_id) OVERRIDE; |
(...skipping 19 matching lines...) Expand all Loading... | |
83 virtual void OnAudioEnd(int session_id) OVERRIDE; | 86 virtual void OnAudioEnd(int session_id) OVERRIDE; |
84 virtual void OnRecognitionEnd(int session_id) OVERRIDE; | 87 virtual void OnRecognitionEnd(int session_id) OVERRIDE; |
85 virtual void OnRecognitionResult( | 88 virtual void OnRecognitionResult( |
86 int session_id, const content::SpeechRecognitionResult& result) OVERRIDE; | 89 int session_id, const content::SpeechRecognitionResult& result) OVERRIDE; |
87 virtual void OnRecognitionError( | 90 virtual void OnRecognitionError( |
88 int session_id, const content::SpeechRecognitionError& error) OVERRIDE; | 91 int session_id, const content::SpeechRecognitionError& error) OVERRIDE; |
89 virtual void OnAudioLevelsChange(int session_id, float volume, | 92 virtual void OnAudioLevelsChange(int session_id, float volume, |
90 float noise_volume) OVERRIDE; | 93 float noise_volume) OVERRIDE; |
91 | 94 |
92 protected: | 95 protected: |
93 // Private constructor to enforce singleton. | 96 // BrowserMainLoop is the only one allowed to istantiate and free us. |
94 friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; | 97 friend class content::BrowserMainLoop; |
98 friend class scoped_ptr<SpeechRecognitionManagerImpl>; // Needed for dtor. | |
95 SpeechRecognitionManagerImpl(); | 99 SpeechRecognitionManagerImpl(); |
96 virtual ~SpeechRecognitionManagerImpl(); | 100 virtual ~SpeechRecognitionManagerImpl(); |
97 | 101 |
98 private: | 102 private: |
99 // Data types for the internal Finite State Machine (FSM). | 103 // Data types for the internal Finite State Machine (FSM). |
100 enum FSMState { | 104 enum FSMState { |
101 SESSION_STATE_IDLE = 0, | 105 SESSION_STATE_IDLE = 0, |
102 SESSION_STATE_CAPTURING_AUDIO, | 106 SESSION_STATE_CAPTURING_AUDIO, |
103 SESSION_STATE_WAITING_FOR_RESULT, | 107 SESSION_STATE_WAITING_FOR_RESULT, |
104 SESSION_STATE_MAX_VALUE = SESSION_STATE_WAITING_FOR_RESULT | 108 SESSION_STATE_MAX_VALUE = SESSION_STATE_WAITING_FOR_RESULT |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 const Session& GetSession(int session_id) const; | 155 const Session& GetSession(int session_id) const; |
152 content::SpeechRecognitionEventListener* GetListener(int session_id) const; | 156 content::SpeechRecognitionEventListener* GetListener(int session_id) const; |
153 content::SpeechRecognitionEventListener* GetDelegateListener() const; | 157 content::SpeechRecognitionEventListener* GetDelegateListener() const; |
154 int GetNextSessionID(); | 158 int GetNextSessionID(); |
155 | 159 |
156 typedef std::map<int, Session> SessionsTable; | 160 typedef std::map<int, Session> SessionsTable; |
157 SessionsTable sessions_; | 161 SessionsTable sessions_; |
158 int session_id_capturing_audio_; | 162 int session_id_capturing_audio_; |
159 int last_session_id_; | 163 int last_session_id_; |
160 bool is_dispatching_event_; | 164 bool is_dispatching_event_; |
161 content::SpeechRecognitionManagerDelegate* delegate_; | 165 scoped_ptr<content::SpeechRecognitionManagerDelegate> delegate_; |
162 }; | 166 }; |
163 | 167 |
164 } // namespace speech | 168 } // namespace speech |
165 | 169 |
166 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ | 170 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
OLD | NEW |