| OLD | NEW |
| 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> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "content/browser/speech/speech_recognizer.h" | 12 #include "content/browser/speech/speech_recognizer.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/common/speech_input_result.h" | 14 #include "content/common/speech_input_result.h" |
| 15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 16 | 16 |
| 17 class SpeechInputPreferences; |
| 18 |
| 17 namespace speech_input { | 19 namespace speech_input { |
| 18 | 20 |
| 19 // This is the gatekeeper for speech recognition in the browser process. It | 21 // This is the gatekeeper for speech recognition in the browser process. It |
| 20 // handles requests received from various render views and makes sure only one | 22 // handles requests received from various render views and makes sure only one |
| 21 // of them can use speech recognition at a time. It also sends recognition | 23 // of them can use speech recognition at a time. It also sends recognition |
| 22 // results and status events to the render views when required. | 24 // results and status events to the render views when required. |
| 23 class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate { | 25 class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate { |
| 24 public: | 26 public: |
| 25 // Implemented by the dispatcher host to relay events to the render views. | 27 // Implemented by the dispatcher host to relay events to the render views. |
| 26 class Delegate { | 28 class Delegate { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 // request. | 53 // request. |
| 52 // |element_rect| is the display bounds of the html element requesting speech | 54 // |element_rect| is the display bounds of the html element requesting speech |
| 53 // input (in page coordinates). | 55 // input (in page coordinates). |
| 54 virtual void StartRecognition(Delegate* delegate, | 56 virtual void StartRecognition(Delegate* delegate, |
| 55 int caller_id, | 57 int caller_id, |
| 56 int render_process_id, | 58 int render_process_id, |
| 57 int render_view_id, | 59 int render_view_id, |
| 58 const gfx::Rect& element_rect, | 60 const gfx::Rect& element_rect, |
| 59 const std::string& language, | 61 const std::string& language, |
| 60 const std::string& grammar, | 62 const std::string& grammar, |
| 61 const std::string& origin_url); | 63 const std::string& origin_url, |
| 64 net::URLRequestContextGetter* context_getter, |
| 65 SpeechInputPreferences* speech_input_prefs); |
| 62 virtual void CancelRecognition(int caller_id); | 66 virtual void CancelRecognition(int caller_id); |
| 63 virtual void CancelAllRequestsWithDelegate(Delegate* delegate); | 67 virtual void CancelAllRequestsWithDelegate(Delegate* delegate); |
| 64 virtual void StopRecording(int caller_id); | 68 virtual void StopRecording(int caller_id); |
| 65 | 69 |
| 66 // SpeechRecognizer::Delegate methods. | 70 // SpeechRecognizer::Delegate methods. |
| 67 virtual void DidStartReceivingAudio(int caller_id); | 71 virtual void DidStartReceivingAudio(int caller_id); |
| 68 virtual void SetRecognitionResult(int caller_id, | 72 virtual void SetRecognitionResult(int caller_id, |
| 69 bool error, | 73 bool error, |
| 70 const SpeechInputResultArray& result); | 74 const SpeechInputResultArray& result); |
| 71 virtual void DidCompleteRecording(int caller_id); | 75 virtual void DidCompleteRecording(int caller_id); |
| 72 virtual void DidCompleteRecognition(int caller_id); | 76 virtual void DidCompleteRecognition(int caller_id); |
| 73 virtual void OnRecognizerError(int caller_id, | 77 virtual void OnRecognizerError(int caller_id, |
| 74 SpeechRecognizer::ErrorCode error); | 78 SpeechRecognizer::ErrorCode error); |
| 75 virtual void DidCompleteEnvironmentEstimation(int caller_id); | 79 virtual void DidCompleteEnvironmentEstimation(int caller_id); |
| 76 virtual void SetInputVolume(int caller_id, float volume, float noise_volume); | 80 virtual void SetInputVolume(int caller_id, float volume, float noise_volume); |
| 77 | 81 |
| 78 void set_censor_results(bool censor) { censor_results_ = censor; } | |
| 79 | |
| 80 bool censor_results() { return censor_results_; } | |
| 81 | |
| 82 protected: | 82 protected: |
| 83 // The pure virtual methods are used for displaying the current state of | 83 // The pure virtual methods are used for displaying the current state of |
| 84 // recognition and for fetching optional request information. | 84 // recognition and for fetching optional request information. |
| 85 | 85 |
| 86 // Get the optional request information if available. | 86 // Get the optional request information if available. |
| 87 virtual void GetRequestInfo(bool* can_report_metrics, | 87 virtual void GetRequestInfo(bool* can_report_metrics, |
| 88 std::string* request_info) = 0; | 88 std::string* request_info) = 0; |
| 89 | 89 |
| 90 // Called when recognition has been requested from point |element_rect_| on | 90 // Called when recognition has been requested from point |element_rect_| on |
| 91 // the view port for the given caller. | 91 // the view port for the given caller. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 scoped_refptr<SpeechRecognizer> recognizer; | 137 scoped_refptr<SpeechRecognizer> recognizer; |
| 138 bool is_active; // Set to true when recording or recognition is going on. | 138 bool is_active; // Set to true when recording or recognition is going on. |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 Delegate* GetDelegate(int caller_id) const; | 141 Delegate* GetDelegate(int caller_id) const; |
| 142 | 142 |
| 143 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; | 143 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; |
| 144 SpeechRecognizerMap requests_; | 144 SpeechRecognizerMap requests_; |
| 145 std::string request_info_; | 145 std::string request_info_; |
| 146 bool can_report_metrics_; | 146 bool can_report_metrics_; |
| 147 bool censor_results_; | |
| 148 int recording_caller_id_; | 147 int recording_caller_id_; |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 // This typedef is to workaround the issue with certain versions of | 150 // This typedef is to workaround the issue with certain versions of |
| 152 // Visual Studio where it gets confused between multiple Delegate | 151 // Visual Studio where it gets confused between multiple Delegate |
| 153 // classes and gives a C2500 error. (I saw this error on the try bots - | 152 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 154 // the workaround was not needed for my machine). | 153 // the workaround was not needed for my machine). |
| 155 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; | 154 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; |
| 156 | 155 |
| 157 } // namespace speech_input | 156 } // namespace speech_input |
| 158 | 157 |
| 159 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 158 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ |
| OLD | NEW |