OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_APP_LIST_SPEECH_RECOGNIZER_H_ | |
6 #define CHROME_BROWSER_UI_APP_LIST_SPEECH_RECOGNIZER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/timer/timer.h" | |
12 #include "content/public/browser/speech_recognition_event_listener.h" | |
13 #include "net/url_request/url_request_context_getter.h" | |
14 #include "ui/app_list/speech_ui_model_observer.h" | |
15 | |
16 namespace app_list { | |
17 | |
18 class SpeechRecognizerDelegate; | |
19 class StartPageService; | |
20 | |
21 // SpeechRecognizer is a wrapper around the speech recognition engine that | |
22 // simplifies its use from the UI thread. This class handles all setup/shutdown, | |
23 // collection of results, error cases, and threading. | |
24 class SpeechRecognizer : public base::RefCountedThreadSafe<SpeechRecognizer>, | |
25 public content::SpeechRecognitionEventListener { | |
26 public: | |
27 SpeechRecognizer(SpeechRecognizerDelegate* delegate, | |
28 net::URLRequestContextGetter* url_request_context_getter, | |
29 const std::string& locale); | |
30 | |
31 // Start/stop the speech recognizer. Must be called on the UI thread. | |
32 void Start(); | |
33 void Stop(); | |
34 | |
35 protected: | |
36 // Overidden from content::SpeechRecognitionEventListener: | |
37 // These are always called on the IO thread. | |
38 void OnRecognitionStart(int session_id) override; | |
39 void OnRecognitionEnd(int session_id) override; | |
40 void OnRecognitionResults( | |
41 int session_id, | |
42 const content::SpeechRecognitionResults& results) override; | |
43 void OnRecognitionError( | |
44 int session_id, const content::SpeechRecognitionError& error) override; | |
45 void OnSoundStart(int session_id) override; | |
46 void OnSoundEnd(int session_id) override; | |
47 void OnAudioLevelsChange( | |
48 int session_id, float volume, float noise_volume) override; | |
49 // Overridden, but with trivial implementations. | |
Matt Giuca
2014/11/03 02:35:52
I don't think this line is necessary.
Anand Mistry (off Chromium)
2014/11/03 06:51:56
Removed.
| |
50 void OnEnvironmentEstimationComplete(int session_id) override; | |
51 void OnAudioStart(int session_id) override; | |
52 void OnAudioEnd(int session_id) override; | |
53 | |
54 private: | |
55 friend class base::RefCountedThreadSafe<SpeechRecognizer>; | |
56 ~SpeechRecognizer(); | |
57 | |
58 void StartOnIOThread( | |
59 int render_process_id, | |
60 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | |
61 void StopOnIOThread(); | |
62 | |
63 void NotifyRecognitionStateChanged(SpeechRecognitionState new_state); | |
64 | |
65 void StartSpeechTimeout(); | |
66 void StopSpeechTimeout(); | |
67 void SpeechTimeout(); | |
68 | |
69 SpeechRecognizerDelegate* delegate_; // Not owned. | |
70 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
71 std::string locale_; | |
72 base::Timer speech_timeout_; | |
73 int session_; | |
74 | |
75 base::WeakPtrFactory<SpeechRecognizer> weak_factory_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); | |
78 }; | |
79 | |
80 } // namespace app_list | |
81 | |
82 #endif // CHROME_BROWSER_UI_APP_LIST_SPEECH_RECOGNIZER_H_ | |
OLD | NEW |