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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_
6 #define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ 6 #define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_
7 7
8 #include <map>
9 #include <string>
10
8 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "content/browser/speech/speech_recognizer.h"
9 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
10 #include "content/common/speech_input_result.h" 14 #include "content/common/speech_input_result.h"
11 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
12 16
13 namespace speech_input { 17 namespace speech_input {
14 18
15 // This is the gatekeeper for speech recognition in the browser process. It 19 // This is the gatekeeper for speech recognition in the browser process. It
16 // handles requests received from various render views and makes sure only one 20 // handles requests received from various render views and makes sure only one
17 // of them can use speech recognition at a time. It also sends recognition 21 // of them can use speech recognition at a time. It also sends recognition
18 // results and status events to the render views when required. 22 // results and status events to the render views when required.
19 class SpeechInputManager { 23 class SpeechInputManager : public SpeechRecognizerDelegate {
20 public: 24 public:
21 // Implemented by the dispatcher host to relay events to the render views. 25 // Implemented by the dispatcher host to relay events to the render views.
22 class Delegate { 26 class Delegate {
23 public: 27 public:
24 virtual void SetRecognitionResult( 28 virtual void SetRecognitionResult(
25 int caller_id, 29 int caller_id,
26 const SpeechInputResultArray& result) = 0; 30 const SpeechInputResultArray& result) = 0;
27 virtual void DidCompleteRecording(int caller_id) = 0; 31 virtual void DidCompleteRecording(int caller_id) = 0;
28 virtual void DidCompleteRecognition(int caller_id) = 0; 32 virtual void DidCompleteRecognition(int caller_id) = 0;
29 33
(...skipping 17 matching lines...) Expand all
47 // request. 51 // request.
48 // |element_rect| is the display bounds of the html element requesting speech 52 // |element_rect| is the display bounds of the html element requesting speech
49 // input (in page coordinates). 53 // input (in page coordinates).
50 virtual void StartRecognition(Delegate* delegate, 54 virtual void StartRecognition(Delegate* delegate,
51 int caller_id, 55 int caller_id,
52 int render_process_id, 56 int render_process_id,
53 int render_view_id, 57 int render_view_id,
54 const gfx::Rect& element_rect, 58 const gfx::Rect& element_rect,
55 const std::string& language, 59 const std::string& language,
56 const std::string& grammar, 60 const std::string& grammar,
57 const std::string& origin_url) = 0; 61 const std::string& origin_url);
58 virtual void CancelRecognition(int caller_id) = 0; 62 virtual void CancelRecognition(int caller_id);
59 virtual void StopRecording(int caller_id) = 0; 63 virtual void CancelAllRequestsWithDelegate(Delegate* delegate);
64 virtual void StopRecording(int caller_id);
60 65
61 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) = 0; 66 // SpeechRecognizer::Delegate methods.
67 virtual void DidStartReceivingAudio(int caller_id);
68 virtual void SetRecognitionResult(int caller_id,
69 bool error,
70 const SpeechInputResultArray& result);
71 virtual void DidCompleteRecording(int caller_id);
72 virtual void DidCompleteRecognition(int caller_id);
73 virtual void OnRecognizerError(int caller_id,
74 SpeechRecognizer::ErrorCode error);
75 virtual void DidCompleteEnvironmentEstimation(int caller_id);
76 virtual void SetInputVolume(int caller_id, float volume, float noise_volume);
62 77
63 void set_censor_results(bool censor) { censor_results_ = censor; } 78 void set_censor_results(bool censor) { censor_results_ = censor; }
64 79
65 bool censor_results() { return censor_results_; } 80 bool censor_results() { return censor_results_; }
66 81
82 protected:
83 // The pure virtual methods are used for displaying the current state of
84 // recognition and for fetching optional request information.
85
86 // Get the optional request information if available.
87 virtual void FetchRequestInfo(bool* can_report_metrics,
Satish 2011/09/20 20:09:55 Fetch -> Get as it is more commonly used?
allanwoj 2011/09/21 11:17:54 Done.
88 std::string* request_info) = 0;
89
90 // Called when recognition has been requested from point |element_rect_| on
91 // the view port for the given caller.
92 virtual void ShowRecognitionRequested(int caller_id,
93 int render_process_id,
94 int render_view_id,
95 const gfx::Rect& element_rect) = 0;
96
97 // Called when recognition is starting up.
98 virtual void ShowWarmUp(int caller_id) = 0;
99
100 // Called when recognition has started.
101 virtual void ShowRecognizing(int caller_id) = 0;
102
103 // Called when recording has started.
104 virtual void ShowRecording(int caller_id) = 0;
105
106 // Continuously updated with the current input volume.
107 virtual void ShowInputVolume(int caller_id,
108 float volume,
109 float noise_volume) = 0;
110
111 // Called when no microphone has been found.
112 virtual void HandleNoMicError(int caller_id) = 0;
Satish 2011/09/20 20:09:55 In context of the above methods, ShowNoMicError se
allanwoj 2011/09/21 11:17:54 Done.
113
114 // Called when there has been a error with the recognition.
115 virtual void HandleRecognizerError(int caller_id,
Satish 2011/09/20 20:09:55 similar to above, how about ShowRecognizerError ?
allanwoj 2011/09/21 11:17:54 Done.
116 SpeechRecognizer::ErrorCode error) = 0;
117
118 // Called when recognition has ended or has been canceled.
119 virtual void DoClose(int caller_id) = 0;
120
121 // Cancels recognition for the specified caller if it is active.
122 void OnFocusChanged(int caller_id);
123
124 bool HasPendingRequest(int caller_id) const;
125
126 // Starts/restarts recognition for an existing request.
127 void StartRecognitionForRequest(int caller_id);
128
129 void CancelRecognitionAndInformDelegate(int caller_id);
130
67 private: 131 private:
132 struct SpeechInputRequest {
133 SpeechInputRequest();
134 ~SpeechInputRequest();
135
136 Delegate* delegate;
137 scoped_refptr<SpeechRecognizer> recognizer;
138 bool is_active; // Set to true when recording or recognition is going on.
139 };
140
141 Delegate* GetDelegate(int caller_id) const;
142
143 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap;
144 SpeechRecognizerMap requests_;
145 std::string request_info_;
146 bool can_report_metrics_;
68 bool censor_results_; 147 bool censor_results_;
148 int recording_caller_id_;
69 }; 149 };
70 150
71 // This typedef is to workaround the issue with certain versions of 151 // This typedef is to workaround the issue with certain versions of
72 // Visual Studio where it gets confused between multiple Delegate 152 // Visual Studio where it gets confused between multiple Delegate
73 // classes and gives a C2500 error. (I saw this error on the try bots - 153 // classes and gives a C2500 error. (I saw this error on the try bots -
74 // the workaround was not needed for my machine). 154 // the workaround was not needed for my machine).
75 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; 155 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate;
76 156
77 } // namespace speech_input 157 } // namespace speech_input
78 158
79 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ 159 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_
OLDNEW
« 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