Chromium Code Reviews| Index: chrome/browser/extensions/extension_speech_input_manager.h |
| diff --git a/chrome/browser/extensions/extension_speech_input_manager.h b/chrome/browser/extensions/extension_speech_input_manager.h |
| index 4d8ef00c6bd898c2881e8148a01f5bc8b0124103..cca4e2f6d0ac0a2ea10e0f36f816d5524b2f83a4 100644 |
| --- a/chrome/browser/extensions/extension_speech_input_manager.h |
| +++ b/chrome/browser/extensions/extension_speech_input_manager.h |
| @@ -8,8 +8,11 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/singleton.h" |
| +#include "base/synchronization/lock.h" |
| +#include "content/browser/speech/speech_recognizer.h" |
| #include "content/common/notification_observer.h" |
| #include "content/common/notification_registrar.h" |
| +#include "content/common/speech_input_result.h" |
| #include <string> |
| class Extension; |
| @@ -17,13 +20,26 @@ class NotificationDetails; |
| class NotificationSource; |
| class Profile; |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| // Manages the speech input requests and responses from the extensions |
| // associated to the given profile. |
| class ExtensionSpeechInputManager : public NotificationObserver, |
| - public base::RefCountedThreadSafe<ExtensionSpeechInputManager> { |
| + public base::RefCountedThreadSafe<ExtensionSpeechInputManager>, |
| + public speech_input::SpeechRecognizerDelegate { |
| public: |
| + enum State { |
| + kIdle = 0, |
| + kStarting, |
| + kRecording, |
| + kStopping, |
| + kShutdown // Internal sink state when the profile is destroyed on shutdown. |
| + }; |
| + |
| // Should not be used directly. Managed by a ProfileKeyedServiceFactory. |
| - explicit ExtensionSpeechInputManager(Profile* profile); |
| + ExtensionSpeechInputManager(Profile* profile, size_t speech_caller_id); |
|
Satish
2011/10/08 23:15:07
why is the second parameter a size_t and not int?
Leandro Graciá Gil
2011/10/09 10:29:21
Done.
|
| // Returns the corresponding manager for the given profile, creating |
| // a new one if required. |
| @@ -32,31 +48,75 @@ class ExtensionSpeechInputManager : public NotificationObserver, |
| // Initialize the ProfileKeyedServiceFactory. |
| static void InitializeFactory(); |
| - // Methods from NotificationObserver. |
| - virtual void Observe(int type, |
| - const NotificationSource& source, |
| - const NotificationDetails& details); |
| - |
| // Request to start speech recognition for the provided extension. |
| - void Start(const Extension *extension); |
| + void Start(const std::string& extension_id, |
| + const std::string& language, |
| + const std::string& grammar, |
| + bool filter_profanities); |
| // Request to stop an ongoing speech recognition. |
| - void Stop(const Extension *extension); |
| + void Stop(const std::string& extension_id); |
| + |
| + // Retrieve the actual state of the API manager. |
| + State state() const { return state_; } |
| // Called by internal ProfileKeyedService class. |
| void ShutdownOnUIThread(); |
| + // Methods from NotificationObserver. |
| + virtual void Observe(int type, |
| + const NotificationSource& source, |
|
Satish
2011/10/08 23:15:07
suggest indenting these params to right and match
Leandro Graciá Gil
2011/10/09 10:29:21
Done.
|
| + const NotificationDetails& details) OVERRIDE; |
| + |
| + // Methods from SpeechRecognizerDelegate. |
| + virtual void SetRecognitionResult( |
| + int caller_id, |
| + const speech_input::SpeechInputResult& result) OVERRIDE; |
| + |
| + virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; |
| + virtual void DidCompleteRecording(int caller_id) OVERRIDE; |
| + virtual void DidCompleteRecognition(int caller_id) OVERRIDE; |
| + virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; |
| + virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; |
| + virtual void OnRecognizerError(int caller_id, |
|
Satish
2011/10/08 23:15:07
ditto
Leandro Graciá Gil
2011/10/09 10:29:21
Done.
|
| + speech_input::SpeechInputError error) OVERRIDE; |
| + virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; |
| + virtual void SetInputVolume(int caller_id, float volume, |
| + float noise_volume) OVERRIDE {} |
| private: |
|
Satish
2011/10/08 23:15:07
add a newline above
Leandro Graciá Gil
2011/10/09 10:29:21
Done.
|
| + void StartOnIOThread( |
| + net::URLRequestContextGetter* context_getter, |
| + const std::string& language, |
| + const std::string& grammar, |
| + bool filter_profanities); |
| + |
| + void ForceStopOnIOThread(); |
| + |
| + void SetRecognitionResultOnUIThread( |
| + const speech_input::SpeechInputResult& result); |
| + |
| + void DidStartReceivingAudioOnUIThread(); |
| + void DispatchError(const std::string& code); |
| + |
| + void DispatchEventToExtension(const std::string& event, |
| + const std::string& json_args); |
|
Satish
2011/10/08 23:15:07
align with param in previous line
Leandro Graciá Gil
2011/10/09 10:29:21
Done.
|
| void ExtensionUnloaded(const std::string& id); |
| - friend class base::RefCountedThreadSafe<ExtensionSpeechInputManager>; |
| - class Factory; |
| + bool ShuttingDown(); |
| virtual ~ExtensionSpeechInputManager(); |
| + friend class base::RefCountedThreadSafe<ExtensionSpeechInputManager>; |
| + class Factory; |
| + |
| Profile* profile_; |
| - scoped_refptr<Extension> extension_; |
| + std::string extension_id_; |
| NotificationRegistrar registrar_; |
| + |
| + int speech_caller_id_; |
| + base::Lock state_lock_; |
| + State state_; |
| + scoped_refptr<speech_input::SpeechRecognizer> recognizer_; |
| }; |
| #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_ |