Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/browser/extensions/extension_speech_input_manager.h

Issue 8201030: Introducing the basic functionality to the speech input experimental API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/synchronization/lock.h"
12 #include "content/browser/speech/speech_recognizer.h"
11 #include "content/common/notification_observer.h" 13 #include "content/common/notification_observer.h"
12 #include "content/common/notification_registrar.h" 14 #include "content/common/notification_registrar.h"
15 #include "content/common/speech_input_result.h"
13 #include <string> 16 #include <string>
14 17
15 class Extension; 18 class Extension;
16 class NotificationDetails; 19 class NotificationDetails;
17 class NotificationSource; 20 class NotificationSource;
18 class Profile; 21 class Profile;
19 22
23 namespace net {
24 class URLRequestContextGetter;
25 }
26
20 // Manages the speech input requests and responses from the extensions 27 // Manages the speech input requests and responses from the extensions
21 // associated to the given profile. 28 // associated to the given profile.
22 class ExtensionSpeechInputManager : public NotificationObserver, 29 class ExtensionSpeechInputManager : public NotificationObserver,
23 public base::RefCountedThreadSafe<ExtensionSpeechInputManager> { 30 public base::RefCountedThreadSafe<ExtensionSpeechInputManager>,
31 public speech_input::SpeechRecognizerDelegate {
24 public: 32 public:
33 enum State {
34 kIdle = 0,
35 kStarting,
36 kRecording,
37 kStopping,
38 kShutdown // Internal sink state when the profile is destroyed on shutdown.
39 };
40
25 // Should not be used directly. Managed by a ProfileKeyedServiceFactory. 41 // Should not be used directly. Managed by a ProfileKeyedServiceFactory.
26 explicit ExtensionSpeechInputManager(Profile* profile); 42 ExtensionSpeechInputManager(Profile* profile, size_t speech_caller_id);
Satish 2011/10/08 23:15:07 why is the second parameter a size_t and not int?
Leandro Graciá Gil 2011/10/09 10:29:21 Done.
27 43
28 // Returns the corresponding manager for the given profile, creating 44 // Returns the corresponding manager for the given profile, creating
29 // a new one if required. 45 // a new one if required.
30 static ExtensionSpeechInputManager* GetForProfile(Profile* profile); 46 static ExtensionSpeechInputManager* GetForProfile(Profile* profile);
31 47
32 // Initialize the ProfileKeyedServiceFactory. 48 // Initialize the ProfileKeyedServiceFactory.
33 static void InitializeFactory(); 49 static void InitializeFactory();
34 50
35 // Methods from NotificationObserver.
36 virtual void Observe(int type,
37 const NotificationSource& source,
38 const NotificationDetails& details);
39
40 // Request to start speech recognition for the provided extension. 51 // Request to start speech recognition for the provided extension.
41 void Start(const Extension *extension); 52 void Start(const std::string& extension_id,
53 const std::string& language,
54 const std::string& grammar,
55 bool filter_profanities);
42 56
43 // Request to stop an ongoing speech recognition. 57 // Request to stop an ongoing speech recognition.
44 void Stop(const Extension *extension); 58 void Stop(const std::string& extension_id);
59
60 // Retrieve the actual state of the API manager.
61 State state() const { return state_; }
45 62
46 // Called by internal ProfileKeyedService class. 63 // Called by internal ProfileKeyedService class.
47 void ShutdownOnUIThread(); 64 void ShutdownOnUIThread();
48 65
66 // Methods from NotificationObserver.
67 virtual void Observe(int type,
68 const NotificationSource& source,
Satish 2011/10/08 23:15:07 suggest indenting these params to right and match
Leandro Graciá Gil 2011/10/09 10:29:21 Done.
69 const NotificationDetails& details) OVERRIDE;
70
71 // Methods from SpeechRecognizerDelegate.
72 virtual void SetRecognitionResult(
73 int caller_id,
74 const speech_input::SpeechInputResult& result) OVERRIDE;
75
76 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE;
77 virtual void DidCompleteRecording(int caller_id) OVERRIDE;
78 virtual void DidCompleteRecognition(int caller_id) OVERRIDE;
79 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE;
80 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE;
81 virtual void OnRecognizerError(int caller_id,
Satish 2011/10/08 23:15:07 ditto
Leandro Graciá Gil 2011/10/09 10:29:21 Done.
82 speech_input::SpeechInputError error) OVERRIDE;
83 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE;
84 virtual void SetInputVolume(int caller_id, float volume,
85 float noise_volume) OVERRIDE {}
49 private: 86 private:
Satish 2011/10/08 23:15:07 add a newline above
Leandro Graciá Gil 2011/10/09 10:29:21 Done.
87 void StartOnIOThread(
88 net::URLRequestContextGetter* context_getter,
89 const std::string& language,
90 const std::string& grammar,
91 bool filter_profanities);
92
93 void ForceStopOnIOThread();
94
95 void SetRecognitionResultOnUIThread(
96 const speech_input::SpeechInputResult& result);
97
98 void DidStartReceivingAudioOnUIThread();
99 void DispatchError(const std::string& code);
100
101 void DispatchEventToExtension(const std::string& event,
102 const std::string& json_args);
Satish 2011/10/08 23:15:07 align with param in previous line
Leandro Graciá Gil 2011/10/09 10:29:21 Done.
50 void ExtensionUnloaded(const std::string& id); 103 void ExtensionUnloaded(const std::string& id);
51 104
105 bool ShuttingDown();
106
107 virtual ~ExtensionSpeechInputManager();
108
52 friend class base::RefCountedThreadSafe<ExtensionSpeechInputManager>; 109 friend class base::RefCountedThreadSafe<ExtensionSpeechInputManager>;
53 class Factory; 110 class Factory;
54 111
55 virtual ~ExtensionSpeechInputManager(); 112 Profile* profile_;
113 std::string extension_id_;
114 NotificationRegistrar registrar_;
56 115
57 Profile* profile_; 116 int speech_caller_id_;
58 scoped_refptr<Extension> extension_; 117 base::Lock state_lock_;
59 NotificationRegistrar registrar_; 118 State state_;
119 scoped_refptr<speech_input::SpeechRecognizer> recognizer_;
60 }; 120 };
61 121
62 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_ 122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPEECH_INPUT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698