Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1600)

Unified Diff: chrome/browser/extensions/extension_tts_api_chromeos.cc

Issue 8334018: Move the code in libcros' chromeos_speech_synthesis.cc into Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments and copyright, cleaned up includes Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_tts_api_chromeos.cc
diff --git a/chrome/browser/extensions/extension_tts_api_chromeos.cc b/chrome/browser/extensions/extension_tts_api_chromeos.cc
index e421897ff0db144bc7b98f741a5f971b7084d59c..6efc6cfee8fe6ef91caf91bd3afeed370b9917d2 100644
--- a/chrome/browser/extensions/extension_tts_api_chromeos.cc
+++ b/chrome/browser/extensions/extension_tts_api_chromeos.cc
@@ -2,19 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/memory/singleton.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "base/task.h"
-#include "chrome/browser/chromeos/cros/cros_library.h"
-#include "chrome/browser/chromeos/cros/speech_synthesis_library.h"
+#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
+#include "chrome/browser/chromeos/dbus/speech_synthesizer_client.h"
#include "chrome/browser/extensions/extension_tts_api_controller.h"
#include "chrome/browser/extensions/extension_tts_api_platform.h"
using base::DoubleToString;
namespace {
-const char kCrosLibraryNotLoadedError[] = "Cros shared library not loaded.";
const int kSpeechCheckDelayIntervalMs = 100;
};
@@ -39,10 +39,12 @@ class ExtensionTtsPlatformImplChromeOs : public ExtensionTtsPlatformImpl {
private:
ExtensionTtsPlatformImplChromeOs()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
+ : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
virtual ~ExtensionTtsPlatformImplChromeOs() {}
void PollUntilSpeechFinishes(int utterance_id);
+ void ContinuePollingIfSpeechIsNotFinished(int utterance_id, bool result);
void AppendSpeakOption(std::string key,
std::string value,
@@ -51,6 +53,7 @@ class ExtensionTtsPlatformImplChromeOs : public ExtensionTtsPlatformImpl {
int utterance_id_;
int utterance_length_;
ScopedRunnableMethodFactory<ExtensionTtsPlatformImplChromeOs> method_factory_;
+ base::WeakPtrFactory<ExtensionTtsPlatformImplChromeOs> weak_ptr_factory_;
friend struct DefaultSingletonTraits<ExtensionTtsPlatformImplChromeOs>;
@@ -67,12 +70,6 @@ bool ExtensionTtsPlatformImplChromeOs::Speak(
const std::string& utterance,
const std::string& lang,
const UtteranceContinuousParameters& params) {
- chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get();
- if (!cros_library->EnsureLoaded()) {
- set_error(kCrosLibraryNotLoadedError);
- return false;
- }
-
utterance_id_ = utterance_id;
utterance_length_ = utterance.size();
@@ -80,14 +77,14 @@ bool ExtensionTtsPlatformImplChromeOs::Speak(
if (!lang.empty()) {
AppendSpeakOption(
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyLocale,
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyLocale,
lang,
&options);
}
if (params.rate >= 0.0) {
AppendSpeakOption(
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyRate,
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyRate,
DoubleToString(params.rate),
&options);
}
@@ -95,7 +92,7 @@ bool ExtensionTtsPlatformImplChromeOs::Speak(
if (params.pitch >= 0.0) {
// The TTS service allows a range of 0 to 2 for speech pitch.
AppendSpeakOption(
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyPitch,
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyPitch,
DoubleToString(params.pitch),
&options);
}
@@ -104,36 +101,29 @@ bool ExtensionTtsPlatformImplChromeOs::Speak(
// The Chrome OS TTS service allows a range of 0 to 5 for speech volume,
// but 5 clips, so map to a range of 0...4.
AppendSpeakOption(
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyVolume,
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyVolume,
DoubleToString(params.volume * 4),
&options);
}
- if (!options.empty()) {
- cros_library->GetSpeechSynthesisLibrary()->SetSpeakProperties(
- options.c_str());
- }
+ chromeos::SpeechSynthesizerClient* speech_synthesizer_client =
+ chromeos::DBusThreadManager::Get()->speech_synthesizer_client();
- bool result =
- cros_library->GetSpeechSynthesisLibrary()->Speak(utterance.c_str());
+ if (!options.empty())
+ speech_synthesizer_client->SetSpeakProperties(options);
- if (result) {
- ExtensionTtsController* controller = ExtensionTtsController::GetInstance();
- controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string());
- PollUntilSpeechFinishes(utterance_id_);
- }
+ speech_synthesizer_client->Speak(utterance);
satorux1 2011/10/18 20:49:25 I was a bit worried about the change here as Speak
hashimoto 2011/10/19 00:08:47 Yes, this change keeps the semantics, nothing is c
+ ExtensionTtsController* controller = ExtensionTtsController::GetInstance();
+ controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string());
+ PollUntilSpeechFinishes(utterance_id_);
- return result;
+ return true;
}
bool ExtensionTtsPlatformImplChromeOs::StopSpeaking() {
- if (chromeos::CrosLibrary::Get()->EnsureLoaded()) {
- return chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()->
- StopSpeaking();
- }
-
- set_error(kCrosLibraryNotLoadedError);
- return false;
+ chromeos::DBusThreadManager::Get()->speech_synthesizer_client()->
+ StopSpeaking();
+ return true;
}
bool ExtensionTtsPlatformImplChromeOs::SendsEvent(TtsEventType event_type) {
@@ -148,22 +138,26 @@ void ExtensionTtsPlatformImplChromeOs::PollUntilSpeechFinishes(
// This utterance must have been interrupted or cancelled.
return;
}
+ chromeos::SpeechSynthesizerClient* speech_synthesizer_client =
+ chromeos::DBusThreadManager::Get()->speech_synthesizer_client();
+ speech_synthesizer_client->IsSpeaking(base::Bind(
+ &ExtensionTtsPlatformImplChromeOs::ContinuePollingIfSpeechIsNotFinished,
+ weak_ptr_factory_.GetWeakPtr(), utterance_id));
satorux1 2011/10/18 20:49:25 Nice! It's now asynchronous thus not blocking UI.
hashimoto 2011/10/19 00:08:47 I tried to make IsSpeaking synchronous, but gave u
+}
- chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get();
- ExtensionTtsController* controller = ExtensionTtsController::GetInstance();
-
- if (!cros_library->EnsureLoaded()) {
- controller->OnTtsEvent(
- utterance_id_, TTS_EVENT_ERROR, 0, kCrosLibraryNotLoadedError);
+void ExtensionTtsPlatformImplChromeOs::ContinuePollingIfSpeechIsNotFinished(
+ int utterance_id, bool is_speaking) {
+ if (utterance_id != utterance_id_) {
+ // This utterance must have been interrupted or cancelled.
return;
}
-
- if (!cros_library->GetSpeechSynthesisLibrary()->IsSpeaking()) {
+ if (!is_speaking) {
+ ExtensionTtsController* controller = ExtensionTtsController::GetInstance();
controller->OnTtsEvent(
utterance_id_, TTS_EVENT_END, utterance_length_, std::string());
return;
}
-
+ // Contniue polling.
MessageLoop::current()->PostDelayedTask(
FROM_HERE, method_factory_.NewRunnableMethod(
&ExtensionTtsPlatformImplChromeOs::PollUntilSpeechFinishes,
@@ -177,9 +171,9 @@ void ExtensionTtsPlatformImplChromeOs::AppendSpeakOption(
std::string* options) {
*options +=
key +
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyEquals +
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyEquals +
value +
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyDelimiter;
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyDelimiter;
}
// static

Powered by Google App Engine
This is Rietveld 408576698