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