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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
6 #define CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "chrome/browser/speech/speech_recognition_bubble_controller.h"
11 #include "content/public/browser/speech_recognition_event_listener.h"
12 #include "content/public/browser/speech_recognition_manager_delegate.h"
13 #include "content/public/browser/speech_recognition_session_config.h"
18 // This is Chrome's implementation of the SpeechRecognitionManagerDelegate
20 class ChromeSpeechRecognitionManagerDelegate
21 : NON_EXPORTED_BASE(public content::SpeechRecognitionManagerDelegate
),
22 public content::SpeechRecognitionEventListener
,
23 public SpeechRecognitionBubbleControllerDelegate
{
25 ChromeSpeechRecognitionManagerDelegate();
26 virtual ~ChromeSpeechRecognitionManagerDelegate();
29 // SpeechRecognitionBubbleControllerDelegate methods.
30 virtual void InfoBubbleButtonClicked(
31 int session_id
, SpeechRecognitionBubble::Button button
) OVERRIDE
;
32 virtual void InfoBubbleFocusChanged(int session_id
) OVERRIDE
;
34 // SpeechRecognitionEventListener methods.
35 virtual void OnRecognitionStart(int session_id
) OVERRIDE
;
36 virtual void OnAudioStart(int session_id
) OVERRIDE
;
37 virtual void OnEnvironmentEstimationComplete(int session_id
) OVERRIDE
;
38 virtual void OnSoundStart(int session_id
) OVERRIDE
;
39 virtual void OnSoundEnd(int session_id
) OVERRIDE
;
40 virtual void OnAudioEnd(int session_id
) OVERRIDE
;
41 virtual void OnRecognitionEnd(int session_id
) OVERRIDE
;
42 virtual void OnRecognitionResults(
43 int session_id
, const content::SpeechRecognitionResults
& result
) OVERRIDE
;
44 virtual void OnRecognitionError(
45 int session_id
, const content::SpeechRecognitionError
& error
) OVERRIDE
;
46 virtual void OnAudioLevelsChange(int session_id
, float volume
,
47 float noise_volume
) OVERRIDE
;
49 // SpeechRecognitionManagerDelegate methods.
50 virtual void GetDiagnosticInformation(bool* can_report_metrics
,
51 std::string
* hardware_info
) OVERRIDE
;
52 virtual void CheckRecognitionIsAllowed(
54 base::Callback
<void(bool ask_user
, bool is_allowed
)> callback
) OVERRIDE
;
55 virtual content::SpeechRecognitionEventListener
* GetEventListener() OVERRIDE
;
58 class OptionalRequestInfo
;
61 // Checks for VIEW_TYPE_TAB_CONTENTS host in the UI thread and notifies back
62 // the result in the IO thread through |callback|.
63 static void CheckRenderViewType(
64 base::Callback
<void(bool ask_user
, bool is_allowed
)> callback
,
65 int render_process_id
,
69 // Starts a new recognition session, using the config of the last one
70 // (which is copied into |last_session_config_|). Used for "try again".
71 void RestartLastSession();
73 // Callback called by |tab_watcher_| on the IO thread to signal tab closure.
74 void TabClosedCallback(int render_process_id
, int render_view_id
);
76 // Lazy initializers for bubble and tray icon controller.
77 SpeechRecognitionBubbleController
* GetBubbleController();
79 scoped_refptr
<SpeechRecognitionBubbleController
> bubble_controller_
;
80 scoped_refptr
<OptionalRequestInfo
> optional_request_info_
;
81 scoped_ptr
<content::SpeechRecognitionSessionConfig
> last_session_config_
;
82 scoped_refptr
<TabWatcher
> tab_watcher_
;
84 DISALLOW_COPY_AND_ASSIGN(ChromeSpeechRecognitionManagerDelegate
);
89 #endif // CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_MANAGER_DELEGATE_H_