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

Side by Side Diff: chrome/browser/speech/tts_controller_impl.cc

Issue 448033002: Eliminate the dependency of Profile from TtsMessageFilter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed compilation error on ChromeOS Created 6 years, 4 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/speech/tts_controller_impl.h ('k') | chrome/browser/speech/tts_message_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/speech/tts_controller_impl.h" 5 #include "chrome/browser/speech/tts_controller_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/float_util.h" 10 #include "base/float_util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 VoiceData::~VoiceData() {} 58 VoiceData::~VoiceData() {}
59 59
60 60
61 // 61 //
62 // Utterance 62 // Utterance
63 // 63 //
64 64
65 // static 65 // static
66 int Utterance::next_utterance_id_ = 0; 66 int Utterance::next_utterance_id_ = 0;
67 67
68 Utterance::Utterance(Profile* profile) 68 Utterance::Utterance(content::BrowserContext* browser_context)
69 : profile_(profile), 69 : browser_context_(browser_context),
70 id_(next_utterance_id_++), 70 id_(next_utterance_id_++),
71 src_id_(-1), 71 src_id_(-1),
72 gender_(TTS_GENDER_NONE), 72 gender_(TTS_GENDER_NONE),
73 can_enqueue_(false), 73 can_enqueue_(false),
74 char_index_(0), 74 char_index_(0),
75 finished_(false) { 75 finished_(false) {
76 options_.reset(new base::DictionaryValue()); 76 options_.reset(new base::DictionaryValue());
77 } 77 }
78 78
79 Utterance::~Utterance() { 79 Utterance::~Utterance() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } else { 146 } else {
147 Stop(); 147 Stop();
148 SpeakNow(utterance); 148 SpeakNow(utterance);
149 } 149 }
150 } 150 }
151 151
152 void TtsControllerImpl::SpeakNow(Utterance* utterance) { 152 void TtsControllerImpl::SpeakNow(Utterance* utterance) {
153 // Ensure we have all built-in voices loaded. This is a no-op if already 153 // Ensure we have all built-in voices loaded. This is a no-op if already
154 // loaded. 154 // loaded.
155 bool loaded_built_in = 155 bool loaded_built_in =
156 GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->profile()); 156 GetPlatformImpl()->LoadBuiltInTtsExtension(utterance->browser_context());
157 157
158 // Get all available voices and try to find a matching voice. 158 // Get all available voices and try to find a matching voice.
159 std::vector<VoiceData> voices; 159 std::vector<VoiceData> voices;
160 GetVoices(utterance->profile(), &voices); 160 GetVoices(utterance->browser_context(), &voices);
161 int index = GetMatchingVoice(utterance, voices); 161 int index = GetMatchingVoice(utterance, voices);
162 162
163 VoiceData voice; 163 VoiceData voice;
164 if (index != -1) { 164 if (index != -1) {
165 // Select the matching voice. 165 // Select the matching voice.
166 voice = voices[index]; 166 voice = voices[index];
167 } else { 167 } else {
168 // However, if no match was found on a platform without native tts voices, 168 // However, if no match was found on a platform without native tts voices,
169 // attempt to get a voice based only on the current locale without respect 169 // attempt to get a voice based only on the current locale without respect
170 // to any supplied voice names. 170 // to any supplied voice names.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if (!current_utterance_ || utterance_id != current_utterance_->id()) { 298 if (!current_utterance_ || utterance_id != current_utterance_->id()) {
299 return; 299 return;
300 } 300 }
301 current_utterance_->OnTtsEvent(event_type, char_index, error_message); 301 current_utterance_->OnTtsEvent(event_type, char_index, error_message);
302 if (current_utterance_->finished()) { 302 if (current_utterance_->finished()) {
303 FinishCurrentUtterance(); 303 FinishCurrentUtterance();
304 SpeakNextUtterance(); 304 SpeakNextUtterance();
305 } 305 }
306 } 306 }
307 307
308 void TtsControllerImpl::GetVoices(Profile* profile, 308 void TtsControllerImpl::GetVoices(content::BrowserContext* browser_context,
309 std::vector<VoiceData>* out_voices) { 309 std::vector<VoiceData>* out_voices) {
310 #if !defined(OS_ANDROID) 310 #if !defined(OS_ANDROID)
311 if (profile && tts_engine_delegate_) 311 if (browser_context && tts_engine_delegate_)
312 tts_engine_delegate_->GetVoices(profile, out_voices); 312 tts_engine_delegate_->GetVoices(browser_context, out_voices);
313 #endif 313 #endif
314 314
315 TtsPlatformImpl* platform_impl = GetPlatformImpl(); 315 TtsPlatformImpl* platform_impl = GetPlatformImpl();
316 if (platform_impl) { 316 if (platform_impl) {
317 // Ensure we have all built-in voices loaded. This is a no-op if already 317 // Ensure we have all built-in voices loaded. This is a no-op if already
318 // loaded. 318 // loaded.
319 platform_impl->LoadBuiltInTtsExtension(profile); 319 platform_impl->LoadBuiltInTtsExtension(browser_context);
320 if (platform_impl->PlatformImplAvailable()) 320 if (platform_impl->PlatformImplAvailable())
321 platform_impl->GetVoices(out_voices); 321 platform_impl->GetVoices(out_voices);
322 } 322 }
323 } 323 }
324 324
325 bool TtsControllerImpl::IsSpeaking() { 325 bool TtsControllerImpl::IsSpeaking() {
326 return current_utterance_ != NULL || GetPlatformImpl()->IsSpeaking(); 326 return current_utterance_ != NULL || GetPlatformImpl()->IsSpeaking();
327 } 327 }
328 328
329 void TtsControllerImpl::FinishCurrentUtterance() { 329 void TtsControllerImpl::FinishCurrentUtterance() {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 } 454 }
455 455
456 void TtsControllerImpl::SetTtsEngineDelegate( 456 void TtsControllerImpl::SetTtsEngineDelegate(
457 TtsEngineDelegate* delegate) { 457 TtsEngineDelegate* delegate) {
458 tts_engine_delegate_ = delegate; 458 tts_engine_delegate_ = delegate;
459 } 459 }
460 460
461 TtsEngineDelegate* TtsControllerImpl::GetTtsEngineDelegate() { 461 TtsEngineDelegate* TtsControllerImpl::GetTtsEngineDelegate() {
462 return tts_engine_delegate_; 462 return tts_engine_delegate_;
463 } 463 }
OLDNEW
« no previous file with comments | « chrome/browser/speech/tts_controller_impl.h ('k') | chrome/browser/speech/tts_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698