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

Unified Diff: chrome/browser/extensions/extension_speech_input_manager.h

Issue 8201030: Introducing the basic functionality to the speech input experimental API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixes. Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
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..7b5242ec5f4f3e980ddc9a943b961a8ee46c9e05 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, int speech_caller_id);
// Returns the corresponding manager for the given profile, creating
// a new one if required.
@@ -32,31 +48,77 @@ 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,
+ 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,
+ 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:
+ 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);
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_;
Satish 2011/10/09 20:01:47 since you have a lock only for accessing/modifying
Leandro GraciĆ” Gil 2011/10/10 18:59:38 Done.
+ State state_;
+ scoped_refptr<speech_input::SpeechRecognizer> recognizer_;
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698