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

Side by Side Diff: content/browser/speech/speech_recognition_dispatcher_host.h

Issue 636863003: Make SpeechRecognition per RenderFrame instead of per RenderView. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes threading issues Created 6 years 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
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 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 "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
11 #include "content/public/browser/browser_message_filter.h"
12 #include "content/public/browser/speech_recognition_event_listener.h" 11 #include "content/public/browser/speech_recognition_event_listener.h"
13 #include "net/url_request/url_request_context_getter.h" 12 #include "content/public/browser/web_contents_observer.h"
14 13
15 struct SpeechRecognitionHostMsg_StartRequest_Params; 14 struct SpeechRecognitionHostMsg_StartRequest_Params;
16 15
16 namespace net {
17 class URLRequestContextGetter;
18 } // namespace net
19
17 namespace content { 20 namespace content {
18 21
19 class SpeechRecognitionManager; 22 class SpeechRecognitionManager;
23 class WebContents;
20 struct SpeechRecognitionResult; 24 struct SpeechRecognitionResult;
25 struct SpeechRecognitionSessionContext;
26 struct SpeechRecognitionSessionConfig;
21 27
22 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by 28 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by
23 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming 29 // WebContents. Basically it acts as a proxy, relaying the events coming from
24 // from the SpeechRecognitionManager to IPC messages (and vice versa). 30 // the SpeechRecognitionManager to IPC messages (and vice versa).
25 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView). 31 // It's the complement of SpeechRecognitionDispatcher (owned by RenderFrame).
32 // It MUST be deleted from the BrowserThread::IO thread.
26 class CONTENT_EXPORT SpeechRecognitionDispatcherHost 33 class CONTENT_EXPORT SpeechRecognitionDispatcherHost
27 : public BrowserMessageFilter, 34 : public WebContentsObserver,
Charlie Reis 2014/12/01 23:49:43 What benefits are we getting from making this a We
mlamouri (slow - plz ping) 2014/12/08 17:41:04 The only real benefit from using WebContentsObserv
Charlie Reis 2014/12/08 20:02:57 Ah, I see. Yes, I think we can handle that more c
mlamouri (slow - plz ping) 2014/12/08 21:08:00 Done. I haven't done anything with RenderFrameDele
Charlie Reis 2014/12/09 00:52:33 Is this a bug, though? We're now tracking things
28 public SpeechRecognitionEventListener { 35 public SpeechRecognitionEventListener {
29 public: 36 public:
30 SpeechRecognitionDispatcherHost( 37 explicit SpeechRecognitionDispatcherHost(WebContents* web_contents);
31 int render_process_id, 38 virtual ~SpeechRecognitionDispatcherHost();
32 net::URLRequestContextGetter* context_getter);
33 39
34 base::WeakPtr<SpeechRecognitionDispatcherHost> AsWeakPtr(); 40 base::WeakPtr<SpeechRecognitionDispatcherHost> AsWeakPtr();
35 41
36 // SpeechRecognitionEventListener methods. 42 // SpeechRecognitionEventListener methods.
37 void OnRecognitionStart(int session_id) override; 43 void OnRecognitionStart(int session_id) override;
38 void OnAudioStart(int session_id) override; 44 void OnAudioStart(int session_id) override;
39 void OnEnvironmentEstimationComplete(int session_id) override; 45 void OnEnvironmentEstimationComplete(int session_id) override;
40 void OnSoundStart(int session_id) override; 46 void OnSoundStart(int session_id) override;
41 void OnSoundEnd(int session_id) override; 47 void OnSoundEnd(int session_id) override;
42 void OnAudioEnd(int session_id) override; 48 void OnAudioEnd(int session_id) override;
43 void OnRecognitionEnd(int session_id) override; 49 void OnRecognitionEnd(int session_id) override;
44 void OnRecognitionResults(int session_id, 50 void OnRecognitionResults(int session_id,
45 const SpeechRecognitionResults& results) override; 51 const SpeechRecognitionResults& results) override;
46 void OnRecognitionError(int session_id, 52 void OnRecognitionError(int session_id,
47 const SpeechRecognitionError& error) override; 53 const SpeechRecognitionError& error) override;
48 void OnAudioLevelsChange(int session_id, 54 void OnAudioLevelsChange(int session_id,
49 float volume, 55 float volume,
50 float noise_volume) override; 56 float noise_volume) override;
51 57
52 // BrowserMessageFilter implementation. 58 // WebContentsObserver implementation.
53 void OnDestruct() const override; 59 bool OnMessageReceived(const IPC::Message& message,
54 bool OnMessageReceived(const IPC::Message& message) override; 60 RenderFrameHost* render_frame_host) override;
55 void OverrideThreadForMessage(const IPC::Message& message, 61 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
56 BrowserThread::ID* thread) override;
57
58 void OnChannelClosing() override;
59 62
60 private: 63 private:
61 friend class base::DeleteHelper<SpeechRecognitionDispatcherHost>;
62 friend class BrowserThread;
63
64 ~SpeechRecognitionDispatcherHost() override;
65
66 void OnStartRequest( 64 void OnStartRequest(
65 RenderFrameHost* render_frame_host,
67 const SpeechRecognitionHostMsg_StartRequest_Params& params); 66 const SpeechRecognitionHostMsg_StartRequest_Params& params);
68 void OnStartRequestOnIO( 67 void StartSession(
69 int embedder_render_process_id,
70 int embedder_render_view_id,
71 const SpeechRecognitionHostMsg_StartRequest_Params& params, 68 const SpeechRecognitionHostMsg_StartRequest_Params& params,
72 int params_render_frame_id, 69 const SpeechRecognitionSessionContext& context,
70 net::URLRequestContextGetter* url_request_context_getter,
73 bool filter_profanities); 71 bool filter_profanities);
74 void OnAbortRequest(int render_view_id, int request_id); 72 void OnAbortRequest(RenderFrameHost* render_frame_host, int request_id);
75 void OnStopCaptureRequest(int render_view_id, int request_id); 73 void OnAbortRequestIO(int render_process_id,
Charlie Reis 2014/12/01 23:49:43 nit: AbortRequestOnIO (similar below)
76 void OnAbortAllRequests(int render_view_id); 74 int render_frame_id,
77 75 int request_id);
78 int render_process_id_; 76 void OnStopCaptureRequest(RenderFrameHost* render_frame_host, int request_id);
79 scoped_refptr<net::URLRequestContextGetter> context_getter_; 77 void OnStopCaptureRequestIO(int render_process_id,
78 int render_frame_id,
79 int request_id);
80 void OnAbortAllRequests(RenderFrameHost* render_frame_host);
81 void OnAbortAllRequestsIO(int render_process_id, int render_frame_id);
80 82
81 // Used for posting asynchronous tasks (on the IO thread) without worrying 83 // Used for posting asynchronous tasks (on the IO thread) without worrying
82 // about this class being destroyed in the meanwhile (due to browser shutdown) 84 // about this class being destroyed in the meanwhile (due to browser shutdown)
83 // since tasks pending on a destroyed WeakPtr are automatically discarded. 85 // since tasks pending on a destroyed WeakPtr are automatically discarded.
84 base::WeakPtrFactory<SpeechRecognitionDispatcherHost> weak_factory_; 86 base::WeakPtrFactory<SpeechRecognitionDispatcherHost> weak_factory_;
85 87
86 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost); 88 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost);
87 }; 89 };
88 90
89 } // namespace content 91 } // namespace content
90 92
91 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ 93 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698