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

Side by Side Diff: chrome/browser/speech/speech_input_extension_manager.h

Issue 9688012: Refactoring of chrome speech recognition architecture (CL1.2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor fix in recognizer unit test due to "others" CL in the middle (9692038) Created 8 years, 9 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) 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_recognition_event_listener.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 SpeechRecognizer; 24 class SpeechRecognizer;
25 } 25 }
26 26
27 namespace net { 27 namespace net {
28 class URLRequestContextGetter; 28 class URLRequestContextGetter;
29 } 29 }
30 30
31 // Used for API tests. 31 // Used for API tests.
32 class SpeechInputExtensionInterface { 32 class SpeechInputExtensionInterface {
33 public: 33 public:
34 SpeechInputExtensionInterface(); 34 SpeechInputExtensionInterface();
35 virtual ~SpeechInputExtensionInterface(); 35 virtual ~SpeechInputExtensionInterface();
36 36
37 // Called from the IO thread. 37 // Called from the IO thread.
38 virtual void StartRecording( 38 virtual void StartRecording(
39 content::SpeechRecognizerDelegate* delegate, 39 content::SpeechRecognitionEventListener* listener,
40 net::URLRequestContextGetter* context_getter, 40 net::URLRequestContextGetter* context_getter,
41 int caller_id, 41 int caller_id,
42 const std::string& language, 42 const std::string& language,
43 const std::string& grammar, 43 const std::string& grammar,
44 bool filter_profanities) = 0; 44 bool filter_profanities) = 0;
45 45
46 virtual void StopRecording(bool recognition_failed) = 0; 46 virtual void StopRecording(bool recognition_failed) = 0;
47 virtual bool HasAudioInputDevices() = 0; 47 virtual bool HasAudioInputDevices() = 0;
48 virtual bool IsCapturingAudio() = 0; 48 virtual bool IsCapturingAudio() = 0;
49 49
50 // Called from the UI thread. 50 // Called from the UI thread.
51 virtual bool HasValidRecognizer() = 0; 51 virtual bool HasValidRecognizer() = 0;
52 }; 52 };
53 53
54 // Manages the speech input requests and responses from the extensions 54 // Manages the speech input requests and responses from the extensions
55 // associated to the given profile. 55 // associated to the given profile.
56 class SpeechInputExtensionManager 56 class SpeechInputExtensionManager
57 : public base::RefCountedThreadSafe<SpeechInputExtensionManager>, 57 : public base::RefCountedThreadSafe<SpeechInputExtensionManager>,
58 public content::SpeechRecognizerDelegate, 58 public content::SpeechRecognitionEventListener,
59 public content::NotificationObserver, 59 public content::NotificationObserver,
60 private SpeechInputExtensionInterface { 60 private SpeechInputExtensionInterface {
61 public: 61 public:
62 enum State { 62 enum State {
63 kIdle = 0, 63 kIdle = 0,
64 kStarting, 64 kStarting,
65 kRecording, 65 kRecording,
66 kStopping, 66 kStopping,
67 kShutdown // Internal sink state when the profile is destroyed on shutdown. 67 kShutdown // Internal sink state when the profile is destroyed on shutdown.
68 }; 68 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void IsRecording(const IsRecordingCallback& callback); 107 void IsRecording(const IsRecordingCallback& callback);
108 108
109 // Called by internal ProfileKeyedService class. 109 // Called by internal ProfileKeyedService class.
110 void ShutdownOnUIThread(); 110 void ShutdownOnUIThread();
111 111
112 // Methods from content::NotificationObserver. 112 // Methods from content::NotificationObserver.
113 virtual void Observe(int type, 113 virtual void Observe(int type,
114 const content::NotificationSource& source, 114 const content::NotificationSource& source,
115 const content::NotificationDetails& details) OVERRIDE; 115 const content::NotificationDetails& details) OVERRIDE;
116 116
117 // Methods from SpeechRecognizerDelegate. 117 // Methods from SpeechRecognitionEventListener.
118 virtual void SetRecognitionResult( 118 virtual void OnRecognitionStart(int caller_id) OVERRIDE;
119 virtual void OnAudioStart(int caller_id) OVERRIDE;
120 virtual void OnEnvironmentEstimationComplete(int caller_id) OVERRIDE;
121 virtual void OnSoundStart(int caller_id) OVERRIDE;
122 virtual void OnSoundEnd(int caller_id) OVERRIDE;
123 virtual void OnAudioEnd(int caller_id) OVERRIDE;
124 virtual void OnRecognitionResult(
125 int caller_id, const content::SpeechRecognitionResult& result) OVERRIDE;
126 virtual void OnRecognitionError(
119 int caller_id, 127 int caller_id,
120 const content::SpeechRecognitionResult& result) OVERRIDE; 128 const content::SpeechRecognitionErrorCode& error) OVERRIDE;
121 129 virtual void OnAudioLevelsChange(int caller_id, float volume,
122 virtual void DidStartReceivingAudio(int caller_id) OVERRIDE; 130 float noise_volume) OVERRIDE;
123 virtual void DidCompleteRecording(int caller_id) OVERRIDE; 131 virtual void OnRecognitionEnd(int caller_id) OVERRIDE;
124 virtual void DidCompleteRecognition(int caller_id) OVERRIDE;
125 virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE;
126 virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE;
127 virtual void OnRecognizerError(int caller_id,
128 content::SpeechRecognitionErrorCode error)
129 OVERRIDE;
130 virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE;
131 virtual void SetInputVolume(int caller_id, float volume,
132 float noise_volume) OVERRIDE;
133 132
134 // Methods for API testing. 133 // Methods for API testing.
135 void SetSpeechInputExtensionInterface( 134 void SetSpeechInputExtensionInterface(
136 SpeechInputExtensionInterface* interface); 135 SpeechInputExtensionInterface* interface);
137 SpeechInputExtensionInterface* GetSpeechInputExtensionInterface(); 136 SpeechInputExtensionInterface* GetSpeechInputExtensionInterface();
138 137
139 private: 138 private:
140 // SpeechInputExtensionInterface methods: 139 // SpeechInputExtensionInterface methods:
141 virtual bool IsCapturingAudio() OVERRIDE; 140 virtual bool IsCapturingAudio() OVERRIDE;
142 virtual bool HasAudioInputDevices() OVERRIDE; 141 virtual bool HasAudioInputDevices() OVERRIDE;
143 virtual bool HasValidRecognizer() OVERRIDE; 142 virtual bool HasValidRecognizer() OVERRIDE;
144 virtual void StartRecording( 143 virtual void StartRecording(
145 content::SpeechRecognizerDelegate* delegate, 144 content::SpeechRecognitionEventListener* listener,
146 net::URLRequestContextGetter* context_getter, 145 net::URLRequestContextGetter* context_getter,
147 int caller_id, 146 int caller_id,
148 const std::string& language, 147 const std::string& language,
149 const std::string& grammar, 148 const std::string& grammar,
150 bool filter_profanities) OVERRIDE; 149 bool filter_profanities) OVERRIDE;
151 150
152 virtual void StopRecording(bool recognition_failed) OVERRIDE; 151 virtual void StopRecording(bool recognition_failed) OVERRIDE;
153 152
154 // Internal methods. 153 // Internal methods.
155 void StartOnIOThread( 154 void StartOnIOThread(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // Used in the UI thread. 196 // Used in the UI thread.
198 scoped_ptr<content::NotificationRegistrar> registrar_; 197 scoped_ptr<content::NotificationRegistrar> registrar_;
199 SpeechInputExtensionInterface* speech_interface_; 198 SpeechInputExtensionInterface* speech_interface_;
200 scoped_ptr<SpeechInputExtensionNotification> notification_; 199 scoped_ptr<SpeechInputExtensionNotification> notification_;
201 200
202 // Used in the IO thread. 201 // Used in the IO thread.
203 scoped_refptr<content::SpeechRecognizer> recognizer_; 202 scoped_refptr<content::SpeechRecognizer> recognizer_;
204 }; 203 };
205 204
206 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ 205 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/speech/speech_input_extension_apitest.cc ('k') | chrome/browser/speech/speech_input_extension_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698