| Index: chrome/browser/chromeos/extensions/speech_synthesis_loader.cc
|
| diff --git a/chrome/browser/chromeos/extensions/speech_synthesis_loader.cc b/chrome/browser/chromeos/extensions/speech_synthesis_loader.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..24784376dfccbafcae12e3b48f47fc9e910b0a26
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/extensions/speech_synthesis_loader.cc
|
| @@ -0,0 +1,89 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/extensions/speech_synthesis_loader.h"
|
| +
|
| +#include "base/prefs/pref_service.h"
|
| +#include "base/values.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/extensions/external_provider_impl.h"
|
| +#include "chrome/common/extensions/extension_constants.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "components/user_prefs/pref_registry_syncable.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +using extensions::ExternalProviderImpl;
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +struct LangToExtensionId {
|
| + const char* lang;
|
| + const char* extension_id;
|
| +};
|
| +
|
| +LangToExtensionId kLangToExtensionIdTable[] = {
|
| + { "en-US", extension_misc::kHighQuality_en_US_ExtensionId }
|
| +};
|
| +} // anonymous namespace
|
| +
|
| +SpeechSynthesisLoader::SpeechSynthesisLoader(Profile* profile)
|
| + : profile_(profile),
|
| + pref_change_registrar_(new PrefChangeRegistrar()),
|
| + weak_ptr_factory_(this) {
|
| + pref_change_registrar_->Init(profile->GetPrefs());
|
| + pref_change_registrar_->Add(
|
| + prefs::kHighQualitySpeechSynthesisLanguages,
|
| + base::Bind(&SpeechSynthesisLoader::StartLoading,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| +
|
| + for (size_t i = 0; i < arraysize(kLangToExtensionIdTable); ++i) {
|
| + lang_to_extension_id_map_[kLangToExtensionIdTable[i].lang] =
|
| + kLangToExtensionIdTable[i].extension_id;
|
| + }
|
| +}
|
| +
|
| +SpeechSynthesisLoader::~SpeechSynthesisLoader() {
|
| +}
|
| +
|
| +void SpeechSynthesisLoader::StartLoading() {
|
| + CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| +
|
| + prefs_.reset(new base::DictionaryValue());
|
| +
|
| + PrefService* pref_service = profile_->GetPrefs();
|
| + const base::ListValue* languages =
|
| + pref_service->GetList(prefs::kHighQualitySpeechSynthesisLanguages);
|
| + for (size_t i = 0; i < languages->GetSize(); ++i) {
|
| + std::string lang;
|
| + if (!languages->GetString(i, &lang))
|
| + continue;
|
| +
|
| + base::hash_map<std::string, std::string>::iterator iter =
|
| + lang_to_extension_id_map_.find(lang);
|
| + if (iter == lang_to_extension_id_map_.end())
|
| + continue;
|
| +
|
| + std::string extension_id = iter->second;
|
| + base::DictionaryValue* extension = new base::DictionaryValue();
|
| + prefs_->Set(extension_id, extension);
|
| + extension->SetString(ExternalProviderImpl::kExternalUpdateUrl,
|
| + extension_urls::GetWebstoreUpdateUrl().spec());
|
| + base::ListValue* supported_locales = new base::ListValue();
|
| + supported_locales->AppendString(g_browser_process->GetApplicationLocale());
|
| + extension->Set(ExternalProviderImpl::kSupportedLocales, supported_locales);
|
| + extension->SetBoolean(ExternalProviderImpl::kIsFromWebstore, true);
|
| + }
|
| +
|
| + LoadFinished();
|
| +}
|
| +
|
| +// static
|
| +void SpeechSynthesisLoader::RegisterProfilePrefs(
|
| + user_prefs::PrefRegistrySyncable* registry) {
|
| + registry->RegisterListPref(prefs::kHighQualitySpeechSynthesisLanguages,
|
| + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|