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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "content/common/speech_input_result.h" | 9 #include "content/common/speech_input_result.h" |
10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
11 | 11 |
12 namespace speech_input { | 12 namespace speech_input { |
13 | 13 |
14 // This is the gatekeeper for speech recognition in the browser process. It | 14 // This is the gatekeeper for speech recognition in the browser process. It |
15 // handles requests received from various render views and makes sure only one | 15 // handles requests received from various render views and makes sure only one |
16 // of them can use speech recognition at a time. It also sends recognition | 16 // of them can use speech recognition at a time. It also sends recognition |
17 // results and status events to the render views when required. | 17 // results and status events to the render views when required. |
18 // This class is a singleton and accessed via the Get method. | 18 // This class is a singleton and accessed via the Get method. |
Satish
2011/08/25 09:08:52
Need to update this comment since the Get() method
jam
2011/08/25 16:36:43
done (moved it to the chrome impl)
| |
19 class SpeechInputManager { | 19 class SpeechInputManager { |
20 public: | 20 public: |
21 // Implemented by the dispatcher host to relay events to the render views. | 21 // Implemented by the dispatcher host to relay events to the render views. |
22 class Delegate { | 22 class Delegate { |
23 public: | 23 public: |
24 virtual void SetRecognitionResult( | 24 virtual void SetRecognitionResult( |
25 int caller_id, | 25 int caller_id, |
26 const SpeechInputResultArray& result) = 0; | 26 const SpeechInputResultArray& result) = 0; |
27 virtual void DidCompleteRecording(int caller_id) = 0; | 27 virtual void DidCompleteRecording(int caller_id) = 0; |
28 virtual void DidCompleteRecognition(int caller_id) = 0; | 28 virtual void DidCompleteRecognition(int caller_id) = 0; |
29 | 29 |
30 protected: | 30 protected: |
31 virtual ~Delegate() {} | 31 virtual ~Delegate() {} |
32 }; | 32 }; |
33 | 33 |
34 SpeechInputManager() : censor_results_(true) {} | 34 SpeechInputManager(); |
35 | 35 |
36 // Invokes the platform provided microphone settings UI in a non-blocking way, | 36 // Invokes the platform provided microphone settings UI in a non-blocking way, |
37 // via the BrowserThread::FILE thread. | 37 // via the BrowserThread::FILE thread. |
38 static void ShowAudioInputSettings(); | 38 static void ShowAudioInputSettings(); |
39 | 39 |
40 // Factory method to access the singleton. We have this method here instead of | 40 virtual ~SpeechInputManager(); |
41 // using Singleton directly in the calling code to aid tests in injection | |
42 // mocks. | |
43 static SpeechInputManager* Get(); | |
44 // Factory method definition useful for tests. | |
45 typedef SpeechInputManager* (AccessorMethod)(); | |
46 | |
47 virtual ~SpeechInputManager() {} | |
48 | 41 |
49 // Handlers for requests from render views. | 42 // Handlers for requests from render views. |
50 | 43 |
51 // |delegate| is a weak pointer and should remain valid until | 44 // |delegate| is a weak pointer and should remain valid until |
52 // its |DidCompleteRecognition| method is called or recognition is cancelled. | 45 // its |DidCompleteRecognition| method is called or recognition is cancelled. |
53 // |render_process_id| is the ID of the renderer process initiating the | 46 // |render_process_id| is the ID of the renderer process initiating the |
54 // request. | 47 // request. |
55 // |element_rect| is the display bounds of the html element requesting speech | 48 // |element_rect| is the display bounds of the html element requesting speech |
56 // input (in page coordinates). | 49 // input (in page coordinates). |
57 virtual void StartRecognition(Delegate* delegate, | 50 virtual void StartRecognition(Delegate* delegate, |
58 int caller_id, | 51 int caller_id, |
59 int render_process_id, | 52 int render_process_id, |
60 int render_view_id, | 53 int render_view_id, |
61 const gfx::Rect& element_rect, | 54 const gfx::Rect& element_rect, |
62 const std::string& language, | 55 const std::string& language, |
63 const std::string& grammar, | 56 const std::string& grammar, |
64 const std::string& origin_url) = 0; | 57 const std::string& origin_url) = 0; |
65 virtual void CancelRecognition(int caller_id) = 0; | 58 virtual void CancelRecognition(int caller_id) = 0; |
66 virtual void StopRecording(int caller_id) = 0; | 59 virtual void StopRecording(int caller_id) = 0; |
67 | 60 |
68 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) = 0; | 61 virtual void CancelAllRequestsWithDelegate(Delegate* delegate) = 0; |
69 | 62 |
70 void set_censor_results(bool censor) { censor_results_ = censor; } | 63 void set_censor_results(bool censor) { censor_results_ = censor; } |
71 | 64 |
72 bool censor_results() { return censor_results_; } | 65 bool censor_results() { return censor_results_; } |
66 | |
73 private: | 67 private: |
74 bool censor_results_; | 68 bool censor_results_; |
75 }; | 69 }; |
76 | 70 |
77 // This typedef is to workaround the issue with certain versions of | 71 // This typedef is to workaround the issue with certain versions of |
78 // Visual Studio where it gets confused between multiple Delegate | 72 // Visual Studio where it gets confused between multiple Delegate |
79 // classes and gives a C2500 error. (I saw this error on the try bots - | 73 // classes and gives a C2500 error. (I saw this error on the try bots - |
80 // the workaround was not needed for my machine). | 74 // the workaround was not needed for my machine). |
81 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; | 75 typedef SpeechInputManager::Delegate SpeechInputManagerDelegate; |
82 | 76 |
83 } // namespace speech_input | 77 } // namespace speech_input |
84 | 78 |
85 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ | 79 #endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_MANAGER_H_ |
OLD | NEW |