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

Unified Diff: content/browser/speech/speech_recognition_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/speech_recognition_dispatcher_host.cc
diff --git a/content/browser/speech/speech_recognition_dispatcher_host.cc b/content/browser/speech/speech_recognition_dispatcher_host.cc
index 1b42f2f911fe3a7f7036eea1c3eb2a337cdc3b53..fc6a69d504883b83d9f7ab1c19bd68bb7314176d 100644
--- a/content/browser/speech/speech_recognition_dispatcher_host.cc
+++ b/content/browser/speech/speech_recognition_dispatcher_host.cc
@@ -26,14 +26,21 @@ SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost(
: BrowserMessageFilter(SpeechRecognitionMsgStart),
is_guest_(is_guest),
render_process_id_(render_process_id),
- context_getter_(context_getter) {
+ context_getter_(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.
}
SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() {
- SpeechRecognitionManager::GetInstance()->AbortAllSessionsForListener(this);
+ SpeechRecognitionManager::GetInstance()->AbortAllSessionsForRenderProcess(
+ render_process_id_);
+}
+
+base::WeakPtr<SpeechRecognitionDispatcherHost>
+SpeechRecognitionDispatcherHost::AsWeakPtr() {
+ return weak_factory_.GetWeakPtr();
}
bool SpeechRecognitionDispatcherHost::OnMessageReceived(
@@ -59,6 +66,10 @@ void SpeechRecognitionDispatcherHost::OverrideThreadForMessage(
*thread = BrowserThread::UI;
}
+void SpeechRecognitionDispatcherHost::OnChannelClosing() {
+ weak_factory_.InvalidateWeakPtrs();
+}
+
void SpeechRecognitionDispatcherHost::OnStartRequest(
const SpeechRecognitionHostMsg_StartRequest_Params& params) {
SpeechRecognitionHostMsg_StartRequest_Params input_params(params);
@@ -129,7 +140,7 @@ void SpeechRecognitionDispatcherHost::OnStartRequestOnIO(
config.filter_profanities = filter_profanities;
config.continuous = params.continuous;
config.interim_results = params.interim_results;
- config.event_listener = this;
+ config.event_listener = AsWeakPtr();
int session_id = SpeechRecognitionManager::GetInstance()->CreateSession(
config);
« no previous file with comments | « content/browser/speech/speech_recognition_dispatcher_host.h ('k') | content/browser/speech/speech_recognition_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698