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

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 is_app and test 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
diff --git a/chrome/browser/search/hotword_service.cc b/chrome/browser/search/hotword_service.cc
index b9f4bfd7d7452beab3561f312bb697f9998091c5..b3d5cd381a39779d40c54b658dab0f8bfba1aa3d 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)
+ return extension_system->extension_service();
+ return NULL;
+}
+
} // 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(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() {
@@ -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,36 @@ 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::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