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 CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/string16.h" | |
hans
2012/05/15 13:35:17
sort order
Primiano Tucci (use gerrit)
2012/05/16 10:16:00
Done.
| |
11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/speech_recognition_event_listener.h" | 17 #include "content/public/browser/speech_recognition_event_listener.h" |
17 | 18 |
18 class Extension; | 19 class Extension; |
19 class Profile; | 20 class Profile; |
20 class SpeechRecognitionTrayIconController; | |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 class NotificationRegistrar; | 23 class NotificationRegistrar; |
24 struct SpeechRecognitionError; | 24 struct SpeechRecognitionError; |
25 class SpeechRecognitionManager; | |
25 struct SpeechRecognitionResult; | 26 struct SpeechRecognitionResult; |
26 class SpeechRecognizer; | |
27 } | 27 } |
28 | 28 |
29 namespace net { | 29 namespace net { |
30 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
31 } | 31 } |
32 | 32 |
33 // Used for API tests. | 33 // Used for API tests. |
34 class SpeechInputExtensionInterface { | 34 class SpeechInputExtensionInterface { |
35 public: | 35 public: |
36 SpeechInputExtensionInterface(); | 36 SpeechInputExtensionInterface(); |
37 virtual ~SpeechInputExtensionInterface(); | 37 virtual ~SpeechInputExtensionInterface(); |
38 | 38 |
39 // Called from the IO thread. | 39 // Called from the IO thread. |
40 virtual void StartRecording( | 40 virtual void StartRecording( |
41 content::SpeechRecognitionEventListener* listener, | 41 content::SpeechRecognitionEventListener* listener, |
42 net::URLRequestContextGetter* context_getter, | 42 net::URLRequestContextGetter* context_getter, |
43 int session_id, | 43 const string16& extension_name, |
44 const std::string& language, | 44 const std::string& language, |
45 const std::string& grammar, | 45 const std::string& grammar, |
46 bool filter_profanities) = 0; | 46 bool filter_profanities, |
47 bool show_notification) = 0; | |
47 | 48 |
48 virtual void StopRecording(bool recognition_failed) = 0; | 49 virtual void StopRecording(bool recognition_failed) = 0; |
49 virtual bool HasAudioInputDevices() = 0; | 50 virtual bool HasAudioInputDevices() = 0; |
50 virtual bool IsCapturingAudio() = 0; | 51 virtual bool IsCapturingAudio() = 0; |
51 | 52 |
52 // Called from the UI thread. | 53 // Called from the UI thread. |
53 virtual bool HasValidRecognizer() = 0; | 54 virtual bool HasValidRecognizer() = 0; |
54 }; | 55 }; |
55 | 56 |
56 // Manages the speech input requests and responses from the extensions | 57 // Manages the speech input requests and responses from the extensions |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 SpeechInputExtensionInterface* GetSpeechInputExtensionInterface(); | 138 SpeechInputExtensionInterface* GetSpeechInputExtensionInterface(); |
138 | 139 |
139 private: | 140 private: |
140 // SpeechInputExtensionInterface methods: | 141 // SpeechInputExtensionInterface methods: |
141 virtual bool IsCapturingAudio() OVERRIDE; | 142 virtual bool IsCapturingAudio() OVERRIDE; |
142 virtual bool HasAudioInputDevices() OVERRIDE; | 143 virtual bool HasAudioInputDevices() OVERRIDE; |
143 virtual bool HasValidRecognizer() OVERRIDE; | 144 virtual bool HasValidRecognizer() OVERRIDE; |
144 virtual void StartRecording( | 145 virtual void StartRecording( |
145 content::SpeechRecognitionEventListener* listener, | 146 content::SpeechRecognitionEventListener* listener, |
146 net::URLRequestContextGetter* context_getter, | 147 net::URLRequestContextGetter* context_getter, |
147 int session_id, | 148 const string16& extension_name, |
148 const std::string& language, | 149 const std::string& language, |
149 const std::string& grammar, | 150 const std::string& grammar, |
150 bool filter_profanities) OVERRIDE; | 151 bool filter_profanities, |
152 bool show_notification) OVERRIDE; | |
151 | 153 |
152 virtual void StopRecording(bool recognition_failed) OVERRIDE; | 154 virtual void StopRecording(bool recognition_failed) OVERRIDE; |
153 | 155 |
154 // Internal methods. | 156 // Internal methods. |
155 void StartOnIOThread( | 157 void StartOnIOThread( |
156 net::URLRequestContextGetter* context_getter, | 158 scoped_refptr<net::URLRequestContextGetter> context_getter, |
159 const string16& extension_name, | |
157 const std::string& language, | 160 const std::string& language, |
158 const std::string& grammar, | 161 const std::string& grammar, |
159 bool filter_profanities); | 162 bool filter_profanities, |
163 bool show_notification); | |
160 void ForceStopOnIOThread(); | 164 void ForceStopOnIOThread(); |
161 void IsRecordingOnIOThread(const IsRecordingCallback& callback); | 165 void IsRecordingOnIOThread(const IsRecordingCallback& callback); |
162 | 166 |
163 void SetRecognitionResultOnUIThread( | 167 void SetRecognitionResultOnUIThread( |
164 const content::SpeechRecognitionResult& result, | 168 const content::SpeechRecognitionResult& result, |
165 const std::string& extension_id); | 169 const std::string& extension_id); |
166 void DidStartReceivingAudioOnUIThread(); | 170 void DidStartReceivingAudioOnUIThread(); |
167 void StopSucceededOnUIThread(); | 171 void StopSucceededOnUIThread(); |
168 void IsRecordingOnUIThread(const IsRecordingCallback& callback, bool result); | 172 void IsRecordingOnUIThread(const IsRecordingCallback& callback, bool result); |
169 | 173 |
170 void DispatchError(const std::string& error, bool dispatch_event); | 174 void DispatchError(const std::string& error, bool dispatch_event); |
171 void DispatchEventToExtension(const std::string& extension_id, | 175 void DispatchEventToExtension(const std::string& extension_id, |
172 const std::string& event, | 176 const std::string& event, |
173 const std::string& json_args); | 177 const std::string& json_args); |
174 void ExtensionUnloaded(const std::string& extension_id); | 178 void ExtensionUnloaded(const std::string& extension_id); |
175 | 179 |
176 void SetInputVolumeOnUIThread(float volume); | |
177 void ResetToIdleState(); | 180 void ResetToIdleState(); |
178 | 181 |
179 virtual ~SpeechInputExtensionManager(); | 182 virtual ~SpeechInputExtensionManager(); |
180 | 183 |
181 friend class base::RefCountedThreadSafe<SpeechInputExtensionManager>; | 184 friend class base::RefCountedThreadSafe<SpeechInputExtensionManager>; |
182 class Factory; | 185 class Factory; |
183 | 186 |
184 // Lock used to allow exclusive access to the state variable and methods that | 187 // Lock used to allow exclusive access to the state variable and methods that |
185 // either read or write on it. This is required since the speech code | 188 // either read or write on it. This is required since the speech code |
186 // operates in the IO thread while the extension code uses the UI thread. | 189 // operates in the IO thread while the extension code uses the UI thread. |
187 base::Lock state_lock_; | 190 base::Lock state_lock_; |
188 | 191 |
189 // Used in the UI thread but also its raw value as notification | 192 // Used in the UI thread but also its raw value as notification |
190 // source in the IO thread, guarded by the state lock and value. | 193 // source in the IO thread, guarded by the state lock and value. |
191 Profile* profile_; | 194 Profile* profile_; |
192 | 195 |
193 // Used in both threads, guarded by the state lock. | 196 // Used in both threads, guarded by the state lock. |
194 State state_; | 197 State state_; |
195 std::string extension_id_in_use_; | 198 std::string extension_id_in_use_; |
196 | 199 |
197 // Used in the UI thread. | 200 // Used in the UI thread. |
198 scoped_ptr<content::NotificationRegistrar> registrar_; | 201 scoped_ptr<content::NotificationRegistrar> registrar_; |
199 SpeechInputExtensionInterface* speech_interface_; | 202 SpeechInputExtensionInterface* speech_interface_; |
200 scoped_refptr<SpeechRecognitionTrayIconController> notification_; | |
201 | 203 |
202 // Used in the IO thread. | 204 // Used in the IO thread. |
203 scoped_refptr<content::SpeechRecognizer> recognizer_; | 205 bool is_recognition_in_progress_; |
206 int speech_recognition_session_id_; | |
204 }; | 207 }; |
205 | 208 |
206 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 209 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
OLD | NEW |