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 "base/synchronization/lock.h" |
| 10 #include "content/browser/speech/speech_recognizer.h" |
| 11 #include "content/public/browser/notification_observer.h" |
9 #include <string> | 12 #include <string> |
10 | 13 |
11 #include "base/callback_forward.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/synchronization/lock.h" | |
15 #include "content/public/browser/notification_observer.h" | |
16 #include "content/public/browser/speech_recognizer_delegate.h" | |
17 | |
18 class Extension; | 14 class Extension; |
19 class Profile; | 15 class Profile; |
20 class SpeechInputExtensionNotification; | 16 class SpeechInputExtensionNotification; |
21 | 17 |
22 namespace content { | 18 namespace content { |
23 class NotificationRegistrar; | 19 class NotificationRegistrar; |
24 class ResourceContext; | 20 class ResourceContext; |
25 } | 21 } |
26 | 22 |
27 namespace net { | 23 namespace net { |
28 class URLRequestContextGetter; | 24 class URLRequestContextGetter; |
29 } | 25 } |
30 | 26 |
31 namespace speech_input { | |
32 class SpeechRecognizer; | |
33 } | |
34 | |
35 // Used for API tests. | 27 // Used for API tests. |
36 class SpeechInputExtensionInterface { | 28 class SpeechInputExtensionInterface { |
37 public: | 29 public: |
38 SpeechInputExtensionInterface(); | 30 SpeechInputExtensionInterface(); |
39 virtual ~SpeechInputExtensionInterface(); | 31 virtual ~SpeechInputExtensionInterface(); |
40 | 32 |
41 // Called from the IO thread. | 33 // Called from the IO thread. |
42 virtual void StartRecording( | 34 virtual void StartRecording( |
43 content::SpeechRecognizerDelegate* delegate, | 35 speech_input::SpeechRecognizerDelegate* delegate, |
44 net::URLRequestContextGetter* context_getter, | 36 net::URLRequestContextGetter* context_getter, |
45 content::ResourceContext* resource_context, | 37 content::ResourceContext* resource_context, |
46 int caller_id, | 38 int caller_id, |
47 const std::string& language, | 39 const std::string& language, |
48 const std::string& grammar, | 40 const std::string& grammar, |
49 bool filter_profanities) = 0; | 41 bool filter_profanities) = 0; |
50 | 42 |
51 virtual void StopRecording(bool recognition_failed) = 0; | 43 virtual void StopRecording(bool recognition_failed) = 0; |
52 virtual bool HasAudioInputDevices( | 44 virtual bool HasAudioInputDevices( |
53 content::ResourceContext* resource_context) = 0; | 45 content::ResourceContext* resource_context) = 0; |
54 virtual bool IsRecordingInProcess( | 46 virtual bool IsRecordingInProcess( |
55 content::ResourceContext* resource_context) = 0; | 47 content::ResourceContext* resource_context) = 0; |
56 | 48 |
57 // Called from the UI thread. | 49 // Called from the UI thread. |
58 virtual bool HasValidRecognizer() = 0; | 50 virtual bool HasValidRecognizer() = 0; |
59 | 51 |
60 protected: | 52 protected: |
61 scoped_refptr<speech_input::SpeechRecognizer> recognizer_; | 53 scoped_refptr<speech_input::SpeechRecognizer> recognizer_; |
62 }; | 54 }; |
63 | 55 |
64 // Manages the speech input requests and responses from the extensions | 56 // Manages the speech input requests and responses from the extensions |
65 // associated to the given profile. | 57 // associated to the given profile. |
66 class SpeechInputExtensionManager | 58 class SpeechInputExtensionManager |
67 : public base::RefCountedThreadSafe<SpeechInputExtensionManager>, | 59 : public base::RefCountedThreadSafe<SpeechInputExtensionManager>, |
68 public content::SpeechRecognizerDelegate, | 60 public speech_input::SpeechRecognizerDelegate, |
69 public content::NotificationObserver, | 61 public content::NotificationObserver, |
70 private SpeechInputExtensionInterface { | 62 private SpeechInputExtensionInterface { |
71 public: | 63 public: |
72 enum State { | 64 enum State { |
73 kIdle = 0, | 65 kIdle = 0, |
74 kStarting, | 66 kStarting, |
75 kRecording, | 67 kRecording, |
76 kStopping, | 68 kStopping, |
77 kShutdown // Internal sink state when the profile is destroyed on shutdown. | 69 kShutdown // Internal sink state when the profile is destroyed on shutdown. |
78 }; | 70 }; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 140 |
149 private: | 141 private: |
150 // SpeechInputExtensionInterface methods: | 142 // SpeechInputExtensionInterface methods: |
151 virtual bool IsRecordingInProcess( | 143 virtual bool IsRecordingInProcess( |
152 content::ResourceContext* resource_context) OVERRIDE; | 144 content::ResourceContext* resource_context) OVERRIDE; |
153 virtual bool HasAudioInputDevices( | 145 virtual bool HasAudioInputDevices( |
154 content::ResourceContext* resource_context) OVERRIDE; | 146 content::ResourceContext* resource_context) OVERRIDE; |
155 virtual bool HasValidRecognizer() OVERRIDE; | 147 virtual bool HasValidRecognizer() OVERRIDE; |
156 | 148 |
157 virtual void StartRecording( | 149 virtual void StartRecording( |
158 content::SpeechRecognizerDelegate* delegate, | 150 speech_input::SpeechRecognizerDelegate* delegate, |
159 net::URLRequestContextGetter* context_getter, | 151 net::URLRequestContextGetter* context_getter, |
160 content::ResourceContext* resource_context, | 152 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. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 State state_; | 202 State state_; |
211 std::string extension_id_in_use_; | 203 std::string extension_id_in_use_; |
212 | 204 |
213 // Used in the UI thread. | 205 // Used in the UI thread. |
214 scoped_ptr<content::NotificationRegistrar> registrar_; | 206 scoped_ptr<content::NotificationRegistrar> registrar_; |
215 SpeechInputExtensionInterface* speech_interface_; | 207 SpeechInputExtensionInterface* speech_interface_; |
216 scoped_ptr<SpeechInputExtensionNotification> notification_; | 208 scoped_ptr<SpeechInputExtensionNotification> notification_; |
217 }; | 209 }; |
218 | 210 |
219 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 211 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
OLD | NEW |