Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: content/browser/speech/speech_recognition_manager_impl.h

Issue 10933018: Speech JavaScript API: Use the MediaStreamManager to ask for user permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove media_stream_manager_ Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/public/browser/speech_recognition_event_listener.h" 16 #include "content/public/browser/speech_recognition_event_listener.h"
16 #include "content/public/browser/speech_recognition_manager.h" 17 #include "content/public/browser/speech_recognition_manager.h"
17 #include "content/public/browser/speech_recognition_session_config.h" 18 #include "content/public/browser/speech_recognition_session_config.h"
18 #include "content/public/browser/speech_recognition_session_context.h" 19 #include "content/public/browser/speech_recognition_session_context.h"
19 #include "content/public/common/speech_recognition_error.h" 20 #include "content/public/common/speech_recognition_error.h"
20 21
21 namespace content { 22 namespace content {
22 class BrowserMainLoop; 23 class BrowserMainLoop;
23 class SpeechRecognitionManagerDelegate; 24 class SpeechRecognitionManagerDelegate;
24 } 25 }
25 26
27 namespace media_stream {
28 class MediaStreamManager;
29 }
30
26 namespace speech { 31 namespace speech {
27 32
28 class SpeechRecognizer; 33 class SpeechRecognizer;
29 34
30 // This is the manager for speech recognition. It is a single instance in 35 // This is the manager for speech recognition. It is a single instance in
31 // the browser process and can serve several requests. Each recognition request 36 // the browser process and can serve several requests. Each recognition request
32 // corresponds to a session, initiated via |CreateSession|. 37 // corresponds to a session, initiated via |CreateSession|.
33 // In every moment the manager has at most one session capturing audio, which 38 //
34 // is identified by |session_id_capturing_audio_|. However, multiple sessions 39 // In any moment, the manager has a single session known as the primary session,
35 // can live in parallel in respect of the aforementioned constraint, i.e. while 40 // |primary_session_id_|.
36 // waiting for results. 41 // This is the session that is capturing audio, waiting for user permission,
37 // This class does not handle user interface objects (bubbles, tray icon). 42 // etc. There may also be other, non-primary, sessions living in parallel that
38 // Those are managed by the delegate, which receives a copy of all sessions 43 // are waiting for results but not recording audio.
39 // events.
40 // 44 //
41 // The SpeechRecognitionManager has the following responsibilities: 45 // The SpeechRecognitionManager has the following responsibilities:
42 // - Handles requests received from various render views and makes sure only 46 // - Handles requests received from various render views and makes sure only
43 // one of them accesses the audio device at any given time. 47 // one of them accesses the audio device at any given time.
44 // - Handles the instantiation of SpeechRecognitionEngine objects when 48 // - Handles the instantiation of SpeechRecognitionEngine objects when
45 // requested by SpeechRecognitionSessions. 49 // requested by SpeechRecognitionSessions.
46 // - Relays recognition results/status/error events of each session to the 50 // - Relays recognition results/status/error events of each session to the
47 // corresponding listener (demuxing on the base of their session_id). 51 // corresponding listener (demuxing on the base of their session_id).
48 // - Relays also recognition results/status/error events of every session to 52 // - Relays also recognition results/status/error events of every session to
49 // the catch-all snoop listener (optionally) provided by the delegate. 53 // the catch-all snoop listener (optionally) provided by the delegate.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 127
124 int id; 128 int id;
125 bool listener_is_active; 129 bool listener_is_active;
126 content::SpeechRecognitionSessionConfig config; 130 content::SpeechRecognitionSessionConfig config;
127 content::SpeechRecognitionSessionContext context; 131 content::SpeechRecognitionSessionContext context;
128 scoped_refptr<SpeechRecognizer> recognizer; 132 scoped_refptr<SpeechRecognizer> recognizer;
129 }; 133 };
130 134
131 // Callback issued by the SpeechRecognitionManagerDelegate for reporting 135 // Callback issued by the SpeechRecognitionManagerDelegate for reporting
132 // asynchronously the result of the CheckRecognitionIsAllowed call. 136 // asynchronously the result of the CheckRecognitionIsAllowed call.
133 void RecognitionAllowedCallback(int session_id, bool is_allowed); 137 void RecognitionAllowedCallback(int session_id,
138 bool ask_user,
139 bool is_allowed);
134 140
135 // Entry point for pushing any external event into the session handling FSM. 141 // Entry point for pushing any external event into the session handling FSM.
136 void DispatchEvent(int session_id, FSMEvent event); 142 void DispatchEvent(int session_id, FSMEvent event);
137 143
138 // Defines the behavior of the session handling FSM, selecting the appropriate 144 // Defines the behavior of the session handling FSM, selecting the appropriate
139 // transition according to the session, its current state and the event. 145 // transition according to the session, its current state and the event.
140 void ExecuteTransitionAndGetNextState( 146 void ExecuteTransitionAndGetNextState(
141 const Session& session, FSMState session_state, FSMEvent event); 147 const Session& session, FSMState session_state, FSMEvent event);
142 148
143 // Retrieves the state of the session, enquiring directly the recognizer. 149 // Retrieves the state of the session, enquiring directly the recognizer.
144 FSMState GetSessionState(int session_id) const; 150 FSMState GetSessionState(int session_id) const;
145 151
146 // The methods below handle transitions of the session handling FSM. 152 // The methods below handle transitions of the session handling FSM.
147 void SessionStart(const Session& session); 153 void SessionStart(const Session& session);
148 void SessionAbort(const Session& session); 154 void SessionAbort(const Session& session);
149 void SessionStopAudioCapture(const Session& session); 155 void SessionStopAudioCapture(const Session& session);
150 void ResetCapturingSessionId(const Session& session); 156 void ResetCapturingSessionId(const Session& session);
151 void SessionDelete(const Session& session); 157 void SessionDelete(const Session& session);
152 void NotFeasible(const Session& session, FSMEvent event); 158 void NotFeasible(const Session& session, FSMEvent event);
153 159
154 bool SessionExists(int session_id) const; 160 bool SessionExists(int session_id) const;
155 const Session& GetSession(int session_id) const; 161 const Session& GetSession(int session_id) const;
156 content::SpeechRecognitionEventListener* GetListener(int session_id) const; 162 content::SpeechRecognitionEventListener* GetListener(int session_id) const;
157 content::SpeechRecognitionEventListener* GetDelegateListener() const; 163 content::SpeechRecognitionEventListener* GetDelegateListener() const;
158 int GetNextSessionID(); 164 int GetNextSessionID();
159 165
160 typedef std::map<int, Session> SessionsTable; 166 typedef std::map<int, Session> SessionsTable;
161 SessionsTable sessions_; 167 SessionsTable sessions_;
162 int session_id_capturing_audio_; 168 int primary_session_id_;
163 int last_session_id_; 169 int last_session_id_;
164 bool is_dispatching_event_; 170 bool is_dispatching_event_;
165 scoped_ptr<content::SpeechRecognitionManagerDelegate> delegate_; 171 scoped_ptr<content::SpeechRecognitionManagerDelegate> delegate_;
166 172
167 // Used for posting asynchronous tasks (on the IO thread) without worrying 173 // Used for posting asynchronous tasks (on the IO thread) without worrying
168 // about this class being destroyed in the meanwhile (due to browser shutdown) 174 // about this class being destroyed in the meanwhile (due to browser shutdown)
169 // since tasks pending on a destroyed WeakPtr are automatically discarded. 175 // since tasks pending on a destroyed WeakPtr are automatically discarded.
170 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_; 176 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_;
177
178 class PermissionRequest;
179 scoped_ptr<PermissionRequest> permission_request_;
171 }; 180 };
172 181
173 } // namespace speech 182 } // namespace speech
174 183
175 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ 184 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698