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

Unified Diff: chrome/browser/search/hotword_service.cc

Issue 210473002: Merge 258106 "[Hotword] Making enabling/disabling the setting en..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1847/src/
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/browser/search/hotword_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/hotword_service.cc
===================================================================
--- chrome/browser/search/hotword_service.cc (revision 259015)
+++ chrome/browser/search/hotword_service.cc (working copy)
@@ -60,6 +60,16 @@
NUM_HOTWORD_EXTENSION_AVAILABILITY_METRICS);
}
+ExtensionService* GetExtensionService(Profile* profile) {
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::Get(profile);
+ if (extension_system)
+ return extension_system->extension_service();
+ return NULL;
+}
+
} // namespace
namespace hotword_internal {
@@ -93,9 +103,19 @@
enabled_state = ENABLED;
else
enabled_state = DISABLED;
+ } else {
+ // If the preference has not been set the hotword extension should
+ // not be running.
+ DisableHotwordExtension(GetExtensionService(profile_));
}
UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state,
NUM_HOTWORD_ENABLED_METRICS);
+
+ pref_registrar_.Init(profile_->GetPrefs());
+ pref_registrar_.Add(
+ prefs::kHotwordSearchEnabled,
+ base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
+ base::Unretained(this)));
}
HotwordService::~HotwordService() {
@@ -130,10 +150,10 @@
extensions::ExtensionSystem* system =
extensions::ExtensionSystem::Get(profile_);
ExtensionService* service = system->extension_service();
- // Do not include disabled extension (false parameter) because if the
- // extension is disabled, it's not available.
+ // Include disabled extensions (true parameter) since it may not be enabled
+ // if the user opted out.
const extensions::Extension* extension =
- service->GetExtensionById(extension_misc::kHotwordExtensionId, false);
+ service->GetExtensionById(extension_misc::kHotwordExtensionId, true);
RecordAvailabilityMetrics(service, extension);
@@ -147,3 +167,38 @@
group != hotword_internal::kHotwordFieldTrialDisabledGroupName &&
DoesHotwordSupportLanguage(profile_);
}
+
+bool HotwordService::RetryHotwordExtension() {
+ ExtensionService* extension_service = GetExtensionService(profile_);
+ if (!extension_service)
+ return false;
+
+ extension_service->ReloadExtension(extension_misc::kHotwordExtensionId);
+ return true;
+}
+
+void HotwordService::EnableHotwordExtension(
+ ExtensionService* extension_service) {
+ if (extension_service)
+ extension_service->EnableExtension(extension_misc::kHotwordExtensionId);
+}
+
+void HotwordService::DisableHotwordExtension(
+ ExtensionService* extension_service) {
+ if (extension_service) {
+ extension_service->DisableExtension(
+ extension_misc::kHotwordExtensionId,
+ extensions::Extension::DISABLE_USER_ACTION);
+ }
+}
+
+void HotwordService::OnHotwordSearchEnabledChanged(
+ const std::string& pref_name) {
+ DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
+
+ ExtensionService* extension_service = GetExtensionService(profile_);
+ if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
+ EnableHotwordExtension(extension_service);
+ else
+ DisableHotwordExtension(extension_service);
+}
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/browser/search/hotword_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698