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 SpeechInputResult; |
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 SpeechRecognitionDispatcherHost; |
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 SpeechRecognitionDispatcherHost* 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 SpeechRecognitionDispatcherHost* 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, |
80 const content::SpeechInputResult& result) OVERRIDE; | 80 const content::SpeechInputResult& result) OVERRIDE; |
81 virtual void DidCompleteRecording(int caller_id) OVERRIDE; | 81 virtual void DidCompleteRecording(int caller_id) OVERRIDE; |
82 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; | 82 virtual void DidCompleteRecognition(int caller_id) OVERRIDE; |
83 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; | 83 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE; |
84 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; | 84 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE; |
85 | 85 |
86 virtual void OnRecognizerError(int caller_id, | 86 virtual void OnRecognizerError(int caller_id, |
87 content::SpeechInputError error) OVERRIDE; | 87 content::SpeechInputError error) OVERRIDE; |
88 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; | 88 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE; |
89 virtual void SetInputVolume(int caller_id, float volume, | 89 virtual void SetInputVolume(int caller_id, float volume, |
90 float noise_volume) OVERRIDE; | 90 float noise_volume) OVERRIDE; |
91 | 91 |
92 protected: | 92 protected: |
93 // Private constructor to enforce singleton. | 93 // Private constructor to enforce singleton. |
94 friend struct DefaultSingletonTraits<SpeechInputManagerImpl>; | 94 friend struct DefaultSingletonTraits<SpeechRecognitionManagerImpl>; |
95 SpeechInputManagerImpl(); | 95 SpeechRecognitionManagerImpl(); |
96 virtual ~SpeechInputManagerImpl(); | 96 virtual ~SpeechRecognitionManagerImpl(); |
97 | 97 |
98 bool HasPendingRequest(int caller_id) const; | 98 bool HasPendingRequest(int caller_id) const; |
99 | 99 |
100 private: | 100 private: |
101 struct SpeechInputRequest { | 101 struct Request { |
102 SpeechInputRequest(); | 102 Request(); |
103 ~SpeechInputRequest(); | 103 ~Request(); |
104 | 104 |
105 SpeechInputDispatcherHost* delegate; | 105 SpeechRecognitionDispatcherHost* delegate; |
106 scoped_refptr<SpeechRecognizerImpl> recognizer; | 106 scoped_refptr<SpeechRecognizerImpl> recognizer; |
107 bool is_active; // Set to true when recording or recognition is going on. | 107 bool is_active; // Set to true when recording or recognition is going on. |
108 }; | 108 }; |
109 | 109 |
110 struct SpeechInputParams; | 110 struct SpeechRecognitionParams; |
111 | 111 |
112 SpeechInputDispatcherHost* GetDelegate(int caller_id) const; | 112 SpeechRecognitionDispatcherHost* GetDelegate(int caller_id) const; |
113 | 113 |
114 void CheckRenderViewTypeAndStartRecognition(const SpeechInputParams& params); | 114 void CheckRenderViewTypeAndStartRecognition( |
115 void ProceedStartingRecognition(const SpeechInputParams& params); | 115 const SpeechRecognitionParams& params); |
| 116 void ProceedStartingRecognition(const SpeechRecognitionParams& params); |
116 | 117 |
117 void CancelRecognitionAndInformDelegate(int caller_id); | 118 void CancelRecognitionAndInformDelegate(int caller_id); |
118 | 119 |
119 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; | 120 typedef std::map<int, Request> SpeechRecognizerMap; |
120 SpeechRecognizerMap requests_; | 121 SpeechRecognizerMap requests_; |
121 std::string request_info_; | 122 std::string request_info_; |
122 bool can_report_metrics_; | 123 bool can_report_metrics_; |
123 int recording_caller_id_; | 124 int recording_caller_id_; |
124 content::SpeechInputManagerDelegate* delegate_; | 125 content::SpeechRecognitionManagerDelegate* delegate_; |
125 }; | 126 }; |
126 | 127 |
127 } // namespace speech_input | 128 } // namespace speech |
128 | 129 |
129 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 130 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_MANAGER_H_ |
OLD | NEW |