Commit 48d140d3 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Revert "Use user preferences for TTS speech rate, pitch and volume if not set."

This reverts commit 6ceb3883.

Reason for revert: New tests have memory leaks.

https://ci.chromium.org/buildbot/chromium.memory/Linux%20Chromium%20OS%20ASan%20LSan%20Tests%20%281%29/27171

Original change's description:
> Use user preferences for TTS speech rate, pitch and volume if not set.
> 
> Bug: 823359
> Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
> Change-Id: I772e1fa78e0f3f7ed3a6ab858f4855f65f18513f
> Reviewed-on: https://chromium-review.googlesource.com/1014491
> Commit-Queue: Katie Dektar <katie@chromium.org>
> Reviewed-by: Jochen Eisinger <jochen@chromium.org>
> Reviewed-by: Nico Weber <thakis@chromium.org>
> Reviewed-by: David Tseng <dtseng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#552826}

TBR=thakis@chromium.org,dtseng@chromium.org,jochen@chromium.org,katie@chromium.org

Change-Id: I8702500882bf4e8a499c7798306976bd18ad260b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 823359
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Reviewed-on: https://chromium-review.googlesource.com/1025290Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552929}
parent 4e18f956
......@@ -149,7 +149,6 @@ include_rules = [
"+third_party/blink/public/platform/web_mouse_wheel_event.h",
"+third_party/blink/public/platform/web_referrer_policy.h",
"+third_party/blink/public/platform/web_security_style.h",
"+third_party/blink/public/platform/web_speech_synthesis_constants.h",
"+third_party/blink/public/platform/web_sudden_termination_disabler_type.h",
"+third_party/blink/public/platform/modules/notifications/web_notification_constants.h",
"+third_party/blink/public/platform/modules/remoteplayback/web_remote_playback_availability.h",
......
......@@ -52,7 +52,6 @@
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/blink/public/platform/web_speech_synthesis_constants.h"
#include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
......@@ -420,16 +419,13 @@ void Preferences::RegisterProfilePrefs(
prefs::kTextToSpeechLangToVoiceName,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF | PrefRegistry::PUBLIC);
registry->RegisterDoublePref(
prefs::kTextToSpeechRate,
blink::SpeechSynthesisConstants::kDefaultTextToSpeechRate,
prefs::kTextToSpeechRate, 1.0,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF | PrefRegistry::PUBLIC);
registry->RegisterDoublePref(
prefs::kTextToSpeechPitch,
blink::SpeechSynthesisConstants::kDefaultTextToSpeechPitch,
prefs::kTextToSpeechPitch, 1.0,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF | PrefRegistry::PUBLIC);
registry->RegisterDoublePref(
prefs::kTextToSpeechVolume,
blink::SpeechSynthesisConstants::kDefaultTextToSpeechVolume,
prefs::kTextToSpeechVolume, 1.0,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF | PrefRegistry::PUBLIC);
}
......
......@@ -19,7 +19,6 @@
#include "chrome/browser/speech/tts_controller.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function_registry.h"
#include "third_party/blink/public/platform/web_speech_synthesis_constants.h"
#include "ui/base/l10n/l10n_util.h"
namespace constants = tts_extension_api_constants;
......@@ -196,7 +195,7 @@ bool TtsSpeakFunction::RunAsync() {
return false;
}
double rate = blink::SpeechSynthesisConstants::kDoublePrefNotSet;
double rate = 1.0;
if (options->HasKey(constants::kRateKey)) {
EXTENSION_FUNCTION_VALIDATE(
options->GetDouble(constants::kRateKey, &rate));
......@@ -206,7 +205,7 @@ bool TtsSpeakFunction::RunAsync() {
}
}
double pitch = blink::SpeechSynthesisConstants::kDoublePrefNotSet;
double pitch = 1.0;
if (options->HasKey(constants::kPitchKey)) {
EXTENSION_FUNCTION_VALIDATE(
options->GetDouble(constants::kPitchKey, &pitch));
......@@ -216,7 +215,7 @@ bool TtsSpeakFunction::RunAsync() {
}
}
double volume = blink::SpeechSynthesisConstants::kDoublePrefNotSet;
double volume = 1.0;
if (options->HasKey(constants::kVolumeKey)) {
EXTENSION_FUNCTION_VALIDATE(
options->GetDouble(constants::kVolumeKey, &volume));
......
......@@ -15,11 +15,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/speech/tts_platform.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "third_party/blink/public/platform/web_speech_synthesis_constants.h"
namespace {
// A value to be used to indicate that there is no char index available.
......@@ -67,10 +63,12 @@ bool IsFinalTtsEventType(TtsEventType event_type) {
// UtteranceContinuousParameters
//
UtteranceContinuousParameters::UtteranceContinuousParameters()
: rate(blink::SpeechSynthesisConstants::kDoublePrefNotSet),
pitch(blink::SpeechSynthesisConstants::kDoublePrefNotSet),
volume(blink::SpeechSynthesisConstants::kDoublePrefNotSet) {}
: rate(-1),
pitch(-1),
volume(-1) {}
//
// VoiceData
......@@ -122,7 +120,7 @@ void Utterance::OnTtsEvent(TtsEventType event_type,
if (event_delegate_)
event_delegate_->OnTtsEvent(this, event_type, char_index, error_message);
if (finished_)
event_delegate_ = nullptr;
event_delegate_ = NULL;
}
void Utterance::Finish() {
......@@ -147,11 +145,11 @@ TtsControllerImpl* TtsControllerImpl::GetInstance() {
}
TtsControllerImpl::TtsControllerImpl()
: current_utterance_(nullptr),
: current_utterance_(NULL),
paused_(false),
platform_impl_(nullptr),
tts_engine_delegate_(nullptr),
pref_service_for_testing_(nullptr) {}
platform_impl_(NULL),
tts_engine_delegate_(NULL) {
}
TtsControllerImpl::~TtsControllerImpl() {
if (current_utterance_) {
......@@ -198,9 +196,7 @@ void TtsControllerImpl::SpeakNow(Utterance* utterance) {
if (index >= 0)
voice = voices[index];
else
voice.native = true;
UpdateUtteranceDefaults(utterance);
voice.native = true; // Try to let
GetPlatformImpl()->WillSpeakUtteranceWithVoice(utterance, voice);
......@@ -235,7 +231,7 @@ void TtsControllerImpl::SpeakNow(Utterance* utterance) {
if (!sends_end_event) {
utterance->Finish();
delete utterance;
current_utterance_ = nullptr;
current_utterance_ = NULL;
SpeakNextUtterance();
}
#endif
......@@ -251,7 +247,7 @@ void TtsControllerImpl::SpeakNow(Utterance* utterance) {
voice,
utterance->continuous_parameters());
if (!success)
current_utterance_ = nullptr;
current_utterance_ = NULL;
// If the native voice wasn't able to process this speech, see if
// the browser has built-in TTS that isn't loaded yet.
......@@ -390,7 +386,7 @@ void TtsControllerImpl::GetVoices(content::BrowserContext* browser_context,
}
bool TtsControllerImpl::IsSpeaking() {
return current_utterance_ != nullptr || GetPlatformImpl()->IsSpeaking();
return current_utterance_ != NULL || GetPlatformImpl()->IsSpeaking();
}
void TtsControllerImpl::FinishCurrentUtterance() {
......@@ -399,7 +395,7 @@ void TtsControllerImpl::FinishCurrentUtterance() {
current_utterance_->OnTtsEvent(TTS_EVENT_INTERRUPTED, kInvalidCharIndex,
std::string());
delete current_utterance_;
current_utterance_ = nullptr;
current_utterance_ = NULL;
}
}
......@@ -536,49 +532,6 @@ int TtsControllerImpl::GetMatchingVoice(
return best_score_index;
}
void TtsControllerImpl::UpdateUtteranceDefaults(Utterance* utterance) {
double rate = utterance->continuous_parameters().rate;
double pitch = utterance->continuous_parameters().pitch;
double volume = utterance->continuous_parameters().volume;
#if defined(OS_CHROMEOS)
// Update pitch, rate and volume from user prefs if not set explicitly
// on this utterance.
const PrefService* prefs = nullptr;
// The utterance->browser_context() is null in tests.
if (utterance->browser_context()) {
const Profile* profile =
Profile::FromBrowserContext(utterance->browser_context());
if (profile)
prefs = profile->GetPrefs();
} else if (pref_service_for_testing_) {
prefs = pref_service_for_testing_;
}
if (rate == blink::SpeechSynthesisConstants::kDoublePrefNotSet) {
rate = prefs ? prefs->GetDouble(prefs::kTextToSpeechRate)
: blink::SpeechSynthesisConstants::kDefaultTextToSpeechRate;
}
if (pitch == blink::SpeechSynthesisConstants::kDoublePrefNotSet) {
pitch = prefs ? prefs->GetDouble(prefs::kTextToSpeechPitch)
: blink::SpeechSynthesisConstants::kDefaultTextToSpeechPitch;
}
if (volume == blink::SpeechSynthesisConstants::kDoublePrefNotSet) {
volume = prefs
? prefs->GetDouble(prefs::kTextToSpeechVolume)
: blink::SpeechSynthesisConstants::kDefaultTextToSpeechVolume;
}
#else
// Update pitch, rate and volume to defaults if not explicity set on
// this utterance.
if (rate == blink::SpeechSynthesisConstants::kDoublePrefNotSet)
rate = blink::SpeechSynthesisConstants::kDefaultTextToSpeechRate;
if (pitch == blink::SpeechSynthesisConstants::kDoublePrefNotSet)
pitch = blink::SpeechSynthesisConstants::kDefaultTextToSpeechPitch;
if (volume == blink::SpeechSynthesisConstants::kDoublePrefNotSet)
volume = blink::SpeechSynthesisConstants::kDefaultTextToSpeechVolume;
#endif // defined(OS_CHROMEOS)
utterance->set_continuous_parameters(rate, pitch, volume);
}
void TtsControllerImpl::VoicesChanged() {
// Existence of platform tts indicates explicit requests to tts. Since
// |VoicesChanged| can occur implicitly, only send if needed.
......@@ -617,7 +570,7 @@ void TtsControllerImpl::RemoveUtteranceEventDelegate(
}
if (current_utterance_ && current_utterance_->event_delegate() == delegate) {
current_utterance_->set_event_delegate(nullptr);
current_utterance_->set_event_delegate(NULL);
if (!current_utterance_->extension_id().empty()) {
if (tts_engine_delegate_)
tts_engine_delegate_->Stop(current_utterance_);
......
......@@ -15,7 +15,6 @@
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "chrome/browser/speech/tts_controller.h"
#include "components/prefs/testing_pref_service.h"
#include "url/gurl.h"
namespace content {
......@@ -57,8 +56,6 @@ class TtsControllerImpl : public TtsController {
private:
FRIEND_TEST_ALL_PREFIXES(TtsControllerTest, TestGetMatchingVoice);
FRIEND_TEST_ALL_PREFIXES(TtsControllerTest,
TestTtsControllerUtteranceDefaults);
// Get the platform TTS implementation (or injected mock).
TtsPlatformImpl* GetPlatformImpl();
......@@ -82,11 +79,6 @@ class TtsControllerImpl : public TtsController {
int GetMatchingVoice(const Utterance* utterance,
std::vector<VoiceData>& voices);
// Updates the utterance to have default values for rate, pitch, and
// volume if they have not yet been set. On Chrome OS, defaults are
// pulled from user prefs, and may not be the same as other platforms.
void UpdateUtteranceDefaults(Utterance* utterance);
friend struct base::DefaultSingletonTraits<TtsControllerImpl>;
// The current utterance being spoken.
......@@ -108,9 +100,6 @@ class TtsControllerImpl : public TtsController {
// The delegate that processes TTS requests with user-installed extensions.
TtsEngineDelegate* tts_engine_delegate_;
// A mock pref service that should be used for testing only.
PrefService* pref_service_for_testing_;
DISALLOW_COPY_AND_ASSIGN(TtsControllerImpl);
};
......
......@@ -7,11 +7,7 @@
#include "base/values.h"
#include "chrome/browser/speech/tts_controller_impl.h"
#include "chrome/browser/speech/tts_platform.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_speech_synthesis_constants.h"
class TtsControllerTest : public testing::Test {
};
......@@ -52,12 +48,12 @@ TEST_F(TtsControllerTest, TestTtsControllerShutdown) {
new TestableTtsController();
controller->SetPlatformImpl(&platform_impl);
Utterance* utterance1 = new Utterance(nullptr);
Utterance* utterance1 = new Utterance(NULL);
utterance1->set_can_enqueue(true);
utterance1->set_src_id(1);
controller->SpeakOrEnqueue(utterance1);
Utterance* utterance2 = new Utterance(nullptr);
Utterance* utterance2 = new Utterance(NULL);
utterance2->set_can_enqueue(true);
utterance2->set_src_id(2);
controller->SpeakOrEnqueue(utterance2);
......@@ -71,7 +67,7 @@ TEST_F(TtsControllerTest, TestGetMatchingVoice) {
TtsControllerImpl* tts_controller = TtsControllerImpl::GetInstance();
{
// Calling GetMatchingVoice with no voices returns -1.
// Calling GetMatchingVoice with no voices returns -1
Utterance utterance(nullptr);
std::vector<VoiceData> voices;
EXPECT_EQ(-1, tts_controller->GetMatchingVoice(&utterance, voices));
......@@ -153,41 +149,3 @@ TEST_F(TtsControllerTest, TestGetMatchingVoice) {
EXPECT_EQ(6, tts_controller->GetMatchingVoice(&utterance, voices));
}
}
#if defined(OS_CHROMEOS)
TEST_F(TtsControllerTest, TestTtsControllerUtteranceDefaults) {
TestableTtsController* controller = new TestableTtsController();
Utterance* utterance1 = new Utterance(nullptr);
// Initialized to default (unset constant) values.
EXPECT_EQ(blink::SpeechSynthesisConstants::kDoublePrefNotSet,
utterance1->continuous_parameters().rate);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDoublePrefNotSet,
utterance1->continuous_parameters().pitch);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDoublePrefNotSet,
utterance1->continuous_parameters().volume);
controller->UpdateUtteranceDefaults(utterance1);
// Updated to global defaults.
EXPECT_EQ(blink::SpeechSynthesisConstants::kDefaultTextToSpeechRate,
utterance1->continuous_parameters().rate);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDefaultTextToSpeechPitch,
utterance1->continuous_parameters().pitch);
EXPECT_EQ(blink::SpeechSynthesisConstants::kDefaultTextToSpeechVolume,
utterance1->continuous_parameters().volume);
// Now we will set prefs and expect those to be used as defaults.
TestingPrefServiceSimple pref_service_;
pref_service_.registry()->RegisterDoublePref(prefs::kTextToSpeechRate, 1.5);
pref_service_.registry()->RegisterDoublePref(prefs::kTextToSpeechPitch, 2.0);
pref_service_.registry()->RegisterDoublePref(prefs::kTextToSpeechVolume, 0.5);
controller->pref_service_for_testing_ = &pref_service_;
Utterance* utterance2 = new Utterance(nullptr);
controller->UpdateUtteranceDefaults(utterance2);
// Updated to pref values.
EXPECT_EQ(1.5f, utterance2->continuous_parameters().rate);
EXPECT_EQ(2.0f, utterance2->continuous_parameters().pitch);
EXPECT_EQ(0.5f, utterance2->continuous_parameters().volume);
}
#endif // defined(OS_CHROMEOS)
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_SPEECH_SYNTHESIS_CONSTANTS_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_SPEECH_SYNTHESIS_CONSTANTS_H_
namespace blink {
// Constants used in Text-to-Speech.
namespace SpeechSynthesisConstants {
const double kDefaultTextToSpeechRate = 1.0;
const double kDefaultTextToSpeechPitch = 1.0;
const double kDefaultTextToSpeechVolume = 1.0;
const double kDoublePrefNotSet = -1.0;
} // namespace SpeechSynthesisConstants
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_SPEECH_SYNTHESIS_CONSTANTS_H_
......@@ -34,7 +34,7 @@ PlatformSpeechSynthesisUtterance* PlatformSpeechSynthesisUtterance::Create(
PlatformSpeechSynthesisUtterance::PlatformSpeechSynthesisUtterance(
PlatformSpeechSynthesisUtteranceClient* client)
: client_(client) {}
: client_(client), volume_(1.0f), rate_(1.0f), pitch_(1.0f) {}
void PlatformSpeechSynthesisUtterance::Trace(blink::Visitor* visitor) {
visitor->Trace(client_);
......
......@@ -26,7 +26,6 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SPEECH_PLATFORM_SPEECH_SYNTHESIS_UTTERANCE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SPEECH_PLATFORM_SPEECH_SYNTHESIS_UTTERANCE_H_
#include "third_party/blink/public/platform/web_speech_synthesis_constants.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/speech/platform_speech_synthesis_voice.h"
......@@ -84,9 +83,9 @@ class PLATFORM_EXPORT PlatformSpeechSynthesisUtterance final
String text_;
String lang_;
scoped_refptr<PlatformSpeechSynthesisVoice> voice_;
float volume_ = SpeechSynthesisConstants::kDoublePrefNotSet;
float rate_ = SpeechSynthesisConstants::kDoublePrefNotSet;
float pitch_ = SpeechSynthesisConstants::kDoublePrefNotSet;
float volume_;
float rate_;
float pitch_;
double start_time_;
};
......
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