| 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_RECOGNITION_MANAGER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 class InputTagSpeechDispatcherHost; | 34 class InputTagSpeechDispatcherHost; |
| 35 | 35 |
| 36 class CONTENT_EXPORT SpeechRecognitionManagerImpl | 36 class CONTENT_EXPORT SpeechRecognitionManagerImpl |
| 37 : NON_EXPORTED_BASE(public content::SpeechRecognitionManager), | 37 : NON_EXPORTED_BASE(public content::SpeechRecognitionManager), |
| 38 NON_EXPORTED_BASE(public content::SpeechRecognitionEventListener) { | 38 NON_EXPORTED_BASE(public content::SpeechRecognitionEventListener) { |
| 39 public: | 39 public: |
| 40 static SpeechRecognitionManagerImpl* GetInstance(); | 40 static SpeechRecognitionManagerImpl* GetInstance(); |
| 41 | 41 |
| 42 // SpeechRecognitionManager implementation: | 42 // SpeechRecognitionManager implementation: |
| 43 virtual void StartRecognitionForRequest(int caller_id) OVERRIDE; | 43 virtual void StartRecognitionForRequest(int session_id) OVERRIDE; |
| 44 virtual void CancelRecognitionForRequest(int caller_id) OVERRIDE; | 44 virtual void CancelRecognitionForRequest(int session_id) OVERRIDE; |
| 45 virtual void FocusLostForRequest(int caller_id) OVERRIDE; | 45 virtual void FocusLostForRequest(int session_id) OVERRIDE; |
| 46 virtual bool HasAudioInputDevices() OVERRIDE; | 46 virtual bool HasAudioInputDevices() OVERRIDE; |
| 47 virtual bool IsCapturingAudio() OVERRIDE; | 47 virtual bool IsCapturingAudio() OVERRIDE; |
| 48 virtual string16 GetAudioInputDeviceModel() OVERRIDE; | 48 virtual string16 GetAudioInputDeviceModel() OVERRIDE; |
| 49 virtual void ShowAudioInputSettings() OVERRIDE; | 49 virtual void ShowAudioInputSettings() OVERRIDE; |
| 50 | 50 |
| 51 // Handlers for requests from render views. | 51 // Handlers for requests from render views. |
| 52 | 52 |
| 53 // |delegate| is a weak pointer and should remain valid until | 53 // |delegate| is a weak pointer and should remain valid until |
| 54 // its |DidCompleteRecognition| method is called or recognition is cancelled. | 54 // its |DidCompleteRecognition| method is called or recognition is cancelled. |
| 55 // |render_process_id| is the ID of the renderer process initiating the | 55 // |render_process_id| is the ID of the renderer process initiating the |
| 56 // request. | 56 // request. |
| 57 // |element_rect| is the display bounds of the html element requesting speech | 57 // |element_rect| is the display bounds of the html element requesting speech |
| 58 // input (in page coordinates). | 58 // input (in page coordinates). |
| 59 virtual void StartRecognition( | 59 virtual void StartRecognition( |
| 60 InputTagSpeechDispatcherHost* delegate, | 60 InputTagSpeechDispatcherHost* delegate, |
| 61 int caller_id, | 61 int session_id, |
| 62 int render_process_id, | 62 int render_process_id, |
| 63 int render_view_id, | 63 int render_view_id, |
| 64 const gfx::Rect& element_rect, | 64 const gfx::Rect& element_rect, |
| 65 const std::string& language, | 65 const std::string& language, |
| 66 const std::string& grammar, | 66 const std::string& grammar, |
| 67 const std::string& origin_url, | 67 const std::string& origin_url, |
| 68 net::URLRequestContextGetter* context_getter, | 68 net::URLRequestContextGetter* context_getter, |
| 69 content::SpeechRecognitionPreferences* speech_recognition_prefs); | 69 content::SpeechRecognitionPreferences* speech_recognition_prefs); |
| 70 virtual void CancelRecognition(int caller_id); | 70 virtual void CancelRecognition(int session_id); |
| 71 virtual void CancelAllRequestsWithDelegate( | 71 virtual void CancelAllRequestsWithDelegate( |
| 72 InputTagSpeechDispatcherHost* delegate); | 72 InputTagSpeechDispatcherHost* delegate); |
| 73 virtual void StopRecording(int caller_id); | 73 virtual void StopRecording(int session_id); |
| 74 | 74 |
| 75 // SpeechRecognitionEventListener methods. | 75 // SpeechRecognitionEventListener methods. |
| 76 virtual void OnRecognitionStart(int caller_id) OVERRIDE; | 76 virtual void OnRecognitionStart(int session_id) OVERRIDE; |
| 77 virtual void OnAudioStart(int caller_id) OVERRIDE; | 77 virtual void OnAudioStart(int session_id) OVERRIDE; |
| 78 virtual void OnEnvironmentEstimationComplete(int caller_id) OVERRIDE; | 78 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE; |
| 79 virtual void OnSoundStart(int caller_id) OVERRIDE; | 79 virtual void OnSoundStart(int session_id) OVERRIDE; |
| 80 virtual void OnSoundEnd(int caller_id) OVERRIDE; | 80 virtual void OnSoundEnd(int session_id) OVERRIDE; |
| 81 virtual void OnAudioEnd(int caller_id) OVERRIDE; | 81 virtual void OnAudioEnd(int session_id) OVERRIDE; |
| 82 virtual void OnRecognitionEnd(int caller_id) OVERRIDE; | 82 virtual void OnRecognitionEnd(int session_id) OVERRIDE; |
| 83 virtual void OnRecognitionResult( | 83 virtual void OnRecognitionResult( |
| 84 int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE; | 84 int session_id, const content::SpeechRecognitionResult& result) OVERRIDE; |
| 85 virtual void OnRecognitionError( | 85 virtual void OnRecognitionError( |
| 86 int caller_id, const content::SpeechRecognitionError& error) OVERRIDE; | 86 int session_id, const content::SpeechRecognitionError& error) OVERRIDE; |
| 87 virtual void OnAudioLevelsChange( | 87 virtual void OnAudioLevelsChange( |
| 88 int caller_id, float volume, float noise_volume) OVERRIDE; | 88 int session_id, float volume, float noise_volume) OVERRIDE; |
| 89 | 89 |
| 90 protected: | 90 protected: |
| 91 // Private constructor to enforce singleton. | 91 // Private constructor to enforce singleton. |
| 92 friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; | 92 friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; |
| 93 SpeechRecognitionManagerImpl(); | 93 SpeechRecognitionManagerImpl(); |
| 94 virtual ~SpeechRecognitionManagerImpl(); | 94 virtual ~SpeechRecognitionManagerImpl(); |
| 95 | 95 |
| 96 bool HasPendingRequest(int caller_id) const; | 96 bool HasPendingRequest(int session_id) const; |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 struct Request { | 99 struct Request { |
| 100 Request(); | 100 Request(); |
| 101 ~Request(); | 101 ~Request(); |
| 102 | 102 |
| 103 InputTagSpeechDispatcherHost* delegate; | 103 InputTagSpeechDispatcherHost* delegate; |
| 104 scoped_refptr<content::SpeechRecognizer> recognizer; | 104 scoped_refptr<content::SpeechRecognizer> recognizer; |
| 105 bool is_active; // Set to true when recording or recognition is going on. | 105 bool is_active; // Set to true when recording or recognition is going on. |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 struct SpeechRecognitionParams; | 108 struct SpeechRecognitionParams; |
| 109 | 109 |
| 110 InputTagSpeechDispatcherHost* GetDelegate(int caller_id) const; | 110 InputTagSpeechDispatcherHost* GetDelegate(int session_id) const; |
| 111 | 111 |
| 112 void CheckRenderViewTypeAndStartRecognition( | 112 void CheckRenderViewTypeAndStartRecognition( |
| 113 const SpeechRecognitionParams& params); | 113 const SpeechRecognitionParams& params); |
| 114 void ProceedStartingRecognition(const SpeechRecognitionParams& params); | 114 void ProceedStartingRecognition(const SpeechRecognitionParams& params); |
| 115 | 115 |
| 116 void CancelRecognitionAndInformDelegate(int caller_id); | 116 void CancelRecognitionAndInformDelegate(int session_id); |
| 117 | 117 |
| 118 typedef std::map<int, Request> SpeechRecognizerMap; | 118 typedef std::map<int, Request> SpeechRecognizerMap; |
| 119 SpeechRecognizerMap requests_; | 119 SpeechRecognizerMap requests_; |
| 120 std::string request_info_; | 120 std::string request_info_; |
| 121 bool can_report_metrics_; | 121 bool can_report_metrics_; |
| 122 int recording_caller_id_; | 122 int recording_session_id_; |
| 123 scoped_ptr<content::SpeechRecognitionManagerDelegate> delegate_; | 123 scoped_ptr<content::SpeechRecognitionManagerDelegate> delegate_; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 } // namespace speech | 126 } // namespace speech |
| 127 | 127 |
| 128 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ | 128 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_IMPL_H_ |
| OLD | NEW |