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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 SpeechSynthesisLoader::SpeechSynthesisLoader(Profile* profile)
21 : profile_(profile),
22 pref_change_registrar_(new PrefChangeRegistrar()),
23 weak_ptr_factory_(this) {
24 pref_change_registrar_->Init(profile->GetPrefs());
25 pref_change_registrar_->Add(
26 prefs::kHighQualitySpeechSynthesisLanguages,
27 base::Bind(&SpeechSynthesisLoader::StartLoading,
28 weak_ptr_factory_.GetWeakPtr()));
29
30 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.
31 extension_misc::kHighQuality_en_US_ExtensionId;
32 }
33
34 SpeechSynthesisLoader::~SpeechSynthesisLoader() {
35 }
36
37 void SpeechSynthesisLoader::StartLoading() {
38 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
39
40 prefs_.reset(new base::DictionaryValue());
41
42 PrefService* pref_service = profile_->GetPrefs();
43 const base::ListValue* languages =
44 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
45 for (size_t i = 0; i < languages->GetSize(); ++i) {
46 std::string lang;
47 if (!languages->GetString(i, &lang))
48 continue;
49
50 base::hash_map<std::string, std::string>::iterator iter =
51 lang_to_extension_id_map_.find(lang);
52 if (iter == lang_to_extension_id_map_.end())
53 continue;
54
55 std::string extension_id = iter->second;
56 base::DictionaryValue* extension = new base::DictionaryValue();
57 prefs_->Set(extension_id, extension);
58 extension->SetString(ExternalProviderImpl::kExternalUpdateUrl,
59 extension_urls::GetWebstoreUpdateUrl().spec());
60 base::ListValue* supported_locales = new base::ListValue();
61 supported_locales->AppendString(g_browser_process->GetApplicationLocale());
62 extension->Set(ExternalProviderImpl::kSupportedLocales, supported_locales);
63 extension->SetBoolean(ExternalProviderImpl::kIsFromWebstore, true);
64 }
65
66 LoadFinished();
67 }
68
69 // static
70 void SpeechSynthesisLoader::RegisterProfilePrefs(
71 user_prefs::PrefRegistrySyncable* registry) {
72 registry->RegisterListPref(prefs::kHighQualitySpeechSynthesisLanguages,
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
74 }
75
76 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698