OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSIONS_SPEECH_INPUT_EXTENSION_SPEECH_INPUT_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_EXTENSION_SPEECH_INPUT_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SPEECH_INPUT_EXTENSION_SPEECH_INPUT_MANAGER_H_ | 6 #define CHROME_BROWSER_SPEECH_EXTENSION_SPEECH_INPUT_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "chrome/browser/speech/extension_speech_input_notification_ui.h" |
11 #include "content/browser/speech/speech_recognizer.h" | 11 #include "content/browser/speech/speech_recognizer.h" |
12 #include "content/common/speech_input_result.h" | 12 #include "content/common/speech_input_result.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 class Extension; | 17 class Extension; |
18 class Profile; | 18 class Profile; |
19 | 19 |
20 namespace net { | 20 namespace net { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; | 116 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; |
117 virtual void DidCompleteRecording(int caller_id) OVERRIDE; | 117 virtual void DidCompleteRecording(int caller_id) OVERRIDE; |
118 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; | 118 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; |
119 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; | 119 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; |
120 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; | 120 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; |
121 virtual void OnRecognizerError(int caller_id, | 121 virtual void OnRecognizerError(int caller_id, |
122 speech_input::SpeechInputError error) | 122 speech_input::SpeechInputError error) |
123 OVERRIDE; | 123 OVERRIDE; |
124 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; | 124 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; |
125 virtual void SetInputVolume(int caller_id, float volume, | 125 virtual void SetInputVolume(int caller_id, float volume, |
126 float noise_volume) OVERRIDE {} | 126 float noise_volume) OVERRIDE; |
127 | 127 |
128 // Methods for API testing. | 128 // Methods for API testing. |
129 void SetExtensionSpeechInterface(ExtensionSpeechInterface* interface); | 129 void SetExtensionSpeechInterface(ExtensionSpeechInterface* interface); |
130 ExtensionSpeechInterface* GetExtensionSpeechInterface(); | 130 ExtensionSpeechInterface* GetExtensionSpeechInterface(); |
131 | 131 |
132 private: | 132 private: |
133 // ExtensionSpeechInterface methods: | 133 // ExtensionSpeechInterface methods: |
134 virtual bool IsRecordingInProcess() OVERRIDE; | 134 virtual bool IsRecordingInProcess() OVERRIDE; |
135 virtual bool HasAudioInputDevices() OVERRIDE; | 135 virtual bool HasAudioInputDevices() OVERRIDE; |
136 virtual bool HasValidRecognizer() OVERRIDE; | 136 virtual bool HasValidRecognizer() OVERRIDE; |
(...skipping 21 matching lines...) Expand all Loading... |
158 const std::string& extension_id); | 158 const std::string& extension_id); |
159 void DidStartReceivingAudioOnUIThread(); | 159 void DidStartReceivingAudioOnUIThread(); |
160 void StopSucceededOnUIThread(); | 160 void StopSucceededOnUIThread(); |
161 | 161 |
162 void DispatchError(const std::string& error, bool dispatch_event); | 162 void DispatchError(const std::string& error, bool dispatch_event); |
163 void DispatchEventToExtension(const std::string& extension_id, | 163 void DispatchEventToExtension(const std::string& extension_id, |
164 const std::string& event, | 164 const std::string& event, |
165 const std::string& json_args); | 165 const std::string& json_args); |
166 void ExtensionUnloaded(const std::string& extension_id); | 166 void ExtensionUnloaded(const std::string& extension_id); |
167 | 167 |
| 168 void SetInputVolumeOnUIThread(float volume); |
168 void ResetToIdleState(); | 169 void ResetToIdleState(); |
169 | 170 |
170 virtual ~ExtensionSpeechInputManager(); | 171 virtual ~ExtensionSpeechInputManager(); |
171 | 172 |
172 friend class base::RefCountedThreadSafe<ExtensionSpeechInputManager>; | 173 friend class base::RefCountedThreadSafe<ExtensionSpeechInputManager>; |
173 class Factory; | 174 class Factory; |
174 | 175 |
175 // Lock used to allow exclusive access to the state variable and methods that | 176 // Lock used to allow exclusive access to the state variable and methods that |
176 // either read or write on it. This is required since the speech code | 177 // either read or write on it. This is required since the speech code |
177 // operates in the IO thread while the extension code uses the UI thread. | 178 // operates in the IO thread while the extension code uses the UI thread. |
178 base::Lock state_lock_; | 179 base::Lock state_lock_; |
179 | 180 |
180 // Used in the UI thread but also its raw value as notification | 181 // Used in the UI thread but also its raw value as notification |
181 // source in the IO thread, guarded by the state lock and value. | 182 // source in the IO thread, guarded by the state lock and value. |
182 Profile* profile_; | 183 Profile* profile_; |
183 | 184 |
184 // Used in both threads, guarded by the state lock. | 185 // Used in both threads, guarded by the state lock. |
185 State state_; | 186 State state_; |
186 std::string extension_id_in_use_; | 187 std::string extension_id_in_use_; |
187 | 188 |
188 // Used in the UI thread. | 189 // Used in the UI thread. |
189 content::NotificationRegistrar registrar_; | 190 content::NotificationRegistrar registrar_; |
190 ExtensionSpeechInterface* speech_interface_; | 191 ExtensionSpeechInterface* speech_interface_; |
| 192 ExtensionSpeechInputNotificationUI notification_; |
191 }; | 193 }; |
192 | 194 |
193 #endif // CHROME_BROWSER_EXTENSIONS_SPEECH_INPUT_EXTENSION_SPEECH_INPUT_MANAGER
_H_ | 195 #endif // CHROME_BROWSER_SPEECH_EXTENSION_SPEECH_INPUT_MANAGER_H_ |
OLD | NEW |