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

Unified Diff: chrome/browser/extensions/external_component_loader.cc

Issue 102263005: Automatically trigger installation of high-quality speech synthesis extension. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix debug assertion Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/external_component_loader.cc
diff --git a/chrome/browser/extensions/external_component_loader.cc b/chrome/browser/extensions/external_component_loader.cc
index ba11aa62351caf1b23a8cfefe1a7829a75f59aef..ecfc18bd44fc9a0558e92dbc6f11fa79f8c52fa4 100644
--- a/chrome/browser/extensions/external_component_loader.cc
+++ b/chrome/browser/extensions/external_component_loader.cc
@@ -5,18 +5,54 @@
#include "chrome/browser/extensions/external_component_loader.h"
#include "base/command_line.h"
+#include "base/prefs/pref_change_registrar.h"
+#include "base/prefs/pref_service.h"
#include "base/values.h"
#include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/external_provider_impl.h"
#include "chrome/common/chrome_switches.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"
namespace extensions {
-ExternalComponentLoader::ExternalComponentLoader() {}
+#if defined(OS_CHROMEOS)
+namespace {
+// Table mapping language codes to the extension ids of high-quality
+// speech synthesis extensions. See the comment in StartLoading() for more.
+struct LangToExtensionId {
+ const char* lang;
+ const char* extension_id;
+};
+LangToExtensionId kLangToExtensionIdTable[] = {
+ { "en-US", extension_misc::kHighQuality_en_US_ExtensionId }
+};
+} // anonymous namespace
+#endif // defined(OS_CHROMEOS)
+
+ExternalComponentLoader::ExternalComponentLoader(Profile* profile)
+ : profile_(profile) {
+#if defined(OS_CHROMEOS)
+ pref_change_registrar_.reset(new PrefChangeRegistrar());
+ pref_change_registrar_->Init(profile->GetPrefs());
+ pref_change_registrar_->Add(
+ prefs::kHighQualitySpeechSynthesisLanguages,
+ base::Bind(&ExternalComponentLoader::StartLoading, AsWeakPtr()));
+
+ for (size_t i = 0; i < arraysize(kLangToExtensionIdTable); ++i) {
+ lang_to_extension_id_map_[kLangToExtensionIdTable[i].lang] =
+ kLangToExtensionIdTable[i].extension_id;
+ }
+#endif
+}
ExternalComponentLoader::~ExternalComponentLoader() {}
void ExternalComponentLoader::StartLoading() {
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
prefs_.reset(new base::DictionaryValue());
std::string appId = extension_misc::kInAppPaymentsSupportAppId;
prefs_->SetString(appId + ".external_update_url",
@@ -30,7 +66,48 @@ void ExternalComponentLoader::StartLoading() {
extension_urls::GetWebstoreUpdateUrl().spec());
}
}
+
+#if defined(OS_CHROMEOS)
+ // Chrome OS comes with medium-quality speech synthesis extensions built-in.
+ // When the user speaks a certain threshold of utterances in the same
+ // session, we set a preference indicating that high quality speech is
+ // enabled for that language. Here, we check the preference and prepare
+ // the list of external extensions to be installed based on that.
+ 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);
+ }
+#endif // defined(OS_CHROMEOS)
+
LoadFinished();
}
+// static
+void ExternalComponentLoader::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+#if defined(OS_CHROMEOS)
+ registry->RegisterListPref(prefs::kHighQualitySpeechSynthesisLanguages,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+#endif
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/external_component_loader.h ('k') | chrome/browser/extensions/external_component_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698