2018-10-24 18:24:11 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Heilig Benedek <benecene@gmail.com>
|
|
|
|
Date: Thu, 18 Oct 2018 17:08:03 -0700
|
|
|
|
Subject: tts.patch
|
|
|
|
|
|
|
|
* Adds patch in //chrome/browser/speech/tts_controller_impl.cc
|
|
|
|
to disable calls using chrome profile class.
|
|
|
|
* Adds patch in //chrome/browser/speech/tts_message_filter.cc
|
|
|
|
to remove reference to browser context when its signaled for
|
|
|
|
destruction from content layer.
|
|
|
|
|
2019-01-08 23:59:47 +00:00
|
|
|
diff --git a/chrome/browser/speech/tts_controller_delegate_impl.cc b/chrome/browser/speech/tts_controller_delegate_impl.cc
|
|
|
|
index 9e071512872c1e9350b29e499a28e3033fa1b95f..905cd40368b029ed546af2fb37b42e6cd8cc1d8e 100644
|
|
|
|
--- a/chrome/browser/speech/tts_controller_delegate_impl.cc
|
|
|
|
+++ b/chrome/browser/speech/tts_controller_delegate_impl.cc
|
|
|
|
@@ -533,12 +533,14 @@ const PrefService* TtsControllerDelegateImpl::GetPrefService(
|
|
|
|
const content::Utterance* utterance) {
|
2018-10-11 13:52:12 +00:00
|
|
|
const PrefService* prefs = nullptr;
|
|
|
|
// The utterance->browser_context() is null in tests.
|
|
|
|
+#if 0
|
|
|
|
if (utterance->browser_context()) {
|
|
|
|
const Profile* profile =
|
|
|
|
Profile::FromBrowserContext(utterance->browser_context());
|
|
|
|
if (profile)
|
|
|
|
prefs = profile->GetPrefs();
|
|
|
|
}
|
|
|
|
+#endif
|
|
|
|
return prefs;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/chrome/browser/speech/tts_message_filter.cc b/chrome/browser/speech/tts_message_filter.cc
|
2019-01-08 23:59:47 +00:00
|
|
|
index 7ff9a9219beffc015ae8a96303595ee529715819..d2394892c2a0d2b4f88407cd412af143cf40881d 100644
|
2018-10-11 13:52:12 +00:00
|
|
|
--- a/chrome/browser/speech/tts_message_filter.cc
|
|
|
|
+++ b/chrome/browser/speech/tts_message_filter.cc
|
2019-01-12 01:00:43 +00:00
|
|
|
@@ -10,8 +10,11 @@
|
2018-10-11 13:52:12 +00:00
|
|
|
#include "base/logging.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
#include "base/task/post_task.h"
|
2018-10-11 13:52:12 +00:00
|
|
|
#include "chrome/browser/chrome_notification_types.h"
|
|
|
|
+#if 0
|
|
|
|
#include "chrome/browser/profiles/profile.h"
|
|
|
|
+#endif
|
|
|
|
#include "chrome/common/tts_messages.h"
|
|
|
|
+#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
|
|
|
|
#include "content/public/browser/browser_context.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2018-10-11 13:52:12 +00:00
|
|
|
#include "content/public/browser/notification_service.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
@@ -19,6 +22,29 @@
|
2018-10-11 13:52:12 +00:00
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
+namespace {
|
|
|
|
+
|
|
|
|
+class TtsMessageFilterShutdownNotifierFactory
|
|
|
|
+ : public BrowserContextKeyedServiceShutdownNotifierFactory {
|
|
|
|
+ public:
|
|
|
|
+ static TtsMessageFilterShutdownNotifierFactory* GetInstance() {
|
|
|
|
+ return base::Singleton<TtsMessageFilterShutdownNotifierFactory>::get();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private:
|
|
|
|
+ friend struct base::DefaultSingletonTraits<
|
|
|
|
+ TtsMessageFilterShutdownNotifierFactory>;
|
|
|
|
+
|
|
|
|
+ TtsMessageFilterShutdownNotifierFactory()
|
|
|
|
+ : BrowserContextKeyedServiceShutdownNotifierFactory("TtsMessageFilter") {}
|
|
|
|
+
|
|
|
|
+ ~TtsMessageFilterShutdownNotifierFactory() override {}
|
|
|
|
+
|
|
|
|
+ DISALLOW_COPY_AND_ASSIGN(TtsMessageFilterShutdownNotifierFactory);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+} // namespace
|
|
|
|
+
|
|
|
|
TtsMessageFilter::TtsMessageFilter(content::BrowserContext* browser_context)
|
|
|
|
: BrowserMessageFilter(TtsMsgStart),
|
|
|
|
browser_context_(browser_context),
|
2019-01-12 01:00:43 +00:00
|
|
|
@@ -26,28 +52,27 @@ TtsMessageFilter::TtsMessageFilter(content::BrowserContext* browser_context)
|
2018-10-11 13:52:12 +00:00
|
|
|
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2019-01-08 23:59:47 +00:00
|
|
|
content::TtsController::GetInstance()->AddVoicesChangedDelegate(this);
|
2018-10-11 13:52:12 +00:00
|
|
|
|
|
|
|
- // TODO(dmazzoni): make it so that we can listen for a BrowserContext
|
|
|
|
- // being destroyed rather than a Profile. http://crbug.com/444668
|
|
|
|
- Profile* profile = Profile::FromBrowserContext(browser_context);
|
|
|
|
- notification_registrar_.Add(this,
|
|
|
|
- chrome::NOTIFICATION_PROFILE_DESTROYED,
|
|
|
|
- content::Source<Profile>(profile));
|
|
|
|
+ browser_context_shutdown_notifier_ =
|
|
|
|
+ TtsMessageFilterShutdownNotifierFactory::GetInstance()
|
|
|
|
+ ->Get(browser_context)
|
|
|
|
+ ->Subscribe(base::Bind(&TtsMessageFilter::BrowserContextDestroyed,
|
|
|
|
+ base::RetainedRef(this)));
|
|
|
|
|
|
|
|
// Balanced in OnChannelClosingInUIThread() to keep the ref-count be non-zero
|
|
|
|
// until all pointers to this class are invalidated.
|
|
|
|
AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
-void TtsMessageFilter::OverrideThreadForMessage(
|
|
|
|
- const IPC::Message& message, BrowserThread::ID* thread) {
|
|
|
|
+void TtsMessageFilter::OverrideThreadForMessage(const IPC::Message& message,
|
|
|
|
+ BrowserThread::ID* thread) {
|
|
|
|
switch (message.type()) {
|
|
|
|
- case TtsHostMsg_InitializeVoiceList::ID:
|
|
|
|
- case TtsHostMsg_Speak::ID:
|
|
|
|
- case TtsHostMsg_Pause::ID:
|
|
|
|
- case TtsHostMsg_Resume::ID:
|
|
|
|
- case TtsHostMsg_Cancel::ID:
|
|
|
|
- *thread = BrowserThread::UI;
|
|
|
|
- break;
|
|
|
|
+ case TtsHostMsg_InitializeVoiceList::ID:
|
|
|
|
+ case TtsHostMsg_Speak::ID:
|
|
|
|
+ case TtsHostMsg_Pause::ID:
|
|
|
|
+ case TtsHostMsg_Resume::ID:
|
|
|
|
+ case TtsHostMsg_Cancel::ID:
|
|
|
|
+ *thread = BrowserThread::UI;
|
|
|
|
+ break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 23:59:47 +00:00
|
|
|
@@ -211,10 +236,8 @@ void TtsMessageFilter::Cleanup() {
|
|
|
|
content::TtsController::GetInstance()->RemoveUtteranceEventDelegate(this);
|
2018-10-11 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-void TtsMessageFilter::Observe(
|
|
|
|
- int type,
|
|
|
|
- const content::NotificationSource& source,
|
|
|
|
- const content::NotificationDetails& details) {
|
|
|
|
+void TtsMessageFilter::BrowserContextDestroyed() {
|
|
|
|
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
|
browser_context_ = nullptr;
|
|
|
|
- notification_registrar_.RemoveAll();
|
|
|
|
+ browser_context_shutdown_notifier_.reset();
|
|
|
|
}
|
|
|
|
diff --git a/chrome/browser/speech/tts_message_filter.h b/chrome/browser/speech/tts_message_filter.h
|
2019-01-08 23:59:47 +00:00
|
|
|
index 2fbbc4b4f2a79eac6b686894f2b6463abe404e50..c4712cebfba0efeb62a9061a997055c94ae41e3e 100644
|
2018-10-11 13:52:12 +00:00
|
|
|
--- a/chrome/browser/speech/tts_message_filter.h
|
|
|
|
+++ b/chrome/browser/speech/tts_message_filter.h
|
2019-01-08 23:59:47 +00:00
|
|
|
@@ -21,7 +21,6 @@ class BrowserContext;
|
|
|
|
struct TtsUtteranceRequest;
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2019-01-08 23:59:47 +00:00
|
|
|
class TtsMessageFilter : public content::BrowserMessageFilter,
|
|
|
|
- public content::NotificationObserver,
|
|
|
|
public content::UtteranceEventDelegate,
|
|
|
|
public content::VoicesChangedDelegate {
|
2018-10-11 13:52:12 +00:00
|
|
|
public:
|
2019-01-08 23:59:47 +00:00
|
|
|
@@ -63,15 +62,13 @@ class TtsMessageFilter : public content::BrowserMessageFilter,
|
2018-10-11 13:52:12 +00:00
|
|
|
// about to be deleted.
|
|
|
|
bool Valid();
|
|
|
|
|
|
|
|
- // content::NotificationObserver implementation.
|
|
|
|
- void Observe(int type,
|
|
|
|
- const content::NotificationSource& source,
|
|
|
|
- const content::NotificationDetails& details) override;
|
|
|
|
+ void BrowserContextDestroyed();
|
|
|
|
|
|
|
|
+ std::unique_ptr<KeyedServiceShutdownNotifier::Subscription>
|
|
|
|
+ browser_context_shutdown_notifier_;
|
|
|
|
content::BrowserContext* browser_context_;
|
|
|
|
mutable base::Lock mutex_;
|
|
|
|
mutable bool valid_;
|
|
|
|
- content::NotificationRegistrar notification_registrar_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TtsMessageFilter);
|
|
|
|
};
|