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 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/speech_recognition_event_listener.h" | 16 #include "content/public/browser/speech_recognition_event_listener.h" |
16 | 17 |
17 class Profile; | 18 class Profile; |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class ListValue; | 21 class ListValue; |
21 } | 22 } |
22 | 23 |
23 namespace content { | 24 namespace content { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 83 |
83 typedef base::Callback<void(bool)> IsRecordingCallback; | 84 typedef base::Callback<void(bool)> IsRecordingCallback; |
84 | 85 |
85 // Should not be used directly. Managed by a ProfileKeyedServiceFactory. | 86 // Should not be used directly. Managed by a ProfileKeyedServiceFactory. |
86 explicit SpeechInputExtensionManager(Profile* profile); | 87 explicit SpeechInputExtensionManager(Profile* profile); |
87 | 88 |
88 // Returns the corresponding manager for the given profile, creating | 89 // Returns the corresponding manager for the given profile, creating |
89 // a new one if required. | 90 // a new one if required. |
90 static SpeechInputExtensionManager* GetForProfile(Profile* profile); | 91 static SpeechInputExtensionManager* GetForProfile(Profile* profile); |
91 | 92 |
92 // Initialize the ProfileKeyedServiceFactory. | |
93 static void InitializeFactory(); | |
94 | |
95 // Request to start speech recognition for the provided extension. | 93 // Request to start speech recognition for the provided extension. |
96 bool Start(const std::string& extension_id, | 94 bool Start(const std::string& extension_id, |
97 const std::string& language, | 95 const std::string& language, |
98 const std::string& grammar, | 96 const std::string& grammar, |
99 bool filter_profanities, | 97 bool filter_profanities, |
100 std::string* error); | 98 std::string* error); |
101 | 99 |
102 // Request to stop an ongoing speech recognition. | 100 // Request to stop an ongoing speech recognition. |
103 bool Stop(const std::string& extension_id, std::string* error); | 101 bool Stop(const std::string& extension_id, std::string* error); |
104 | 102 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 179 |
182 void ResetToIdleState(); | 180 void ResetToIdleState(); |
183 | 181 |
184 void AbortAllSessionsOnIOThread(); | 182 void AbortAllSessionsOnIOThread(); |
185 | 183 |
186 int GetRenderProcessIDForExtension(const std::string& extension_id) const; | 184 int GetRenderProcessIDForExtension(const std::string& extension_id) const; |
187 | 185 |
188 virtual ~SpeechInputExtensionManager(); | 186 virtual ~SpeechInputExtensionManager(); |
189 | 187 |
190 friend class base::RefCountedThreadSafe<SpeechInputExtensionManager>; | 188 friend class base::RefCountedThreadSafe<SpeechInputExtensionManager>; |
191 class Factory; | |
192 | 189 |
193 // Lock used to allow exclusive access to the state variable and methods that | 190 // Lock used to allow exclusive access to the state variable and methods that |
194 // either read or write on it. This is required since the speech code | 191 // either read or write on it. This is required since the speech code |
195 // operates in the IO thread while the extension code uses the UI thread. | 192 // operates in the IO thread while the extension code uses the UI thread. |
196 base::Lock state_lock_; | 193 base::Lock state_lock_; |
197 | 194 |
198 // Used in the UI thread but also its raw value as notification | 195 // Used in the UI thread but also its raw value as notification |
199 // source in the IO thread, guarded by the state lock and value. | 196 // source in the IO thread, guarded by the state lock and value. |
200 Profile* profile_; | 197 Profile* profile_; |
201 | 198 |
202 // Used in both threads, guarded by the state lock. | 199 // Used in both threads, guarded by the state lock. |
203 State state_; | 200 State state_; |
204 std::string extension_id_in_use_; | 201 std::string extension_id_in_use_; |
205 | 202 |
206 // Used in the UI thread. | 203 // Used in the UI thread. |
207 scoped_ptr<content::NotificationRegistrar> registrar_; | 204 scoped_ptr<content::NotificationRegistrar> registrar_; |
208 SpeechInputExtensionInterface* speech_interface_; | 205 SpeechInputExtensionInterface* speech_interface_; |
209 | 206 |
210 // Used in the IO thread. | 207 // Used in the IO thread. |
211 bool is_recognition_in_progress_; | 208 bool is_recognition_in_progress_; |
212 int speech_recognition_session_id_; | 209 int speech_recognition_session_id_; |
213 }; | 210 }; |
214 | 211 |
| 212 namespace extensions { |
| 213 |
| 214 class SpeechInputAPI : public ProfileKeyedAPI { |
| 215 public: |
| 216 explicit SpeechInputAPI(Profile* profile); |
| 217 virtual ~SpeechInputAPI(); |
| 218 |
| 219 // Convenience method to get the SpeechInputExtensionAPI for a profile. |
| 220 static SpeechInputAPI* GetForProfile(Profile* profile); |
| 221 |
| 222 // ProfileKeyedAPI implementation. |
| 223 static ProfileKeyedAPIFactory<SpeechInputAPI>* GetFactoryInstance(); |
| 224 |
| 225 SpeechInputExtensionManager* manager() const { return manager_.get(); } |
| 226 |
| 227 private: |
| 228 friend class ProfileKeyedAPIFactory<SpeechInputAPI>; |
| 229 |
| 230 // ProfileKeyedAPI implementation. |
| 231 static const char* service_name() { |
| 232 return "SpeechInputAPI"; |
| 233 } |
| 234 static const bool kServiceIsNULLWhileTesting = true; |
| 235 static const bool kServiceIsCreatedWithProfile = true; |
| 236 // Methods from ProfileKeyedService. |
| 237 virtual void Shutdown() OVERRIDE; |
| 238 |
| 239 scoped_refptr<SpeechInputExtensionManager> manager_; |
| 240 }; |
| 241 |
| 242 } // namespace extensions |
| 243 |
215 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ | 244 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ |
OLD | NEW |