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