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

Unified Diff: content/browser/speech/input_tag_speech_dispatcher_host.cc

Issue 170243005: Making sure that SpeechRecognitionDispatcherHost is not used after free (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed comments Created 6 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/speech/input_tag_speech_dispatcher_host.cc
diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.cc b/content/browser/speech/input_tag_speech_dispatcher_host.cc
index 6bd92ff06ec855add0444916369fcf8507ef2049..e38f90f37154897d80665163afd4d012a16e4125 100644
--- a/content/browser/speech/input_tag_speech_dispatcher_host.cc
+++ b/content/browser/speech/input_tag_speech_dispatcher_host.cc
@@ -28,14 +28,22 @@ InputTagSpeechDispatcherHost::InputTagSpeechDispatcherHost(
: BrowserMessageFilter(SpeechRecognitionMsgStart),
is_guest_(is_guest),
render_process_id_(render_process_id),
- url_request_context_getter_(url_request_context_getter) {
+ url_request_context_getter_(url_request_context_getter),
+ weak_factory_(this) {
// Do not add any non-trivial initialization here, instead do it lazily when
// required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or
// add an Init() method.
}
InputTagSpeechDispatcherHost::~InputTagSpeechDispatcherHost() {
- SpeechRecognitionManager::GetInstance()->AbortAllSessionsForListener(this);
+ SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderProcess(
+ render_process_id_);
+}
+
+base::WeakPtr<InputTagSpeechDispatcherHost>
+InputTagSpeechDispatcherHost::AsWeakPtr() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ return weak_factory_.GetWeakPtr();
}
bool InputTagSpeechDispatcherHost::OnMessageReceived(
@@ -61,8 +69,12 @@ void InputTagSpeechDispatcherHost::OverrideThreadForMessage(
*thread = BrowserThread::UI;
}
+void InputTagSpeechDispatcherHost::OnChannelClosing() {
+ weak_factory_.InvalidateWeakPtrs();
+}
+
void InputTagSpeechDispatcherHost::OnStartRecognition(
- const InputTagSpeechHostMsg_StartRecognition_Params& params) {
+ const InputTagSpeechHostMsg_StartRecognition_Params& params) {
InputTagSpeechHostMsg_StartRecognition_Params input_params(params);
int render_process_id = render_process_id_;
// The chrome layer is mostly oblivious to BrowserPlugin guests and so it
@@ -124,7 +136,7 @@ void InputTagSpeechDispatcherHost::StartRecognitionOnIO(
config.initial_context = context;
config.url_request_context_getter = url_request_context_getter_.get();
config.filter_profanities = filter_profanities;
- config.event_listener = this;
+ config.event_listener = AsWeakPtr();
int session_id = SpeechRecognitionManager::GetInstance()->CreateSession(
config);
« no previous file with comments | « content/browser/speech/input_tag_speech_dispatcher_host.h ('k') | content/browser/speech/speech_recognition_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698