Commit e0987ee4 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Ensures TTS platform is not null

This CL is moving a branch to a DCHECK.

The GetTtsPlatform() can't safely be null since other piece of code
in the same file are using the pointer without any safety check.

Example:
  if (GetTtsPlatform()->PlatformImplAvailable()) {
    GetTtsPlatform()->ClearError();
    GetTtsPlatform()->StopSpeaking();
  }

After reading the code, I came to the conclusion that it can't be
null.

The TtsPlatform::GetInstance(...) will take the tts platform
from:
  GetContentClient()->browser()->GetTtsPlatform();
If this is null, it will returns:
 TtsPlatformImpl::GetInstance() instead.

Each platform has the proper implementation PlatformImpl.

Change-Id: Ib4e88dd1be3b557dd30c3c55041e7d8d4f0e1401
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438198
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812254}
parent 848a025e
...@@ -272,13 +272,12 @@ void TtsControllerImpl::OnTtsEvent(int utterance_id, ...@@ -272,13 +272,12 @@ void TtsControllerImpl::OnTtsEvent(int utterance_id,
void TtsControllerImpl::GetVoices(BrowserContext* browser_context, void TtsControllerImpl::GetVoices(BrowserContext* browser_context,
std::vector<VoiceData>* out_voices) { std::vector<VoiceData>* out_voices) {
TtsPlatform* tts_platform = GetTtsPlatform(); TtsPlatform* tts_platform = GetTtsPlatform();
if (tts_platform) { DCHECK(tts_platform);
// Ensure we have all built-in voices loaded. This is a no-op if already // Ensure we have all built-in voices loaded. This is a no-op if already
// loaded. // loaded.
tts_platform->LoadBuiltInTtsEngine(browser_context); tts_platform->LoadBuiltInTtsEngine(browser_context);
if (tts_platform->PlatformImplAvailable()) if (tts_platform->PlatformImplAvailable())
tts_platform->GetVoices(out_voices); tts_platform->GetVoices(out_voices);
}
if (browser_context && engine_delegate_) if (browser_context && engine_delegate_)
engine_delegate_->GetVoices(browser_context, out_voices); engine_delegate_->GetVoices(browser_context, out_voices);
......
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