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

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

Issue 2675713002: Switch Speech Recognition to asynchronous callback-based AudioManager interactions. (Closed)
Patch Set: review comments addressed Created 3 years, 10 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
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 <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
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 AudioSystem;
24 }
25
22 namespace content { 26 namespace content {
23 class BrowserMainLoop; 27 class BrowserMainLoop;
24 class MediaStreamManager; 28 class MediaStreamManager;
25 class MediaStreamUIProxy; 29 class MediaStreamUIProxy;
26 class SpeechRecognitionManagerDelegate; 30 class SpeechRecognitionManagerDelegate;
27 class SpeechRecognizer; 31 class SpeechRecognizer;
28 32
29 // 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
30 // the browser process and can serve several requests. Each recognition request 34 // the browser process and can serve several requests. Each recognition request
31 // corresponds to a session, initiated via |CreateSession|. 35 // corresponds to a session, initiated via |CreateSession|.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 float volume, 89 float volume,
86 float noise_volume) override; 90 float noise_volume) override;
87 91
88 SpeechRecognitionManagerDelegate* delegate() const { return delegate_.get(); } 92 SpeechRecognitionManagerDelegate* delegate() const { return delegate_.get(); }
89 93
90 protected: 94 protected:
91 // BrowserMainLoop is the only one allowed to istantiate and free us. 95 // BrowserMainLoop is the only one allowed to istantiate and free us.
92 friend class BrowserMainLoop; 96 friend class BrowserMainLoop;
93 // Needed for dtor. 97 // Needed for dtor.
94 friend std::default_delete<SpeechRecognitionManagerImpl>; 98 friend std::default_delete<SpeechRecognitionManagerImpl>;
95 SpeechRecognitionManagerImpl(MediaStreamManager* media_stream_manager); 99 SpeechRecognitionManagerImpl(media::AudioSystem* audio_system,
100 MediaStreamManager* media_stream_manager);
96 ~SpeechRecognitionManagerImpl() override; 101 ~SpeechRecognitionManagerImpl() override;
97 102
98 private: 103 private:
99 // Data types for the internal Finite State Machine (FSM). 104 // Data types for the internal Finite State Machine (FSM).
100 enum FSMState { 105 enum FSMState {
101 SESSION_STATE_IDLE = 0, 106 SESSION_STATE_IDLE = 0,
102 SESSION_STATE_CAPTURING_AUDIO, 107 SESSION_STATE_CAPTURING_AUDIO,
103 SESSION_STATE_WAITING_FOR_RESULT, 108 SESSION_STATE_WAITING_FOR_RESULT,
104 SESSION_STATE_MAX_VALUE = SESSION_STATE_WAITING_FOR_RESULT 109 SESSION_STATE_MAX_VALUE = SESSION_STATE_WAITING_FOR_RESULT
105 }; 110 };
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 void ResetCapturingSessionId(const Session& session); 164 void ResetCapturingSessionId(const Session& session);
160 void SessionDelete(Session* session); 165 void SessionDelete(Session* session);
161 void NotFeasible(const Session& session, FSMEvent event); 166 void NotFeasible(const Session& session, FSMEvent event);
162 167
163 bool SessionExists(int session_id) const; 168 bool SessionExists(int session_id) const;
164 Session* GetSession(int session_id) const; 169 Session* GetSession(int session_id) const;
165 SpeechRecognitionEventListener* GetListener(int session_id) const; 170 SpeechRecognitionEventListener* GetListener(int session_id) const;
166 SpeechRecognitionEventListener* GetDelegateListener() const; 171 SpeechRecognitionEventListener* GetDelegateListener() const;
167 int GetNextSessionID(); 172 int GetNextSessionID();
168 173
174 media::AudioSystem* audio_system_;
169 MediaStreamManager* media_stream_manager_; 175 MediaStreamManager* media_stream_manager_;
170 typedef std::map<int, Session*> SessionsTable; 176 typedef std::map<int, Session*> SessionsTable;
171 SessionsTable sessions_; 177 SessionsTable sessions_;
172 int primary_session_id_; 178 int primary_session_id_;
173 int last_session_id_; 179 int last_session_id_;
174 bool is_dispatching_event_; 180 bool is_dispatching_event_;
175 std::unique_ptr<SpeechRecognitionManagerDelegate> delegate_; 181 std::unique_ptr<SpeechRecognitionManagerDelegate> delegate_;
176 182
177 // Used for posting asynchronous tasks (on the IO thread) without worrying 183 // Used for posting asynchronous tasks (on the IO thread) without worrying
178 // 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)
179 // since tasks pending on a destroyed WeakPtr are automatically discarded. 185 // since tasks pending on a destroyed WeakPtr are automatically discarded.
180 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_; 186 base::WeakPtrFactory<SpeechRecognitionManagerImpl> weak_factory_;
181 }; 187 };
182 188
183 } // namespace content 189 } // namespace content
184 190
185 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ 191 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698