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

Unified Diff: chrome/browser/chromeos/extensions/speech_synthesis_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: Rebase 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/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..213360f7a259ca0ad8e58400f9730338f26ccc82
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/speech_synthesis_loader.cc
@@ -0,0 +1,76 @@
+// 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 {
+
+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()));
+
+ lang_to_extension_id_map_["en-US"] =
Dmitry Polukhin 2013/12/05 18:35:32 Nit, I suspect we will expand it in future so let'
dmazzoni 2013/12/05 23:19:47 Done.
+ extension_misc::kHighQuality_en_US_ExtensionId;
+}
+
+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);
Dmitry Polukhin 2013/12/05 18:35:32 Why do we need more than one language here?
dmazzoni 2013/12/05 23:19:47 Suppose a French-Canadian user has their UI set to
Dmitry Polukhin 2013/12/05 23:29:19 Sounds reasonable, I didn't think about this uses
+ 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

Powered by Google App Engine
This is Rietveld 408576698