OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/tts_dispatcher.h" | 5 #include "chrome/renderer/tts_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/tts_messages.h" | 10 #include "chrome/common/tts_messages.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 void TtsDispatcher::Resume() { | 80 void TtsDispatcher::Resume() { |
81 RenderThread::Get()->Send(new TtsHostMsg_Resume()); | 81 RenderThread::Get()->Send(new TtsHostMsg_Resume()); |
82 } | 82 } |
83 | 83 |
84 void TtsDispatcher::Cancel() { | 84 void TtsDispatcher::Cancel() { |
85 RenderThread::Get()->Send(new TtsHostMsg_Cancel()); | 85 RenderThread::Get()->Send(new TtsHostMsg_Cancel()); |
86 } | 86 } |
87 | 87 |
88 WebSpeechSynthesisUtterance TtsDispatcher::FindUtterance(int utterance_id) { | 88 WebSpeechSynthesisUtterance TtsDispatcher::FindUtterance(int utterance_id) { |
89 base::hash_map<int, WebSpeechSynthesisUtterance>::const_iterator iter = | 89 const auto iter = utterance_id_map_.find(utterance_id); |
90 utterance_id_map_.find(utterance_id); | |
91 if (iter == utterance_id_map_.end()) | 90 if (iter == utterance_id_map_.end()) |
92 return WebSpeechSynthesisUtterance(); | 91 return WebSpeechSynthesisUtterance(); |
93 return iter->second; | 92 return iter->second; |
94 } | 93 } |
95 | 94 |
96 void TtsDispatcher::OnSetVoiceList(const std::vector<TtsVoice>& voices) { | 95 void TtsDispatcher::OnSetVoiceList(const std::vector<TtsVoice>& voices) { |
97 WebVector<WebSpeechSynthesisVoice> out_voices(voices.size()); | 96 WebVector<WebSpeechSynthesisVoice> out_voices(voices.size()); |
98 for (size_t i = 0; i < voices.size(); ++i) { | 97 for (size_t i = 0; i < voices.size(); ++i) { |
99 out_voices[i] = WebSpeechSynthesisVoice(); | 98 out_voices[i] = WebSpeechSynthesisVoice(); |
100 out_voices[i].SetVoiceURI(WebString::FromUTF8(voices[i].voice_uri)); | 99 out_voices[i].SetVoiceURI(WebString::FromUTF8(voices[i].voice_uri)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 void TtsDispatcher::OnSpeakingErrorOccurred(int utterance_id, | 190 void TtsDispatcher::OnSpeakingErrorOccurred(int utterance_id, |
192 const std::string& error_message) { | 191 const std::string& error_message) { |
193 WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id); | 192 WebSpeechSynthesisUtterance utterance = FindUtterance(utterance_id); |
194 if (utterance.IsNull()) | 193 if (utterance.IsNull()) |
195 return; | 194 return; |
196 | 195 |
197 // The web speech API doesn't support an error message. | 196 // The web speech API doesn't support an error message. |
198 synthesizer_client_->SpeakingErrorOccurred(utterance); | 197 synthesizer_client_->SpeakingErrorOccurred(utterance); |
199 utterance_id_map_.erase(utterance_id); | 198 utterance_id_map_.erase(utterance_id); |
200 } | 199 } |
OLD | NEW |