| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/extensions/speech_synthesis_loader.h" |
| 6 |
| 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/external_provider_impl.h" |
| 11 #include "chrome/common/extensions/extension_constants.h" |
| 12 #include "chrome/common/pref_names.h" |
| 13 #include "components/user_prefs/pref_registry_syncable.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 |
| 16 using extensions::ExternalProviderImpl; |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 namespace { |
| 21 struct LangToExtensionId { |
| 22 const char* lang; |
| 23 const char* extension_id; |
| 24 }; |
| 25 |
| 26 LangToExtensionId kLangToExtensionIdTable[] = { |
| 27 { "en-US", extension_misc::kHighQuality_en_US_ExtensionId } |
| 28 }; |
| 29 } // anonymous namespace |
| 30 |
| 31 SpeechSynthesisLoader::SpeechSynthesisLoader(Profile* profile) |
| 32 : profile_(profile), |
| 33 pref_change_registrar_(new PrefChangeRegistrar()), |
| 34 weak_ptr_factory_(this) { |
| 35 pref_change_registrar_->Init(profile->GetPrefs()); |
| 36 pref_change_registrar_->Add( |
| 37 prefs::kHighQualitySpeechSynthesisLanguages, |
| 38 base::Bind(&SpeechSynthesisLoader::StartLoading, |
| 39 weak_ptr_factory_.GetWeakPtr())); |
| 40 |
| 41 for (size_t i = 0; i < arraysize(kLangToExtensionIdTable); ++i) { |
| 42 lang_to_extension_id_map_[kLangToExtensionIdTable[i].lang] = |
| 43 kLangToExtensionIdTable[i].extension_id; |
| 44 } |
| 45 } |
| 46 |
| 47 SpeechSynthesisLoader::~SpeechSynthesisLoader() { |
| 48 } |
| 49 |
| 50 void SpeechSynthesisLoader::StartLoading() { |
| 51 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 52 |
| 53 prefs_.reset(new base::DictionaryValue()); |
| 54 |
| 55 PrefService* pref_service = profile_->GetPrefs(); |
| 56 const base::ListValue* languages = |
| 57 pref_service->GetList(prefs::kHighQualitySpeechSynthesisLanguages); |
| 58 for (size_t i = 0; i < languages->GetSize(); ++i) { |
| 59 std::string lang; |
| 60 if (!languages->GetString(i, &lang)) |
| 61 continue; |
| 62 |
| 63 base::hash_map<std::string, std::string>::iterator iter = |
| 64 lang_to_extension_id_map_.find(lang); |
| 65 if (iter == lang_to_extension_id_map_.end()) |
| 66 continue; |
| 67 |
| 68 std::string extension_id = iter->second; |
| 69 base::DictionaryValue* extension = new base::DictionaryValue(); |
| 70 prefs_->Set(extension_id, extension); |
| 71 extension->SetString(ExternalProviderImpl::kExternalUpdateUrl, |
| 72 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 73 base::ListValue* supported_locales = new base::ListValue(); |
| 74 supported_locales->AppendString(g_browser_process->GetApplicationLocale()); |
| 75 extension->Set(ExternalProviderImpl::kSupportedLocales, supported_locales); |
| 76 extension->SetBoolean(ExternalProviderImpl::kIsFromWebstore, true); |
| 77 } |
| 78 |
| 79 LoadFinished(); |
| 80 } |
| 81 |
| 82 // static |
| 83 void SpeechSynthesisLoader::RegisterProfilePrefs( |
| 84 user_prefs::PrefRegistrySyncable* registry) { |
| 85 registry->RegisterListPref(prefs::kHighQualitySpeechSynthesisLanguages, |
| 86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 87 } |
| 88 |
| 89 } // namespace chromeos |
| OLD | NEW |