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

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: update comment 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
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..c36c655422e4fc13751cd25c7eb918fbfd736186 100644
--- a/chrome/browser/search/hotword_service.cc
+++ b/chrome/browser/search/hotword_service.cc
@@ -8,12 +8,15 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
+#include "base/threading/worker_pool.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "ui/base/l10n/l10n_util.h"
@@ -94,9 +97,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 +144,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);
@@ -161,3 +174,39 @@ bool HotwordService::RetryHotwordExtension() {
extension_service->ReloadExtension(extension_misc::kHotwordExtensionId);
return true;
}
+
+void HotwordService::DisableHotwordExtension() {
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::Get(profile_);
+ if (!extension_system || !extension_system->extension_service())
+ return;
+ ExtensionService* extension_service = extension_system->extension_service();
+
+ extension_service->DisableExtension(
+ extension_misc::kHotwordExtensionId,
+ extensions::Extension::DISABLE_USER_ACTION);
miket_OOO 2014/03/12 21:54:46 I agree this isn't sufficiently distinct from a ty
+}
+
+void HotwordService::EnableHotwordExtension() {
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::Get(profile_);
+ if (!extension_system || !extension_system->extension_service())
+ return;
+ ExtensionService* extension_service = extension_system->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();
miket_OOO 2014/03/12 21:54:46 It would be way cooler to refactor the work to gra
rpetterson 2014/03/12 23:27:32 Done. But factored into a separate method since Di
+ else
+ DisableHotwordExtension();
+}

Powered by Google App Engine
This is Rietveld 408576698