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

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

Issue 10407120: Moving tray icon and notification balloon for background speech recognition sessions to ChromeSpeec… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed tray icon tooltip message. Created 8 years, 6 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/string16.h"
15 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
16 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/speech_recognition_event_listener.h" 16 #include "content/public/browser/speech_recognition_event_listener.h"
18 17
19 class Profile; 18 class Profile;
20 19
21 namespace content { 20 namespace content {
22 class NotificationRegistrar; 21 class NotificationRegistrar;
23 struct SpeechRecognitionError; 22 struct SpeechRecognitionError;
24 class SpeechRecognitionManager; 23 class SpeechRecognitionManager;
25 struct SpeechRecognitionResult; 24 struct SpeechRecognitionResult;
26 } 25 }
27 26
28 namespace net { 27 namespace net {
29 class URLRequestContextGetter; 28 class URLRequestContextGetter;
30 } 29 }
31 30
32 // Used for API tests. 31 // Used for API tests.
33 class SpeechInputExtensionInterface { 32 class SpeechInputExtensionInterface {
34 public: 33 public:
35 SpeechInputExtensionInterface(); 34 SpeechInputExtensionInterface();
36 virtual ~SpeechInputExtensionInterface(); 35 virtual ~SpeechInputExtensionInterface();
37 36
38 // Called from the IO thread. 37 // Called from the IO thread.
39 virtual void StartRecording( 38 virtual void StartRecording(
40 content::SpeechRecognitionEventListener* listener, 39 content::SpeechRecognitionEventListener* listener,
41 net::URLRequestContextGetter* context_getter, 40 net::URLRequestContextGetter* context_getter,
42 const string16& extension_name, 41 const std::string& extension_name,
43 const std::string& language, 42 const std::string& language,
44 const std::string& grammar, 43 const std::string& grammar,
45 bool filter_profanities, 44 bool filter_profanities,
46 bool show_notification) = 0; 45 int render_process_id) = 0;
47 46
48 virtual void StopRecording(bool recognition_failed) = 0; 47 virtual void StopRecording(bool recognition_failed) = 0;
49 virtual bool HasAudioInputDevices() = 0; 48 virtual bool HasAudioInputDevices() = 0;
50 virtual bool IsCapturingAudio() = 0; 49 virtual bool IsCapturingAudio() = 0;
51 50
52 // Called from the UI thread. 51 // Called from the UI thread.
53 virtual bool HasValidRecognizer() = 0; 52 virtual bool HasValidRecognizer() = 0;
54 }; 53 };
55 54
56 // Manages the speech input requests and responses from the extensions 55 // Manages the speech input requests and responses from the extensions
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::SpeechRecognitionEventListener* listener, 144 content::SpeechRecognitionEventListener* listener,
146 net::URLRequestContextGetter* context_getter, 145 net::URLRequestContextGetter* context_getter,
147 const string16& extension_name, 146 const std::string& extension_name,
148 const std::string& language, 147 const std::string& language,
149 const std::string& grammar, 148 const std::string& grammar,
150 bool filter_profanities, 149 bool filter_profanities,
151 bool show_notification) OVERRIDE; 150 int render_process_id) OVERRIDE;
152 151
153 virtual void StopRecording(bool recognition_failed) OVERRIDE; 152 virtual void StopRecording(bool recognition_failed) OVERRIDE;
154 153
155 // Internal methods. 154 // Internal methods.
156 void StartOnIOThread( 155 void StartOnIOThread(
157 scoped_refptr<net::URLRequestContextGetter> context_getter, 156 scoped_refptr<net::URLRequestContextGetter> context_getter,
158 const string16& extension_name, 157 const std::string& extension_name,
159 const std::string& language, 158 const std::string& language,
160 const std::string& grammar, 159 const std::string& grammar,
161 bool filter_profanities, 160 bool filter_profanities,
162 bool show_notification); 161 int render_process_id);
163 void ForceStopOnIOThread(); 162 void ForceStopOnIOThread();
164 void IsRecordingOnIOThread(const IsRecordingCallback& callback); 163 void IsRecordingOnIOThread(const IsRecordingCallback& callback);
165 164
166 void SetRecognitionResultOnUIThread( 165 void SetRecognitionResultOnUIThread(
167 const content::SpeechRecognitionResult& result, 166 const content::SpeechRecognitionResult& result,
168 const std::string& extension_id); 167 const std::string& extension_id);
169 void DidStartReceivingAudioOnUIThread(); 168 void DidStartReceivingAudioOnUIThread();
170 void StopSucceededOnUIThread(); 169 void StopSucceededOnUIThread();
171 void IsRecordingOnUIThread(const IsRecordingCallback& callback, bool result); 170 void IsRecordingOnUIThread(const IsRecordingCallback& callback, bool result);
172 171
173 void DispatchError(const std::string& error, bool dispatch_event); 172 void DispatchError(const std::string& error, bool dispatch_event);
174 void DispatchEventToExtension(const std::string& extension_id, 173 void DispatchEventToExtension(const std::string& extension_id,
175 const std::string& event, 174 const std::string& event,
176 const std::string& json_args); 175 const std::string& json_args);
177 void ExtensionUnloaded(const std::string& extension_id); 176 void ExtensionUnloaded(const std::string& extension_id);
178 177
179 void ResetToIdleState(); 178 void ResetToIdleState();
180 179
181 void AbortAllSessionsOnIOThread(); 180 void AbortAllSessionsOnIOThread();
182 181
182 int GetRenderProcessIDForExtension(const std::string& extension_id) const;
183
183 virtual ~SpeechInputExtensionManager(); 184 virtual ~SpeechInputExtensionManager();
184 185
185 friend class base::RefCountedThreadSafe<SpeechInputExtensionManager>; 186 friend class base::RefCountedThreadSafe<SpeechInputExtensionManager>;
186 class Factory; 187 class Factory;
187 188
188 // Lock used to allow exclusive access to the state variable and methods that 189 // Lock used to allow exclusive access to the state variable and methods that
189 // either read or write on it. This is required since the speech code 190 // either read or write on it. This is required since the speech code
190 // operates in the IO thread while the extension code uses the UI thread. 191 // operates in the IO thread while the extension code uses the UI thread.
191 base::Lock state_lock_; 192 base::Lock state_lock_;
192 193
193 // Used in the UI thread but also its raw value as notification 194 // Used in the UI thread but also its raw value as notification
194 // source in the IO thread, guarded by the state lock and value. 195 // source in the IO thread, guarded by the state lock and value.
195 Profile* profile_; 196 Profile* profile_;
196 197
197 // Used in both threads, guarded by the state lock. 198 // Used in both threads, guarded by the state lock.
198 State state_; 199 State state_;
199 std::string extension_id_in_use_; 200 std::string extension_id_in_use_;
200 201
201 // Used in the UI thread. 202 // Used in the UI thread.
202 scoped_ptr<content::NotificationRegistrar> registrar_; 203 scoped_ptr<content::NotificationRegistrar> registrar_;
203 SpeechInputExtensionInterface* speech_interface_; 204 SpeechInputExtensionInterface* speech_interface_;
204 205
205 // Used in the IO thread. 206 // Used in the IO thread.
206 bool is_recognition_in_progress_; 207 bool is_recognition_in_progress_;
207 int speech_recognition_session_id_; 208 int speech_recognition_session_id_;
208 }; 209 };
209 210
210 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_ 211 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698