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 CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "content/common/content_export.h"
10 #include "content/public/browser/browser_message_filter.h"
11 #include "content/public/browser/speech_recognition_event_listener.h"
12 #include "net/url_request/url_request_context_getter.h"
14 struct SpeechRecognitionHostMsg_StartRequest_Params
;
18 class SpeechRecognitionManager
;
19 class SpeechRecognitionPreferences
;
20 struct SpeechRecognitionResult
;
22 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by
23 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming
24 // from the SpeechRecognitionManager to IPC messages (and vice versa).
25 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView).
26 class CONTENT_EXPORT SpeechRecognitionDispatcherHost
27 : public BrowserMessageFilter
,
28 public SpeechRecognitionEventListener
{
30 SpeechRecognitionDispatcherHost(
31 int render_process_id
,
32 net::URLRequestContextGetter
* context_getter
,
33 SpeechRecognitionPreferences
* recognition_preferences
);
35 // SpeechRecognitionEventListener methods.
36 virtual void OnRecognitionStart(int session_id
) OVERRIDE
;
37 virtual void OnAudioStart(int session_id
) OVERRIDE
;
38 virtual void OnEnvironmentEstimationComplete(int session_id
) OVERRIDE
;
39 virtual void OnSoundStart(int session_id
) OVERRIDE
;
40 virtual void OnSoundEnd(int session_id
) OVERRIDE
;
41 virtual void OnAudioEnd(int session_id
) OVERRIDE
;
42 virtual void OnRecognitionEnd(int session_id
) OVERRIDE
;
43 virtual void OnRecognitionResults(
45 const SpeechRecognitionResults
& results
) OVERRIDE
;
46 virtual void OnRecognitionError(
48 const SpeechRecognitionError
& error
) OVERRIDE
;
49 virtual void OnAudioLevelsChange(int session_id
,
51 float noise_volume
) OVERRIDE
;
53 // BrowserMessageFilter implementation.
54 virtual bool OnMessageReceived(const IPC::Message
& message
,
55 bool* message_was_ok
) OVERRIDE
;
57 // Singleton manager setter useful for tests.
58 static void SetManagerForTests(SpeechRecognitionManager
* manager
);
61 virtual ~SpeechRecognitionDispatcherHost();
64 const SpeechRecognitionHostMsg_StartRequest_Params
& params
);
65 void OnAbortRequest(int render_view_id
, int request_id
);
66 void OnStopCaptureRequest(int render_view_id
, int request_id
);
68 // Returns the speech recognition manager to forward requests to.
69 SpeechRecognitionManager
* manager();
71 int render_process_id_
;
72 scoped_refptr
<net::URLRequestContextGetter
> context_getter_
;
73 scoped_refptr
<SpeechRecognitionPreferences
> recognition_preferences_
;
75 static SpeechRecognitionManager
* manager_for_tests_
;
77 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost
);
80 } // namespace content
82 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_