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 content { | 22 namespace content { |
23 class BrowserMainLoop; | 23 class BrowserMainLoop; |
| 24 class MediaStreamUIProxy; |
24 class SpeechRecognitionManagerDelegate; | 25 class SpeechRecognitionManagerDelegate; |
25 class SpeechRecognizer; | 26 class SpeechRecognizer; |
26 | 27 |
27 // This is the manager for speech recognition. It is a single instance in | 28 // This is the manager for speech recognition. It is a single instance in |
28 // the browser process and can serve several requests. Each recognition request | 29 // the browser process and can serve several requests. Each recognition request |
29 // corresponds to a session, initiated via |CreateSession|. | 30 // corresponds to a session, initiated via |CreateSession|. |
30 // | 31 // |
31 // In any moment, the manager has a single session known as the primary session, | 32 // In any moment, the manager has a single session known as the primary session, |
32 // |primary_session_id_|. | 33 // |primary_session_id_|. |
33 // This is the session that is capturing audio, waiting for user permission, | 34 // This is the session that is capturing audio, waiting for user permission, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 117 |
117 struct Session { | 118 struct Session { |
118 Session(); | 119 Session(); |
119 ~Session(); | 120 ~Session(); |
120 | 121 |
121 int id; | 122 int id; |
122 bool listener_is_active; | 123 bool listener_is_active; |
123 SpeechRecognitionSessionConfig config; | 124 SpeechRecognitionSessionConfig config; |
124 SpeechRecognitionSessionContext context; | 125 SpeechRecognitionSessionContext context; |
125 scoped_refptr<SpeechRecognizer> recognizer; | 126 scoped_refptr<SpeechRecognizer> recognizer; |
| 127 scoped_ptr<MediaStreamUIProxy> ui; |
126 }; | 128 }; |
127 | 129 |
128 // Callback issued by the SpeechRecognitionManagerDelegate for reporting | 130 // Callback issued by the SpeechRecognitionManagerDelegate for reporting |
129 // asynchronously the result of the CheckRecognitionIsAllowed call. | 131 // asynchronously the result of the CheckRecognitionIsAllowed call. |
130 void RecognitionAllowedCallback(int session_id, | 132 void RecognitionAllowedCallback(int session_id, |
131 bool ask_user, | 133 bool ask_user, |
132 bool is_allowed); | 134 bool is_allowed); |
133 | 135 |
134 // Callback to get back the result of a media request. |label| is the string | 136 // Callback to get back the result of a media request. |devices| is an array |
135 // to identify the request; |devices| is an array of devices approved to be | 137 // of devices approved to be used for the request, |devices| is empty if the |
136 // used for the request, |devices| is empty if the users deny the request. | 138 // users deny the request. |
137 void MediaRequestPermissionCallback(const std::string& label, | 139 void MediaRequestPermissionCallback(int session_id, |
138 const MediaStreamDevices& devices); | 140 const MediaStreamDevices& devices, |
| 141 scoped_ptr<MediaStreamUIProxy> stream_ui); |
139 | 142 |
140 // Entry point for pushing any external event into the session handling FSM. | 143 // Entry point for pushing any external event into the session handling FSM. |
141 void DispatchEvent(int session_id, FSMEvent event); | 144 void DispatchEvent(int session_id, FSMEvent event); |
142 | 145 |
143 // Defines the behavior of the session handling FSM, selecting the appropriate | 146 // Defines the behavior of the session handling FSM, selecting the appropriate |
144 // transition according to the session, its current state and the event. | 147 // transition according to the session, its current state and the event. |
145 void ExecuteTransitionAndGetNextState( | 148 void ExecuteTransitionAndGetNextState(Session* session, |
146 const Session& session, FSMState session_state, FSMEvent event); | 149 FSMState session_state, |
| 150 FSMEvent event); |
147 | 151 |
148 // Retrieves the state of the session, enquiring directly the recognizer. | 152 // Retrieves the state of the session, enquiring directly the recognizer. |
149 FSMState GetSessionState(int session_id) const; | 153 FSMState GetSessionState(int session_id) const; |
150 | 154 |
151 // The methods below handle transitions of the session handling FSM. | 155 // The methods below handle transitions of the session handling FSM. |
152 void SessionStart(const Session& session); | 156 void SessionStart(const Session& session); |
153 void SessionAbort(const Session& session); | 157 void SessionAbort(const Session& session); |
154 void SessionStopAudioCapture(const Session& session); | 158 void SessionStopAudioCapture(const Session& session); |
155 void ResetCapturingSessionId(const Session& session); | 159 void ResetCapturingSessionId(const Session& session); |
156 void SessionDelete(const Session& session); | 160 void SessionDelete(Session* session); |
157 void NotFeasible(const Session& session, FSMEvent event); | 161 void NotFeasible(const Session& session, FSMEvent event); |
158 | 162 |
159 bool SessionExists(int session_id) const; | 163 bool SessionExists(int session_id) const; |
160 const Session& GetSession(int session_id) const; | 164 Session* GetSession(int session_id) const; |
161 SpeechRecognitionEventListener* GetListener(int session_id) const; | 165 SpeechRecognitionEventListener* GetListener(int session_id) const; |
162 SpeechRecognitionEventListener* GetDelegateListener() const; | 166 SpeechRecognitionEventListener* GetDelegateListener() const; |
163 int GetNextSessionID(); | 167 int GetNextSessionID(); |
164 | 168 |
165 typedef std::map<int, Session> SessionsTable; | 169 typedef std::map<int, Session*> SessionsTable; |
166 SessionsTable sessions_; | 170 SessionsTable sessions_; |
167 int primary_session_id_; | 171 int primary_session_id_; |
168 int last_session_id_; | 172 int last_session_id_; |
169 bool is_dispatching_event_; | 173 bool is_dispatching_event_; |
170 scoped_ptr<SpeechRecognitionManagerDelegate> delegate_; | 174 scoped_ptr<SpeechRecognitionManagerDelegate> delegate_; |
171 | 175 |
172 // Used for posting asynchronous tasks (on the IO thread) without worrying | 176 // Used for posting asynchronous tasks (on the IO thread) without worrying |
173 // about this class being destroyed in the meanwhile (due to browser shutdown) | 177 // about this class being destroyed in the meanwhile (due to browser shutdown) |
174 // since tasks pending on a destroyed WeakPtr are automatically discarded. | 178 // since tasks pending on a destroyed WeakPtr are automatically discarded. |
175 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_; | 179 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_; |
176 }; | 180 }; |
177 | 181 |
178 } // namespace content | 182 } // namespace content |
179 | 183 |
180 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ | 184 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
OLD | NEW |