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

Unified Diff: chrome/browser/speech/tts_message_filter.cc

Issue 692203002: Stop utterances from a tab when that tab is closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't hold lock during destruction Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/speech/tts_message_filter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/speech/tts_message_filter.cc
diff --git a/chrome/browser/speech/tts_message_filter.cc b/chrome/browser/speech/tts_message_filter.cc
index 4925359d7c841653c24fe5373e2e0f510d91523e..71c3df03cd3c439d3fce6be2fff667c4dc87984e 100644
--- a/chrome/browser/speech/tts_message_filter.cc
+++ b/chrome/browser/speech/tts_message_filter.cc
@@ -16,12 +16,12 @@ TtsMessageFilter::TtsMessageFilter(int render_process_id,
: BrowserMessageFilter(TtsMsgStart),
render_process_id_(render_process_id),
browser_context_(browser_context),
- weak_ptr_factory_(this) {
+ valid_(true) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController::GetInstance()->AddVoicesChangedDelegate(this);
// Balanced in OnChannelClosingInUIThread() to keep the ref-count be non-zero
- // until all WeakPtr's are invalidated.
+ // until all pointers to this class are invalidated.
AddRef();
}
@@ -52,15 +52,31 @@ bool TtsMessageFilter::OnMessageReceived(const IPC::Message& message) {
}
void TtsMessageFilter::OnChannelClosing() {
+ base::AutoLock lock(mutex_);
+ valid_ = false;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&TtsMessageFilter::OnChannelClosingInUIThread, this));
}
+bool TtsMessageFilter::Valid() {
+ base::AutoLock lock(mutex_);
+ return valid_;
+}
+
void TtsMessageFilter::OnDestruct() const {
+ {
+ base::AutoLock lock(mutex_);
+ valid_ = false;
+ }
BrowserThread::DeleteOnUIThread::Destruct(this);
}
+TtsMessageFilter::~TtsMessageFilter() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ Cleanup();
+}
+
void TtsMessageFilter::OnInitializeVoiceList() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
TtsController* tts_controller = TtsController::GetInstance();
@@ -96,7 +112,7 @@ void TtsMessageFilter::OnSpeak(const TtsUtteranceRequest& request) {
params.volume = request.volume;
utterance->set_continuous_parameters(params);
- utterance->set_event_delegate(weak_ptr_factory_.GetWeakPtr());
+ utterance->set_event_delegate(this);
TtsController::GetInstance()->SpeakOrEnqueue(utterance.release());
}
@@ -120,6 +136,9 @@ void TtsMessageFilter::OnTtsEvent(Utterance* utterance,
TtsEventType event_type,
int char_index,
const std::string& error_message) {
+ if (!Valid())
+ return;
+
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
switch (event_type) {
case TTS_EVENT_START:
@@ -157,20 +176,20 @@ void TtsMessageFilter::OnTtsEvent(Utterance* utterance,
}
void TtsMessageFilter::OnVoicesChanged() {
+ if (!Valid())
+ return;
+
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
OnInitializeVoiceList();
}
void TtsMessageFilter::OnChannelClosingInUIThread() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- TtsController::GetInstance()->RemoveVoicesChangedDelegate(this);
-
- weak_ptr_factory_.InvalidateWeakPtrs();
+ Cleanup();
Release(); // Balanced in TtsMessageFilter().
}
-TtsMessageFilter::~TtsMessageFilter() {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(!weak_ptr_factory_.HasWeakPtrs());
+void TtsMessageFilter::Cleanup() {
TtsController::GetInstance()->RemoveVoicesChangedDelegate(this);
+ TtsController::GetInstance()->RemoveUtteranceEventDelegate(this);
}
« no previous file with comments | « chrome/browser/speech/tts_message_filter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698