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

Unified Diff: content/browser/speech/speech_recognition_dispatcher_host.h

Issue 170243005: Making sure that SpeechRecognitionDispatcherHost is not used after free (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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.h
diff --git a/content/browser/speech/speech_recognition_dispatcher_host.h b/content/browser/speech/speech_recognition_dispatcher_host.h
index b50f260958d5156c00b690992de672d3c6ec18a9..e74447139a9e76e57ea7e982a6dc53ab86b729e3 100644
--- a/content/browser/speech/speech_recognition_dispatcher_host.h
+++ b/content/browser/speech/speech_recognition_dispatcher_host.h
@@ -6,6 +6,7 @@
#define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/speech_recognition_event_listener.h"
@@ -31,6 +32,8 @@ class CONTENT_EXPORT SpeechRecognitionDispatcherHost
int render_process_id,
net::URLRequestContextGetter* context_getter);
+ base::WeakPtr<SpeechRecognitionDispatcherHost> AsWeakPtr();
+
// SpeechRecognitionEventListener methods.
virtual void OnRecognitionStart(int session_id) OVERRIDE;
virtual void OnAudioStart(int session_id) OVERRIDE;
@@ -56,6 +59,8 @@ class CONTENT_EXPORT SpeechRecognitionDispatcherHost
const IPC::Message& message,
BrowserThread::ID* thread) OVERRIDE;
+ virtual void OnChannelClosing() OVERRIDE;
+
private:
virtual ~SpeechRecognitionDispatcherHost();
@@ -73,6 +78,11 @@ class CONTENT_EXPORT SpeechRecognitionDispatcherHost
int render_process_id_;
scoped_refptr<net::URLRequestContextGetter> context_getter_;
+ // Used for posting asynchronous tasks (on the IO thread) without worrying
+ // about this class being destroyed in the meanwhile (due to browser shutdown)
+ // since tasks pending on a destroyed WeakPtr are automatically discarded.
+ base::WeakPtrFactory<SpeechRecognitionDispatcherHost> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost);
};

Powered by Google App Engine
This is Rietveld 408576698