Commit 43168c1b authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Make ChromeOS TTS PlatformImpl a leaky instance

This CL is making the TtsPlatformImpl instance a leaky
instance since the singleton is alive for the whole
duration of the process.

The use of WeakPtr is no longer required.

Bug: 1133813
Change-Id: I311e8bd354523be7cbdb07d0e87876141ec5e81d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441967Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813301}
parent dd76cd91
......@@ -11,8 +11,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/tts_platform.h"
TtsPlatformImplChromeOs::TtsPlatformImplChromeOs() {}
TtsPlatformImplChromeOs::~TtsPlatformImplChromeOs() {}
TtsPlatformImplChromeOs::TtsPlatformImplChromeOs() = default;
bool TtsPlatformImplChromeOs::PlatformImplAvailable() {
return arc::ArcServiceManager::Get() && arc::ArcServiceManager::Get()
......@@ -42,7 +41,7 @@ void TtsPlatformImplChromeOs::Speak(
// Parse SSML and process speech.
content::TtsController::GetInstance()->StripSSML(
utterance, base::BindOnce(&TtsPlatformImplChromeOs::ProcessSpeech,
weak_factory_.GetWeakPtr(), utterance_id, lang,
base::Unretained(this), utterance_id, lang,
voice, params, std::move(on_speak_finished)));
}
......@@ -117,5 +116,6 @@ bool TtsPlatformImplChromeOs::IsSpeaking() {
// static
TtsPlatformImplChromeOs*
TtsPlatformImplChromeOs::GetInstance() {
return base::Singleton<TtsPlatformImplChromeOs>::get();
static base::NoDestructor<TtsPlatformImplChromeOs> tts_platform;
return tts_platform.get();
}
......@@ -6,12 +6,16 @@
#define CHROME_BROWSER_SPEECH_TTS_CHROMEOS_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "content/public/browser/tts_platform.h"
// This class includes extension-based tts through LoadBuiltInTtsExtension and
// native tts through ARC.
class TtsPlatformImplChromeOs : public content::TtsPlatform {
public:
TtsPlatformImplChromeOs(const TtsPlatformImplChromeOs&) = delete;
TtsPlatformImplChromeOs& operator=(const TtsPlatformImplChromeOs&) = delete;
// TtsPlatform overrides:
bool PlatformImplAvailable() override;
bool LoadBuiltInTtsEngine(content::BrowserContext* browser_context) override;
......@@ -39,8 +43,8 @@ class TtsPlatformImplChromeOs : public content::TtsPlatform {
static TtsPlatformImplChromeOs* GetInstance();
private:
friend base::NoDestructor<TtsPlatformImplChromeOs>;
TtsPlatformImplChromeOs();
virtual ~TtsPlatformImplChromeOs();
void ProcessSpeech(int utterance_id,
const std::string& lang,
......@@ -49,13 +53,7 @@ class TtsPlatformImplChromeOs : public content::TtsPlatform {
base::OnceCallback<void(bool)> on_speak_finished,
const std::string& parsed_utterance);
friend struct base::DefaultSingletonTraits<TtsPlatformImplChromeOs>;
std::string error_;
base::WeakPtrFactory<TtsPlatformImplChromeOs> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplChromeOs);
};
#endif // CHROME_BROWSER_SPEECH_TTS_CHROMEOS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment