Chromium Code Reviews| Index: chrome/browser/speech/tts_controller.cc |
| diff --git a/chrome/browser/speech/tts_controller.cc b/chrome/browser/speech/tts_controller.cc |
| index d7fb66e1e63bd4c78bd6ff20acc8081211aa6e57..0d1d131574d46b53b921ec675b9253cef29207d5 100644 |
| --- a/chrome/browser/speech/tts_controller.cc |
| +++ b/chrome/browser/speech/tts_controller.cc |
| @@ -117,6 +117,7 @@ TtsController* TtsController::GetInstance() { |
| TtsController::TtsController() |
| : current_utterance_(NULL), |
| + paused_(false), |
| platform_impl_(NULL) { |
| } |
| @@ -131,7 +132,7 @@ TtsController::~TtsController() { |
| } |
| void TtsController::SpeakOrEnqueue(Utterance* utterance) { |
| - if (IsSpeaking() && utterance->can_enqueue()) { |
| + if (paused_ || (IsSpeaking() && utterance->can_enqueue())) { |
|
David Tseng
2013/05/13 17:49:54
I don't remember why isSpeaking is needed here. It
dmazzoni
2013/05/13 19:34:38
Are you thinking about the change we made on Mac w
dmazzoni
2013/05/14 16:50:27
Got it. That won't happen because IsSpeaking check
|
| utterance_queue_.push(utterance); |
| } else { |
|
David Tseng
2013/05/13 17:49:54
What happens if we're currently paused and get a n
dmazzoni
2013/05/14 16:50:27
Done.
|
| Stop(); |
| @@ -196,6 +197,7 @@ void TtsController::SpeakNow(Utterance* utterance) { |
| } |
| void TtsController::Stop() { |
| + paused_ = false; |
| if (current_utterance_ && !current_utterance_->extension_id().empty()) { |
| ExtensionTtsEngineStop(current_utterance_); |
| } else { |
| @@ -210,6 +212,28 @@ void TtsController::Stop() { |
| ClearUtteranceQueue(true); // Send events. |
| } |
| +void TtsController::Pause() { |
| + paused_ = true; |
| + if (current_utterance_ && !current_utterance_->extension_id().empty()) { |
| + ExtensionTtsEnginePause(current_utterance_); |
| + } else if (current_utterance_) { |
| + GetPlatformImpl()->clear_error(); |
| + GetPlatformImpl()->Pause(); |
| + } |
| +} |
| + |
| +void TtsController::Resume() { |
| + paused_ = false; |
| + if (current_utterance_ && !current_utterance_->extension_id().empty()) { |
| + ExtensionTtsEngineResume(current_utterance_); |
| + } else if (current_utterance_) { |
| + GetPlatformImpl()->clear_error(); |
| + GetPlatformImpl()->Resume(); |
| + } else { |
| + SpeakNextUtterance(); |
| + } |
| +} |
| + |
| void TtsController::OnTtsEvent(int utterance_id, |
| TtsEventType event_type, |
| int char_index, |
| @@ -253,6 +277,9 @@ void TtsController::FinishCurrentUtterance() { |
| } |
| void TtsController::SpeakNextUtterance() { |
| + if (paused_) |
| + return; |
| + |
| // Start speaking the next utterance in the queue. Keep trying in case |
| // one fails but there are still more in the queue to try. |
| while (!utterance_queue_.empty() && !current_utterance_) { |