| 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 CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_MANAGER_H_ |
| 6 #define CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_MANAGER_H_ | 6 #define CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 12 #include "chrome/browser/speech/speech_input_bubble_controller.h" | 10 #include "chrome/browser/speech/speech_input_bubble_controller.h" |
| 13 #include "content/browser/speech/speech_input_manager.h" | 11 #include "content/browser/speech/speech_input_manager.h" |
| 14 #include "content/browser/speech/speech_recognizer.h" | |
| 15 | 12 |
| 16 namespace speech_input { | 13 namespace speech_input { |
| 17 | 14 |
| 18 // This is Chrome's implementation of the SpeechInputManager interface. This | 15 // This is Chrome's implementation of the SpeechInputManager interface. This |
| 19 // class is a singleton and accessed via the Get method. | 16 // class is a singleton and accessed via the Get method. |
| 20 class ChromeSpeechInputManager : public SpeechInputManager, | 17 class ChromeSpeechInputManager : public SpeechInputManager, |
| 21 public SpeechInputBubbleControllerDelegate, | 18 public SpeechInputBubbleControllerDelegate { |
| 22 public SpeechRecognizerDelegate { | |
| 23 public: | 19 public: |
| 24 static ChromeSpeechInputManager* GetInstance(); | 20 static ChromeSpeechInputManager* GetInstance(); |
| 25 | 21 |
| 26 // SpeechInputManager methods. | |
| 27 virtual void StartRecognition(SpeechInputManagerDelegate* delegate, | |
| 28 int caller_id, | |
| 29 int render_process_id, | |
| 30 int render_view_id, | |
| 31 const gfx::Rect& element_rect, | |
| 32 const std::string& language, | |
| 33 const std::string& grammar, | |
| 34 const std::string& origin_url); | |
| 35 virtual void CancelRecognition(int caller_id); | |
| 36 virtual void StopRecording(int caller_id); | |
| 37 virtual void CancelAllRequestsWithDelegate( | |
| 38 SpeechInputManagerDelegate* delegate); | |
| 39 | |
| 40 // SpeechRecognizer::Delegate methods. | |
| 41 virtual void DidStartReceivingAudio(int caller_id); | |
| 42 virtual void SetRecognitionResult(int caller_id, | |
| 43 bool error, | |
| 44 const SpeechInputResultArray& result); | |
| 45 virtual void DidCompleteRecording(int caller_id); | |
| 46 virtual void DidCompleteRecognition(int caller_id); | |
| 47 virtual void OnRecognizerError(int caller_id, | |
| 48 SpeechRecognizer::ErrorCode error); | |
| 49 virtual void DidCompleteEnvironmentEstimation(int caller_id); | |
| 50 virtual void SetInputVolume(int caller_id, float volume, float noise_volume); | |
| 51 | |
| 52 // SpeechInputBubbleController::Delegate methods. | 22 // SpeechInputBubbleController::Delegate methods. |
| 53 virtual void InfoBubbleButtonClicked(int caller_id, | 23 virtual void InfoBubbleButtonClicked(int caller_id, |
| 54 SpeechInputBubble::Button button); | 24 SpeechInputBubble::Button button); |
| 55 virtual void InfoBubbleFocusChanged(int caller_id); | 25 virtual void InfoBubbleFocusChanged(int caller_id); |
| 56 | 26 |
| 27 protected: |
| 28 // SpeechInputManager methods. |
| 29 virtual void GetRequestInfo(bool* can_report_metrics, |
| 30 std::string* request_info); |
| 31 virtual void ShowRecognitionRequested(int caller_id, |
| 32 int render_process_id, |
| 33 int render_view_id, |
| 34 const gfx::Rect& element_rect); |
| 35 virtual void ShowWarmUp(int caller_id); |
| 36 virtual void ShowRecognizing(int caller_id); |
| 37 virtual void ShowRecording(int caller_id); |
| 38 virtual void ShowInputVolume(int caller_id, |
| 39 float volume, |
| 40 float noise_volume); |
| 41 virtual void ShowNoMicError(int caller_id); |
| 42 virtual void ShowRecognizerError(int caller_id, |
| 43 SpeechRecognizer::ErrorCode error); |
| 44 virtual void DoClose(int caller_id); |
| 45 |
| 57 private: | 46 private: |
| 58 class OptionalRequestInfo; | 47 class OptionalRequestInfo; |
| 59 | 48 |
| 60 struct SpeechInputRequest { | |
| 61 SpeechInputRequest(); | |
| 62 ~SpeechInputRequest(); | |
| 63 | |
| 64 SpeechInputManagerDelegate* delegate; | |
| 65 scoped_refptr<SpeechRecognizer> recognizer; | |
| 66 bool is_active; // Set to true when recording or recognition is going on. | |
| 67 }; | |
| 68 | |
| 69 // Private constructor to enforce singleton. | 49 // Private constructor to enforce singleton. |
| 70 friend struct DefaultSingletonTraits<ChromeSpeechInputManager>; | 50 friend struct DefaultSingletonTraits<ChromeSpeechInputManager>; |
| 71 ChromeSpeechInputManager(); | 51 ChromeSpeechInputManager(); |
| 72 virtual ~ChromeSpeechInputManager(); | 52 virtual ~ChromeSpeechInputManager(); |
| 73 | 53 |
| 74 bool HasPendingRequest(int caller_id) const; | |
| 75 SpeechInputManagerDelegate* GetDelegate(int caller_id) const; | |
| 76 | |
| 77 void CancelRecognitionAndInformDelegate(int caller_id); | |
| 78 | |
| 79 // Starts/restarts recognition for an existing request. | |
| 80 void StartRecognitionForRequest(int caller_id); | |
| 81 | |
| 82 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; | |
| 83 SpeechRecognizerMap requests_; | |
| 84 int recording_caller_id_; | |
| 85 scoped_refptr<SpeechInputBubbleController> bubble_controller_; | 54 scoped_refptr<SpeechInputBubbleController> bubble_controller_; |
| 86 scoped_refptr<OptionalRequestInfo> optional_request_info_; | 55 scoped_refptr<OptionalRequestInfo> optional_request_info_; |
| 87 | 56 |
| 88 DISALLOW_COPY_AND_ASSIGN(ChromeSpeechInputManager); | 57 DISALLOW_COPY_AND_ASSIGN(ChromeSpeechInputManager); |
| 89 }; | 58 }; |
| 90 | 59 |
| 91 } // namespace speech_input | 60 } // namespace speech_input |
| 92 | 61 |
| 93 #endif // CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_MANAGER_H_ | 62 #endif // CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_MANAGER_H_ |
| OLD | NEW |