OLD | NEW |
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 CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
10 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
11 #include "content/public/browser/browser_message_filter.h" | 13 #include "content/public/browser/browser_message_filter.h" |
| 14 #include "content/public/browser/web_contents_observer.h" |
12 #include "content/public/browser/speech_recognition_event_listener.h" | 15 #include "content/public/browser/speech_recognition_event_listener.h" |
13 #include "net/url_request/url_request_context_getter.h" | |
14 | 16 |
15 struct SpeechRecognitionHostMsg_StartRequest_Params; | 17 struct SpeechRecognitionHostMsg_StartRequest_Params; |
16 | 18 |
| 19 namespace net { |
| 20 class URLRequestContextGetter; |
| 21 } // namespace net |
| 22 |
17 namespace content { | 23 namespace content { |
18 | 24 |
19 class SpeechRecognitionManager; | 25 class SpeechRecognitionManager; |
| 26 class WebContents; |
20 struct SpeechRecognitionResult; | 27 struct SpeechRecognitionResult; |
| 28 struct SpeechRecognitionSessionContext; |
| 29 struct SpeechRecognitionSessionConfig; |
21 | 30 |
22 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by | 31 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by |
23 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming | 32 // BrowserMessageFilter. Basically it acts as a proxy, relaying the events |
24 // from the SpeechRecognitionManager to IPC messages (and vice versa). | 33 // coming from the SpeechRecognitionManager to IPC messages (and vice versa). |
25 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView). | 34 // It's the complement of SpeechRecognitionDispatcher (owned by RenderFrame). |
26 class CONTENT_EXPORT SpeechRecognitionDispatcherHost | 35 class CONTENT_EXPORT SpeechRecognitionDispatcherHost |
27 : public BrowserMessageFilter, | 36 : public BrowserMessageFilter, |
28 public SpeechRecognitionEventListener { | 37 public SpeechRecognitionEventListener { |
29 public: | 38 public: |
30 SpeechRecognitionDispatcherHost( | 39 explicit SpeechRecognitionDispatcherHost(int render_process_id); |
31 int render_process_id, | |
32 net::URLRequestContextGetter* context_getter); | |
33 | 40 |
34 base::WeakPtr<SpeechRecognitionDispatcherHost> AsWeakPtr(); | 41 base::WeakPtr<SpeechRecognitionDispatcherHost> AsWeakPtr(); |
35 | 42 |
36 // SpeechRecognitionEventListener methods. | 43 // SpeechRecognitionEventListener methods. |
37 void OnRecognitionStart(int session_id) override; | 44 void OnRecognitionStart(int session_id) override; |
38 void OnAudioStart(int session_id) override; | 45 void OnAudioStart(int session_id) override; |
39 void OnEnvironmentEstimationComplete(int session_id) override; | 46 void OnEnvironmentEstimationComplete(int session_id) override; |
40 void OnSoundStart(int session_id) override; | 47 void OnSoundStart(int session_id) override; |
41 void OnSoundEnd(int session_id) override; | 48 void OnSoundEnd(int session_id) override; |
42 void OnAudioEnd(int session_id) override; | 49 void OnAudioEnd(int session_id) override; |
43 void OnRecognitionEnd(int session_id) override; | 50 void OnRecognitionEnd(int session_id) override; |
44 void OnRecognitionResults(int session_id, | 51 void OnRecognitionResults(int session_id, |
45 const SpeechRecognitionResults& results) override; | 52 const SpeechRecognitionResults& results) override; |
46 void OnRecognitionError(int session_id, | 53 void OnRecognitionError(int session_id, |
47 const SpeechRecognitionError& error) override; | 54 const SpeechRecognitionError& error) override; |
48 void OnAudioLevelsChange(int session_id, | 55 void OnAudioLevelsChange(int session_id, |
49 float volume, | 56 float volume, |
50 float noise_volume) override; | 57 float noise_volume) override; |
51 | 58 |
52 // BrowserMessageFilter implementation. | 59 // BrowserMessageFilter implementation. |
53 void OnDestruct() const override; | 60 void OnDestruct() const override; |
54 bool OnMessageReceived(const IPC::Message& message) override; | 61 void OnChannelClosing() override; |
55 void OverrideThreadForMessage(const IPC::Message& message, | 62 void OverrideThreadForMessage(const IPC::Message& message, |
56 BrowserThread::ID* thread) override; | 63 BrowserThread::ID* thread) override; |
57 | 64 bool OnMessageReceived(const IPC::Message& message) override; |
58 void OnChannelClosing() override; | |
59 | 65 |
60 private: | 66 private: |
61 friend class base::DeleteHelper<SpeechRecognitionDispatcherHost>; | 67 friend class base::DeleteHelper<SpeechRecognitionDispatcherHost>; |
62 friend class BrowserThread; | 68 friend class BrowserThread; |
63 | 69 |
| 70 class FrameDeletedObserver; |
| 71 |
64 ~SpeechRecognitionDispatcherHost() override; | 72 ~SpeechRecognitionDispatcherHost() override; |
65 | 73 |
66 void OnStartRequest( | 74 void OnStartRequest( |
67 const SpeechRecognitionHostMsg_StartRequest_Params& params); | 75 const SpeechRecognitionHostMsg_StartRequest_Params& params); |
68 void OnStartRequestOnIO( | 76 void StartSession( |
69 int embedder_render_process_id, | |
70 int embedder_render_view_id, | |
71 const SpeechRecognitionHostMsg_StartRequest_Params& params, | 77 const SpeechRecognitionHostMsg_StartRequest_Params& params, |
72 int params_render_frame_id, | 78 const SpeechRecognitionSessionContext& context, |
| 79 net::URLRequestContextGetter* url_request_context_getter, |
73 bool filter_profanities); | 80 bool filter_profanities); |
74 void OnAbortRequest(int render_view_id, int request_id); | 81 void OnAbortRequest(int render_frame_id, int request_id); |
75 void OnStopCaptureRequest(int render_view_id, int request_id); | 82 void OnStopCaptureRequest(int render_frame_id, int request_id); |
76 void OnAbortAllRequests(int render_view_id); | 83 void OnAbortAllRequests(int render_frame_id); |
| 84 |
| 85 // These methods must be called on the UI thread. |
| 86 void CreateObserverFor(WebContents* web_contents); |
| 87 void RemoveObserverFor(WebContents* web_contents); |
| 88 void AbortAllRequestsFromUI(int render_frame_id); |
77 | 89 |
78 int render_process_id_; | 90 int render_process_id_; |
79 scoped_refptr<net::URLRequestContextGetter> context_getter_; | 91 |
| 92 using FrameDeletedObservers = std::map<WebContents*, FrameDeletedObserver*>; |
| 93 FrameDeletedObservers frame_deleted_observers_; |
80 | 94 |
81 // Used for posting asynchronous tasks (on the IO thread) without worrying | 95 // Used for posting asynchronous tasks (on the IO thread) without worrying |
82 // about this class being destroyed in the meanwhile (due to browser shutdown) | 96 // about this class being destroyed in the meanwhile (due to browser shutdown) |
83 // since tasks pending on a destroyed WeakPtr are automatically discarded. | 97 // since tasks pending on a destroyed WeakPtr are automatically discarded. |
84 base::WeakPtrFactory<SpeechRecognitionDispatcherHost> weak_factory_; | 98 base::WeakPtrFactory<SpeechRecognitionDispatcherHost> weak_factory_; |
85 | 99 |
86 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost); | 100 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost); |
87 }; | 101 }; |
88 | 102 |
89 } // namespace content | 103 } // namespace content |
90 | 104 |
91 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ | 105 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
OLD | NEW |