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 cf58b3d918d2a0c7db4b41ad679c71f1cd2b3e74..331549918459ada4020d8bcf46425df3c2426fc6 100644 |
--- a/chrome/browser/extensions/extension_tts_api_chromeos.cc |
+++ b/chrome/browser/extensions/extension_tts_api_chromeos.cc |
@@ -7,15 +7,15 @@ |
#include "base/memory/weak_ptr.h" |
#include "base/message_loop.h" |
#include "base/string_number_conversions.h" |
-#include "chrome/browser/chromeos/cros/cros_library.h" |
-#include "chrome/browser/chromeos/cros/speech_synthesis_library.h" |
+#include "base/task.h" |
satorux1
2011/10/19 05:15:47
I think base/task.h is unnecessary.
hashimoto
2011/10/19 06:02:14
Removed.
It seems that this include and |method_f
|
+#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; |
}; |
@@ -40,10 +40,12 @@ class ExtensionTtsPlatformImplChromeOs : public ExtensionTtsPlatformImpl { |
private: |
ExtensionTtsPlatformImplChromeOs() |
- : ALLOW_THIS_IN_INITIALIZER_LIST(ptr_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); |
dmazzoni
2011/10/19 05:01:15
By the way, it would be fantastic if we could impl
satorux1
2011/10/19 05:15:47
Agreed. Polling is uncool. :)
One way to do it is
hashimoto
2011/10/19 05:18:25
OK, I will.
It looks that currently no signal is s
|
void AppendSpeakOption(std::string key, |
std::string value, |
@@ -51,7 +53,8 @@ class ExtensionTtsPlatformImplChromeOs : public ExtensionTtsPlatformImpl { |
int utterance_id_; |
int utterance_length_; |
- base::WeakPtrFactory<ExtensionTtsPlatformImplChromeOs> ptr_factory_; |
+ ScopedRunnableMethodFactory<ExtensionTtsPlatformImplChromeOs> method_factory_; |
+ base::WeakPtrFactory<ExtensionTtsPlatformImplChromeOs> weak_ptr_factory_; |
friend struct DefaultSingletonTraits<ExtensionTtsPlatformImplChromeOs>; |
@@ -68,12 +71,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(); |
@@ -81,14 +78,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); |
} |
@@ -96,7 +93,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); |
} |
@@ -105,36 +102,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); |
+ 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) { |
@@ -149,26 +139,30 @@ 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)); |
+} |
- 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; |
} |
- |
+ // Continue polling. |
MessageLoop::current()->PostDelayedTask( |
FROM_HERE, base::Bind( |
&ExtensionTtsPlatformImplChromeOs::PollUntilSpeechFinishes, |
- ptr_factory_.GetWeakPtr(), |
+ weak_ptr_factory_.GetWeakPtr(), |
utterance_id), |
kSpeechCheckDelayIntervalMs); |
} |
@@ -179,9 +173,9 @@ void ExtensionTtsPlatformImplChromeOs::AppendSpeakOption( |
std::string* options) { |
*options += |
key + |
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyEquals + |
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyEquals + |
value + |
- chromeos::SpeechSynthesisLibrary::kSpeechPropertyDelimiter; |
+ chromeos::SpeechSynthesizerClient::kSpeechPropertyDelimiter; |
} |
// static |