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

Side by Side Diff: chrome/browser/extensions/external_component_loader.cc

Issue 149233004: Revert "Automatically trigger installation of high-quality speech synthesis extension." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Don't remove WillSpeakUtteranceWithVoice, it is dependent upon by a test now. Created 6 years, 10 months 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/external_component_loader.h" 5 #include "chrome/browser/extensions/external_component_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_change_registrar.h" 8 #include "base/prefs/pref_change_registrar.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" 11 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/external_provider_impl.h" 13 #include "chrome/browser/extensions/external_provider_impl.h"
14 #include "chrome/browser/search/hotword_service_factory.h" 14 #include "chrome/browser/search/hotword_service_factory.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "components/user_prefs/pref_registry_syncable.h" 18 #include "components/user_prefs/pref_registry_syncable.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 20
21 namespace extensions { 21 namespace extensions {
22 22
23 #if defined(OS_CHROMEOS)
24 namespace {
25 // Table mapping language codes to the extension ids of high-quality
26 // speech synthesis extensions. See the comment in StartLoading() for more.
27 struct LangToExtensionId {
28 const char* lang;
29 const char* extension_id;
30 };
31 LangToExtensionId kLangToExtensionIdTable[] = {
32 { "en-US", extension_misc::kHighQuality_en_US_ExtensionId }
33 };
34 } // anonymous namespace
35 #endif // defined(OS_CHROMEOS)
36
37 ExternalComponentLoader::ExternalComponentLoader(Profile* profile) 23 ExternalComponentLoader::ExternalComponentLoader(Profile* profile)
38 : profile_(profile) { 24 : profile_(profile) {
39 #if defined(OS_CHROMEOS)
40 pref_change_registrar_.reset(new PrefChangeRegistrar());
41 pref_change_registrar_->Init(profile->GetPrefs());
42 pref_change_registrar_->Add(
43 prefs::kHighQualitySpeechSynthesisLanguages,
44 base::Bind(&ExternalComponentLoader::StartLoading, AsWeakPtr()));
45
46 for (size_t i = 0; i < arraysize(kLangToExtensionIdTable); ++i) {
47 lang_to_extension_id_map_[kLangToExtensionIdTable[i].lang] =
48 kLangToExtensionIdTable[i].extension_id;
49 }
50 #endif
51 } 25 }
52 26
53 ExternalComponentLoader::~ExternalComponentLoader() {} 27 ExternalComponentLoader::~ExternalComponentLoader() {}
54 28
55 void ExternalComponentLoader::StartLoading() { 29 void ExternalComponentLoader::StartLoading() {
56 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
57 prefs_.reset(new base::DictionaryValue()); 30 prefs_.reset(new base::DictionaryValue());
58 std::string appId = extension_misc::kInAppPaymentsSupportAppId; 31 std::string appId = extension_misc::kInAppPaymentsSupportAppId;
59 prefs_->SetString(appId + ".external_update_url", 32 prefs_->SetString(appId + ".external_update_url",
60 extension_urls::GetWebstoreUpdateUrl().spec()); 33 extension_urls::GetWebstoreUpdateUrl().spec());
61 34
62 if (HotwordServiceFactory::IsHotwordAllowed(profile_)) { 35 if (HotwordServiceFactory::IsHotwordAllowed(profile_)) {
63 std::string hotwordId = extension_misc::kHotwordExtensionId; 36 std::string hotwordId = extension_misc::kHotwordExtensionId;
64 prefs_->SetString(hotwordId + ".external_update_url", 37 prefs_->SetString(hotwordId + ".external_update_url",
65 extension_urls::GetWebstoreUpdateUrl().spec()); 38 extension_urls::GetWebstoreUpdateUrl().spec());
66 } 39 }
67 40
68 if (CommandLine::ForCurrentProcess()-> 41 if (CommandLine::ForCurrentProcess()->
69 GetSwitchValueASCII(switches::kEnableEnhancedBookmarks) != "0") { 42 GetSwitchValueASCII(switches::kEnableEnhancedBookmarks) != "0") {
70 std::string ext_id = GetEnhancedBookmarksExtensionId(); 43 std::string ext_id = GetEnhancedBookmarksExtensionId();
71 if (!ext_id.empty()) { 44 if (!ext_id.empty()) {
72 prefs_->SetString(ext_id + ".external_update_url", 45 prefs_->SetString(ext_id + ".external_update_url",
73 extension_urls::GetWebstoreUpdateUrl().spec()); 46 extension_urls::GetWebstoreUpdateUrl().spec());
74 } 47 }
75 } 48 }
76
77 #if defined(OS_CHROMEOS)
78 // Chrome OS comes with medium-quality speech synthesis extensions built-in.
79 // When the user speaks a certain threshold of utterances in the same
80 // session, we set a preference indicating that high quality speech is
81 // enabled for that language. Here, we check the preference and prepare
82 // the list of external extensions to be installed based on that.
83 PrefService* pref_service = profile_->GetPrefs();
84 const base::ListValue* languages =
85 pref_service->GetList(prefs::kHighQualitySpeechSynthesisLanguages);
86 for (size_t i = 0; i < languages->GetSize(); ++i) {
87 std::string lang;
88 if (!languages->GetString(i, &lang))
89 continue;
90
91 base::hash_map<std::string, std::string>::iterator iter =
92 lang_to_extension_id_map_.find(lang);
93 if (iter == lang_to_extension_id_map_.end())
94 continue;
95
96 std::string extension_id = iter->second;
97 base::DictionaryValue* extension = new base::DictionaryValue();
98 prefs_->Set(extension_id, extension);
99 extension->SetString(ExternalProviderImpl::kExternalUpdateUrl,
100 extension_urls::GetWebstoreUpdateUrl().spec());
101 base::ListValue* supported_locales = new base::ListValue();
102 supported_locales->AppendString(g_browser_process->GetApplicationLocale());
103 extension->Set(ExternalProviderImpl::kSupportedLocales, supported_locales);
104 extension->SetBoolean(ExternalProviderImpl::kIsFromWebstore, true);
105 }
106 #endif // defined(OS_CHROMEOS)
107
108 LoadFinished(); 49 LoadFinished();
109 } 50 }
110 51
111 // static
112 void ExternalComponentLoader::RegisterProfilePrefs(
113 user_prefs::PrefRegistrySyncable* registry) {
114 #if defined(OS_CHROMEOS)
115 registry->RegisterListPref(prefs::kHighQualitySpeechSynthesisLanguages,
116 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
117 #endif
118 }
119
120 } // namespace extensions 52 } // namespace extensions
OLDNEW
« 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