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); |