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