tts.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Andy Dill <[email protected]>
  3. Date: Wed, 23 Jan 2019 10:33:55 -0800
  4. Subject: move text-to-speech out of chromium_src
  5. diff --git a/chrome/browser/speech/tts_controller_impl.cc b/chrome/browser/speech/tts_controller_impl.cc
  6. index 2ca56c3a247e674ee15b0a0ee30e6c2941aa93d3..f58e33b3c0198e4333f98cd1928c8f6d9be45738 100644
  7. --- a/chrome/browser/speech/tts_controller_impl.cc
  8. +++ b/chrome/browser/speech/tts_controller_impl.cc
  9. @@ -624,12 +624,14 @@ const PrefService* TtsControllerImpl::GetPrefService(
  10. const Utterance* utterance) {
  11. const PrefService* prefs = nullptr;
  12. // The utterance->browser_context() is null in tests.
  13. +#if 0
  14. if (utterance->browser_context()) {
  15. const Profile* profile =
  16. Profile::FromBrowserContext(utterance->browser_context());
  17. if (profile)
  18. prefs = profile->GetPrefs();
  19. }
  20. +#endif
  21. return prefs;
  22. }
  23. diff --git a/chrome/browser/speech/tts_mac.mm b/chrome/browser/speech/tts_mac.mm
  24. index 74996d854df318de0e01873f27f6662bf4998cf8..d3bf665c2963560a2bf35afaca56ec5b57d0890b 100644
  25. --- a/chrome/browser/speech/tts_mac.mm
  26. +++ b/chrome/browser/speech/tts_mac.mm
  27. @@ -11,7 +11,6 @@
  28. #include "base/values.h"
  29. #include "chrome/browser/speech/tts_controller.h"
  30. #include "chrome/browser/speech/tts_platform.h"
  31. -#include "extensions/browser/extension_function.h"
  32. #import <Cocoa/Cocoa.h>
  33. diff --git a/chrome/browser/speech/tts_message_filter.cc b/chrome/browser/speech/tts_message_filter.cc
  34. index 013c7a9c60f95475d63701c4f6848cb00dac19d9..73a244a726e3e1a1b5b52ca0e8e3b209aaf432ff 100644
  35. --- a/chrome/browser/speech/tts_message_filter.cc
  36. +++ b/chrome/browser/speech/tts_message_filter.cc
  37. @@ -9,14 +9,40 @@
  38. #include "base/bind.h"
  39. #include "base/logging.h"
  40. #include "chrome/browser/chrome_notification_types.h"
  41. +#if 0
  42. #include "chrome/browser/profiles/profile.h"
  43. +#endif
  44. #include "chrome/common/tts_messages.h"
  45. +#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
  46. #include "content/public/browser/browser_context.h"
  47. #include "content/public/browser/notification_service.h"
  48. #include "content/public/browser/render_process_host.h"
  49. using content::BrowserThread;
  50. +namespace {
  51. +
  52. +class TtsMessageFilterShutdownNotifierFactory
  53. + : public BrowserContextKeyedServiceShutdownNotifierFactory {
  54. + public:
  55. + static TtsMessageFilterShutdownNotifierFactory* GetInstance() {
  56. + return base::Singleton<TtsMessageFilterShutdownNotifierFactory>::get();
  57. + }
  58. +
  59. + private:
  60. + friend struct base::DefaultSingletonTraits<
  61. + TtsMessageFilterShutdownNotifierFactory>;
  62. +
  63. + TtsMessageFilterShutdownNotifierFactory()
  64. + : BrowserContextKeyedServiceShutdownNotifierFactory("TtsMessageFilter") {}
  65. +
  66. + ~TtsMessageFilterShutdownNotifierFactory() override {}
  67. +
  68. + DISALLOW_COPY_AND_ASSIGN(TtsMessageFilterShutdownNotifierFactory);
  69. +};
  70. +
  71. +} // namespace
  72. +
  73. TtsMessageFilter::TtsMessageFilter(content::BrowserContext* browser_context)
  74. : BrowserMessageFilter(TtsMsgStart),
  75. browser_context_(browser_context),
  76. @@ -24,28 +50,27 @@ TtsMessageFilter::TtsMessageFilter(content::BrowserContext* browser_context)
  77. CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  78. TtsController::GetInstance()->AddVoicesChangedDelegate(this);
  79. - // TODO(dmazzoni): make it so that we can listen for a BrowserContext
  80. - // being destroyed rather than a Profile. http://crbug.com/444668
  81. - Profile* profile = Profile::FromBrowserContext(browser_context);
  82. - notification_registrar_.Add(this,
  83. - chrome::NOTIFICATION_PROFILE_DESTROYED,
  84. - content::Source<Profile>(profile));
  85. + browser_context_shutdown_notifier_ =
  86. + TtsMessageFilterShutdownNotifierFactory::GetInstance()
  87. + ->Get(browser_context)
  88. + ->Subscribe(base::Bind(&TtsMessageFilter::BrowserContextDestroyed,
  89. + base::RetainedRef(this)));
  90. // Balanced in OnChannelClosingInUIThread() to keep the ref-count be non-zero
  91. // until all pointers to this class are invalidated.
  92. AddRef();
  93. }
  94. -void TtsMessageFilter::OverrideThreadForMessage(
  95. - const IPC::Message& message, BrowserThread::ID* thread) {
  96. +void TtsMessageFilter::OverrideThreadForMessage(const IPC::Message& message,
  97. + BrowserThread::ID* thread) {
  98. switch (message.type()) {
  99. - case TtsHostMsg_InitializeVoiceList::ID:
  100. - case TtsHostMsg_Speak::ID:
  101. - case TtsHostMsg_Pause::ID:
  102. - case TtsHostMsg_Resume::ID:
  103. - case TtsHostMsg_Cancel::ID:
  104. - *thread = BrowserThread::UI;
  105. - break;
  106. + case TtsHostMsg_InitializeVoiceList::ID:
  107. + case TtsHostMsg_Speak::ID:
  108. + case TtsHostMsg_Pause::ID:
  109. + case TtsHostMsg_Resume::ID:
  110. + case TtsHostMsg_Cancel::ID:
  111. + *thread = BrowserThread::UI;
  112. + break;
  113. }
  114. }
  115. @@ -207,10 +232,8 @@ void TtsMessageFilter::Cleanup() {
  116. TtsController::GetInstance()->RemoveUtteranceEventDelegate(this);
  117. }
  118. -void TtsMessageFilter::Observe(
  119. - int type,
  120. - const content::NotificationSource& source,
  121. - const content::NotificationDetails& details) {
  122. +void TtsMessageFilter::BrowserContextDestroyed() {
  123. + CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  124. browser_context_ = nullptr;
  125. - notification_registrar_.RemoveAll();
  126. + browser_context_shutdown_notifier_.reset();
  127. }
  128. diff --git a/chrome/browser/speech/tts_message_filter.h b/chrome/browser/speech/tts_message_filter.h
  129. index cc9e2806b5c3942472785bf3a3a32e23d859971d..d21fb42f1aca2906b8d8968bd1a46721fbc55edb 100644
  130. --- a/chrome/browser/speech/tts_message_filter.h
  131. +++ b/chrome/browser/speech/tts_message_filter.h
  132. @@ -9,10 +9,9 @@
  133. #include "base/memory/weak_ptr.h"
  134. #include "base/synchronization/lock.h"
  135. #include "chrome/browser/speech/tts_controller.h"
  136. +#include "components/keyed_service/core/keyed_service_shutdown_notifier.h"
  137. #include "content/public/browser/browser_message_filter.h"
  138. #include "content/public/browser/browser_thread.h"
  139. -#include "content/public/browser/notification_observer.h"
  140. -#include "content/public/browser/notification_registrar.h"
  141. namespace content {
  142. class BrowserContext;
  143. @@ -22,7 +21,6 @@ struct TtsUtteranceRequest;
  144. class TtsMessageFilter
  145. : public content::BrowserMessageFilter,
  146. - public content::NotificationObserver,
  147. public UtteranceEventDelegate,
  148. public VoicesChangedDelegate {
  149. public:
  150. @@ -64,15 +62,13 @@ class TtsMessageFilter
  151. // about to be deleted.
  152. bool Valid();
  153. - // content::NotificationObserver implementation.
  154. - void Observe(int type,
  155. - const content::NotificationSource& source,
  156. - const content::NotificationDetails& details) override;
  157. + void BrowserContextDestroyed();
  158. + std::unique_ptr<KeyedServiceShutdownNotifier::Subscription>
  159. + browser_context_shutdown_notifier_;
  160. content::BrowserContext* browser_context_;
  161. mutable base::Lock mutex_;
  162. mutable bool valid_;
  163. - content::NotificationRegistrar notification_registrar_;
  164. DISALLOW_COPY_AND_ASSIGN(TtsMessageFilter);
  165. };