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

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

Issue 196753002: [Hotword] Making enabling/disabling the setting enable/disable the hotword extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unneeded includes 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') | extensions/browser/admin_policy.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
diff --git a/chrome/browser/search/hotword_service.cc b/chrome/browser/search/hotword_service.cc
index b9f4bfd7d7452beab3561f312bb697f9998091c5..1ab57dcbf36593a176d8a0c5a09053e75253ff85 100644
--- a/chrome/browser/search/hotword_service.cc
+++ b/chrome/browser/search/hotword_service.cc
@@ -61,6 +61,16 @@ void RecordAvailabilityMetrics(
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 || !extension_system->extension_service())
Jered 2014/03/12 23:30:49 nit: simpler if written if (extension_system) re
rpetterson 2014/03/12 23:34:29 Done.
+ return NULL;
+ return extension_system->extension_service();
+}
+
} // namespace
namespace hotword_internal {
@@ -94,9 +104,19 @@ HotwordService::HotwordService(Profile* profile)
enabled_state = ENABLED;
else
enabled_state = DISABLED;
+ } else {
+ // If the preference has not been set the hotword extension should
+ // not be running.
+ DisableHotwordExtension();
}
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() {
@@ -131,10 +151,10 @@ bool HotwordService::IsServiceAvailable() {
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);
@@ -150,14 +170,34 @@ bool HotwordService::IsHotwordAllowed() {
}
bool HotwordService::RetryHotwordExtension() {
- CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
- extensions::ExtensionSystem* extension_system =
- extensions::ExtensionSystem::Get(profile_);
- if (!extension_system || !extension_system->extension_service())
+ ExtensionService* extension_service = GetExtensionService(profile_);
+ if (!extension_service)
return false;
- ExtensionService* extension_service = extension_system->extension_service();
extension_service->ReloadExtension(extension_misc::kHotwordExtensionId);
return true;
}
+
+void HotwordService::DisableHotwordExtension() {
+ ExtensionService* extension_service = GetExtensionService(profile_);
+ if (extension_service)
Jered 2014/03/12 23:30:49 nit: prefer if wrapped lines go in {} but up to yo
rpetterson 2014/03/12 23:34:29 I agree. I just missed that when doing the refacto
+ extension_service->DisableExtension(
+ extension_misc::kHotwordExtensionId,
+ extensions::Extension::DISABLE_USER_ACTION);
+}
+
+void HotwordService::EnableHotwordExtension() {
+ ExtensionService* extension_service = GetExtensionService(profile_);
+ if (extension_service)
+ extension_service->EnableExtension(extension_misc::kHotwordExtensionId);
+}
+
+void HotwordService::OnHotwordSearchEnabledChanged(
+ const std::string& pref_name) {
+ DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
+
+ if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
+ EnableHotwordExtension();
+ else
+ DisableHotwordExtension();
+}
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | extensions/browser/admin_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698