Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ | |
| 6 #define CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ | |
| 7 | |
| 8 #include <queue> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/singleton.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "chrome/browser/speech/tts_controller.h" | |
| 17 #include "url/gurl.h" | |
| 18 | |
| 19 // Singleton class that manages text-to-speech for the TTS and TTS engine | |
| 20 // extension APIs, maintaining a queue of pending utterances and keeping | |
| 21 // track of all state. | |
| 22 class TtsControllerImpl : public TtsController { | |
| 23 public: | |
| 24 // Get the single instance of this class. | |
| 25 static TtsControllerImpl* GetInstance(); | |
| 26 | |
| 27 virtual bool IsSpeaking() OVERRIDE; | |
|
sky
2014/07/23 19:23:24
nit: We generally prefix overrides sections with s
| |
| 28 virtual void SpeakOrEnqueue(Utterance* utterance) OVERRIDE; | |
| 29 virtual void Stop() OVERRIDE; | |
| 30 virtual void Pause() OVERRIDE; | |
| 31 virtual void Resume() OVERRIDE; | |
| 32 virtual void OnTtsEvent(int utterance_id, | |
| 33 TtsEventType event_type, | |
| 34 int char_index, | |
| 35 const std::string& error_message) OVERRIDE; | |
| 36 virtual void GetVoices(Profile* profile, | |
| 37 std::vector<VoiceData>* out_voices) OVERRIDE; | |
| 38 virtual void RetrySpeakingQueuedUtterances() OVERRIDE; | |
| 39 virtual void VoicesChanged() OVERRIDE; | |
| 40 virtual void AddVoicesChangedDelegate( | |
| 41 VoicesChangedDelegate* delegate) OVERRIDE; | |
| 42 virtual void RemoveVoicesChangedDelegate( | |
| 43 VoicesChangedDelegate* delegate) OVERRIDE; | |
| 44 virtual void SetTtsEngineDelegate(TtsEngineDelegate* delegate) OVERRIDE; | |
| 45 virtual void SetPlatformImpl(TtsPlatformImpl* platform_impl) OVERRIDE; | |
| 46 virtual int QueueSize() OVERRIDE; | |
| 47 | |
| 48 protected: | |
| 49 TtsControllerImpl(); | |
| 50 virtual ~TtsControllerImpl(); | |
| 51 | |
| 52 private: | |
| 53 // Get the platform TTS implementation (or injected mock). | |
| 54 TtsPlatformImpl* GetPlatformImpl(); | |
| 55 | |
| 56 // Start speaking the given utterance. Will either take ownership of | |
| 57 // |utterance| or delete it if there's an error. Returns true on success. | |
| 58 void SpeakNow(Utterance* utterance); | |
| 59 | |
| 60 // Clear the utterance queue. If send_events is true, will send | |
| 61 // TTS_EVENT_CANCELLED events on each one. | |
| 62 void ClearUtteranceQueue(bool send_events); | |
| 63 | |
| 64 // Finalize and delete the current utterance. | |
| 65 void FinishCurrentUtterance(); | |
| 66 | |
| 67 // Start speaking the next utterance in the queue. | |
| 68 void SpeakNextUtterance(); | |
| 69 | |
| 70 // Given an utterance and a vector of voices, return the | |
| 71 // index of the voice that best matches the utterance. | |
| 72 int GetMatchingVoice(const Utterance* utterance, | |
| 73 std::vector<VoiceData>& voices); | |
| 74 | |
| 75 friend struct DefaultSingletonTraits<TtsControllerImpl>; | |
| 76 | |
| 77 // The current utterance being spoken. | |
| 78 Utterance* current_utterance_; | |
| 79 | |
| 80 // Whether the queue is paused or not. | |
| 81 bool paused_; | |
| 82 | |
| 83 // A queue of utterances to speak after the current one finishes. | |
| 84 std::queue<Utterance*> utterance_queue_; | |
| 85 | |
| 86 // A set of delegates that want to be notified when the voices change. | |
| 87 std::set<VoicesChangedDelegate*> voices_changed_delegates_; | |
| 88 | |
| 89 // A pointer to the platform implementation of text-to-speech, for | |
| 90 // dependency injection. | |
| 91 TtsPlatformImpl* platform_impl_; | |
| 92 | |
| 93 // The delegate that processes TTS requests with user-installed extensions. | |
| 94 TtsEngineDelegate* tts_engine_delegate_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(TtsControllerImpl); | |
| 97 }; | |
| 98 | |
| 99 #endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ | |
| OLD | NEW |