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

Unified Diff: content/browser/speech/speech_input_manager.h

Issue 7838028: Refactor SpeechInputManager between chrome/ and content/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 3 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
« no previous file with comments | « content/browser/speech/speech_input_browsertest.cc ('k') | content/browser/speech/speech_input_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/speech/speech_input_manager.h
diff --git a/content/browser/speech/speech_input_manager.h b/content/browser/speech/speech_input_manager.h
index a68e79014142291296e1e8727b39e875430afa39..afac4427d69189065779be67286041e918c337f6 100644
--- a/content/browser/speech/speech_input_manager.h
+++ b/content/browser/speech/speech_input_manager.h
@@ -5,7 +5,11 @@
#ifndef CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_
#define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_
+#include <map>
+#include <string>
+
#include "base/basictypes.h"
+#include "content/browser/speech/speech_recognizer.h"
#include "content/common/content_export.h"
#include "content/common/speech_input_result.h"
#include "ui/gfx/rect.h"
@@ -16,7 +20,7 @@ namespace speech_input {
// handles requests received from various render views and makes sure only one
// of them can use speech recognition at a time. It also sends recognition
// results and status events to the render views when required.
-class SpeechInputManager {
+class SpeechInputManager : public SpeechRecognizerDelegate {
public:
// Implemented by the dispatcher host to relay events to the render views.
class Delegate {
@@ -54,18 +58,94 @@ class SpeechInputManager {
const gfx::Rect& element_rect,
const std::string& language,
const std::string& grammar,
- const std::string& origin_url) = 0;
- virtual void CancelRecognition(int caller_id) = 0;
- virtual void StopRecording(int caller_id) = 0;
-
- virtual void CancelAllRequestsWithDelegate(Delegate* delegate) = 0;
+ const std::string& origin_url);
+ virtual void CancelRecognition(int caller_id);
+ virtual void CancelAllRequestsWithDelegate(Delegate* delegate);
+ virtual void StopRecording(int caller_id);
+
+ // SpeechRecognizer::Delegate methods.
+ virtual void DidStartReceivingAudio(int caller_id);
+ virtual void SetRecognitionResult(int caller_id,
+ bool error,
+ const SpeechInputResultArray& result);
+ virtual void DidCompleteRecording(int caller_id);
+ virtual void DidCompleteRecognition(int caller_id);
+ virtual void OnRecognizerError(int caller_id,
+ SpeechRecognizer::ErrorCode error);
+ virtual void DidCompleteEnvironmentEstimation(int caller_id);
+ virtual void SetInputVolume(int caller_id, float volume, float noise_volume);
void set_censor_results(bool censor) { censor_results_ = censor; }
bool censor_results() { return censor_results_; }
+ protected:
+ // The pure virtual methods are used for displaying the current state of
+ // recognition and for fetching optional request information.
+
+ // Get the optional request information if available.
+ virtual void GetRequestInfo(bool* can_report_metrics,
+ std::string* request_info) = 0;
+
+ // Called when recognition has been requested from point |element_rect_| on
+ // the view port for the given caller.
+ virtual void ShowRecognitionRequested(int caller_id,
+ int render_process_id,
+ int render_view_id,
+ const gfx::Rect& element_rect) = 0;
+
+ // Called when recognition is starting up.
+ virtual void ShowWarmUp(int caller_id) = 0;
+
+ // Called when recognition has started.
+ virtual void ShowRecognizing(int caller_id) = 0;
+
+ // Called when recording has started.
+ virtual void ShowRecording(int caller_id) = 0;
+
+ // Continuously updated with the current input volume.
+ virtual void ShowInputVolume(int caller_id,
+ float volume,
+ float noise_volume) = 0;
+
+ // Called when no microphone has been found.
+ virtual void ShowNoMicError(int caller_id) = 0;
+
+ // Called when there has been a error with the recognition.
+ virtual void ShowRecognizerError(int caller_id,
+ SpeechRecognizer::ErrorCode error) = 0;
+
+ // Called when recognition has ended or has been canceled.
+ virtual void DoClose(int caller_id) = 0;
+
+ // Cancels recognition for the specified caller if it is active.
+ void OnFocusChanged(int caller_id);
+
+ bool HasPendingRequest(int caller_id) const;
+
+ // Starts/restarts recognition for an existing request.
+ void StartRecognitionForRequest(int caller_id);
+
+ void CancelRecognitionAndInformDelegate(int caller_id);
+
private:
+ struct SpeechInputRequest {
+ SpeechInputRequest();
+ ~SpeechInputRequest();
+
+ Delegate* delegate;
+ scoped_refptr<SpeechRecognizer> recognizer;
+ bool is_active; // Set to true when recording or recognition is going on.
+ };
+
+ Delegate* GetDelegate(int caller_id) const;
+
+ typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap;
+ SpeechRecognizerMap requests_;
+ std::string request_info_;
+ bool can_report_metrics_;
bool censor_results_;
+ int recording_caller_id_;
};
// This typedef is to workaround the issue with certain versions of
« no previous file with comments | « content/browser/speech/speech_input_browsertest.cc ('k') | content/browser/speech/speech_input_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698