| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RECOGNITION_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_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 "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "content/public/browser/speech_input_manager.h" | 15 #include "content/public/browser/speech_recognition_manager.h" |
| 16 #include "content/public/browser/speech_recognizer_delegate.h" | 16 #include "content/public/browser/speech_recognizer_delegate.h" |
| 17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 18 | 18 |
| 19 class AudioManager; | 19 class AudioManager; |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 class ResourceContext; | 22 class ResourceContext; |
| 23 class SpeechInputManagerDelegate; | 23 class SpeechRecognitionManagerDelegate; |
| 24 class SpeechInputPreferences; | 24 class SpeechRecognitionPreferences; |
| 25 struct SpeechInputResult; | 25 struct SpeechRecognitionResult; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace net { | 28 namespace net { |
| 29 class URLRequestContextGetter; | 29 class URLRequestContextGetter; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace speech_input { | 32 namespace speech { |
| 33 | 33 |
| 34 class SpeechInputDispatcherHost; | 34 class InputTagSpeechDispatcherHost; |
| 35 class SpeechRecognizerImpl; | 35 class SpeechRecognizerImpl; |
| 36 | 36 |
| 37 class CONTENT_EXPORT SpeechInputManagerImpl | 37 class CONTENT_EXPORT SpeechRecognitionManagerImpl |
| 38 : NON_EXPORTED_BASE(public content::SpeechInputManager), | 38 : NON_EXPORTED_BASE(public content::SpeechRecognitionManager), |
| 39 NON_EXPORTED_BASE(public content::SpeechRecognizerDelegate) { | 39 NON_EXPORTED_BASE(public content::SpeechRecognizerDelegate) { |
| 40 public: | 40 public: |
| 41 static SpeechInputManagerImpl* GetInstance(); | 41 static SpeechRecognitionManagerImpl* GetInstance(); |
| 42 | 42 |
| 43 // SpeechInputManager implementation: | 43 // SpeechRecognitionManager implementation: |
| 44 virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; | 44 virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; |
| 45 virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; | 45 virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; |
| 46 virtual void FocusLostForRequest(int caller_id) OVERRIDE; | 46 virtual void FocusLostForRequest(int caller_id) OVERRIDE; |
| 47 virtual bool HasAudioInputDevices() OVERRIDE; | 47 virtual bool HasAudioInputDevices() OVERRIDE; |
| 48 virtual bool IsRecordingInProcess() OVERRIDE; | 48 virtual bool IsCapturingAudio() OVERRIDE; |
| 49 virtual string16 GetAudioInputDeviceModel() OVERRIDE; | 49 virtual string16 GetAudioInputDeviceModel() OVERRIDE; |
| 50 virtual void ShowAudioInputSettings() OVERRIDE; | 50 virtual void ShowAudioInputSettings() OVERRIDE; |
| 51 | 51 |
| 52 // Handlers for requests from render views. | 52 // Handlers for requests from render views. |
| 53 | 53 |
| 54 // |delegate| is a weak pointer and should remain valid until | 54 // |delegate| is a weak pointer and should remain valid until |
| 55 // its |DidCompleteRecognition| method is called or recognition is cancelled. | 55 // its |DidCompleteRecognition| method is called or recognition is cancelled. |
| 56 // |render_process_id| is the ID of the renderer process initiating the | 56 // |render_process_id| is the ID of the renderer process initiating the |
| 57 // request. | 57 // request. |
| 58 // |element_rect| is the display bounds of the html element requesting speech | 58 // |element_rect| is the display bounds of the html element requesting speech |
| 59 // input (in page coordinates). | 59 // input (in page coordinates). |
| 60 virtual void StartRecognition( | 60 virtual void StartRecognition( |
| 61 SpeechInputDispatcherHost* delegate, | 61 InputTagSpeechDispatcherHost* delegate, |
| 62 int caller_id, | 62 int caller_id, |
| 63 int render_process_id, | 63 int render_process_id, |
| 64 int render_view_id, | 64 int render_view_id, |
| 65 const gfx::Rect& element_rect, | 65 const gfx::Rect& element_rect, |
| 66 const std::string& language, | 66 const std::string& language, |
| 67 const std::string& grammar, | 67 const std::string& grammar, |
| 68 const std::string& origin_url, | 68 const std::string& origin_url, |
| 69 net::URLRequestContextGetter* context_getter, | 69 net::URLRequestContextGetter* context_getter, |
| 70 content::SpeechInputPreferences* speech_input_prefs); | 70 content::SpeechRecognitionPreferences* speech_recognition_prefs); |
| 71 virtual void CancelRecognition(int caller_id); | 71 virtual void CancelRecognition(int caller_id); |
| 72 virtual void CancelAllRequestsWithDelegate( | 72 virtual void CancelAllRequestsWithDelegate( |
| 73 SpeechInputDispatcherHost* delegate); | 73 InputTagSpeechDispatcherHost* delegate); |
| 74 virtual void StopRecording(int caller_id); | 74 virtual void StopRecording(int caller_id); |
| 75 | 75 |
| 76 // Overridden from content::SpeechRecognizerDelegate: | 76 // Overridden from content::SpeechRecognizerDelegate: |
| 77 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; | 77 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; |
| 78 virtual void SetRecognitionResult( | 78 virtual void SetRecognitionResult( |
| 79 int caller_id, | 79 int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; |
| 80 const content::SpeechInputResult& result) OVERRIDE; | |
| 81 virtual void DidCompleteRecording(int caller_id) OVERRIDE; | 80 virtual void DidCompleteRecording(int caller_id) OVERRIDE; |
| 82 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; | 81 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; |
| 83 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; | 82 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; |
| 84 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; | 83 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; |
| 85 | 84 |
| 86 virtual void OnRecognizerError(int caller_id, | 85 virtual void OnRecognizerError( |
| 87 content::SpeechInputError error) OVERRIDE; | 86 int caller_id, content::SpeechRecognitionErrorCode error) OVERRIDE; |
| 88 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; | 87 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; |
| 89 virtual void SetInputVolume(int caller_id, float volume, | 88 virtual void SetInputVolume(int caller_id, float volume, |
| 90 float noise_volume) OVERRIDE; | 89 float noise_volume) OVERRIDE; |
| 91 | 90 |
| 92 protected: | 91 protected: |
| 93 // Private constructor to enforce singleton. | 92 // Private constructor to enforce singleton. |
| 94 friend struct DefaultSingletonTraits<SpeechInputManagerImpl>; | 93 friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; |
| 95 SpeechInputManagerImpl(); | 94 SpeechRecognitionManagerImpl(); |
| 96 virtual ~SpeechInputManagerImpl(); | 95 virtual ~SpeechRecognitionManagerImpl(); |
| 97 | 96 |
| 98 bool HasPendingRequest(int caller_id) const; | 97 bool HasPendingRequest(int caller_id) const; |
| 99 | 98 |
| 100 private: | 99 private: |
| 101 struct SpeechInputRequest { | 100 struct Request { |
| 102 SpeechInputRequest(); | 101 Request(); |
| 103 ~SpeechInputRequest(); | 102 ~Request(); |
| 104 | 103 |
| 105 SpeechInputDispatcherHost* delegate; | 104 InputTagSpeechDispatcherHost* delegate; |
| 106 scoped_refptr<SpeechRecognizerImpl> recognizer; | 105 scoped_refptr<SpeechRecognizerImpl> recognizer; |
| 107 bool is_active; // Set to true when recording or recognition is going on. | 106 bool is_active; // Set to true when recording or recognition is going on. |
| 108 }; | 107 }; |
| 109 | 108 |
| 110 struct SpeechInputParams; | 109 struct SpeechRecognitionParams; |
| 111 | 110 |
| 112 SpeechInputDispatcherHost* GetDelegate(int caller_id) const; | 111 InputTagSpeechDispatcherHost* GetDelegate(int caller_id) const; |
| 113 | 112 |
| 114 void CheckRenderViewTypeAndStartRecognition(const SpeechInputParams& params); | 113 void CheckRenderViewTypeAndStartRecognition( |
| 115 void ProceedStartingRecognition(const SpeechInputParams& params); | 114 const SpeechRecognitionParams& params); |
| 115 void ProceedStartingRecognition(const SpeechRecognitionParams& params); |
| 116 | 116 |
| 117 void CancelRecognitionAndInformDelegate(int caller_id); | 117 void CancelRecognitionAndInformDelegate(int caller_id); |
| 118 | 118 |
| 119 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; | 119 typedef std::map<int, Request> SpeechRecognizerMap; |
| 120 SpeechRecognizerMap requests_; | 120 SpeechRecognizerMap requests_; |
| 121 std::string request_info_; | 121 std::string request_info_; |
| 122 bool can_report_metrics_; | 122 bool can_report_metrics_; |
| 123 int recording_caller_id_; | 123 int recording_caller_id_; |
| 124 content::SpeechInputManagerDelegate* delegate_; | 124 content::SpeechRecognitionManagerDelegate* delegate_; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 } // namespace speech_input | 127 } // namespace speech |
| 128 | 128 |
| 129 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 129 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ |
| OLD | NEW |