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 CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/speech_recognizer_delegate.h" | 16 #include "content/public/browser/speech_recognizer_delegate.h" |
17 | 17 |
18 class Extension; | 18 class Extension; |
19 class Profile; | 19 class Profile; |
20 class SpeechInputExtensionNotification; | 20 class SpeechInputExtensionNotification; |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 class NotificationRegistrar; | 23 class NotificationRegistrar; |
24 class ResourceContext; | |
25 } | 24 } |
26 | 25 |
27 namespace net { | 26 namespace net { |
28 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
29 } | 28 } |
30 | 29 |
31 namespace speech_input { | 30 namespace speech_input { |
32 class SpeechRecognizer; | 31 class SpeechRecognizer; |
33 } | 32 } |
34 | 33 |
35 // Used for API tests. | 34 // Used for API tests. |
36 class SpeechInputExtensionInterface { | 35 class SpeechInputExtensionInterface { |
37 public: | 36 public: |
38 SpeechInputExtensionInterface(); | 37 SpeechInputExtensionInterface(); |
39 virtual ~SpeechInputExtensionInterface(); | 38 virtual ~SpeechInputExtensionInterface(); |
40 | 39 |
41 // Called from the IO thread. | 40 // Called from the IO thread. |
42 virtual void StartRecording( | 41 virtual void StartRecording( |
43 content::SpeechRecognizerDelegate* delegate, | 42 content::SpeechRecognizerDelegate* delegate, |
44 net::URLRequestContextGetter* context_getter, | 43 net::URLRequestContextGetter* context_getter, |
45 content::ResourceContext* resource_context, | |
46 int caller_id, | 44 int caller_id, |
47 const std::string& language, | 45 const std::string& language, |
48 const std::string& grammar, | 46 const std::string& grammar, |
49 bool filter_profanities) = 0; | 47 bool filter_profanities) = 0; |
50 | 48 |
51 virtual void StopRecording(bool recognition_failed) = 0; | 49 virtual void StopRecording(bool recognition_failed) = 0; |
52 virtual bool HasAudioInputDevices( | 50 virtual bool HasAudioInputDevices() = 0; |
53 content::ResourceContext* resource_context) = 0; | 51 virtual bool IsRecordingInProcess() = 0; |
54 virtual bool IsRecordingInProcess( | |
55 content::ResourceContext* resource_context) = 0; | |
56 | 52 |
57 // Called from the UI thread. | 53 // Called from the UI thread. |
58 virtual bool HasValidRecognizer() = 0; | 54 virtual bool HasValidRecognizer() = 0; |
59 | 55 |
60 protected: | 56 protected: |
61 scoped_refptr<speech_input::SpeechRecognizer> recognizer_; | 57 scoped_refptr<speech_input::SpeechRecognizer> recognizer_; |
62 }; | 58 }; |
63 | 59 |
64 // Manages the speech input requests and responses from the extensions | 60 // Manages the speech input requests and responses from the extensions |
65 // associated to the given profile. | 61 // associated to the given profile. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 virtual void SetInputVolume(int caller_id, float volume, | 137 virtual void SetInputVolume(int caller_id, float volume, |
142 float noise_volume) OVERRIDE; | 138 float noise_volume) OVERRIDE; |
143 | 139 |
144 // Methods for API testing. | 140 // Methods for API testing. |
145 void SetSpeechInputExtensionInterface( | 141 void SetSpeechInputExtensionInterface( |
146 SpeechInputExtensionInterface* interface); | 142 SpeechInputExtensionInterface* interface); |
147 SpeechInputExtensionInterface* GetSpeechInputExtensionInterface(); | 143 SpeechInputExtensionInterface* GetSpeechInputExtensionInterface(); |
148 | 144 |
149 private: | 145 private: |
150 // SpeechInputExtensionInterface methods: | 146 // SpeechInputExtensionInterface methods: |
151 virtual bool IsRecordingInProcess( | 147 virtual bool IsRecordingInProcess() OVERRIDE; |
152 content::ResourceContext* resource_context) OVERRIDE; | 148 virtual bool HasAudioInputDevices() OVERRIDE; |
153 virtual bool HasAudioInputDevices( | |
154 content::ResourceContext* resource_context) OVERRIDE; | |
155 virtual bool HasValidRecognizer() OVERRIDE; | 149 virtual bool HasValidRecognizer() OVERRIDE; |
156 | |
157 virtual void StartRecording( | 150 virtual void StartRecording( |
158 content::SpeechRecognizerDelegate* delegate, | 151 content::SpeechRecognizerDelegate* delegate, |
159 net::URLRequestContextGetter* context_getter, | 152 net::URLRequestContextGetter* context_getter, |
160 content::ResourceContext* resource_context, | |
161 int caller_id, | 153 int caller_id, |
162 const std::string& language, | 154 const std::string& language, |
163 const std::string& grammar, | 155 const std::string& grammar, |
164 bool filter_profanities) OVERRIDE; | 156 bool filter_profanities) OVERRIDE; |
165 | 157 |
166 virtual void StopRecording(bool recognition_failed) OVERRIDE; | 158 virtual void StopRecording(bool recognition_failed) OVERRIDE; |
167 | 159 |
168 // Internal methods. | 160 // Internal methods. |
169 void StartOnIOThread( | 161 void StartOnIOThread( |
170 net::URLRequestContextGetter* context_getter, | 162 net::URLRequestContextGetter* context_getter, |
171 content::ResourceContext* resource_context, | |
172 const std::string& language, | 163 const std::string& language, |
173 const std::string& grammar, | 164 const std::string& grammar, |
174 bool filter_profanities); | 165 bool filter_profanities); |
175 void ForceStopOnIOThread(); | 166 void ForceStopOnIOThread(); |
176 void IsRecordingOnIOThread(const IsRecordingCallback& callback, | 167 void IsRecordingOnIOThread(const IsRecordingCallback& callback); |
177 content::ResourceContext* resource_context); | |
178 | 168 |
179 void SetRecognitionResultOnUIThread( | 169 void SetRecognitionResultOnUIThread( |
180 const content::SpeechInputResult& result, | 170 const content::SpeechInputResult& result, |
181 const std::string& extension_id); | 171 const std::string& extension_id); |
182 void DidStartReceivingAudioOnUIThread(); | 172 void DidStartReceivingAudioOnUIThread(); |
183 void StopSucceededOnUIThread(); | 173 void StopSucceededOnUIThread(); |
184 void IsRecordingOnUIThread(const IsRecordingCallback& callback, bool result); | 174 void IsRecordingOnUIThread(const IsRecordingCallback& callback, bool result); |
185 | 175 |
186 void DispatchError(const std::string& error, bool dispatch_event); | 176 void DispatchError(const std::string& error, bool dispatch_event); |
187 void DispatchEventToExtension(const std::string& extension_id, | 177 void DispatchEventToExtension(const std::string& extension_id, |
(...skipping 22 matching lines...) Expand all Loading... |
210 State state_; | 200 State state_; |
211 std::string extension_id_in_use_; | 201 std::string extension_id_in_use_; |
212 | 202 |
213 // Used in the UI thread. | 203 // Used in the UI thread. |
214 scoped_ptr<content::NotificationRegistrar> registrar_; | 204 scoped_ptr<content::NotificationRegistrar> registrar_; |
215 SpeechInputExtensionInterface* speech_interface_; | 205 SpeechInputExtensionInterface* speech_interface_; |
216 scoped_ptr<SpeechInputExtensionNotification> notification_; | 206 scoped_ptr<SpeechInputExtensionNotification> notification_; |
217 }; | 207 }; |
218 | 208 |
219 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 209 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
OLD | NEW |